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.

192 lines
6.1KB

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