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.

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