submit_page.dart 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import 'package:file_picker/file_picker.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_tracker/dio/track_dao.dart';
  4. import 'package:flutter_tracker/model/config.dart';
  5. import 'package:flutter_tracker/model/submit_model.dart';
  6. import 'package:flutter_tracker/utils/app_util.dart';
  7. import 'package:shared_preferences/shared_preferences.dart';
  8. /// Description:
  9. /// Time : 2021年12月03日 Friday
  10. /// Author : liuyuqi.gov@msncn
  11. class SubmitPage extends StatefulWidget {
  12. const SubmitPage({Key key}) : super(key: key);
  13. @override
  14. _SubmitPageState createState() => _SubmitPageState();
  15. }
  16. class _SubmitPageState extends State<SubmitPage> {
  17. final TextEditingController _controllerUsn = TextEditingController();
  18. final TextEditingController _controllerTel = TextEditingController();
  19. final TextEditingController _controllerAddress = TextEditingController();
  20. final GlobalKey _formKey = GlobalKey<FormState>();
  21. String _userName = "";
  22. String _tel = "";
  23. String _addresds = "";
  24. bool _heathStatus = false;
  25. String _filePath;
  26. Size get _size => MediaQuery.of(context).size;
  27. @override
  28. Widget build(BuildContext context) {
  29. return Scaffold(
  30. appBar: AppBar(
  31. title: Text("疫情上报"),
  32. ),
  33. body: SingleChildScrollView(
  34. child: Padding(
  35. padding: const EdgeInsets.only(left: 8.0, right: 8),
  36. child: Column(
  37. children: [
  38. TextFormField(
  39. autofocus: true,
  40. controller: _controllerUsn,
  41. decoration: const InputDecoration(
  42. labelText: "姓名:",
  43. hintText: "请输入真实姓名",
  44. icon: Icon(Icons.person)),
  45. // 校验用户名
  46. validator: (v) {
  47. return v.trim().length > 0 ? null : "姓名不能为空";
  48. },
  49. onChanged: (inputStr) {
  50. _userName = inputStr;
  51. },
  52. ),
  53. TextFormField(
  54. controller: _controllerTel,
  55. decoration: const InputDecoration(
  56. labelText: "电话:",
  57. hintText: "联系电话",
  58. icon: Icon(Icons.phone)),
  59. validator: (v) {
  60. return v.trim().length > 11 ? null : "手机号错误";
  61. },
  62. onChanged: (inputStr) {
  63. _tel = inputStr;
  64. },
  65. ),
  66. TextFormField(
  67. controller: _controllerAddress,
  68. decoration: const InputDecoration(
  69. labelText: "住址:",
  70. hintText: "请输入家庭住址",
  71. icon: Icon(Icons.house)),
  72. validator: (v) {
  73. return v.trim().length > 0 ? null : "请输入地址";
  74. },
  75. onChanged: (inputStr) {
  76. _addresds = inputStr;
  77. },
  78. ),
  79. SizedBox(
  80. height: 10,
  81. ),
  82. Align(
  83. child: Text(
  84. "健康状态:",
  85. style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
  86. ),
  87. alignment: Alignment.centerLeft,
  88. ),
  89. RadioListTile(
  90. title: Text("阴性"),
  91. value: true,
  92. groupValue: _heathStatus,
  93. onChanged: (value) {
  94. setState(() {
  95. _heathStatus = value;
  96. });
  97. },
  98. ),
  99. RadioListTile(
  100. title: Text("阳性"),
  101. value: false,
  102. groupValue: _heathStatus,
  103. onChanged: (value) {
  104. setState(() {
  105. _heathStatus = value;
  106. });
  107. },
  108. ),
  109. SizedBox(
  110. height: 10,
  111. ),
  112. Align(
  113. child: Text(
  114. "核酸检测:",
  115. style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
  116. ),
  117. alignment: Alignment.centerLeft,
  118. ),
  119. Text("请拍照上传清晰的核酸证明图片"),
  120. InkWell(
  121. onTap: () {
  122. chooseImg();
  123. },
  124. child: Container(
  125. child: Image.asset(
  126. "assets/images/add.png",
  127. width: 160,
  128. height: 160,
  129. ),
  130. ),
  131. ),
  132. Container(
  133. child: Image.asset(
  134. "",
  135. width: 160,
  136. height: 160,
  137. ),
  138. ),
  139. SizedBox(
  140. height: 10,
  141. ),
  142. Container(
  143. width: 150,
  144. child: InkWell(
  145. onTap: () {
  146. // 登录
  147. submitInfo();
  148. },
  149. child: Container(
  150. width: double.infinity,
  151. height: AppUtil.height(80),
  152. padding: EdgeInsets.only(
  153. right: AppUtil.width(20), left: AppUtil.width(20)),
  154. decoration: BoxDecoration(
  155. gradient: const LinearGradient(colors: [
  156. ThemeColor.loignColor,
  157. ThemeColor.loignColor
  158. ]),
  159. borderRadius: BorderRadius.circular(10),
  160. boxShadow: const [
  161. BoxShadow(
  162. offset: Offset(1.0, 5.0),
  163. color: ThemeColor.loignColor,
  164. blurRadius: 5.0,
  165. )
  166. ]),
  167. child: const Center(
  168. child: Text(
  169. "提交",
  170. style: TextStyle(fontSize: 20, color: Colors.white),
  171. ),
  172. ),
  173. ),
  174. ),
  175. ),
  176. ],
  177. ),
  178. ),
  179. ),
  180. );
  181. }
  182. void submitInfo() async {
  183. SharedPreferences prefs = await SharedPreferences.getInstance();
  184. String token = prefs.getString("token");
  185. var uploadTrack =
  186. TrackDao.uploadTrack(token, _tel, _addresds, _heathStatus, _filePath);
  187. }
  188. void chooseImg() async {
  189. FilePickerResult result = await FilePicker.platform.pickFiles(
  190. type: FileType.custom,
  191. allowedExtensions: ['jpg', 'pdf', 'doc'],
  192. );
  193. if (result != null) {
  194. print('---选择的路径---' + result.files.single.path);
  195. showDialog<Null>(
  196. context: context,
  197. barrierDismissible: false,
  198. builder: (BuildContext context) {
  199. return AlertDialog(
  200. //可滑动
  201. content: SingleChildScrollView(
  202. child: ListBody(
  203. children: <Widget>[
  204. Text('是否确定上传文件?'),
  205. ],
  206. ),
  207. ),
  208. actions: <Widget>[
  209. TextButton(
  210. child: Text('确定'),
  211. onPressed: () async {
  212. SharedPreferences prefs =
  213. await SharedPreferences.getInstance();
  214. var token = prefs.getString("token");
  215. SubmitModel fileEntity = await TrackDao.uploadImg(token,
  216. result.files.single.path, result.files.single.name);
  217. AppUtil.buildToast("fileEntity.msgModel.msg");
  218. prefs.setString("fileName", result.files.single.name);
  219. prefs.setInt("fileid", 11);
  220. setState(() {
  221. _filePath = result.files.single.path;
  222. });
  223. Navigator.of(context).pop();
  224. },
  225. ),
  226. TextButton(
  227. child: Text('取消'),
  228. onPressed: () {
  229. Navigator.of(context).pop();
  230. },
  231. ),
  232. ],
  233. );
  234. });
  235. } else {
  236. print('用户停止了选择文件');
  237. }
  238. }
  239. }