소스 검색

修改启动页,添加引导页

yanyi 3 년 전
부모
커밋
6c3d8e973a
7개의 변경된 파일170개의 추가작업 그리고 36개의 파일을 삭제
  1. BIN
      assets/images/logo.png
  2. 58 0
      lib/Screens/Guide/guide_screen.dart
  3. 0 13
      lib/Screens/Welcome/welcome_screen.dart
  4. 0 18
      lib/components/body.dart
  5. 2 2
      lib/constants.dart
  6. 108 2
      lib/main.dart
  7. 2 1
      pubspec.yaml

BIN
assets/images/logo.png


+ 58 - 0
lib/Screens/Guide/guide_screen.dart

@@ -0,0 +1,58 @@
+import 'package:flutter/material.dart';
+
+class GuideScreen extends StatelessWidget {
+  const GuideScreen({Key? key}) : super(key: key);
+
+  @override
+  Widget build(BuildContext context) {
+    return Guide();
+  }
+}
+
+class Guide extends StatefulWidget {
+  const Guide({Key? key}) : super(key: key);
+
+  @override
+  _GuideScreenState createState() => _GuideScreenState();
+}
+
+class _GuideScreenState extends State<Guide>
+    with SingleTickerProviderStateMixin {
+  late AnimationController _controller;
+
+  @override
+  void initState() {
+    super.initState();
+    _controller = AnimationController(vsync: this);
+  }
+
+  @override
+  void dispose() {
+    super.dispose();
+    _controller.dispose();
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    return Container(
+      child: PageView.builder(
+        itemBuilder: _pageItemBuilder,
+        //当页面选中后回调此方法
+        onPageChanged: (int index) {
+          print("当前页面$index");
+        },
+        //值为flase时 显示第一个页面 然后从左向右开始滑动
+        //值为true时 显示最后一个页面 然后从右向左开始滑动
+        reverse: false,
+        //滑动到页面底部无回弹效果
+        physics: BouncingScrollPhysics(),
+        //横向滑动切换
+        scrollDirection: Axis.horizontal,
+      ),
+    );
+  }
+
+  Widget _pageItemBuilder(BuildContext context, int index) {
+    return Stack();
+  }
+}

+ 0 - 13
lib/Screens/Welcome/welcome_screen.dart

@@ -1,13 +0,0 @@
-import 'package:flutter/material.dart';
-import 'package:flutter_demo/components/body.dart';
-
-class WelcomeScreen extends StatelessWidget {
-  const WelcomeScreen({Key? key}) : super(key: key);
-
-  @override
-  Widget build(BuildContext context) {
-    return Scaffold(
-      body: Body(),
-    );
-  }
-}

+ 0 - 18
lib/components/body.dart

@@ -1,18 +0,0 @@
-import 'package:flutter/material.dart';
-
-class Body extends StatelessWidget {
-  const Body({Key? key}) : super(key: key);
-
-  @override
-  Widget build(BuildContext context) {
-    Size size = MediaQuery.of(context).size;
-    return Container(
-      height: size.height,
-      width: double.infinity,
-      color: Colors.red,
-      child: Stack(
-        children: <Widget>[],
-      ),
-    );
-  }
-}

+ 2 - 2
lib/constants.dart

@@ -1,4 +1,4 @@
 import 'package:flutter/cupertino.dart';
 
-const kPrimaryColor = Color(0xFF6F35A5);
-const kPrimaryLightColor = Color(0xfff1e6ff);
+const kPrimaryColor = Color(0xff23ba9c);
+const kPrimaryLightColor = Color(0xff23ba9c);

+ 108 - 2
lib/main.dart

@@ -1,7 +1,11 @@
+import 'dart:async';
+
 import 'package:flutter/material.dart';
-import 'package:flutter_demo/Screens/Welcome/welcome_screen.dart';
+import 'package:flutter/services.dart';
 import 'package:flutter_demo/constants.dart';
 
+import 'Screens/Guide/guide_screen.dart';
+
 void main() {
   runApp(MyApp());
 }
@@ -9,6 +13,7 @@ void main() {
 class MyApp extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
+    // Size size = MediaQuery.of(context).size;
     return MaterialApp(
       debugShowCheckedModeBanner: false,
       title: 'Flutter Demo',
@@ -16,7 +21,108 @@ class MyApp extends StatelessWidget {
           primaryColor: kPrimaryColor,
           scaffoldBackgroundColor: Colors.white,
           primaryColorLight: kPrimaryLightColor),
-      home: WelcomeScreen(),
+      home: Scaffold(
+        body: SplashScreen(),
+      ),
+    );
+  }
+}
+
+class SplashScreen extends StatefulWidget {
+  const SplashScreen({Key? key}) : super(key: key);
+
+  @override
+  State<SplashScreen> createState() => _SplashScreenState();
+}
+
+class _SplashScreenState extends State<SplashScreen> {
+  int _countdown = 3;
+  Timer? _countdownTimer;
+
+  @override
+  void initState() {
+    super.initState();
+    _startRecordTime();
+  }
+
+  /// 定时自动跳转页面
+  void _startRecordTime() {
+    _countdownTimer = Timer.periodic(Duration(seconds: 1), (timer) {
+      setState(() {
+        if (_countdown <= 1) {
+          Navigator.of(context).pop();
+          Navigator.of(context).push(MaterialPageRoute(builder: (context) {
+            return GuideScreen();
+          }));
+          _countdownTimer?.cancel();
+          _countdownTimer = null;
+        } else {
+          _countdown -= 1;
+        }
+      });
+    });
+  }
+
+  @override
+  void dispose() {
+    super.dispose();
+    if (_countdownTimer != null && _countdownTimer!.isActive) {
+      _countdownTimer!.cancel();
+      _countdownTimer = null;
+    }
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    SystemChrome.setEnabledSystemUIOverlays([]);
+    Size size = MediaQuery.of(context).size;
+    return Container(
+      height: size.height,
+      width: double.infinity,
+      color: Color(0xffc3eff2),
+      constraints: BoxConstraints.expand(),
+      child: Stack(
+        alignment: AlignmentDirectional.bottomCenter,
+        children: <Widget>[
+          Positioned(
+              bottom: 60,
+              child: Row(
+                children: <Widget>[
+                  Image(
+                    image: AssetImage('assets/images/logo.png'),
+                    width: 80,
+                    height: 80,
+                  ),
+                  Padding(
+                    padding: const EdgeInsets.only(left: 25),
+                    child: Column(
+                      crossAxisAlignment: CrossAxisAlignment.start,
+                      children: <Widget>[
+                        Text(
+                          "享有康康",
+                          style: TextStyle(
+                            color: Color(0xff42c293),
+                            fontSize: 24,
+                            fontStyle: FontStyle.italic,
+                            fontWeight: FontWeight.w700,
+                            decoration: TextDecoration.none,
+                          ),
+                        ),
+                        Text(
+                          "为您的家庭保驾护航",
+                          style: TextStyle(
+                              fontWeight: FontWeight.w600,
+                              decoration: TextDecoration.none,
+                              fontSize: 15,
+                              color: Color(0xff6e6e6e)),
+                        )
+                      ],
+                    ),
+                  )
+                ],
+              ))
+        ],
+      ),
     );
   }
 }

+ 2 - 1
pubspec.yaml

@@ -45,7 +45,8 @@ flutter:
   uses-material-design: true
 
   # To add assets to your application, add an assets section, like this:
-  # assets:
+  assets:
+    - assets/images/
   #   - images/a_dot_burr.jpeg
   #   - images/a_dot_ham.jpeg