root_page.dart 5.5 KB

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