root_page.dart 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart';
  2. import 'package:bbyyy/my_tools/event_bus.dart';
  3. import 'package:bbyyy/my_tools/global.dart';
  4. import 'package:bbyyy/my_tools/my_colors.dart';
  5. import 'package:bbyyy/my_tools/my_cookie.dart';
  6. import 'package:bbyyy/my_tools/my_views.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter/services.dart';
  9. import 'home_page.dart';
  10. import 'root_page_view.dart';
  11. class RootPage1 extends StatefulWidget {
  12. @override
  13. _RootPage1State createState() => _RootPage1State();
  14. }
  15. class _RootPage1State extends State<RootPage1> {
  16. PageController pageController = PageController(initialPage: 0);
  17. DateTime lastPopTime;
  18. @override
  19. void initState() {
  20. super.initState();
  21. EventBus().on('toLogin', (arg) {
  22. showDialog(
  23. context: context,
  24. builder: (BuildContext context) {
  25. return Material(
  26. color: Colors.black12,
  27. child: Center(
  28. child: Container(
  29. decoration: BoxDecoration(
  30. borderRadius: BorderRadius.circular(16),
  31. color: Colors.white,
  32. ),
  33. height: 180,
  34. margin: EdgeInsets.symmetric(horizontal: 18),
  35. padding: EdgeInsets.symmetric(horizontal: 8, vertical: 12),
  36. child: Column(
  37. children: [
  38. Expanded(
  39. child: Center(
  40. child: Container(
  41. child: MyViews().myText('完整体验请前往注册登录', MyColors.c333333, 14),
  42. margin: EdgeInsets.symmetric(horizontal: 20),
  43. ),
  44. ),
  45. ),
  46. Container(
  47. height: 0.5,
  48. color: MyColors.cE7E7E7,
  49. margin: EdgeInsets.only(bottom: 12),
  50. ),
  51. Container(
  52. margin: EdgeInsets.symmetric(horizontal: 10),
  53. child: Row(
  54. children: [
  55. Expanded(
  56. child: GestureDetector(
  57. onTap: () {
  58. Navigator.pop(context);
  59. },
  60. behavior: HitTestBehavior.translucent,
  61. child: Container(
  62. decoration: BoxDecoration(
  63. borderRadius: BorderRadius.only(
  64. topLeft: Radius.circular(20),
  65. bottomLeft: Radius.circular(20),
  66. ),
  67. border: Border.all(
  68. color: MyColors.cFF4233, width: 1.1),
  69. color: Colors.white),
  70. child: MyViews().myText('下次再说', MyColors.cFF4233, 14),
  71. height: 40,
  72. alignment: Alignment.center,
  73. ),
  74. ),
  75. ),
  76. Expanded(
  77. child: GestureDetector(
  78. behavior: HitTestBehavior.translucent,
  79. onTap: (){
  80. Navigator.pop(context);
  81. MyCookie().clean();
  82. navigatorKey.currentState.pushNamedAndRemoveUntil('/loginPage', ModalRoute.withName("/loginPage"));
  83. },
  84. child: Container(
  85. decoration: BoxDecoration(
  86. borderRadius: BorderRadius.only(
  87. topRight: Radius.circular(20),
  88. bottomRight: Radius.circular(20),
  89. ),
  90. color: MyColors.cFF4233),
  91. height: 40,
  92. child: MyViews().myText('现在就去', Colors.white, 14),
  93. alignment: Alignment.center,
  94. ),
  95. ),
  96. )
  97. ],
  98. ),
  99. )
  100. ],
  101. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  102. ),
  103. ),
  104. ),
  105. );
  106. },
  107. );
  108. });
  109. }
  110. @override
  111. Widget build(BuildContext context) {
  112. return WillPopScope(
  113. onWillPop: () async {
  114. if (lastPopTime == null ||
  115. DateTime.now().difference(lastPopTime) > Duration(seconds: 2)) {
  116. lastPopTime = DateTime.now();
  117. EasyLoading.showToast('再按一次退出');
  118. } else {
  119. lastPopTime = DateTime.now();
  120. await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
  121. }
  122. return false;
  123. },
  124. child: Scaffold(
  125. backgroundColor: Colors.transparent,
  126. body: Column(
  127. children: [
  128. Expanded(
  129. child: PageView(
  130. controller: pageController,
  131. children: [HomePage1()],
  132. physics: NeverScrollableScrollPhysics(),
  133. ),
  134. ),
  135. RootPageView1().bottomNavigationBar(),
  136. ],
  137. ),
  138. ),
  139. );
  140. }
  141. }