import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart'; import 'package:bbyyy/my_tools/event_bus.dart'; import 'package:bbyyy/my_tools/global.dart'; import 'package:bbyyy/my_tools/my_colors.dart'; import 'package:bbyyy/my_tools/my_cookie.dart'; import 'package:bbyyy/my_tools/my_views.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'home_page.dart'; import 'root_page_view.dart'; class RootPage1 extends StatefulWidget { @override _RootPage1State createState() => _RootPage1State(); } class _RootPage1State extends State { PageController pageController = PageController(initialPage: 0); DateTime lastPopTime; @override void initState() { super.initState(); EventBus().on('toLogin', (arg) { showDialog( context: context, builder: (BuildContext context) { return Material( color: Colors.black12, child: Center( child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(16), color: Colors.white, ), height: 180, margin: EdgeInsets.symmetric(horizontal: 18), padding: EdgeInsets.symmetric(horizontal: 8, vertical: 12), child: Column( children: [ Expanded( child: Center( child: Container( child: MyViews().myText('完整体验请前往注册登录', MyColors.c333333, 14), margin: EdgeInsets.symmetric(horizontal: 20), ), ), ), Container( height: 0.5, color: MyColors.cE7E7E7, margin: EdgeInsets.only(bottom: 12), ), Container( margin: EdgeInsets.symmetric(horizontal: 10), child: Row( children: [ Expanded( child: GestureDetector( onTap: () { Navigator.pop(context); }, behavior: HitTestBehavior.translucent, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.only( topLeft: Radius.circular(20), bottomLeft: Radius.circular(20), ), border: Border.all( color: MyColors.cFF4233, width: 1.1), color: Colors.white), child: MyViews().myText('下次再说', MyColors.cFF4233, 14), height: 40, alignment: Alignment.center, ), ), ), Expanded( child: GestureDetector( behavior: HitTestBehavior.translucent, onTap: (){ Navigator.pop(context); MyCookie().clean(); navigatorKey.currentState.pushNamedAndRemoveUntil('/loginPage', ModalRoute.withName("/loginPage")); }, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.only( topRight: Radius.circular(20), bottomRight: Radius.circular(20), ), color: MyColors.cFF4233), height: 40, child: MyViews().myText('现在就去', Colors.white, 14), alignment: Alignment.center, ), ), ) ], ), ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), ), ); }, ); }); } @override Widget build(BuildContext context) { return WillPopScope( onWillPop: () async { if (lastPopTime == null || DateTime.now().difference(lastPopTime) > Duration(seconds: 2)) { lastPopTime = DateTime.now(); EasyLoading.showToast('再按一次退出'); } else { lastPopTime = DateTime.now(); await SystemChannels.platform.invokeMethod('SystemNavigator.pop'); } return false; }, child: Scaffold( backgroundColor: Colors.transparent, body: Column( children: [ Expanded( child: PageView( controller: pageController, children: [HomePage1()], physics: NeverScrollableScrollPhysics(), ), ), RootPageView1().bottomNavigationBar(), ], ), ), ); } }