Browse Source

完成基本框架

liuyuqi-dellpc 2 years ago
parent
commit
ab99f44d2d

+ 4 - 0
lib/dio/api.dart

@@ -2,4 +2,8 @@ class Api {
   static const String _host = "http://flutter.yoqi.me/API/flutter_tracker";
   static String login = _host + "/login";
   static String logout = _host + "/logout";
+  static String register = _host + "/register";
+  static String getUserInfo = _host + "/getUserInfo";
+  static String uploadImg = _host + "/uploadImg";
+  static String uploadTrack = _host + "/uploadTrack";
 }

+ 14 - 1
lib/dio/login_dao.dart

@@ -16,4 +16,17 @@ class LoginDao {
     Response response = await Dio().get(Api.logout);
     return true;
   }
-}
+
+  static Future<UserModel> register(String username, String password) async {
+    params.addAll({"username": username, "password": password});
+    Response response = await Dio().post(Api.register, queryParameters: params);
+    return UserModel.fromJson(response.data);
+  }
+
+  static Future<UserModel> getUserInfo(String token) async {
+    params.addAll({"token": token});
+    Response response =
+        await Dio().get(Api.getUserInfo, queryParameters: params);
+    return UserModel.fromJson(response.data);
+  }
+}

+ 32 - 0
lib/dio/track_dao.dart

@@ -0,0 +1,32 @@
+import 'package:dio/dio.dart';
+import 'package:flutter_tracker/dio/api.dart';
+import 'package:flutter_tracker/model/submit_model.dart';
+
+class TrackDao {
+  Map<String, dynamic> params = <String, dynamic>{};
+
+  Future<SubmitModel> uploadImg(
+      String token, String filePath, String fileName) async {
+    params.addAll({"token": token, "filePath": filePath, "fileName": fileName});
+
+    await Dio().post(Api.uploadImg, queryParameters: params).then((response) {
+      return SubmitModel.fromJson(response.data);
+    });
+    return null;
+  }
+
+  Future<SubmitModel> uploadTrack(
+      String token, String telphone, String address, String health) async {
+    params.addAll({
+      "token": token,
+      "telphone": telphone,
+      "address": address,
+      "health": health
+    });
+
+    await Dio().post(Api.uploadTrack, queryParameters: params).then((response) {
+      return SubmitModel.fromJson(response.data);
+    });
+    return null;
+  }
+}

+ 31 - 32
lib/index_page.dart

@@ -1,6 +1,7 @@
 import 'package:flutter/material.dart';
 import 'package:flutter_tracker/pages/home_page.dart';
 import 'package:flutter_tracker/pages/mine_page.dart';
+import 'package:flutter_tracker/pages/track_page.dart';
 
 class IndexPage extends StatefulWidget {
   const IndexPage({Key key}) : super(key: key);
@@ -11,41 +12,39 @@ class IndexPage extends StatefulWidget {
 
 class _IndexPageState extends State<IndexPage> {
   int navIndex = 0;
+  List<Widget> pages = [
+    const HomePage(),
+    const TrackPage(),
+    const MinePage(),
+  ];
+  Widget currentPage;
+
+  @override
+  void initState() {
+    super.initState();
+    currentPage = pages[navIndex];
+  }
 
   @override
   Widget build(BuildContext context) {
     return Scaffold(
-        backgroundColor: Color(0xF1F6F9ff),
-        body: Column(
-          children: [
-            TopMenu(),
-            Expanded(
-                child: Row(children: [
-              Expanded(
-                child: LeftMenu(navIndex, (int index) {
-                  setState(() {
-                    navIndex = index;
-                  });
-                }),
-                flex: 1,
-              ),
-              Expanded(
-                child: Builder(
-                  builder: (context) {
-                    switch (navIndex) {
-                      case 0:
-                        return HomePage();
-                      case 1:
-                        return MinePage();
-                      default:
-                        return HomePage();
-                    }
-                  },
-                ),
-                flex: 11,
-              )
-            ]))
-          ],
-        ));
+      backgroundColor: Color(0xF1F6F9ff),
+      body: currentPage,
+      bottomNavigationBar: BottomNavigationBar(
+        type: BottomNavigationBarType.fixed,
+        items: [
+          const BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
+          const BottomNavigationBarItem(
+              icon: Icon(Icons.art_track), label: "追踪"),
+          const BottomNavigationBarItem(icon: Icon(Icons.person), label: "我的"),
+        ],
+        onTap: (index) {
+          setState(() {
+            navIndex = index;
+            currentPage = pages[navIndex];
+          });
+        },
+      ),
+    );
   }
 }

+ 2 - 2
lib/main.dart

@@ -1,5 +1,5 @@
 import 'package:flutter/material.dart';
-import 'package:flutter_tracker/pages/home_page.dart';
+import 'package:flutter_tracker/index_page.dart';
 
 void main() {
   runApp(const MyApp());
@@ -17,7 +17,7 @@ class MyApp extends StatelessWidget {
         primarySwatch: Colors.blue,
       ),
       debugShowCheckedModeBanner: false,
-      home: HomePage(),
+      home: const IndexPage(),
     );
   }
 }

+ 26 - 0
lib/model/submit_model.dart

@@ -0,0 +1,26 @@
+import 'package:flutter_tracker/utils/time_util.dart';
+
+class SubmitModel {
+  int userid;
+  DateTime time;
+  String address;
+  String telphone;
+  int health;
+  String pic;
+
+  SubmitModel(
+      {this.userid,
+      this.time,
+      this.address,
+      this.telphone,
+      this.health,
+      this.pic});
+
+  SubmitModel.fromJson(Map<String, dynamic> json) {
+    userid = int.parse(json['userid']);
+    time = TimeUtil.getDateTime(json['time']);
+    address = json['address'];
+    telphone = json['telphone'];
+    health = json['health'];
+  }
+}

+ 15 - 0
lib/pages/about_page.dart

@@ -0,0 +1,15 @@
+import 'package:flutter/material.dart';
+
+class AboutPage extends StatefulWidget {
+  const AboutPage({Key key}) : super(key: key);
+
+  @override
+  _AboutPageState createState() => _AboutPageState();
+}
+
+class _AboutPageState extends State<AboutPage> {
+  @override
+  Widget build(BuildContext context) {
+    return Container();
+  }
+}

+ 15 - 0
lib/pages/help_page.dart

@@ -0,0 +1,15 @@
+import 'package:flutter/material.dart';
+
+class HelpPage extends StatefulWidget {
+  const HelpPage({Key key}) : super(key: key);
+
+  @override
+  _HelpPageState createState() => _HelpPageState();
+}
+
+class _HelpPageState extends State<HelpPage> {
+  @override
+  Widget build(BuildContext context) {
+    return Container();
+  }
+}

+ 3 - 1
lib/pages/home_page.dart

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

+ 3 - 1
lib/pages/mine_page.dart

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

+ 15 - 0
lib/pages/settings_page.dart

@@ -0,0 +1,15 @@
+import 'package:flutter/material.dart';
+
+class SettingsPage extends StatefulWidget {
+  const SettingsPage({Key key}) : super(key: key);
+
+  @override
+  _SettingsPageState createState() => _SettingsPageState();
+}
+
+class _SettingsPageState extends State<SettingsPage> {
+  @override
+  Widget build(BuildContext context) {
+    return Container();
+  }
+}

+ 15 - 0
lib/pages/submit_page.dart

@@ -0,0 +1,15 @@
+import 'package:flutter/material.dart';
+
+class SubmitPage extends StatefulWidget {
+  const SubmitPage({Key key}) : super(key: key);
+
+  @override
+  _SubmitPageState createState() => _SubmitPageState();
+}
+
+class _SubmitPageState extends State<SubmitPage> {
+  @override
+  Widget build(BuildContext context) {
+    return Container();
+  }
+}

+ 17 - 0
lib/pages/track_page.dart

@@ -0,0 +1,17 @@
+import 'package:flutter/material.dart';
+
+class TrackPage extends StatefulWidget {
+  const TrackPage({Key key}) : super(key: key);
+
+  @override
+  _TrackPageState createState() => _TrackPageState();
+}
+
+class _TrackPageState extends State<TrackPage> {
+  @override
+  Widget build(BuildContext context) {
+    return Container(
+      child: Text('Track'),
+    );
+  }
+}

+ 15 - 0
lib/pages/welcome_page.dart

@@ -0,0 +1,15 @@
+import 'package:flutter/material.dart';
+
+class WelComePage extends StatefulWidget {
+  const WelComePage({Key key}) : super(key: key);
+
+  @override
+  _WelComePageState createState() => _WelComePageState();
+}
+
+class _WelComePageState extends State<WelComePage> {
+  @override
+  Widget build(BuildContext context) {
+    return Container();
+  }
+}

+ 3 - 0
lib/routes/routes.dart

@@ -0,0 +1,3 @@
+class Routes {
+
+}

+ 8 - 0
lib/utils/time_util.dart

@@ -0,0 +1,8 @@
+class TimeUtil {
+  static DateTime getDateTime(json) {
+    if (json == null) {
+      return null;
+    }
+    return DateTime.parse(json);
+  }
+}

+ 3 - 1
pubspec.yaml

@@ -12,6 +12,8 @@ dependencies:
   dio: ^4.0.0
   shared_preferences: ^2.0.7
   fluttertoast: ^8.0.8
+  flutter_screenutil: ^5.0.0+2
+  #  image_packer: ^0.6.3+4
 
 dev_dependencies:
   flutter_test:
@@ -19,4 +21,4 @@ dev_dependencies:
   flutter_lints: ^1.0.0
 
 flutter:
-  uses-material-design: true
+  uses-material-design: true