main.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_demo/constants.dart';
  5. import 'Screens/Guide/guide_screen.dart';
  6. void main() {
  7. runApp(MyApp());
  8. }
  9. class MyApp extends StatelessWidget {
  10. @override
  11. Widget build(BuildContext context) {
  12. // Size size = MediaQuery.of(context).size;
  13. return MaterialApp(
  14. debugShowCheckedModeBanner: false,
  15. title: 'Flutter Demo',
  16. theme: ThemeData(
  17. primaryColor: kPrimaryColor,
  18. scaffoldBackgroundColor: Colors.white,
  19. primaryColorLight: kPrimaryLightColor),
  20. home: Scaffold(
  21. body: SplashScreen(),
  22. ),
  23. );
  24. }
  25. }
  26. class SplashScreen extends StatefulWidget {
  27. const SplashScreen({Key? key}) : super(key: key);
  28. @override
  29. State<SplashScreen> createState() => _SplashScreenState();
  30. }
  31. class _SplashScreenState extends State<SplashScreen> {
  32. int _countdown = 3;
  33. Timer? _countdownTimer;
  34. @override
  35. void initState() {
  36. super.initState();
  37. _startRecordTime();
  38. }
  39. /// 定时自动跳转页面
  40. void _startRecordTime() {
  41. _countdownTimer = Timer.periodic(Duration(seconds: 1), (timer) {
  42. setState(() {
  43. if (_countdown <= 1) {
  44. Navigator.of(context).pop();
  45. Navigator.of(context).push(MaterialPageRoute(builder: (context) {
  46. return GuideScreen();
  47. }));
  48. _countdownTimer?.cancel();
  49. _countdownTimer = null;
  50. } else {
  51. _countdown -= 1;
  52. }
  53. });
  54. });
  55. }
  56. @override
  57. void dispose() {
  58. super.dispose();
  59. if (_countdownTimer != null && _countdownTimer!.isActive) {
  60. _countdownTimer!.cancel();
  61. _countdownTimer = null;
  62. }
  63. }
  64. @override
  65. Widget build(BuildContext context) {
  66. SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]); //隐藏顶部状态栏
  67. Size size = MediaQuery.of(context).size;
  68. final EdgeInsets padding = MediaQuery.of(context).padding;
  69. return Container(
  70. height: size.height,
  71. width: double.infinity,
  72. padding: EdgeInsets.fromLTRB(0, padding.top, 0, padding.bottom),
  73. color: Color(0xffc3eff2),
  74. constraints: BoxConstraints.expand(),
  75. child: Stack(
  76. alignment: AlignmentDirectional.bottomCenter,
  77. children: <Widget>[
  78. Positioned(
  79. bottom: 60,
  80. child: Row(
  81. children: <Widget>[
  82. Image(
  83. image: AssetImage('assets/images/logo.png'),
  84. width: 80,
  85. height: 80,
  86. ),
  87. Padding(
  88. padding: const EdgeInsets.only(left: 25),
  89. child: Column(
  90. crossAxisAlignment: CrossAxisAlignment.start,
  91. children: <Widget>[
  92. Text(
  93. "享有康康",
  94. style: TextStyle(
  95. color: Color(0xff42c293),
  96. fontSize: 24,
  97. fontStyle: FontStyle.italic,
  98. fontWeight: FontWeight.w700,
  99. decoration: TextDecoration.none,
  100. ),
  101. ),
  102. Text(
  103. "为您的家庭保驾护航",
  104. style: TextStyle(
  105. fontWeight: FontWeight.w600,
  106. decoration: TextDecoration.none,
  107. fontSize: 15,
  108. color: Color(0xff6e6e6e)),
  109. )
  110. ],
  111. ),
  112. )
  113. ],
  114. ))
  115. ],
  116. ),
  117. );
  118. }
  119. }