|
@@ -1,7 +1,12 @@
|
|
|
+import 'package:file_picker/file_picker.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
+import 'package:flutter_tracker/dio/track_dao.dart';
|
|
|
import 'package:flutter_tracker/model/config.dart';
|
|
|
+import 'package:flutter_tracker/model/submit_model.dart';
|
|
|
import 'package:flutter_tracker/utils/app_util.dart';
|
|
|
-/// Description:
|
|
|
+import 'package:shared_preferences/shared_preferences.dart';
|
|
|
+
|
|
|
+/// Description:
|
|
|
/// Time : 2021年12月03日 Friday
|
|
|
/// Author : liuyuqi.gov@msncn
|
|
|
class SubmitPage extends StatefulWidget {
|
|
@@ -12,7 +17,6 @@ class SubmitPage extends StatefulWidget {
|
|
|
}
|
|
|
|
|
|
class _SubmitPageState extends State<SubmitPage> {
|
|
|
- Size get _size => MediaQuery.of(context).size;
|
|
|
final TextEditingController _controllerUsn = TextEditingController();
|
|
|
final TextEditingController _controllerTel = TextEditingController();
|
|
|
final TextEditingController _controllerAddress = TextEditingController();
|
|
@@ -21,6 +25,11 @@ class _SubmitPageState extends State<SubmitPage> {
|
|
|
String _userName = "";
|
|
|
String _tel = "";
|
|
|
String _addresds = "";
|
|
|
+ bool _heathStatus = false;
|
|
|
+
|
|
|
+ String _filePath;
|
|
|
+
|
|
|
+ Size get _size => MediaQuery.of(context).size;
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
@@ -28,154 +37,212 @@ class _SubmitPageState extends State<SubmitPage> {
|
|
|
appBar: AppBar(
|
|
|
title: Text("疫情上报"),
|
|
|
),
|
|
|
- body: SizedBox(
|
|
|
- width: _size.width,
|
|
|
- child: SingleChildScrollView(
|
|
|
- child: Padding(
|
|
|
- padding:
|
|
|
- const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
|
|
|
- child: Column(
|
|
|
- children: [
|
|
|
- TextFormField(
|
|
|
- autofocus: true,
|
|
|
- controller: _controllerUsn,
|
|
|
- decoration: const InputDecoration(
|
|
|
- labelText: "姓名:",
|
|
|
- hintText: "请输入真实姓名",
|
|
|
- icon: Icon(Icons.person)),
|
|
|
- // 校验用户名
|
|
|
- validator: (v) {
|
|
|
- return v.trim().length > 0 ? null : "姓名不能为空";
|
|
|
- },
|
|
|
- onChanged: (inputStr) {
|
|
|
- _userName = inputStr;
|
|
|
- },
|
|
|
+ body: SingleChildScrollView(
|
|
|
+ child: Padding(
|
|
|
+ padding: const EdgeInsets.only(left: 8.0, right: 8),
|
|
|
+ child: Column(
|
|
|
+ children: [
|
|
|
+ TextFormField(
|
|
|
+ autofocus: true,
|
|
|
+ controller: _controllerUsn,
|
|
|
+ decoration: const InputDecoration(
|
|
|
+ labelText: "姓名:",
|
|
|
+ hintText: "请输入真实姓名",
|
|
|
+ icon: Icon(Icons.person)),
|
|
|
+ // 校验用户名
|
|
|
+ validator: (v) {
|
|
|
+ return v.trim().length > 0 ? null : "姓名不能为空";
|
|
|
+ },
|
|
|
+ onChanged: (inputStr) {
|
|
|
+ _userName = inputStr;
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ TextFormField(
|
|
|
+ controller: _controllerTel,
|
|
|
+ decoration: const InputDecoration(
|
|
|
+ labelText: "电话:",
|
|
|
+ hintText: "联系电话",
|
|
|
+ icon: Icon(Icons.phone)),
|
|
|
+ validator: (v) {
|
|
|
+ return v.trim().length > 11 ? null : "手机号错误";
|
|
|
+ },
|
|
|
+ onChanged: (inputStr) {
|
|
|
+ _tel = inputStr;
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ TextFormField(
|
|
|
+ controller: _controllerAddress,
|
|
|
+ decoration: const InputDecoration(
|
|
|
+ labelText: "住址:",
|
|
|
+ hintText: "请输入家庭住址",
|
|
|
+ icon: Icon(Icons.house)),
|
|
|
+ validator: (v) {
|
|
|
+ return v.trim().length > 0 ? null : "请输入地址";
|
|
|
+ },
|
|
|
+ onChanged: (inputStr) {
|
|
|
+ _addresds = inputStr;
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ SizedBox(
|
|
|
+ height: 10,
|
|
|
+ ),
|
|
|
+ Align(
|
|
|
+ child: Text(
|
|
|
+ "健康状态:",
|
|
|
+ style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
|
|
),
|
|
|
- TextFormField(
|
|
|
- controller: _controllerTel,
|
|
|
- decoration: const InputDecoration(
|
|
|
- labelText: "电话:",
|
|
|
- hintText: "联系电话",
|
|
|
- icon: Icon(Icons.phone)),
|
|
|
- validator: (v) {
|
|
|
- return v.trim().length > 11 ? null : "手机号错误";
|
|
|
- },
|
|
|
- onChanged: (inputStr) {
|
|
|
- _tel = inputStr;
|
|
|
- },
|
|
|
+ alignment: Alignment.centerLeft,
|
|
|
+ ),
|
|
|
+ RadioListTile(
|
|
|
+ title: Text("阴性"),
|
|
|
+ value: true,
|
|
|
+ groupValue: _heathStatus,
|
|
|
+ onChanged: (value) {
|
|
|
+ setState(() {
|
|
|
+ _heathStatus = value;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ RadioListTile(
|
|
|
+ title: Text("阳性"),
|
|
|
+ value: false,
|
|
|
+ groupValue: _heathStatus,
|
|
|
+ onChanged: (value) {
|
|
|
+ setState(() {
|
|
|
+ _heathStatus = value;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ SizedBox(
|
|
|
+ height: 10,
|
|
|
+ ),
|
|
|
+ Align(
|
|
|
+ child: Text(
|
|
|
+ "核酸检测:",
|
|
|
+ style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
|
|
),
|
|
|
- TextFormField(
|
|
|
- controller: _controllerAddress,
|
|
|
- decoration: const InputDecoration(
|
|
|
- labelText: "住址:",
|
|
|
- hintText: "请输入家庭住址",
|
|
|
- icon: Icon(Icons.house)),
|
|
|
- validator: (v) {
|
|
|
- return v.trim().length > 0 ? null : "请输入地址";
|
|
|
- },
|
|
|
- onChanged: (inputStr) {
|
|
|
- _addresds = inputStr;
|
|
|
- },
|
|
|
- ),
|
|
|
- SizedBox(
|
|
|
- height: 10,
|
|
|
- ),
|
|
|
- Align(
|
|
|
- child: Text(
|
|
|
- "健康状态:",
|
|
|
- style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
|
|
+ alignment: Alignment.centerLeft,
|
|
|
+ ),
|
|
|
+ Text("请拍照上传清晰的核酸证明图片"),
|
|
|
+ InkWell(
|
|
|
+ onTap: () {
|
|
|
+ chooseImg();
|
|
|
+ },
|
|
|
+ child: Container(
|
|
|
+ child: Image.asset(
|
|
|
+ "assets/images/add.png",
|
|
|
+ width: 160,
|
|
|
+ height: 160,
|
|
|
),
|
|
|
- alignment: Alignment.centerLeft,
|
|
|
- ),
|
|
|
- Row(
|
|
|
- children: [
|
|
|
- RadioListTile(
|
|
|
- title: Text("阴性"),
|
|
|
- value: 0,
|
|
|
- groupValue: 0,
|
|
|
- onChanged: (value) {},
|
|
|
- ),
|
|
|
- RadioListTile(
|
|
|
- title: Text("阳性"),
|
|
|
- value: 1,
|
|
|
- groupValue: 0,
|
|
|
- onChanged: (value) {},
|
|
|
- ),
|
|
|
- ],
|
|
|
),
|
|
|
- SizedBox(
|
|
|
- height: 10,
|
|
|
+ ),
|
|
|
+ Container(
|
|
|
+ child: Image.asset(
|
|
|
+ "",
|
|
|
+ width: 160,
|
|
|
+ height: 160,
|
|
|
),
|
|
|
- Align(
|
|
|
- child: Text(
|
|
|
- "核酸检测:",
|
|
|
- style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
|
|
- ),
|
|
|
- alignment: Alignment.centerLeft,
|
|
|
- ),
|
|
|
- Text("请拍照上传清晰的核酸证明图片"),
|
|
|
- InkWell(
|
|
|
+ ),
|
|
|
+ SizedBox(
|
|
|
+ height: 10,
|
|
|
+ ),
|
|
|
+ Container(
|
|
|
+ width: 150,
|
|
|
+ child: InkWell(
|
|
|
onTap: () {
|
|
|
- chooseImg();
|
|
|
+ // 登录
|
|
|
+ submitInfo();
|
|
|
},
|
|
|
child: Container(
|
|
|
- child: Image.asset(
|
|
|
- "assets/images/add.png",
|
|
|
- width: 160,
|
|
|
- height: 160,
|
|
|
- ),
|
|
|
- ),
|
|
|
- ),
|
|
|
- SizedBox(
|
|
|
- height: 10,
|
|
|
- ),
|
|
|
- Container(
|
|
|
- width: 150,
|
|
|
- child: InkWell(
|
|
|
- onTap: () {
|
|
|
- // 登录
|
|
|
- submitInfo();
|
|
|
- },
|
|
|
- child: Container(
|
|
|
- width: double.infinity,
|
|
|
- height: AppUtil.height(80),
|
|
|
- padding: EdgeInsets.only(
|
|
|
- right: AppUtil.width(20), left: AppUtil.width(20)),
|
|
|
- decoration: BoxDecoration(
|
|
|
- gradient: const LinearGradient(colors: [
|
|
|
- ThemeColor.loignColor,
|
|
|
- ThemeColor.loignColor
|
|
|
- ]),
|
|
|
- borderRadius: BorderRadius.circular(10),
|
|
|
- boxShadow: const [
|
|
|
- BoxShadow(
|
|
|
- offset: Offset(1.0, 5.0),
|
|
|
- color: ThemeColor.loignColor,
|
|
|
- blurRadius: 5.0,
|
|
|
- )
|
|
|
- ]),
|
|
|
- child: const Center(
|
|
|
- child: Text(
|
|
|
- "登录",
|
|
|
- style: TextStyle(fontSize: 20, color: Colors.white),
|
|
|
- ),
|
|
|
+ width: double.infinity,
|
|
|
+ height: AppUtil.height(80),
|
|
|
+ padding: EdgeInsets.only(
|
|
|
+ right: AppUtil.width(20), left: AppUtil.width(20)),
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ gradient: const LinearGradient(colors: [
|
|
|
+ ThemeColor.loignColor,
|
|
|
+ ThemeColor.loignColor
|
|
|
+ ]),
|
|
|
+ borderRadius: BorderRadius.circular(10),
|
|
|
+ boxShadow: const [
|
|
|
+ BoxShadow(
|
|
|
+ offset: Offset(1.0, 5.0),
|
|
|
+ color: ThemeColor.loignColor,
|
|
|
+ blurRadius: 5.0,
|
|
|
+ )
|
|
|
+ ]),
|
|
|
+ child: const Center(
|
|
|
+ child: Text(
|
|
|
+ "提交",
|
|
|
+ style: TextStyle(fontSize: 20, color: Colors.white),
|
|
|
),
|
|
|
),
|
|
|
),
|
|
|
),
|
|
|
- ],
|
|
|
- ),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
),
|
|
|
),
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- void submitInfo() {
|
|
|
-
|
|
|
+ void submitInfo() async {
|
|
|
+ SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
+ String token = prefs.getString("token");
|
|
|
+ var uploadTrack =
|
|
|
+ TrackDao.uploadTrack(token, _tel, _addresds, _heathStatus, _filePath);
|
|
|
}
|
|
|
|
|
|
- void chooseImg() {
|
|
|
-
|
|
|
+ void chooseImg() async {
|
|
|
+ FilePickerResult result = await FilePicker.platform.pickFiles(
|
|
|
+ type: FileType.custom,
|
|
|
+ allowedExtensions: ['jpg', 'pdf', 'doc'],
|
|
|
+ );
|
|
|
+ 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();
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ );
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ print('用户停止了选择文件');
|
|
|
+ }
|
|
|
}
|
|
|
}
|