You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

717 lines
30KB

  1. import 'dart:convert';
  2. import 'package:farm_tpf/custom_model/Media.dart';
  3. import 'package:farm_tpf/custom_model/Nursery.dart';
  4. import 'package:farm_tpf/custom_model/NurseryDetail.dart';
  5. import 'package:farm_tpf/custom_model/Supply.dart';
  6. import 'package:farm_tpf/data/api/app_exception.dart';
  7. import 'package:farm_tpf/data/repository/repository.dart';
  8. import 'package:farm_tpf/presentation/custom_widgets/bloc/media_helper_bloc.dart';
  9. import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart';
  10. import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart';
  11. import 'package:farm_tpf/presentation/screens/actions/bloc/action_detail_bloc.dart';
  12. import 'package:farm_tpf/presentation/screens/actions/nursery/bloc/expansion_list_bloc.dart';
  13. import 'package:farm_tpf/presentation/screens/actions/state_management_helper/change_file_controller.dart';
  14. import 'package:farm_tpf/presentation/screens/actions/state_management_helper/change_supply.dart';
  15. import 'package:farm_tpf/presentation/screens/resources/sc_resource_helper.dart';
  16. import 'package:farm_tpf/utils/bloc/bloc/status_add_form_bloc.dart';
  17. import 'package:farm_tpf/utils/const_color.dart';
  18. import 'package:farm_tpf/utils/const_common.dart';
  19. import 'package:farm_tpf/utils/const_string.dart';
  20. import 'package:farm_tpf/utils/const_style.dart';
  21. import 'package:farm_tpf/utils/pref.dart';
  22. import 'package:farm_tpf/utils/validators.dart';
  23. import 'package:flutter/material.dart';
  24. import 'package:flutter_bloc/flutter_bloc.dart';
  25. import 'package:flutter_cache_manager/flutter_cache_manager.dart';
  26. import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
  27. import 'package:get/get.dart';
  28. import 'package:get/state_manager.dart';
  29. import 'package:intl/intl.dart';
  30. import 'package:keyboard_dismisser/keyboard_dismisser.dart';
  31. import 'package:mime/mime.dart';
  32. import 'package:pattern_formatter/pattern_formatter.dart';
  33. import 'package:farm_tpf/utils/formatter.dart';
  34. class EditActionNurseryScreen extends StatefulWidget {
  35. final int cropId;
  36. final bool isEdit;
  37. final int activityId;
  38. EditActionNurseryScreen(
  39. {@required this.cropId, this.isEdit = false, this.activityId});
  40. @override
  41. _EditActionNurseryState createState() => _EditActionNurseryState();
  42. }
  43. class _EditActionNurseryState extends State<EditActionNurseryScreen> {
  44. final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
  45. final _repository = Repository();
  46. GlobalKey<FormState> _formKey = GlobalKey();
  47. bool _autoValidate = false;
  48. Nursery _nursery = Nursery();
  49. var pref = LocalPref();
  50. TextEditingController _substrateController = TextEditingController();
  51. TextEditingController _seedLengthController = TextEditingController();
  52. TextEditingController _quantityController = TextEditingController();
  53. TextEditingController _seedIncubationTimeController = TextEditingController();
  54. TextEditingController _descriptionController = TextEditingController();
  55. TextEditingController _workerNameController = TextEditingController();
  56. TextEditingController _trayNumberController = TextEditingController();
  57. final _executeByController = TextEditingController();
  58. String executeTimeView;
  59. DateTime executeTime = DateTime.now();
  60. List<NurseryDetail> currentNurseryDetail = List<NurseryDetail>();
  61. int currentIndexUpdate = -1;
  62. bool isResetForm = true;
  63. final changeSupply = Get.put(ChangeSupply());
  64. int selectedSupplyId = -1;
  65. List<String> filePaths = List<String>();
  66. var changeFileController = Get.put(ChangeFileController());
  67. Future<Null> getSharedPrefs() async {
  68. var currentFullName = await pref.getString(DATA_CONST.CURRENT_FULL_NAME);
  69. _executeByController.text = currentFullName ?? "";
  70. }
  71. @override
  72. void initState() {
  73. super.initState();
  74. getSharedPrefs();
  75. changeSupply.initValue();
  76. changeFileController.initValue();
  77. _nursery.nurseryDetail = new List<NurseryDetail>();
  78. var parsedExecuteDate =
  79. DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(executeTime);
  80. _nursery.executeDate = "$parsedExecuteDate";
  81. executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(executeTime);
  82. _nursery.cropId = widget.cropId;
  83. }
  84. _validateInputs() async {
  85. if (_formKey.currentState.validate()) {
  86. _formKey.currentState.save();
  87. LoadingDialog.showLoadingDialog(context);
  88. _nursery.nurseryDetail = currentNurseryDetail;
  89. filePaths = Get.find<ChangeFileController>().files;
  90. var activityNursery = jsonEncode(_nursery.toJson()).toString();
  91. //ADD NEW
  92. if (_nursery.activityId == null) {
  93. _repository.createAction((value) {
  94. LoadingDialog.hideLoadingDialog(context);
  95. Get.back(result: value);
  96. Get.snackbar(label_add_success, "Hoạt động ươm",
  97. snackPosition: SnackPosition.BOTTOM);
  98. }, (error) {
  99. LoadingDialog.hideLoadingDialog(context);
  100. _scaffoldKey.currentState.showSnackBar(SnackBar(
  101. content: Row(
  102. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  103. children: <Widget>[
  104. Flexible(child: Text(AppException.handleError(error))),
  105. Icon(Icons.error),
  106. ],
  107. ),
  108. backgroundColor: Colors.red,
  109. duration: Duration(seconds: 3),
  110. ));
  111. },
  112. apiAddAction: ConstCommon.apiAddNursery,
  113. paramActivity: ConstCommon.paramsActionNursery,
  114. activityAction: activityNursery,
  115. filePaths: filePaths);
  116. } else {
  117. //UPDATE
  118. _repository.updateAction((value) {
  119. LoadingDialog.hideLoadingDialog(context);
  120. Get.back(result: value);
  121. Get.snackbar(label_update_success, "Hoạt động ươm",
  122. snackPosition: SnackPosition.BOTTOM);
  123. }, (error) {
  124. LoadingDialog.hideLoadingDialog(context);
  125. _scaffoldKey.currentState.showSnackBar(SnackBar(
  126. content: Row(
  127. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  128. children: <Widget>[
  129. Flexible(child: Text(AppException.handleError(error))),
  130. Icon(Icons.error),
  131. ],
  132. ),
  133. backgroundColor: Colors.red,
  134. duration: Duration(seconds: 3),
  135. ));
  136. },
  137. apiUpdateAction: ConstCommon.apiUpdateNursery,
  138. paramActivity: ConstCommon.paramsActionNursery,
  139. activityAction: activityNursery,
  140. filePaths: filePaths);
  141. }
  142. } else {
  143. _autoValidate = true;
  144. }
  145. }
  146. Widget _btnExecuteTimePicker() {
  147. return FlatButton(
  148. padding: EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0),
  149. onPressed: () {
  150. DatePicker.showDateTimePicker(context,
  151. showTitleActions: true, onChanged: (date) {}, onConfirm: (date) {
  152. setState(() {
  153. var parsedDate =
  154. DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(date);
  155. _nursery.executeDate = "$parsedDate";
  156. executeTimeView = DateFormat("dd/MM/yyyy HH:mm").format(date);
  157. });
  158. }, currentTime: executeTime, locale: LocaleType.vi);
  159. },
  160. child: Container(
  161. padding:
  162. EdgeInsets.only(top: 0.0, right: 0.0, bottom: 10.5, left: 0.0),
  163. decoration: BoxDecoration(
  164. border: kBorderTextField,
  165. ),
  166. child: Row(
  167. children: [
  168. Expanded(
  169. child: Text(
  170. //TODO: check condition
  171. executeTimeView == null ? "$executeTime" : executeTimeView,
  172. style: TextStyle(fontSize: 14.0, color: Colors.black87),
  173. )),
  174. Icon(
  175. Icons.date_range,
  176. color: Colors.blue,
  177. ),
  178. ],
  179. )));
  180. }
  181. Widget _btnSelectSubstrates() {
  182. return FlatButton(
  183. padding: EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0),
  184. onPressed: () {
  185. Navigator.of(context)
  186. .push(MaterialPageRoute(
  187. builder: (_) => ResourceHelperScreen(
  188. titleName: "Giá thể",
  189. type: ConstCommon.supplyTypeAll,
  190. selectedId: Get.find<ChangeSupply>().selectedSupplyId),
  191. fullscreenDialog: false))
  192. .then((value) {
  193. if (value != null) {
  194. var result = value as Supply;
  195. _nursery.substratesId = result.id;
  196. changeSupply.change(result);
  197. print("Home: $value");
  198. }
  199. });
  200. },
  201. child: Container(
  202. padding:
  203. EdgeInsets.only(top: 0.0, right: 0.0, bottom: 10.5, left: 0.0),
  204. decoration: BoxDecoration(
  205. border: kBorderTextField,
  206. ),
  207. child: Row(
  208. children: [
  209. GetBuilder<ChangeSupply>(
  210. builder: (_) => Expanded(
  211. child: Text(
  212. changeSupply.selectedSupplyName == null
  213. ? "Loại giá thể"
  214. : changeSupply.selectedSupplyName.toString(),
  215. style: TextStyle(
  216. fontSize: 14.0, color: Colors.black87)))),
  217. Icon(
  218. Icons.arrow_drop_down,
  219. color: Colors.grey,
  220. ),
  221. ],
  222. )));
  223. }
  224. Widget _seedLengthField() {
  225. return TextFormField(
  226. keyboardType: TextInputType.numberWithOptions(decimal: true),
  227. inputFormatters: [
  228. ThousandsFormatter(
  229. formatter: NumberFormat("#,###.##", "es"), allowFraction: true)
  230. ],
  231. decoration: InputDecoration(labelText: "Chiều dài mần"),
  232. controller: _seedLengthController,
  233. onSaved: (newValue) {
  234. _nursery.seedLength = newValue.parseDoubleThousand();
  235. },
  236. );
  237. }
  238. Widget _quantityField() {
  239. return TextFormField(
  240. keyboardType: TextInputType.numberWithOptions(decimal: true),
  241. inputFormatters: [
  242. ThousandsFormatter(
  243. formatter: NumberFormat("#,###.##", "es"), allowFraction: true)
  244. ],
  245. decoration: InputDecoration(labelText: "Số lượng hạt gieo"),
  246. controller: _quantityController,
  247. onSaved: (newValue) {
  248. _nursery.quantity = newValue.parseDoubleThousand();
  249. },
  250. );
  251. }
  252. Widget _seedIncubationTimeField() {
  253. return TextFormField(
  254. keyboardType: TextInputType.numberWithOptions(decimal: true),
  255. inputFormatters: [
  256. ThousandsFormatter(
  257. formatter: NumberFormat("#,###.##", "es"), allowFraction: true)
  258. ],
  259. decoration: InputDecoration(labelText: "Thời gian ngâm hạt"),
  260. controller: _seedIncubationTimeController,
  261. onSaved: (newValue) {
  262. _nursery.seedIncubationTime = newValue.parseDoubleThousand();
  263. },
  264. );
  265. }
  266. Widget _desciptionField() {
  267. return TextFormField(
  268. keyboardType: TextInputType.text,
  269. decoration: InputDecoration(labelText: "Ghi chú"),
  270. controller: _descriptionController,
  271. onSaved: (newValue) {
  272. _nursery.description = newValue;
  273. },
  274. );
  275. }
  276. Widget _executeByField() {
  277. return TextFormField(
  278. keyboardType: TextInputType.text,
  279. decoration: InputDecoration(labelText: "Người thực hiện"),
  280. enabled: false,
  281. controller: _executeByController,
  282. onSaved: (newValue) {},
  283. );
  284. }
  285. Widget _btnAddWorker() {
  286. //TODO :check flow error sua item -> xoa list -> bam nut them
  287. return Builder(builder: (context) {
  288. return BlocConsumer<StatusAddFormBloc, StatusAddFormState>(
  289. listener: (context, state) {
  290. if (state is Edit) {
  291. isResetForm = false;
  292. _workerNameController.text = state.nurseryDetail.workerName;
  293. _trayNumberController.text = state.nurseryDetail.trayNumber;
  294. } else if (state is Delete) {
  295. if (currentIndexUpdate == state.index) {
  296. isResetForm = true;
  297. _workerNameController.text = "";
  298. _trayNumberController.text = "";
  299. }
  300. } else {
  301. isResetForm = true;
  302. _workerNameController.text = "";
  303. _trayNumberController.text = "";
  304. }
  305. }, builder: (context, state) {
  306. return Container(
  307. padding: EdgeInsets.all(8.0),
  308. decoration: BoxDecoration(
  309. shape: BoxShape.rectangle,
  310. borderRadius: BorderRadius.circular(10),
  311. color: Colors.white,
  312. border: Border.all(color: COLOR_CONST.DEFAULT)),
  313. child: Column(
  314. children: [
  315. TextFormField(
  316. keyboardType: TextInputType.text,
  317. controller: _workerNameController,
  318. decoration: InputDecoration(labelText: "Tên công nhân"),
  319. onSaved: (newValue) {},
  320. ),
  321. TextFormField(
  322. keyboardType: TextInputType.text,
  323. controller: _trayNumberController,
  324. decoration: InputDecoration(labelText: "Ươm khây số"),
  325. onSaved: (newValue) {},
  326. ),
  327. Align(
  328. alignment: Alignment.centerRight,
  329. child: Row(
  330. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  331. children: [
  332. isResetForm
  333. ? Container()
  334. : OutlineButton(
  335. shape: RoundedRectangleBorder(
  336. borderRadius: new BorderRadius.circular(8.0)),
  337. child: Text("Huỷ"),
  338. onPressed: () {
  339. context.bloc<StatusAddFormBloc>().add(Reset());
  340. }),
  341. FlatButton(
  342. color: COLOR_CONST.DEFAULT,
  343. shape: RoundedRectangleBorder(
  344. borderRadius: new BorderRadius.circular(8.0)),
  345. onPressed: () {
  346. if (_workerNameController.text.isEmpty ||
  347. _trayNumberController.text.isEmpty) {
  348. return;
  349. }
  350. NurseryDetail _nurseryDetail = NurseryDetail()
  351. ..workerName = _workerNameController.text
  352. ..trayNumber = _trayNumberController.text;
  353. if (state is Edit) {
  354. context.bloc<ExpansionListBloc>().add(Update(
  355. index: state.index,
  356. item: _nurseryDetail,
  357. items: state.items));
  358. } else {
  359. currentNurseryDetail.insert(0, _nurseryDetail);
  360. BlocProvider.of<ExpansionListBloc>(context)
  361. .add(AddNew(items: currentNurseryDetail));
  362. }
  363. context.bloc<StatusAddFormBloc>().add(Reset());
  364. },
  365. child: Text(
  366. (state is Edit) ? "Sửa" : "Thêm",
  367. style: TextStyle(color: Colors.white),
  368. ))
  369. ],
  370. ),
  371. ),
  372. ],
  373. ));
  374. });
  375. });
  376. }
  377. Widget _buildListAddWorker() {
  378. return Builder(builder: (context) {
  379. return BlocBuilder<ExpansionListBloc, ExpansionListState>(
  380. builder: (context, state) {
  381. if (state is ExpansionListSuccess) {
  382. currentNurseryDetail = state.items;
  383. if (currentNurseryDetail.isEmpty) {
  384. return Container();
  385. }
  386. return Container(
  387. height: 70,
  388. child: ListView.builder(
  389. physics: ClampingScrollPhysics(),
  390. scrollDirection: Axis.horizontal,
  391. shrinkWrap: true,
  392. itemCount: currentNurseryDetail.length,
  393. itemBuilder: (context, index) {
  394. return GestureDetector(
  395. onTap: () {
  396. print("edit worker");
  397. currentIndexUpdate = index;
  398. context.bloc<StatusAddFormBloc>().add(Changed(
  399. status: CRUDStatus.edit,
  400. index: index,
  401. nurseryDetail: currentNurseryDetail[index],
  402. items: currentNurseryDetail));
  403. },
  404. child: Card(
  405. child: Stack(
  406. alignment: Alignment.bottomCenter,
  407. overflow: Overflow.visible,
  408. children: <Widget>[
  409. Positioned(
  410. child: ClipRRect(
  411. borderRadius: BorderRadius.circular(8),
  412. child: Container(
  413. padding: EdgeInsets.all(4),
  414. width: 120,
  415. child: Column(
  416. children: [
  417. SizedBox(
  418. height: 12.0,
  419. ),
  420. Flexible(
  421. child: Text(
  422. currentNurseryDetail[index]
  423. .workerName ??
  424. "",
  425. overflow: TextOverflow.ellipsis,
  426. maxLines: 1),
  427. ),
  428. Flexible(
  429. child: Text(currentNurseryDetail[index]
  430. .trayNumber ??
  431. ""))
  432. ],
  433. ),
  434. ),
  435. )),
  436. Positioned(
  437. top: -10,
  438. right: -10,
  439. child: IconButton(
  440. icon: Icon(
  441. Icons.cancel,
  442. color: Colors.redAccent,
  443. ),
  444. onPressed: () {
  445. print("Delete worker");
  446. context.bloc<ExpansionListBloc>().add(
  447. DeleteItem(
  448. index: index,
  449. items: currentNurseryDetail));
  450. context.bloc<StatusAddFormBloc>().add(
  451. Changed(
  452. status: CRUDStatus.delete,
  453. index: index,
  454. nurseryDetail:
  455. currentNurseryDetail[index],
  456. items: currentNurseryDetail));
  457. }),
  458. )
  459. ],
  460. )));
  461. }));
  462. } else if (state is ExpansionListFailure) {
  463. return Container();
  464. } else {
  465. return Container();
  466. }
  467. });
  468. });
  469. }
  470. _actionAppBar() {
  471. IconButton iconButton;
  472. if (1 == 1) {
  473. iconButton = IconButton(
  474. icon: Icon(
  475. Icons.done,
  476. color: Colors.black,
  477. ),
  478. onPressed: () {
  479. FocusScopeNode currentFocus = FocusScope.of(context);
  480. if (!currentFocus.hasPrimaryFocus) {
  481. currentFocus.unfocus();
  482. }
  483. _validateInputs();
  484. },
  485. );
  486. return <Widget>[iconButton];
  487. }
  488. return <Widget>[Container()];
  489. }
  490. @override
  491. Widget build(BuildContext context) => KeyboardDismisser(
  492. gestures: [
  493. GestureType.onTap,
  494. GestureType.onPanUpdateDownDirection,
  495. ],
  496. child: Scaffold(
  497. key: _scaffoldKey,
  498. appBar: AppBar(
  499. centerTitle: true,
  500. title: Text(plot_action_nursery),
  501. actions: _actionAppBar()),
  502. body: KeyboardDismisser(
  503. child: MultiBlocProvider(
  504. providers: [
  505. BlocProvider<ExpansionListBloc>(
  506. create: (context) => ExpansionListBloc(),
  507. ),
  508. BlocProvider<StatusAddFormBloc>(
  509. create: (context) => StatusAddFormBloc(),
  510. ),
  511. BlocProvider<ActionDetailBloc>(
  512. create: (context) =>
  513. ActionDetailBloc(repository: Repository())
  514. ..add(FetchData(
  515. isNeedFetchData: widget.isEdit,
  516. apiActivity: ConstCommon.apiDetailNursery,
  517. activityId: widget.activityId))),
  518. BlocProvider<MediaHelperBloc>(
  519. create: (context) =>
  520. MediaHelperBloc()..add(ChangeListMedia(items: [])),
  521. )
  522. ],
  523. child: Form(
  524. key: _formKey,
  525. autovalidate: _autoValidate,
  526. child: SingleChildScrollView(
  527. padding: EdgeInsets.all(8.0),
  528. child: BlocConsumer<ActionDetailBloc,
  529. ActionDetailState>(
  530. listener: (context, state) async {
  531. if (state is ActionDetailFailure) {
  532. print("fail");
  533. LoadingDialog.hideLoadingDialog(context);
  534. } else if (state is ActionDetailSuccess) {
  535. LoadingDialog.hideLoadingDialog(context);
  536. print("success");
  537. print(state.item);
  538. _nursery = Nursery.fromJson(state.item);
  539. _seedLengthController.text = _nursery
  540. .seedLength
  541. .formatNumtoStringDecimal();
  542. _quantityController.text = _nursery.quantity
  543. .formatNumtoStringDecimal();
  544. _seedIncubationTimeController.text = _nursery
  545. .seedIncubationTime
  546. .formatNumtoStringDecimal();
  547. _descriptionController.text =
  548. _nursery.description;
  549. _executeByController.text =
  550. _nursery.executeBy;
  551. try {
  552. executeTime =
  553. DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
  554. .parse(_nursery.executeDate);
  555. } catch (_) {}
  556. executeTimeView =
  557. DateFormat("dd/MM/yyyy HH:mm")
  558. .format(executeTime);
  559. //Show media
  560. if (_nursery.media != null) {
  561. await cacheFiles(_nursery.media)
  562. .then((value) {
  563. print("then: ${value.length}");
  564. BlocProvider.of<MediaHelperBloc>(context)
  565. .add(ChangeListMedia(items: value));
  566. }).whenComplete(() {
  567. print("completed");
  568. });
  569. }
  570. //Show worker
  571. if (_nursery.nurseryDetail.length > 0) {
  572. BlocProvider.of<ExpansionListBloc>(context)
  573. .add(AddNew(
  574. items: _nursery.nurseryDetail));
  575. }
  576. //change subStrates
  577. if (_nursery.substratesId != null) {
  578. Get.find<ChangeSupply>().changeByIdAndName(
  579. _nursery.substratesId,
  580. _nursery.substrateName);
  581. }
  582. } else if (state is ActionDetailInitial) {
  583. print("init");
  584. } else if (state is ActionDetailLoading) {
  585. print("loading");
  586. LoadingDialog.showLoadingDialog(context);
  587. }
  588. },
  589. builder: (context, state) {
  590. return Column(
  591. children: <Widget>[
  592. Container(
  593. width: double.infinity,
  594. child: Text(
  595. "Ngày thực hiện *",
  596. style: TextStyle(
  597. color: Colors.black54,
  598. fontSize: 13.0),
  599. ),
  600. ),
  601. _btnExecuteTimePicker(),
  602. SizedBox(
  603. height: 8.0,
  604. ),
  605. Container(
  606. width: double.infinity,
  607. child: Text(
  608. "Loại giá thể",
  609. style: TextStyle(
  610. color: Colors.black54,
  611. fontSize: 13.0),
  612. ),
  613. ),
  614. _btnSelectSubstrates(),
  615. SizedBox(
  616. height: 8.0,
  617. ),
  618. _seedLengthField(),
  619. SizedBox(
  620. height: 8.0,
  621. ),
  622. _quantityField(),
  623. SizedBox(
  624. height: 8.0,
  625. ),
  626. _seedIncubationTimeField(),
  627. SizedBox(
  628. height: 8.0,
  629. ),
  630. _desciptionField(),
  631. SizedBox(
  632. height: 8.0,
  633. ),
  634. _executeByField(),
  635. SizedBox(
  636. height: 8.0,
  637. ),
  638. _btnAddWorker(),
  639. SizedBox(
  640. height: 8.0,
  641. ),
  642. _buildListAddWorker(),
  643. SizedBox(
  644. height: 8.0,
  645. ),
  646. BlocBuilder<MediaHelperBloc,
  647. MediaHelperState>(
  648. builder: (context, state) {
  649. if (state is MediaHelperSuccess) {
  650. print("length: " +
  651. state.items.length.toString());
  652. return WidgetMediaPicker(
  653. currentItems: state.items,
  654. onChangeFiles: (filePaths) async {
  655. Get.find<ChangeFileController>()
  656. .addAllFile(filePaths);
  657. });
  658. } else {
  659. return Center(
  660. child: CircularProgressIndicator());
  661. }
  662. }),
  663. ],
  664. );
  665. },
  666. ),
  667. ))))));
  668. @override
  669. void dispose() {
  670. _substrateController.dispose();
  671. _seedLengthController.dispose();
  672. _quantityController.dispose();
  673. _seedIncubationTimeController.dispose();
  674. _descriptionController.dispose();
  675. _executeByController.dispose();
  676. super.dispose();
  677. }
  678. Future<List<Media>> cacheFiles(String existedMedias) async {
  679. var medias = List<Media>();
  680. var mediaPathsLocal = List<String>();
  681. var mediaPaths = existedMedias.split(";");
  682. for (int i = 0; i < mediaPaths.length; i++) {
  683. var tempFile = await DefaultCacheManager()
  684. .getSingleFile(ConstCommon.baseImageUrl + mediaPaths[i]);
  685. print(tempFile.path);
  686. var isVideo = lookupMimeType(tempFile.path) == "video/mp4";
  687. print("file type: " + lookupMimeType(tempFile.path));
  688. Media media = Media()
  689. ..pathFile = tempFile.path
  690. ..isVideo = isVideo;
  691. medias.add(media);
  692. mediaPathsLocal.add(tempFile.path);
  693. }
  694. Get.find<ChangeFileController>().addAllFile(filePaths);
  695. return medias;
  696. }
  697. }