|
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:farm_tpf/custom_model/ActionType.dart';
- import 'package:farm_tpf/data/repository/repository.dart';
- import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart';
- import 'package:farm_tpf/presentation/screens/actions/sc_action.dart';
- import 'package:farm_tpf/presentation/screens/plot_detail/bloc/cubit/plot_action_type_cubit.dart';
- import 'package:farm_tpf/utils/const_assets.dart';
- import 'package:farm_tpf/utils/const_color.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_bloc/flutter_bloc.dart';
- import 'package:get/get.dart';
-
- class PlotActionScreen extends StatefulWidget {
- final int cropId;
- final String cropCode;
- final int cropType;
- PlotActionScreen({this.cropId, this.cropCode, this.cropType});
- @override
- _PlotActionScreenState createState() => _PlotActionScreenState();
- }
-
- class _PlotActionScreenState extends State<PlotActionScreen>
- with AutomaticKeepAliveClientMixin {
- List<ActionType> actions = <ActionType>[];
-
- @override
- void initState() {
- super.initState();
- // _initActionButtons();
- }
-
- @override
- void dispose() {
- super.dispose();
- }
-
- // _initActionButtons() {
- // //type: 0- Trồng, 1- ướm
- // if (widget.cropType == 1) {
- // actions.add(ActionType(
- // plot_action_nursery,
- // EditActionNurseryScreen(
- // cropId: widget.cropId,
- // ),
- // AppAssets.icActionNursery));
- // } else if (widget.cropType == 0) {
- // actions.add(ActionType(
- // plot_action_plant,
- // EditActionPlantScreen(
- // cropId: widget.cropId,
- // ),
- // AppAssets.icActionPlant));
- // }
-
- // actions.add(ActionType(
- // plot_action_crop_status,
- // EditActionCropStatusScreen(
- // cropId: widget.cropId,
- // ),
- // AppAssets.icActionCropStatus));
- // actions.add(ActionType(
- // plot_action_environment_update,
- // EditActionEnvironmentUpdate(
- // cropId: widget.cropId,
- // ),
- // AppAssets.icActionEnvironment));
- // actions.add(ActionType(
- // plot_action_dung,
- // EditActionDungScreen(
- // cropId: widget.cropId,
- // ),
- // AppAssets.icActionDung));
- // actions.add(ActionType(
- // plot_action_spraying,
- // EditActionSprayingScreen(
- // cropId: widget.cropId,
- // ),
- // AppAssets.icActionSpraying));
- // actions.add(ActionType(
- // plot_action_disease,
- // EditActionDiseaseScreen(
- // cropId: widget.cropId,
- // ),
- // AppAssets.icActionDisease));
- // actions.add(ActionType(
- // plot_action_use_water,
- // EditActionUseWaterScreen(
- // cropId: widget.cropId,
- // ),
- // AppAssets.icActionUseWater));
- // actions.add(ActionType(
- // plot_action_other,
- // EditActionOtherScreen(
- // cropId: widget.cropId,
- // ),
- // AppAssets.icActionOther));
- // actions.add(ActionType(
- // plot_action_harvest,
- // EditActionHarvestScreen(
- // cropId: widget.cropId,
- // ),
- // AppAssets.icActionHarvest));
- // actions.add(ActionType(
- // plot_action_finish,
- // EditActionEndScreen(
- // cropId: widget.cropId,
- // ),
- // AppAssets.icActionEnd));
- // }
-
- Widget _createActionButtons(ActionType actionType, BuildContext _context) {
- return GestureDetector(
- onTap: () {
- Get.to(ActionScreen(
- cropId: widget.cropId,
- idAction: actionType.id,
- title: actionType.description,
- activityType: actionType.name,
- activityId: -1,
- isEdit: false,
- ));
- },
- child: Container(
- margin: EdgeInsets.all(8),
- decoration: BoxDecoration(
- border: Border.all(color: Colors.grey, width: 0.1),
- color: Colors.white,
- borderRadius: BorderRadius.all(Radius.circular(8.0)),
- boxShadow: <BoxShadow>[
- BoxShadow(
- color: AppColors.GRAY1.withOpacity(0.2),
- offset: Offset(1.1, 1.1),
- blurRadius: 4.0),
- ],
- ),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- 1 == 1
- ? Image.asset(
- AppAssets.logo,
- width: Get.width / 9,
- height: Get.width / 9,
- )
- : CachedNetworkImage(
- imageUrl: "http://via.placeholder.com/350x150",
- placeholder: (context, url) =>
- CircularProgressIndicator(),
- errorWidget: (context, url, error) => Icon(Icons.error),
- ),
- Text(
- actionType.description,
- textAlign: TextAlign.center,
- style: TextStyle(
- fontWeight: FontWeight.bold,
- fontSize: 13,
- color: AppColors.BLACK2,
- ),
- ),
- ],
- ),
- ));
- }
-
- @override
- Widget build(BuildContext context) {
- return BlocProvider(
- create: (contex) => PlotActionTypeCubit(Repository())
- ..getAllActionTypes(widget.cropType),
- child: BlocBuilder<PlotActionTypeCubit, PlotActionTypeState>(
- builder: (context, state) {
- if (state is PlotActionTypeLoading) {
- return LoadingListPage();
- } else if (state is PlotActionTypeSuccess) {
- return GridView.count(
- shrinkWrap: true,
- crossAxisCount: 3,
- children: state.actionTypes.map(
- (item) {
- return _createActionButtons(item, context);
- },
- ).toList());
- } else if (state is PlotActionTypeError) {
- return Center(child: Text(state.error));
- } else {
- //init
- return Container();
- }
- },
- ));
- }
-
- @override
- bool get wantKeepAlive => true;
- }
|