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.

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