StartWindow.dart 3.9 KB

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