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.

179 lines
5.7KB

  1. import 'package:farm_tpf/presentation/screens/actions/crop_status/sc_edit_action_crop_status.dart';
  2. import 'package:farm_tpf/presentation/screens/actions/disease/sc_edit_action_disease.dart';
  3. import 'package:farm_tpf/presentation/screens/actions/dung/sc_edit_action_dung.dart';
  4. import 'package:farm_tpf/presentation/screens/actions/end/sc_edit_action_end.dart';
  5. import 'package:farm_tpf/presentation/screens/actions/environment_update/sc_edit_action_environment_update.dart';
  6. import 'package:farm_tpf/presentation/screens/actions/harvest/sc_edit_action_harvest.dart';
  7. import 'package:farm_tpf/presentation/screens/actions/nursery/sc_edit_action_nursery.dart';
  8. import 'package:farm_tpf/presentation/screens/actions/other/sc_edit_action_other.dart';
  9. import 'package:farm_tpf/presentation/screens/actions/plant/sc_edit_action_plant.dart';
  10. import 'package:farm_tpf/presentation/screens/actions/spraying/sc_edit_action_spraying.dart';
  11. import 'package:farm_tpf/presentation/screens/actions/use_water/sc_edit_action_user_water.dart';
  12. import 'package:farm_tpf/utils/const_assets.dart';
  13. import 'package:farm_tpf/utils/const_color.dart';
  14. import 'package:farm_tpf/utils/const_string.dart';
  15. import 'package:flutter/material.dart';
  16. import 'package:get/get.dart';
  17. class PlotActionScreen extends StatefulWidget {
  18. int? cropId;
  19. String? cropCode;
  20. int? cropType;
  21. PlotActionScreen({this.cropId, this.cropCode, this.cropType});
  22. @override
  23. _PlotActionScreenState createState() => _PlotActionScreenState();
  24. }
  25. class _PlotActionScreenState extends State<PlotActionScreen> with AutomaticKeepAliveClientMixin {
  26. List<ActionType> actions = <ActionType>[];
  27. @override
  28. void initState() {
  29. super.initState();
  30. _initActionButtons();
  31. }
  32. @override
  33. void dispose() {
  34. super.dispose();
  35. }
  36. _initActionButtons() {
  37. //type: 0- Trồng, 1- ướm
  38. if (widget.cropType == 1) {
  39. actions.add(ActionType(
  40. plot_action_nursery,
  41. EditActionNurseryScreen(
  42. cropId: widget.cropId ?? -1,
  43. ),
  44. AppAssets.icActionNursery));
  45. } else if (widget.cropType == 0) {
  46. actions.add(ActionType(
  47. plot_action_plant,
  48. EditActionPlantScreen(
  49. cropId: widget.cropId ?? -1,
  50. ),
  51. AppAssets.icActionPlant));
  52. }
  53. actions.add(ActionType(
  54. plot_action_crop_status,
  55. EditActionCropStatusScreen(
  56. cropId: widget.cropId ?? -1,
  57. ),
  58. AppAssets.icActionCropStatus));
  59. actions.add(ActionType(
  60. plot_action_environment_update,
  61. EditActionEnvironmentUpdate(
  62. cropId: widget.cropId ?? -1,
  63. ),
  64. AppAssets.icActionEnvironment));
  65. actions.add(ActionType(
  66. plot_action_dung,
  67. EditActionDungScreen(
  68. cropId: widget.cropId ?? -1,
  69. ),
  70. AppAssets.icActionDung));
  71. actions.add(ActionType(
  72. plot_action_spraying,
  73. EditActionSprayingScreen(
  74. cropId: widget.cropId ?? -1,
  75. ),
  76. AppAssets.icActionSpraying));
  77. actions.add(ActionType(
  78. plot_action_disease,
  79. EditActionDiseaseScreen(
  80. cropId: widget.cropId ?? -1,
  81. ),
  82. AppAssets.icActionDisease));
  83. actions.add(ActionType(
  84. plot_action_use_water,
  85. EditActionUseWaterScreen(
  86. cropId: widget.cropId ?? -1,
  87. ),
  88. AppAssets.icActionUseWater));
  89. actions.add(ActionType(
  90. plot_action_other,
  91. EditActionOtherScreen(
  92. cropId: widget.cropId ?? -1,
  93. ),
  94. AppAssets.icActionOther));
  95. actions.add(ActionType(
  96. plot_action_harvest,
  97. EditActionHarvestScreen(
  98. cropId: widget.cropId ?? -1,
  99. ),
  100. AppAssets.icActionHarvest));
  101. actions.add(ActionType(
  102. plot_action_finish,
  103. EditActionEndScreen(
  104. cropId: widget.cropId ?? -1,
  105. ),
  106. AppAssets.icActionEnd));
  107. }
  108. Widget _createActionButtons(ActionType actionType, BuildContext _context) {
  109. return GestureDetector(
  110. onTap: () {
  111. Navigator.of(context).push(MaterialPageRoute(builder: (context) => actionType.listScreen));
  112. },
  113. child: Container(
  114. margin: const EdgeInsets.all(8),
  115. decoration: BoxDecoration(
  116. border: Border.all(color: Colors.grey, width: 0.1),
  117. color: Colors.white,
  118. borderRadius: const BorderRadius.all(Radius.circular(8.0)),
  119. boxShadow: <BoxShadow>[
  120. BoxShadow(color: AppColors.GRAY1.withOpacity(0.2), offset: const Offset(1.1, 1.1), blurRadius: 4.0),
  121. ],
  122. ),
  123. child: Column(
  124. mainAxisAlignment: MainAxisAlignment.center,
  125. crossAxisAlignment: CrossAxisAlignment.center,
  126. children: [
  127. Image.asset(
  128. actionType.icon,
  129. width: Get.width / 9,
  130. height: Get.width / 9,
  131. ),
  132. Text(
  133. actionType.actionName,
  134. textAlign: TextAlign.center,
  135. style: TextStyle(
  136. fontWeight: FontWeight.bold,
  137. fontSize: 13,
  138. color: AppColors.BLACK2,
  139. ),
  140. ),
  141. ],
  142. ),
  143. ));
  144. }
  145. @override
  146. Widget build(BuildContext context) {
  147. return GridView.count(
  148. shrinkWrap: true,
  149. crossAxisCount: 3,
  150. children: actions.map(
  151. (item) {
  152. return _createActionButtons(item, context);
  153. },
  154. ).toList());
  155. }
  156. @override
  157. bool get wantKeepAlive => true;
  158. }
  159. class ActionType {
  160. Widget listScreen = SizedBox();
  161. String actionName = '';
  162. String icon = '';
  163. ActionType(String actionName, Widget listScreen, String icon) {
  164. this.actionName = actionName;
  165. this.listScreen = listScreen;
  166. this.icon = icon;
  167. }
  168. }