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.

190 lines
6.0KB

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