Browse Source

继续完成欢迎页面

liuyuqi-dellpc 2 years ago
parent
commit
386d7403bd

+ 6 - 5
lib/index_page.dart

@@ -28,15 +28,16 @@ class _IndexPageState extends State<IndexPage> {
   @override
   Widget build(BuildContext context) {
     return Scaffold(
-      backgroundColor: Color(0xF1F6F9ff),
+      backgroundColor: const Color(0xF1F6F9ff),
       body: currentPage,
       bottomNavigationBar: BottomNavigationBar(
         type: BottomNavigationBarType.fixed,
-        items: [
-          const BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
-          const BottomNavigationBarItem(
+        currentIndex: navIndex,
+        items: const [
+          BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
+          BottomNavigationBarItem(
               icon: Icon(Icons.art_track), label: "追踪"),
-          const BottomNavigationBarItem(icon: Icon(Icons.person), label: "我的"),
+          BottomNavigationBarItem(icon: Icon(Icons.person), label: "我的"),
         ],
         onTap: (index) {
           setState(() {

+ 11 - 7
lib/main.dart

@@ -1,5 +1,6 @@
 import 'package:flutter/material.dart';
-import 'package:flutter_tracker/index_page.dart';
+import 'package:flutter_screenutil/flutter_screenutil.dart';
+import 'package:flutter_tracker/pages/welcome_page.dart';
 
 void main() {
   runApp(const MyApp());
@@ -11,13 +12,16 @@ class MyApp extends StatelessWidget {
   // This widget is the root of your application.
   @override
   Widget build(BuildContext context) {
-    return MaterialApp(
-      title: '追踪者',
-      theme: ThemeData(
-        primarySwatch: Colors.blue,
+    return ScreenUtilInit(
+      designSize: const Size(750, 1344),
+      builder: () => MaterialApp(
+        title: '追踪者',
+        theme: ThemeData(
+          primarySwatch: Colors.blue,
+        ),
+        debugShowCheckedModeBanner: false,
+        home: const WelComePage(),
       ),
-      debugShowCheckedModeBanner: false,
-      home: const IndexPage(),
     );
   }
 }

+ 13 - 0
lib/model/config.dart

@@ -0,0 +1,13 @@
+import 'package:flutter/material.dart';
+
+class Config {}
+
+class ThemeColor {
+  static const Color appBg = Color(0xfff5f6f7);
+  static const Color appBarTopBg = Color(0xff00C2FD);
+  static const Color appBarBottomBg = Color(0xff00C2FD);
+  static const Color hintTextColor = Color(0xff333333);
+  static const Color subTextColor = Color(0xff999999);
+  static const Color starColor = Color(0xFFFFA516);
+  static const Color loignColor = Color(0xFFFE976A);
+}

+ 1 - 3
lib/pages/home_page.dart

@@ -10,8 +10,6 @@ class HomePage extends StatefulWidget {
 class _HomePageState extends State<HomePage> {
   @override
   Widget build(BuildContext context) {
-    return Container(
-      child: Text('Home'),
-    );
+    return const Center(child: Text('Home'));
   }
 }

+ 82 - 1
lib/pages/login_page.dart

@@ -1,4 +1,5 @@
 import 'package:flutter/material.dart';
+import 'package:shared_preferences/shared_preferences.dart';
 
 class LoginPage extends StatefulWidget {
   const LoginPage({Key key}) : super(key: key);
@@ -8,8 +9,88 @@ class LoginPage extends StatefulWidget {
 }
 
 class _LoginPageState extends State<LoginPage> {
+  final TextEditingController _usernameController = TextEditingController();
+  final TextEditingController _passwordController = TextEditingController();
+  final _formKey = GlobalKey<FormState>();
+
+  String _username;
+  String _password;
+
+  @override
+  void initState() {
+    super.initState();
+    loadData();
+  }
+
   @override
   Widget build(BuildContext context) {
-    return Container();
+    return Scaffold(
+        appBar: AppBar(title: Text('登录')),
+        body: Form(
+          key: _formKey,
+          child: Column(
+            children: <Widget>[
+              TextFormField(
+                controller: _usernameController,
+                decoration: InputDecoration(
+                  labelText: '用户名',
+                  hintText: '请输入用户名',
+                ),
+                validator: (value) {
+                  if (value.isEmpty) {
+                    return '用户名不能为空';
+                  }
+                  return null;
+                },
+                onSaved: (value) {
+                  _username = value;
+                },
+              ),
+              TextFormField(
+                controller: _passwordController,
+                decoration: InputDecoration(
+                  labelText: '密码',
+                  hintText: '请输入密码',
+                ),
+                obscureText: true,
+                validator: (value) {
+                  if (value.isEmpty) {
+                    return '密码不能为空';
+                  }
+                  return null;
+                },
+                onSaved: (value) {
+                  _password = value;
+                },
+              ),
+              RaisedButton(
+                child: Text('登录'),
+                onPressed: () {
+                  login();
+                },
+              ),
+            ],
+          ),
+        ));
+  }
+
+  void loadData() async {
+    SharedPreferences prefs = await SharedPreferences.getInstance();
+    String username = prefs.getString('username');
+    String password = prefs.getString('password');
+    if (username != null && password != null) {
+      _usernameController.text = username;
+      _passwordController.text = password;
+    }
+  }
+
+  void login() async {
+    if (_formKey.currentState.validate()) {
+      _formKey.currentState.save();
+      SharedPreferences prefs = await SharedPreferences.getInstance();
+      prefs.setString('username', _username);
+      prefs.setString('password', _password);
+      Navigator.of(context).pushReplacementNamed('/home');
+    }
   }
 }

+ 1 - 1
lib/pages/mine_page.dart

@@ -11,7 +11,7 @@ class _MinePageState extends State<MinePage> {
   @override
   Widget build(BuildContext context) {
    return Container(
-      child: Text('Mine'),
+      child: Center(child: Text('Mine')),
     );
   }
 }

+ 1 - 1
lib/pages/track_page.dart

@@ -11,7 +11,7 @@ class _TrackPageState extends State<TrackPage> {
   @override
   Widget build(BuildContext context) {
     return Container(
-      child: Text('Track'),
+      child: Center(child: Text('Track')),
     );
   }
 }

+ 99 - 1
lib/pages/welcome_page.dart

@@ -1,4 +1,8 @@
 import 'package:flutter/material.dart';
+import 'package:flutter_tracker/model/config.dart';
+import 'package:flutter_tracker/pages/login_page.dart';
+import 'package:flutter_tracker/pages/register_page.dart';
+import 'package:flutter_tracker/utils/app_util.dart';
 
 class WelComePage extends StatefulWidget {
   const WelComePage({Key key}) : super(key: key);
@@ -10,6 +14,100 @@ class WelComePage extends StatefulWidget {
 class _WelComePageState extends State<WelComePage> {
   @override
   Widget build(BuildContext context) {
-    return Container();
+    return Stack(
+      children: [
+        Container(
+          child: Image.asset(
+            "assets/images/home.jpg",
+            fit: BoxFit.cover,
+            width: double.infinity,
+            height: double.infinity,
+          ),
+        ),
+        Positioned(
+          bottom: 80,
+          child: Container(
+            width: MediaQuery.of(context).size.width,
+            alignment: Alignment.center,
+            child: Row(
+              mainAxisAlignment: MainAxisAlignment.center,
+              children: [
+                Container(
+                  width: 150,
+                  child: InkWell(
+                    onTap: () {
+                      // 登录
+                      Navigator.of(context).push(
+                          MaterialPageRoute(builder: (context) => LoginPage()));
+                    },
+                    child: Container(
+                      width: double.infinity,
+                      height: AppUtil.height(100),
+                      padding: EdgeInsets.only(
+                          right: AppUtil.width(20), left: AppUtil.width(20)),
+                      decoration: BoxDecoration(
+                          gradient: LinearGradient(colors: [
+                            ThemeColor.loignColor,
+                            ThemeColor.loignColor
+                          ]),
+                          borderRadius: BorderRadius.circular(10),
+                          boxShadow: [
+                            BoxShadow(
+                              offset: Offset(1.0, 5.0),
+                              color: ThemeColor.loignColor,
+                              blurRadius: 5.0,
+                            )
+                          ]),
+                      child: Center(
+                        child: Text(
+                          "登录",
+                          style: TextStyle(fontSize: 20, color: Colors.white),
+                        ),
+                      ),
+                    ),
+                  ),
+                ),
+                Container(
+                  width: 150,
+                  child: InkWell(
+                    onTap: () {
+                      //注册
+                      Navigator.of(context).push(MaterialPageRoute(
+                          builder: (context) => RegisterPage()));
+                    },
+                    child: Container(
+                      margin: EdgeInsets.only(left: 20.0),
+                      width: double.infinity,
+                      height: AppUtil.height(100),
+                      padding: EdgeInsets.only(
+                          right: AppUtil.width(20), left: AppUtil.width(20)),
+                      decoration: BoxDecoration(
+                          gradient: LinearGradient(colors: [
+                            ThemeColor.loignColor,
+                            ThemeColor.loignColor
+                          ]),
+                          borderRadius: BorderRadius.circular(10),
+                          boxShadow: [
+                            BoxShadow(
+                              offset: Offset(1.0, 5.0),
+                              color: ThemeColor.loignColor,
+                              blurRadius: 5.0,
+                            )
+                          ]),
+                      child: Center(
+                        child: Text(
+                          "注册",
+                          style: TextStyle(fontSize: 20, color: Colors.white),
+                        ),
+                      ),
+                    ),
+                  ),
+                ),
+              ],
+            ),
+          ),
+        )
+      ],
+    );
   }
 }

+ 28 - 0
lib/routes/routes.dart

@@ -1,3 +1,31 @@
+import 'package:flutter/cupertino.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_tracker/pages/about_page.dart';
+import 'package:flutter_tracker/pages/help_page.dart';
+import 'package:flutter_tracker/pages/home_page.dart';
+import 'package:flutter_tracker/pages/login_page.dart';
+import 'package:flutter_tracker/pages/mine_page.dart';
+import 'package:flutter_tracker/pages/register_page.dart';
+import 'package:flutter_tracker/pages/submit_page.dart';
+import 'package:flutter_tracker/pages/track_page.dart';
+import 'package:flutter_tracker/pages/welcome_page.dart';
+
 class Routes {
+  Map routes = {
+    "/home": (context) => HomePage(),
+    "/track": (context) => TrackPage(),
+    "/mine": (context) => MinePage(),
+    "/about": (context) => AboutPage(),
+    "/help": (context) => HelpPage(),
+    "/login": (context) => LoginPage(),
+    "/register": (context) => RegisterPage(),
+    "/submit": (context) => SubmitPage(),
+    "/welcome": (context) => WelComePage(),
+  };
 
+  Route Function(RouteSettings settings) onGenerateRoute =
+      (RouteSettings settings) {
+    final String name = settings.name;
+    return MaterialPageRoute(builder: (_) => Scaffold());
+  };
 }

+ 15 - 0
lib/utils/app_util.dart

@@ -0,0 +1,15 @@
+import 'package:flutter_screenutil/flutter_screenutil.dart';
+
+class AppUtil {
+  static double height(double value) {
+    return ScreenUtil().setHeight(value);
+  }
+
+  static double width(double value) {
+    return ScreenUtil().setWidth(value);
+  }
+
+  static double sp(double value) {
+    return ScreenUtil().setSp(value);
+  }
+}

+ 7 - 0
pubspec.lock

@@ -90,6 +90,13 @@ packages:
       url: "https://pub.flutter-io.cn"
     source: hosted
     version: "1.0.4"
+  flutter_screenutil:
+    dependency: "direct main"
+    description:
+      name: flutter_screenutil
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "5.0.1"
   flutter_test:
     dependency: "direct dev"
     description: flutter

+ 2 - 0
pubspec.yaml

@@ -22,3 +22,5 @@ dev_dependencies:
 
 flutter:
   uses-material-design: true
+  assets:
+    - assets/images/