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.

165 lines
5.2KB

  1. import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart';
  2. import 'package:farm_tpf/presentation/custom_widgets/button_widget.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/scheduler.dart';
  5. import 'package:flutter_bloc/flutter_bloc.dart';
  6. import 'package:keyboard_dismisser/keyboard_dismisser.dart';
  7. import '../../../models/item_dropdown.dart';
  8. import '../../../utils/utils.dart';
  9. import '../../custom_widgets/date_picker/date_picker_widget.dart';
  10. import '../../custom_widgets/dropdown/dropdown_bottom_sheet.dart';
  11. import '../../custom_widgets/textfield/text_field_normal.dart';
  12. import 'cubit/update_activity_cubit.dart';
  13. import 'widgets/item_column.dart';
  14. class UpdateActivityPage extends StatefulWidget {
  15. final String stampCode;
  16. const UpdateActivityPage({super.key, required this.stampCode});
  17. @override
  18. State<UpdateActivityPage> createState() => _UpdateActivityPageState();
  19. }
  20. class _UpdateActivityPageState extends State<UpdateActivityPage> {
  21. final bloc = UpdateActivityCubit();
  22. @override
  23. void initState() {
  24. super.initState();
  25. bloc.preparedData();
  26. }
  27. @override
  28. void dispose() {
  29. bloc.dispose();
  30. super.dispose();
  31. }
  32. @override
  33. Widget build(BuildContext context) {
  34. return Scaffold(
  35. appBar: AppBarWidget(),
  36. body: BlocListener<UpdateActivityCubit, UpdateActivityState>(
  37. bloc: bloc,
  38. listener: ((context, state) {
  39. if (state is UpdateActivityLoading) {
  40. SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
  41. UtilWidget.showLoading();
  42. });
  43. } else if (state is UpdateActivityFailure) {
  44. SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
  45. UtilWidget.hideLoading();
  46. // UtilWidget.showToastError(state.errorMessage);
  47. });
  48. } else if (state is UpdateActivityPrepareDataSuccessful) {
  49. SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
  50. UtilWidget.hideLoading();
  51. });
  52. }
  53. }),
  54. child: KeyboardDismisser(
  55. child: Container(
  56. child: Form(
  57. key: bloc.formKey,
  58. child: Column(
  59. children: [
  60. Expanded(
  61. child: _widgetBody(),
  62. ),
  63. Padding(
  64. padding: const EdgeInsets.all(8.0),
  65. child: ButtonWidget(
  66. title: 'Cập nhật',
  67. onPressed: () {
  68. bloc.onSubmit(widget.stampCode);
  69. },
  70. ),
  71. ),
  72. ],
  73. ),
  74. ),
  75. ),
  76. ),
  77. ),
  78. );
  79. }
  80. Widget _widgetBody() {
  81. return Container(
  82. padding: const EdgeInsets.all(16),
  83. child: SingleChildScrollView(
  84. child: Column(
  85. crossAxisAlignment: CrossAxisAlignment.start,
  86. children: [
  87. ItemColumnWidget(
  88. title: 'Hoạt động',
  89. child: ValueListenableBuilder<String>(
  90. valueListenable: bloc.selectedActivityType,
  91. builder: (context, selected, _) {
  92. return ValueListenableBuilder<List<ItemDropDown>>(
  93. valueListenable: bloc.activityTypes,
  94. builder: (context, types, _) {
  95. return DropdownBottomSheet(
  96. dataSources: types,
  97. initValue: selected,
  98. onSelected: (val) {
  99. bloc.selectedActivityType.value = val.key ?? '';
  100. },
  101. hint: 'Hoạt động',
  102. );
  103. },
  104. );
  105. }),
  106. ),
  107. const SizedBox(
  108. height: 8,
  109. ),
  110. ItemColumnWidget(
  111. title: 'Mô tả',
  112. child: TextFieldNormal(
  113. controller: bloc.descriptionCtl,
  114. maxLines: 1,
  115. hint: 'Mô tả',
  116. ),
  117. ),
  118. SizedBox(
  119. height: 8,
  120. ),
  121. ValueListenableBuilder<DateTime>(
  122. valueListenable: bloc.actionDate,
  123. builder: (context, actionDate, _) {
  124. return ItemColumnWidget(
  125. title: 'Ngày cập nhập',
  126. child: DatePickerWidget(
  127. initDateTime: actionDate,
  128. onUpdateDateTime: (selectedDate) {
  129. if (selectedDate != null) {
  130. bloc.actionDate.value = selectedDate;
  131. }
  132. },
  133. ),
  134. );
  135. },
  136. ),
  137. SizedBox(
  138. height: 8,
  139. ),
  140. ItemColumnWidget(
  141. title: 'Vị trí',
  142. child: TextFieldNormal(
  143. controller: bloc.locationCtl,
  144. maxLines: 1,
  145. hint: 'Vị trí',
  146. ),
  147. ),
  148. const SizedBox(
  149. height: 16,
  150. ),
  151. ],
  152. ),
  153. ),
  154. );
  155. }
  156. }