import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'OpenRoom.dart'; //创建房间 import 'dart:async'; class StartWindow extends StatefulWidget { @override StartWindowState createState() => StartWindowState(); } class StartWindowState extends State { int _num = 10; bool isNext = true; Timer timer; @override void initState() { super.initState(); timer=Timer.periodic(Duration(seconds: 1), (timer){ if(_num==0){ Navigator.of(context).pop(false); timer.cancel(); } else { setState(() { _num--; }); } }); } @override Widget build(BuildContext context) { ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context); return GestureDetector( // onTap: () { // Navigator.of(context).pop(); // }, child: WillPopScope( child: Scaffold( backgroundColor: Color(0xCC000000), body: Container( child: Center( child: Container( padding: EdgeInsets.only(top: 29, bottom: 21), width: ScreenUtil().setWidth(272), height: ScreenUtil().setWidth(319), decoration: BoxDecoration( image: DecorationImage( image: AssetImage('images/img_kaishiyouxi.png'), )), child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text('点击确认开始游戏', style: TextStyle(color: Color(0xFFFDC372), fontSize: 20, fontWeight: FontWeight.w600)), _centerContent(), Container( width: double.infinity, margin: EdgeInsets.symmetric(horizontal: 42), height: 44, child: RaisedButton( textTheme: ButtonTextTheme.primary, child: Text('确认'), onPressed: () { timer.cancel(); Navigator.of(context).pop(true); }, ), ) ], ), )), ), ), onWillPop: () { return Future.value(false); }, ), ); } Widget _centerContent() { return Container( width: ScreenUtil().setWidth(131), height: ScreenUtil().setWidth(131), decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(100)), gradient: LinearGradient( colors: [Color(0xFFC18C4A), Color(0xFFE2AD5C)], begin: Alignment.topCenter, end: Alignment.bottomCenter, ), ), child: Center( child: Container( width: ScreenUtil().setWidth(80), height: ScreenUtil().setWidth(80), decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(100)), color: Color(0xFFF5C271), ), child: Center( child: Container( width: ScreenUtil().setWidth(60), height: ScreenUtil().setWidth(60), decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(100)), gradient: LinearGradient( colors: [Color(0xFFDF605C), Color(0xFFB34B48)], begin: Alignment.topLeft, end: Alignment.bottomRight, ), ), child: Center( child: Text( '$_num', style: TextStyle(color: Colors.white, fontSize: 32, fontWeight: FontWeight.w600), ), ), ), ), ), ), ); } }