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.

197 lines
6.3KB

  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:farm_tpf/custom_model/ActionType.dart';
  3. import 'package:farm_tpf/data/repository/repository.dart';
  4. import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart';
  5. import 'package:farm_tpf/presentation/screens/actions/sc_action.dart';
  6. import 'package:farm_tpf/presentation/screens/plot_detail/bloc/cubit/plot_action_type_cubit.dart';
  7. import 'package:farm_tpf/utils/const_assets.dart';
  8. import 'package:farm_tpf/utils/const_color.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:flutter_bloc/flutter_bloc.dart';
  11. import 'package:get/get.dart';
  12. class PlotActionScreen extends StatefulWidget {
  13. final int cropId;
  14. final String cropCode;
  15. final int cropType;
  16. PlotActionScreen({this.cropId, this.cropCode, this.cropType});
  17. @override
  18. _PlotActionScreenState createState() => _PlotActionScreenState();
  19. }
  20. class _PlotActionScreenState extends State<PlotActionScreen>
  21. with AutomaticKeepAliveClientMixin {
  22. List<ActionType> actions = <ActionType>[];
  23. @override
  24. void initState() {
  25. super.initState();
  26. // _initActionButtons();
  27. }
  28. @override
  29. void dispose() {
  30. super.dispose();
  31. }
  32. // _initActionButtons() {
  33. // //type: 0- Trồng, 1- ướm
  34. // if (widget.cropType == 1) {
  35. // actions.add(ActionType(
  36. // plot_action_nursery,
  37. // EditActionNurseryScreen(
  38. // cropId: widget.cropId,
  39. // ),
  40. // AppAssets.icActionNursery));
  41. // } else if (widget.cropType == 0) {
  42. // actions.add(ActionType(
  43. // plot_action_plant,
  44. // EditActionPlantScreen(
  45. // cropId: widget.cropId,
  46. // ),
  47. // AppAssets.icActionPlant));
  48. // }
  49. // actions.add(ActionType(
  50. // plot_action_crop_status,
  51. // EditActionCropStatusScreen(
  52. // cropId: widget.cropId,
  53. // ),
  54. // AppAssets.icActionCropStatus));
  55. // actions.add(ActionType(
  56. // plot_action_environment_update,
  57. // EditActionEnvironmentUpdate(
  58. // cropId: widget.cropId,
  59. // ),
  60. // AppAssets.icActionEnvironment));
  61. // actions.add(ActionType(
  62. // plot_action_dung,
  63. // EditActionDungScreen(
  64. // cropId: widget.cropId,
  65. // ),
  66. // AppAssets.icActionDung));
  67. // actions.add(ActionType(
  68. // plot_action_spraying,
  69. // EditActionSprayingScreen(
  70. // cropId: widget.cropId,
  71. // ),
  72. // AppAssets.icActionSpraying));
  73. // actions.add(ActionType(
  74. // plot_action_disease,
  75. // EditActionDiseaseScreen(
  76. // cropId: widget.cropId,
  77. // ),
  78. // AppAssets.icActionDisease));
  79. // actions.add(ActionType(
  80. // plot_action_use_water,
  81. // EditActionUseWaterScreen(
  82. // cropId: widget.cropId,
  83. // ),
  84. // AppAssets.icActionUseWater));
  85. // actions.add(ActionType(
  86. // plot_action_other,
  87. // EditActionOtherScreen(
  88. // cropId: widget.cropId,
  89. // ),
  90. // AppAssets.icActionOther));
  91. // actions.add(ActionType(
  92. // plot_action_harvest,
  93. // EditActionHarvestScreen(
  94. // cropId: widget.cropId,
  95. // ),
  96. // AppAssets.icActionHarvest));
  97. // actions.add(ActionType(
  98. // plot_action_finish,
  99. // EditActionEndScreen(
  100. // cropId: widget.cropId,
  101. // ),
  102. // AppAssets.icActionEnd));
  103. // }
  104. Widget _createActionButtons(ActionType actionType, BuildContext _context) {
  105. return GestureDetector(
  106. onTap: () {
  107. Get.to(ActionScreen(
  108. cropId: widget.cropId,
  109. idAction: actionType.id,
  110. title: actionType.description,
  111. activityType: actionType.name,
  112. activityId: -1,
  113. isEdit: false,
  114. ));
  115. },
  116. child: Container(
  117. margin: EdgeInsets.all(8),
  118. decoration: BoxDecoration(
  119. border: Border.all(color: Colors.grey, width: 0.1),
  120. color: Colors.white,
  121. borderRadius: BorderRadius.all(Radius.circular(8.0)),
  122. boxShadow: <BoxShadow>[
  123. BoxShadow(
  124. color: AppColors.GRAY1.withOpacity(0.2),
  125. offset: Offset(1.1, 1.1),
  126. blurRadius: 4.0),
  127. ],
  128. ),
  129. child: Column(
  130. mainAxisAlignment: MainAxisAlignment.center,
  131. crossAxisAlignment: CrossAxisAlignment.center,
  132. children: [
  133. 1 == 1
  134. ? Image.asset(
  135. AppAssets.logo,
  136. width: Get.width / 9,
  137. height: Get.width / 9,
  138. )
  139. : CachedNetworkImage(
  140. imageUrl: "http://via.placeholder.com/350x150",
  141. placeholder: (context, url) =>
  142. CircularProgressIndicator(),
  143. errorWidget: (context, url, error) => Icon(Icons.error),
  144. ),
  145. Text(
  146. actionType.description,
  147. textAlign: TextAlign.center,
  148. style: TextStyle(
  149. fontWeight: FontWeight.bold,
  150. fontSize: 13,
  151. color: AppColors.BLACK2,
  152. ),
  153. ),
  154. ],
  155. ),
  156. ));
  157. }
  158. @override
  159. Widget build(BuildContext context) {
  160. return BlocProvider(
  161. create: (contex) => PlotActionTypeCubit(Repository())
  162. ..getAllActionTypes(widget.cropType),
  163. child: BlocBuilder<PlotActionTypeCubit, PlotActionTypeState>(
  164. builder: (context, state) {
  165. if (state is PlotActionTypeLoading) {
  166. return LoadingListPage();
  167. } else if (state is PlotActionTypeSuccess) {
  168. return GridView.count(
  169. shrinkWrap: true,
  170. crossAxisCount: 3,
  171. children: state.actionTypes.map(
  172. (item) {
  173. return _createActionButtons(item, context);
  174. },
  175. ).toList());
  176. } else if (state is PlotActionTypeError) {
  177. return Center(child: Text(state.error));
  178. } else {
  179. //init
  180. return Container();
  181. }
  182. },
  183. ));
  184. }
  185. @override
  186. bool get wantKeepAlive => true;
  187. }