Browse Source

完成提交页面

liuyuqi-dellpc 2 years ago
parent
commit
cccdec4e2d
2 changed files with 32 additions and 50 deletions
  1. 2 2
      lib/dio/track_dao.dart
  2. 30 48
      lib/pages/submit_page.dart

+ 2 - 2
lib/dio/track_dao.dart

@@ -20,8 +20,8 @@ class TrackDao {
     return null;
   }
 
-  static Future<SubmitModel> uploadTrack(String token, String telphone,
-      String address, bool health, String filePath) async {
+  static Future<SubmitModel> uploadTrack(
+      String token, String telphone, String address, bool health) async {
     params.addAll({
       "token": token,
       "telphone": telphone,

+ 30 - 48
lib/pages/submit_page.dart

@@ -1,3 +1,5 @@
+import 'dart:io';
+
 import 'package:file_picker/file_picker.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_tracker/dio/track_dao.dart';
@@ -136,13 +138,7 @@ class _SubmitPageState extends State<SubmitPage> {
                   ),
                 ),
               ),
-              Container(
-                child: Image.asset(
-                  "",
-                  width: 160,
-                  height: 160,
-                ),
-              ),
+              buildUploadImage(),
               SizedBox(
                 height: 10,
               ),
@@ -180,6 +176,9 @@ class _SubmitPageState extends State<SubmitPage> {
                   ),
                 ),
               ),
+              const SizedBox(
+                height: 50,
+              ),
             ],
           ),
         ),
@@ -187,11 +186,23 @@ class _SubmitPageState extends State<SubmitPage> {
     );
   }
 
+  Widget buildUploadImage() {
+    if (_filePath != null) {
+      return Image.file(
+        File(_filePath),
+        width: 160,
+        height: 160,
+      );
+    } else {
+      return Text("");
+    }
+  }
+
   void submitInfo() async {
     SharedPreferences prefs = await SharedPreferences.getInstance();
     String token = prefs.getString("token");
     var uploadTrack =
-        TrackDao.uploadTrack(token, _tel, _addresds, _heathStatus, _filePath);
+        TrackDao.uploadTrack(token, _tel, _addresds, _heathStatus);
   }
 
   void chooseImg() async {
@@ -201,46 +212,17 @@ class _SubmitPageState extends State<SubmitPage> {
     );
     if (result != null) {
       print('---选择的路径---' + result.files.single.path);
-      showDialog<Null>(
-          context: context,
-          barrierDismissible: false,
-          builder: (BuildContext context) {
-            return AlertDialog(
-              //可滑动
-              content: SingleChildScrollView(
-                child: ListBody(
-                  children: <Widget>[
-                    Text('是否确定上传文件?'),
-                  ],
-                ),
-              ),
-              actions: <Widget>[
-                TextButton(
-                  child: Text('确定'),
-                  onPressed: () async {
-                    SharedPreferences prefs =
-                        await SharedPreferences.getInstance();
-                    var token = prefs.getString("token");
-                    SubmitModel fileEntity = await TrackDao.uploadImg(token,
-                        result.files.single.path, result.files.single.name);
-                    AppUtil.buildToast("fileEntity.msgModel.msg");
-                    prefs.setString("fileName", result.files.single.name);
-                    prefs.setInt("fileid", 11);
-                    setState(() {
-                      _filePath = result.files.single.path;
-                    });
-                    Navigator.of(context).pop();
-                  },
-                ),
-                TextButton(
-                  child: Text('取消'),
-                  onPressed: () {
-                    Navigator.of(context).pop();
-                  },
-                ),
-              ],
-            );
-          });
+      setState(() {
+        _filePath = result.files.single.path;
+      });
+
+      SharedPreferences prefs = await SharedPreferences.getInstance();
+      var token = prefs.getString("token");
+      SubmitModel fileEntity = await TrackDao.uploadImg(
+          token, result.files.single.path, result.files.single.name);
+      AppUtil.buildToast("fileEntity.msgModel.msg");
+      prefs.setString("fileName", result.files.single.name);
+      prefs.setInt("fileid", 11);
     } else {
       print('用户停止了选择文件');
     }