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.

194 lines
6.2KB

  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. },
  113. child: Container(
  114. margin: EdgeInsets.all(8),
  115. decoration: BoxDecoration(
  116. border: Border.all(color: Colors.grey, width: 0.1),
  117. color: Colors.white,
  118. borderRadius: BorderRadius.all(Radius.circular(8.0)),
  119. boxShadow: <BoxShadow>[
  120. BoxShadow(
  121. color: AppColors.GRAY1.withOpacity(0.2),
  122. offset: Offset(1.1, 1.1),
  123. blurRadius: 4.0),
  124. ],
  125. ),
  126. child: Column(
  127. mainAxisAlignment: MainAxisAlignment.center,
  128. crossAxisAlignment: CrossAxisAlignment.center,
  129. children: [
  130. 1 == 1
  131. ? Image.asset(
  132. AppAssets.logo,
  133. width: Get.width / 9,
  134. height: Get.width / 9,
  135. )
  136. : CachedNetworkImage(
  137. imageUrl: "http://via.placeholder.com/350x150",
  138. placeholder: (context, url) =>
  139. CircularProgressIndicator(),
  140. errorWidget: (context, url, error) => Icon(Icons.error),
  141. ),
  142. Text(
  143. actionType.description,
  144. textAlign: TextAlign.center,
  145. style: TextStyle(
  146. fontWeight: FontWeight.bold,
  147. fontSize: 13,
  148. color: AppColors.BLACK2,
  149. ),
  150. ),
  151. ],
  152. ),
  153. ));
  154. }
  155. @override
  156. Widget build(BuildContext context) {
  157. return BlocProvider(
  158. create: (contex) => PlotActionTypeCubit(Repository())
  159. ..getAllActionTypes(widget.cropType),
  160. child: BlocBuilder<PlotActionTypeCubit, PlotActionTypeState>(
  161. builder: (context, state) {
  162. if (state is PlotActionTypeLoading) {
  163. return LoadingListPage();
  164. } else if (state is PlotActionTypeSuccess) {
  165. return GridView.count(
  166. shrinkWrap: true,
  167. crossAxisCount: 3,
  168. children: state.actionTypes.map(
  169. (item) {
  170. return _createActionButtons(item, context);
  171. },
  172. ).toList());
  173. } else if (state is PlotActionTypeError) {
  174. return Center(child: Text(state.error));
  175. } else {
  176. //init
  177. return Container();
  178. }
  179. },
  180. ));
  181. }
  182. @override
  183. bool get wantKeepAlive => true;
  184. }