main.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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([]);
  67. Size size = MediaQuery.of(context).size;
  68. return Container(
  69. height: size.height,
  70. width: double.infinity,
  71. color: Color(0xffc3eff2),
  72. constraints: BoxConstraints.expand(),
  73. child: Stack(
  74. alignment: AlignmentDirectional.bottomCenter,
  75. children: <Widget>[
  76. Positioned(
  77. bottom: 60,
  78. child: Row(
  79. children: <Widget>[
  80. Image(
  81. image: AssetImage('assets/images/logo.png'),
  82. width: 80,
  83. height: 80,
  84. ),
  85. Padding(
  86. padding: const EdgeInsets.only(left: 25),
  87. child: Column(
  88. crossAxisAlignment: CrossAxisAlignment.start,
  89. children: <Widget>[
  90. Text(
  91. "享有康康",
  92. style: TextStyle(
  93. color: Color(0xff42c293),
  94. fontSize: 24,
  95. fontStyle: FontStyle.italic,
  96. fontWeight: FontWeight.w700,
  97. decoration: TextDecoration.none,
  98. ),
  99. ),
  100. Text(
  101. "为您的家庭保驾护航",
  102. style: TextStyle(
  103. fontWeight: FontWeight.w600,
  104. decoration: TextDecoration.none,
  105. fontSize: 15,
  106. color: Color(0xff6e6e6e)),
  107. )
  108. ],
  109. ),
  110. )
  111. ],
  112. ))
  113. ],
  114. ),
  115. );
  116. }
  117. }