StartWindow.dart 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'OpenRoom.dart'; //创建房间
  4. import 'dart:async';
  5. import '../styles/colors.dart';
  6. class StartWindow extends StatefulWidget {
  7. @override
  8. StartWindowState createState() => StartWindowState();
  9. }
  10. class StartWindowState extends State<StartWindow> with SingleTickerProviderStateMixin {
  11. int _num = 10;
  12. bool isNext = true;
  13. Timer timer;
  14. AnimationController animationController;
  15. @override
  16. void initState() {
  17. super.initState();
  18. animationController = AnimationController(
  19. vsync: this,
  20. duration: Duration(seconds: 10),
  21. );
  22. animationController.repeat();
  23. timer = Timer.periodic(Duration(seconds: 1), (timer) {
  24. if (_num == 0) {
  25. Navigator.of(context).pop(false);
  26. timer.cancel();
  27. } else {
  28. setState(() {
  29. _num--;
  30. });
  31. }
  32. });
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. return GestureDetector(
  37. // onTap: () {
  38. // Navigator.of(context).pop();
  39. // },
  40. child: WillPopScope(
  41. child: Scaffold(
  42. backgroundColor: Color(0xCC000000),
  43. body: Container(
  44. child: Center(
  45. child: Container(
  46. padding: EdgeInsets.only(top: 28, bottom: 30),
  47. width: 270,
  48. height: 334,
  49. decoration: BoxDecoration(
  50. color: Color(0xE6293559),
  51. border: Border.all(width: 1, color: PRIMARY_COLOR),
  52. image: DecorationImage(image: AssetImage('images/img_guangmang.png'), fit: BoxFit.contain),
  53. ),
  54. child: Stack(
  55. children: <Widget>[
  56. Align(
  57. alignment: Alignment.topCenter,
  58. child: Text(
  59. '点击确认开始游戏',
  60. style: TextStyle(
  61. color: PRIMARY_COLOR,
  62. fontSize: 20,
  63. fontWeight: FontWeight.bold,
  64. ),
  65. ),
  66. ),
  67. _centerContent(),
  68. Align(
  69. alignment: Alignment.bottomCenter,
  70. child: Container(
  71. padding: EdgeInsets.fromLTRB(25, 0, 25, 0),
  72. width: double.infinity,
  73. child: MaterialButton(
  74. highlightElevation: 0,
  75. height: 36,
  76. color: PRIMARY_COLOR,
  77. child: Text(
  78. '确认',
  79. style: TextStyle(
  80. fontSize: 14,
  81. fontWeight: FontWeight.bold,
  82. color: Colors.white,
  83. ),
  84. ),
  85. onPressed: () {
  86. timer.cancel();
  87. Navigator.of(context).pop(true);
  88. },
  89. ),
  90. ),
  91. ),
  92. ],
  93. ),
  94. ),
  95. ),
  96. ),
  97. ),
  98. onWillPop: () {
  99. return Future.value(false);
  100. },
  101. ),
  102. );
  103. }
  104. Widget _centerContent() {
  105. return Stack(
  106. children: <Widget>[
  107. Center(
  108. child: Container(
  109. width: 128,
  110. height: 128,
  111. decoration: BoxDecoration(
  112. borderRadius: BorderRadius.all(Radius.circular(100)),
  113. color: PRIMARY_COLOR,
  114. boxShadow: [
  115. BoxShadow(
  116. color: Color(0xD41990F8),
  117. offset: Offset.zero,
  118. blurRadius: 17,
  119. ),
  120. ],
  121. ),
  122. ),
  123. ),
  124. Center(
  125. child: Container(
  126. width: 80,
  127. height: 80,
  128. decoration: BoxDecoration(
  129. color: Color(0xFF26D1FB),
  130. borderRadius: BorderRadius.all(Radius.circular(40)),
  131. ),
  132. ),
  133. ),
  134. Center(
  135. child: Container(
  136. width: 64,
  137. height: 64,
  138. decoration: BoxDecoration(
  139. color: Color(0xFF0E88CA),
  140. borderRadius: BorderRadius.all(Radius.circular(32)),
  141. ),
  142. ),
  143. ),
  144. Center(
  145. child: AnimatedBuilder(
  146. animation: animationController,
  147. child: Image.asset('images/spinner.png'),
  148. builder: (context, widget) {
  149. return Transform.rotate(
  150. angle: -animationController.value * 6.3,
  151. child: widget,
  152. );
  153. },
  154. ),
  155. ),
  156. Center(
  157. child: Text(
  158. '$_num',
  159. style: TextStyle(color: Colors.white, fontSize: 34, fontWeight: FontWeight.bold),
  160. ),
  161. ),
  162. ],
  163. );
  164. }
  165. }