StartWindow.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'OpenRoom.dart'; //创建房间
  5. class StartWindow extends StatefulWidget {
  6. @override
  7. StartWindowState createState() => StartWindowState();
  8. }
  9. class StartWindowState extends State<StartWindow> {
  10. int _num = 10;
  11. bool isNext = true;
  12. getNum() async {
  13. if (!isNext) {
  14. Navigator.of(context).pop(true);
  15. return;
  16. }
  17. await Future.delayed(const Duration(seconds: 1));
  18. if (_num == 0) {
  19. if (isNext) {
  20. Navigator.of(context).pop(false);
  21. }
  22. return;
  23. }
  24. if (isNext) {
  25. setState(() {
  26. _num--;
  27. });
  28. getNum();
  29. } else {
  30. Navigator.of(context).pop(true);
  31. return;
  32. }
  33. }
  34. @override
  35. void initState() {
  36. super.initState();
  37. Future.delayed(Duration.zero, () {
  38. getNum();
  39. });
  40. }
  41. @override
  42. Widget build(BuildContext context) {
  43. ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context);
  44. return GestureDetector(
  45. // onTap: () {
  46. // Navigator.of(context).pop();
  47. // },
  48. child: WillPopScope(
  49. child: Scaffold(
  50. backgroundColor: Color(0xCC000000),
  51. body: Container(
  52. child: Center(
  53. child: Container(
  54. padding: EdgeInsets.only(top: 29, bottom: 21),
  55. width: ScreenUtil().setWidth(272),
  56. height: ScreenUtil().setWidth(319),
  57. decoration: BoxDecoration(
  58. image: DecorationImage(
  59. image: AssetImage('images/img_kaishiyouxi.png'),
  60. )),
  61. child: Column(
  62. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  63. children: <Widget>[
  64. Text('点击确认开始游戏', style: TextStyle(color: Color(0xFFFDC372), fontSize: 20, fontWeight: FontWeight.w600)),
  65. _centerContent(),
  66. Container(
  67. width: double.infinity,
  68. margin: EdgeInsets.symmetric(horizontal: 42),
  69. height: 44,
  70. child: RaisedButton(
  71. textTheme: ButtonTextTheme.primary,
  72. child: Text('确认'),
  73. onPressed: () {
  74. isNext = false;
  75. },
  76. ),
  77. )
  78. ],
  79. ),
  80. )),
  81. ),
  82. ),
  83. onWillPop: () {
  84. return Future.value(false);
  85. },
  86. ),
  87. );
  88. }
  89. Widget _centerContent() {
  90. return Container(
  91. width: ScreenUtil().setWidth(131),
  92. height: ScreenUtil().setWidth(131),
  93. decoration: BoxDecoration(
  94. borderRadius: BorderRadius.all(Radius.circular(100)),
  95. gradient: LinearGradient(
  96. colors: [Color(0xFFC18C4A), Color(0xFFE2AD5C)],
  97. begin: Alignment.topCenter,
  98. end: Alignment.bottomCenter,
  99. ),
  100. ),
  101. child: Center(
  102. child: Container(
  103. width: ScreenUtil().setWidth(80),
  104. height: ScreenUtil().setWidth(80),
  105. decoration: BoxDecoration(
  106. borderRadius: BorderRadius.all(Radius.circular(100)),
  107. color: Color(0xFFF5C271),
  108. ),
  109. child: Center(
  110. child: Container(
  111. width: ScreenUtil().setWidth(60),
  112. height: ScreenUtil().setWidth(60),
  113. decoration: BoxDecoration(
  114. borderRadius: BorderRadius.all(Radius.circular(100)),
  115. gradient: LinearGradient(
  116. colors: [Color(0xFFDF605C), Color(0xFFB34B48)],
  117. begin: Alignment.topLeft,
  118. end: Alignment.bottomRight,
  119. ),
  120. ),
  121. child: Center(
  122. child: Text(
  123. "$_num",
  124. style: TextStyle(color: Colors.white, fontSize: 32, fontWeight: FontWeight.w600),
  125. ),
  126. ),
  127. ),
  128. ),
  129. ),
  130. ),
  131. );
  132. }
  133. }