按下移动后退按钮后,网站应用程序未退出

时间:2020-01-24 22:38:00

标签: android flutter flutter-layout flutter-plugin flutterwebviewplugin

我使该应用程序具有导航栏中的功能。(重新加载WebPage)(返回WebPage)。(浏览的网页的转发。) 我面临的问题是我想退出应用程序,它没有通过移动后退按钮退出。在模拟器应用程序中正在退出,但在实际的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,
                  ),
                ],
              ),
            ),
      },
    );
  }
}

1 个答案:

答案 0 :(得分:0)

完成“颤振清除”命令后,它可以正确退出。