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.

137 lines
4.5KB

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