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.

147 lines
4.9KB

  1. import 'package:auto_size_text/auto_size_text.dart';
  2. import 'package:cached_network_image/cached_network_image.dart';
  3. import 'package:farm_tpf/custom_model/ActionType.dart';
  4. import 'package:farm_tpf/data/repository/repository.dart';
  5. import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart';
  6. import 'package:farm_tpf/presentation/screens/actions/environment_update/sc_edit_action_environment_update.dart';
  7. import 'package:farm_tpf/presentation/screens/actions/sc_action.dart';
  8. import 'package:farm_tpf/presentation/screens/plot_detail/bloc/cubit/plot_action_type_cubit.dart';
  9. import 'package:farm_tpf/utils/const_assets.dart';
  10. import 'package:farm_tpf/utils/const_color.dart';
  11. import 'package:farm_tpf/utils/const_common.dart';
  12. import 'package:flutter/material.dart';
  13. import 'package:flutter_bloc/flutter_bloc.dart';
  14. import 'package:get/get.dart';
  15. class PlotActionScreen extends StatefulWidget {
  16. final int cropId;
  17. final String cropCode;
  18. final int cropType;
  19. PlotActionScreen({this.cropId, this.cropCode, this.cropType});
  20. @override
  21. _PlotActionScreenState createState() => _PlotActionScreenState();
  22. }
  23. class _PlotActionScreenState extends State<PlotActionScreen>
  24. with AutomaticKeepAliveClientMixin {
  25. List<ActionType> actions = <ActionType>[];
  26. @override
  27. void initState() {
  28. super.initState();
  29. }
  30. @override
  31. void dispose() {
  32. super.dispose();
  33. }
  34. Widget _createActionButtons(ActionType actionType, BuildContext _context) {
  35. return GestureDetector(
  36. onTap: () {
  37. if (actionType.name == 'ACTIVE_TYPE_UPDATE_ENV') {
  38. Get.to(EditActionEnvironmentUpdate(
  39. cropId: widget.cropId,
  40. activityId: -1,
  41. isEdit: false,
  42. ));
  43. } else {
  44. Get.to(ActionScreen(
  45. cropId: widget.cropId,
  46. idAction: actionType.id,
  47. title: actionType.description,
  48. activityType: actionType.name,
  49. activityId: -1,
  50. isEdit: false,
  51. ));
  52. }
  53. },
  54. child: Container(
  55. margin: EdgeInsets.all(8),
  56. padding: EdgeInsets.all(4),
  57. decoration: BoxDecoration(
  58. border: Border.all(color: Colors.grey, width: 0.1),
  59. color: Colors.white,
  60. borderRadius: BorderRadius.all(Radius.circular(8.0)),
  61. boxShadow: <BoxShadow>[
  62. BoxShadow(
  63. color: AppColors.GRAY1.withOpacity(0.2),
  64. offset: Offset(1.1, 1.1),
  65. blurRadius: 4.0),
  66. ],
  67. ),
  68. child: Column(
  69. mainAxisAlignment: MainAxisAlignment.center,
  70. crossAxisAlignment: CrossAxisAlignment.center,
  71. children: [
  72. Expanded(
  73. flex: 1,
  74. child: SizedBox(
  75. width: Get.width / 10,
  76. height: Get.height / 10,
  77. child: CachedNetworkImage(
  78. imageUrl:
  79. '${ConstCommon.baseImageUrl}${actionType.urlLogo}',
  80. placeholder: (context, url) => Icon(
  81. Icons.broken_image,
  82. color: Colors.grey[300],
  83. ),
  84. errorWidget: (context, url, error) => Image.asset(
  85. AppAssets.logo,
  86. ),
  87. ),
  88. ),
  89. ),
  90. Expanded(
  91. flex: 1,
  92. child: Align(
  93. alignment: Alignment.center,
  94. child: AutoSizeText(
  95. actionType.description,
  96. textAlign: TextAlign.center,
  97. style: TextStyle(
  98. fontWeight: FontWeight.bold,
  99. fontSize: 13,
  100. color: AppColors.BLACK2,
  101. ),
  102. maxLines: 2,
  103. ),
  104. ),
  105. ),
  106. ],
  107. ),
  108. ));
  109. }
  110. @override
  111. Widget build(BuildContext context) {
  112. return BlocProvider(
  113. create: (contex) => PlotActionTypeCubit(Repository())
  114. ..getAllActionTypes(widget.cropType),
  115. child: BlocBuilder<PlotActionTypeCubit, PlotActionTypeState>(
  116. builder: (context, state) {
  117. if (state is PlotActionTypeLoading) {
  118. return LoadingListPage();
  119. } else if (state is PlotActionTypeSuccess) {
  120. return GridView.count(
  121. shrinkWrap: true,
  122. crossAxisCount: 3,
  123. children: state.actionTypes.map(
  124. (item) {
  125. return _createActionButtons(item, context);
  126. },
  127. ).toList());
  128. } else if (state is PlotActionTypeError) {
  129. return Center(child: Text(state.error));
  130. } else {
  131. //init
  132. return Container();
  133. }
  134. },
  135. ));
  136. }
  137. @override
  138. bool get wantKeepAlive => true;
  139. }