import 'package:farm_tpf/data/repository/repository.dart'; import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart'; import 'package:farm_tpf/presentation/custom_widgets/bloc/media_helper_bloc.dart'; import 'package:farm_tpf/presentation/custom_widgets/button_widget.dart'; import 'package:farm_tpf/presentation/custom_widgets/widget_field_time_picker.dart'; import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart'; import 'package:farm_tpf/presentation/custom_widgets/widget_media_picker.dart'; import 'package:farm_tpf/presentation/screens/actions/cubit/action_ui_cubit.dart'; import 'package:farm_tpf/utils/pref.dart'; import 'package:farm_tpf/utils/validators.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:get/get.dart'; import 'package:keyboard_dismisser/keyboard_dismisser.dart'; import 'state_management_helper/change_file_controller.dart'; class ActionScreen extends StatefulWidget { final int idAction; final String title; ActionScreen({@required this.idAction, @required this.title}); @override _ActionScreenState createState() => _ActionScreenState(); } class _ActionScreenState extends State { final _scaffoldKey = GlobalKey(); var _formKey = GlobalKey(); var pref = LocalPref(); final _executeByController = TextEditingController(); DateTime executeTime = DateTime.now(); List filePaths = List(); var changeFileController = Get.put(ChangeFileController()); Future getSharedPrefs() async { var currentFullName = await pref.getString(DATA_CONST.CURRENT_FULL_NAME); _executeByController.text = currentFullName ?? ""; } @override void initState() { super.initState(); getSharedPrefs(); } _validateInputs() async { if (_formKey.currentState.validate()) { _formKey.currentState.save(); LoadingDialog.showLoadingDialog(context); filePaths = Get.find().newFiles; //Create request general model try { //ADD NEW //Update } catch (e) { LoadingDialog.hideLoadingDialog(context); print(e.toString()); } } else { // } } Widget _btnExecuteTimePicker() { return WidgetFieldDateTimePicker( initDateTime: executeTime, onUpdateDateTime: (selectedDate) { // }); } Widget _executeByField() { return TextFormField( keyboardType: TextInputType.text, decoration: InputDecoration(labelText: "Người thực hiện"), enabled: false, controller: _executeByController, onSaved: (newValue) {}, ); } @override Widget build(BuildContext context) => KeyboardDismisser( gestures: [ GestureType.onTap, GestureType.onPanUpdateDownDirection, ], child: Scaffold( backgroundColor: Colors.white, key: _scaffoldKey, appBar: AppBarWidget( isBack: true, action: InkWell( child: Text( 'Lưu', style: TextStyle( color: Colors.red, fontWeight: FontWeight.normal), ), onTap: () {}, ), ), body: KeyboardDismisser( child: MultiBlocProvider( providers: [ BlocProvider( create: (context) => ActionUiCubit(repository: Repository()) ..getActionUIForm(widget.idAction)), BlocProvider( create: (context) => MediaHelperBloc()..add(ChangeListMedia(items: [])), ) ], child: Form( key: _formKey, child: SafeArea( child: SingleChildScrollView( child: BlocConsumer( listener: (context, state) async { if (state is ActionUiLoading) { LoadingDialog.hideLoadingDialog(context); } else if (state is ActionUiSuccess) { LoadingDialog.hideLoadingDialog(context); } else if (state is ActionUiFailure) { LoadingDialog.showLoadingDialog(context); } }, builder: (context, state) { return Column( children: [ Padding( padding: const EdgeInsets.all(8.0), child: Column( children: [ Container( width: double.infinity, child: Text( "Ngày thực hiện *", style: TextStyle( color: Colors.black54, fontSize: 13.0), ), ), _btnExecuteTimePicker(), SizedBox( height: 8.0, ), _executeByField(), SizedBox( height: 8.0, ), ], ), ), Container( width: double.infinity, height: 16, color: Colors.grey[200], ), BlocBuilder( builder: (context, state) { if (state is MediaHelperSuccess) { return WidgetMediaPicker( currentItems: state.items, onChangeFiles: (newPathFiles, deletePathFiles) async { Get.find() .change(newPathFiles, deletePathFiles); }); } else { return Center( child: CircularProgressIndicator()); } }), Padding( padding: const EdgeInsets.all(8.0), child: ButtonWidget( title: 'CẬP NHẬT', onPressed: () { FocusScopeNode currentFocus = FocusScope.of(context); if (!currentFocus.hasPrimaryFocus) { currentFocus.unfocus(); } _validateInputs(); }), ), ], ); }, ), ), )), )))); @override void dispose() { _executeByController.dispose(); super.dispose(); } }