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.

138 lines
4.6KB

  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. color: Colors.grey[300],
  74. ),
  75. errorWidget: (context, url, error) => Image.asset(
  76. AppAssets.logo,
  77. ),
  78. ),
  79. ),
  80. ),
  81. Expanded(
  82. flex: 1,
  83. child: Align(
  84. alignment: Alignment.center,
  85. child: AutoSizeText(
  86. actionType.description,
  87. textAlign: TextAlign.center,
  88. style: TextStyle(
  89. fontWeight: FontWeight.bold,
  90. fontSize: 13,
  91. color: AppColors.BLACK2,
  92. ),
  93. maxLines: 2,
  94. ),
  95. ),
  96. ),
  97. ],
  98. ),
  99. ));
  100. }
  101. @override
  102. Widget build(BuildContext context) {
  103. return BlocProvider(
  104. create: (contex) => PlotActionTypeCubit(Repository())
  105. ..getAllActionTypes(widget.cropType),
  106. child: BlocBuilder<PlotActionTypeCubit, PlotActionTypeState>(
  107. builder: (context, state) {
  108. if (state is PlotActionTypeLoading) {
  109. return LoadingListPage();
  110. } else if (state is PlotActionTypeSuccess) {
  111. return GridView.count(
  112. shrinkWrap: true,
  113. crossAxisCount: 3,
  114. children: state.actionTypes.map(
  115. (item) {
  116. return _createActionButtons(item, context);
  117. },
  118. ).toList());
  119. } else if (state is PlotActionTypeError) {
  120. return Center(child: Text(state.error));
  121. } else {
  122. //init
  123. return Container();
  124. }
  125. },
  126. ));
  127. }
  128. @override
  129. bool get wantKeepAlive => true;
  130. }