簡體   English   中英

在顫動中按下移動后退按鈕后,網站應用程序未退出

[英]Website App is not Exiting after pressing mobile back button in flutter

我使應用程序在導航欄中具有功能。(重新加載網頁)(返回網頁)。(瀏覽網頁的前進。)我面臨的問題我想退出應用程序,它不是通過移動后退按鈕退出。在模擬器中應用程序正在退出,但在實際的 android 設備中它沒有退出。 我如何退出應用程序。 我是新手,所以不知道怎么做。

代碼:main.dart

import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
main()=>runApp(MyApp());
class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
   int currentTab = 1;
   void splitScreen(int i) {
    switch (i) {
      case 0:
        FlutterWebviewPlugin().close();
        break;
      case 1:
        FlutterWebviewPlugin().reload();
        break;
      case 2:
        FlutterWebviewPlugin().goForward();
        break;
    }
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter WebView Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      routes: {
        "/": (_) => new WebviewScaffold(
              url: "https://www.lucrurile-care-conteaza-cel-mai-mult.ro/",
              // appBar: new AppBar(
              //   title: new Text("Widget webview"),

              // ),
              withZoom: true,
              withLocalStorage: true,
              hidden: true,
              initialChild: Center(
                child: Container(
                  height: 210,
                  width: 200,
                  decoration: BoxDecoration(
                    // shape: BoxShape.circle,
                    // boxShadow: [
                    //   BoxShadow(
                    //       color: Colors.black87,
                    //       blurRadius: 10.0,
                    //       spreadRadius: 0.5,
                    //       offset: Offset.fromDirection(10)),
                    // ],
                    image: DecorationImage(
                        image: AssetImage(
                          'images/3f2c979b214d06e9caab8ba8326864f3.gif',
                        ),
                        fit: BoxFit.cover),
                  ),
                ),
              ),
              bottomNavigationBar: BottomNavigationBar(
                currentIndex: currentTab,
                onTap: (i) {
                  splitScreen(i);
                  setState(() {
                    currentTab = i;
                  });

    },
                items: [
                  BottomNavigationBarItem(
                    icon: Icon(Icons.arrow_back_ios),
                    title: Text('Back'),
                    backgroundColor: Colors.blue,
                  ),
                   BottomNavigationBarItem(
                    icon: Icon(Icons.refresh),
                    title: Text('Refresh'),
                    backgroundColor: Colors.blue,
                  ), BottomNavigationBarItem(
                    icon: Icon(Icons.arrow_forward_ios),
                    title: Text('Forward'),
                    backgroundColor: Colors.blue,
                  ),
                ],
              ),
            ),
      },
    );
  }
}

完成 flutter clean 命令后,它會正確退出。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM