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.

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