Browse Source

ui action button screen

master
daivph 5 years ago
parent
commit
43e3ad2a23
13 changed files with 83 additions and 383 deletions
  1. BIN
      assets/png/icActionCropStatus.png
  2. BIN
      assets/png/icActionDisease.png
  3. BIN
      assets/png/icActionDung.png
  4. BIN
      assets/png/icActionEnd.png
  5. BIN
      assets/png/icActionEnvironment.png
  6. BIN
      assets/png/icActionHarvest.png
  7. BIN
      assets/png/icActionNursery.png
  8. BIN
      assets/png/icActionOther.png
  9. BIN
      assets/png/icActionPlant.png
  10. BIN
      assets/png/icActionSpraying.png
  11. BIN
      assets/png/icActionUseWater.png
  12. +72
    -383
      lib/presentation/screens/plot_detail/sc_plot_action.dart
  13. +11
    -0
      lib/utils/const_assets.dart

BIN
assets/png/icActionCropStatus.png View File

Before After
Width: 256  |  Height: 256  |  Size: 4.1KB

BIN
assets/png/icActionDisease.png View File

Before After
Width: 256  |  Height: 256  |  Size: 8.4KB

BIN
assets/png/icActionDung.png View File

Before After
Width: 256  |  Height: 256  |  Size: 7.3KB

BIN
assets/png/icActionEnd.png View File

Before After
Width: 256  |  Height: 256  |  Size: 4.5KB

BIN
assets/png/icActionEnvironment.png View File

Before After
Width: 256  |  Height: 256  |  Size: 3.8KB

BIN
assets/png/icActionHarvest.png View File

Before After
Width: 256  |  Height: 256  |  Size: 8.8KB

BIN
assets/png/icActionNursery.png View File

Before After
Width: 256  |  Height: 256  |  Size: 4.3KB

BIN
assets/png/icActionOther.png View File

Before After
Width: 256  |  Height: 256  |  Size: 4.5KB

BIN
assets/png/icActionPlant.png View File

Before After
Width: 256  |  Height: 256  |  Size: 6.5KB

BIN
assets/png/icActionSpraying.png View File

Before After
Width: 256  |  Height: 256  |  Size: 4.0KB

BIN
assets/png/icActionUseWater.png View File

Before After
Width: 256  |  Height: 256  |  Size: 2.7KB

+ 72
- 383
lib/presentation/screens/plot_detail/sc_plot_action.dart View File

@@ -1,28 +1,18 @@
import 'package:farm_tpf/custom_model/CropPlot.dart';
import 'package:farm_tpf/data/repository/repository.dart';
import 'package:farm_tpf/presentation/custom_widgets/bottom_loader.dart';
import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart';
import 'package:farm_tpf/presentation/screens/actions/crop_status/sc_edit_action_crop_status.dart';
import 'package:farm_tpf/presentation/screens/actions/disease/sc_edit_action_disease.dart';
import 'package:farm_tpf/presentation/screens/actions/dung/sc_edit_action_dung.dart';
import 'package:farm_tpf/presentation/screens/actions/end/sc_edit_action_end.dart';
import 'package:farm_tpf/presentation/screens/actions/environment_update/sc_edit_action_environment_update.dart';
import 'package:farm_tpf/presentation/screens/actions/harvest/sc_edit_action_harvest.dart';
import 'package:farm_tpf/presentation/screens/actions/harvest_process/sc_edit_action_harvest_process.dart';
import 'package:farm_tpf/presentation/screens/actions/nursery/sc_edit_action_nursery.dart';
import 'package:farm_tpf/presentation/screens/actions/other/sc_edit_action_other.dart';
import 'package:farm_tpf/presentation/screens/actions/packing/sc_edit_action_packing.dart';
import 'package:farm_tpf/presentation/screens/actions/plant/sc_edit_action_plant.dart';
import 'package:farm_tpf/presentation/screens/actions/sell/sc_edit_action_sell.dart';
import 'package:farm_tpf/presentation/screens/actions/spraying/sc_edit_action_spraying.dart';
import 'package:farm_tpf/presentation/screens/actions/use_water/sc_edit_action_user_water.dart';
import 'package:farm_tpf/presentation/screens/plot/sc_plot.dart';
import 'package:farm_tpf/presentation/screens/plot_detail/bloc/plot_detail_bloc.dart';
import 'package:farm_tpf/utils/const_assets.dart';
import 'package:farm_tpf/utils/const_color.dart';
import 'package:farm_tpf/utils/const_string.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:farm_tpf/utils/formatter.dart';
import 'package:get/get.dart';

class PlotActionScreen extends StatefulWidget {
@@ -37,19 +27,15 @@ class PlotActionScreen extends StatefulWidget {
class _PlotActionScreenState extends State<PlotActionScreen>
with AutomaticKeepAliveClientMixin {
List<ActionType> actions = new List<ActionType>();
ScrollController _scrollController;
var blocPlotDetail = PlotDetailBloc(repository: Repository());

@override
void initState() {
super.initState();
_scrollController = ScrollController()..addListener(() => setState(() {}));
_initActionButtons();
}

@override
void dispose() {
blocPlotDetail.close();
super.dispose();
}

@@ -60,435 +46,138 @@ class _PlotActionScreenState extends State<PlotActionScreen>
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 BlocBuilder<PlotDetailBloc, PlotDetailState>(
cubit: blocPlotDetail,
builder: (context, state) {
return GestureDetector(
onTap: () {
Navigator.of(context)
.push(MaterialPageRoute(
builder: (context) => actionType.listScreen))
.then((value) {
if (value != null) {
try {
blocPlotDetail.add(OnRefresh(cropId: widget.cropId));
} catch (e) {
print(e);
}
}
});
},
child: Container(
margin: EdgeInsets.all(2.5),
decoration: BoxDecoration(
color: AppColors.WHITE,
borderRadius: BorderRadius.all(Radius.circular(4.0)),
boxShadow: <BoxShadow>[
BoxShadow(
color: AppColors.GRAY1.withOpacity(0.2),
offset: Offset(1.1, 1.1),
blurRadius: 4.0),
],
return GestureDetector(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => actionType.listScreen));
},
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: [
Image.asset(
actionType.icon,
width: Get.width / 6,
height: Get.width / 6,
),
Text(
actionType.actionName,
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: AppColors.BLACK2,
),
child: Align(
alignment: Alignment.center,
child: Text(
actionType.actionName,
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 11,
color: AppColors.BLACK2,
),
)),
));
});
}

bool _showTitle(BuildContext context) {
var kExpandedHeight = MediaQuery.of(context).size.width * 0.625 + 24;
return _scrollController.hasClients &&
_scrollController.offset > kExpandedHeight - kToolbarHeight;
}

@override
Widget build(BuildContext context) {
return BlocBuilder<PlotDetailBloc, PlotDetailState>(
cubit: blocPlotDetail,
builder: (context, state) {
return NestedScrollView(
controller: _scrollController,
headerSliverBuilder: (context, innerBoxScrolled) => [
SliverAppBar(
floating: false,
pinned: false,
backgroundColor: Colors.white,
leading: Container(),
title: null,
// title: _showTitle(context) ? Text(plot_detail_title) : null,
//Height flexibleSpace : WidthScreen /2 * 4/16 * 5(row) + 8(space) *3
expandedHeight:
MediaQuery.of(context).size.width * 0.625 + 24,
flexibleSpace: _showTitle(context)
? null
: BlocBuilder<PlotDetailBloc, PlotDetailState>(
cubit: blocPlotDetail,
builder: (contextB, state) {
return FlexibleSpaceBar(
centerTitle: true,
title: GridView.count(
shrinkWrap: true,
crossAxisCount: 2,
childAspectRatio: 16 / 4,
children: actions.map(
(item) {
return _createActionButtons(
item, contextB);
},
).toList()),
);
})),
),
],
body: BlocBuilder<PlotDetailBloc, PlotDetailState>(
cubit: blocPlotDetail,
builder: (context, state) {
return InfinityView(
cropId: widget.cropId,
parentScroll: _scrollController,
plotDetailBloc: blocPlotDetail,
);
}),
);
});
}

@override
bool get wantKeepAlive => true;
}

class InfinityView extends StatefulWidget {
int cropId;
String cropCode;
ScrollController parentScroll;
PlotDetailBloc plotDetailBloc;
InfinityView(
{this.cropId,
this.cropCode,
@required this.parentScroll,
@required this.plotDetailBloc});
@override
_InfinityViewState createState() => _InfinityViewState();
}

class _InfinityViewState extends State<InfinityView> {
final _scrollController = ScrollController();
final _scrollThreshold = 250.0;
var heightOfActionButton = Get.width * 0.625 + 24;
var heightHeaderList = 44;
var heightListWithoutHeader = Get.height - (Get.width * 0.625 + 24) - 44;
var currentOffset = 0.0;

@override
void initState() {
widget.plotDetailBloc
.add(DataFetched(cropId: widget.cropId, cropCode: widget.cropCode));
_scrollController.addListener(() {
final maxScroll = _scrollController.position.maxScrollExtent;
final currentScroll = _scrollController.position.pixels;
if (maxScroll - currentScroll < _scrollThreshold) {
widget.plotDetailBloc
.add(DataFetched(cropId: widget.cropId, cropCode: widget.cropCode));
}
});
widget.parentScroll.addListener(() {
setState(() {
currentOffset = widget.parentScroll.offset;
heightListWithoutHeader = Get.height -
heightOfActionButton -
heightHeaderList +
currentOffset;
});
});
super.initState();
),
));
}

@override
Widget build(BuildContext context) {
return BlocBuilder<PlotDetailBloc, PlotDetailState>(
cubit: widget.plotDetailBloc,
builder: (context, state) {
if (state is PlotDetailFailure) {
return Center(child: Text(state.errorString));
}
if (state is PlotDetailSuccess) {
if (state.items.isEmpty) {
return Center(child: Text("Không có dữ liệu lịch sử canh tác"));
}
List<Activities> currentItems = List<Activities>.from(state.items);
return Scaffold(
body: RefreshIndicator(
child: Column(
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
color: AppColors.WHITE_50,
border: Border(
top: BorderSide(
width: 0.5, color: AppColors.DEFAULT),
bottom: BorderSide(
width: 0.5, color: AppColors.DEFAULT)),
),
child: Container(
child: Row(
children: [
Expanded(
child: Text(
plot_detail_title,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.normal),
)),
GestureDetector(
child: (0 == currentOffset)
? Icon(Icons.arrow_upward)
: Icon(Icons.arrow_downward_outlined),
onTap: () {
if (currentOffset == 0) {
widget.parentScroll.animateTo(
heightOfActionButton,
duration: Duration(milliseconds: 500),
curve: Curves.easeOut);
} else {
widget.parentScroll.animateTo(0.0,
duration: Duration(milliseconds: 500),
curve: Curves.easeOut);
}
}),
],
),
),
),
),
Expanded(
flex: heightListWithoutHeader ~/ heightHeaderList,
child: ListView.builder(
physics: AlwaysScrollableScrollPhysics(),
itemBuilder: (BuildContext context, int index) {
return index >= state.items.length
? BottomLoader()
: ItemInfinityWidget(
currentItems: currentItems,
item: state.items[index],
currentPage: state.page,
currentReachedMax: state.hasReachedMax);
},
itemCount: state.hasReachedMax
? state.items.length
: state.items.length + 1,
controller: _scrollController,
))
],
),
onRefresh: () async {
widget.plotDetailBloc.add(OnRefresh(
cropId: widget.cropId, cropCode: widget.cropCode));
}),
);
}
return Center(
child: LoadingListPage(),
);
},
);
}

@override
void dispose() {
_scrollController.dispose();
super.dispose();
return GridView.count(
shrinkWrap: true,
crossAxisCount: 2,
children: actions.map(
(item) {
return _createActionButtons(item, context);
},
).toList());
}
}

class ItemInfinityWidget extends StatelessWidget {
final List<Activities> currentItems;
final Activities item;
final int currentPage;
final bool currentReachedMax;

const ItemInfinityWidget(
{Key key,
@required this.currentItems,
@required this.item,
@required this.currentPage,
@required this.currentReachedMax})
: super(key: key);

@override
Widget build(BuildContext context) {
return GestureDetector(
child: Card(
child: ListTile(
title: Text(item.activityTypeDescription ?? ''),
subtitle: Text(item.executeDate.format_DDMMYY_HHmm()),
),
),
onTap: () {
if (item.activityTypeName == "ACTIVE_TYPE_NURSERY") {
Get.to(EditActionNurseryScreen(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
} else if (item.activityTypeName == "ACTIVE_TYPE_STATUS_CROP") {
Get.to(EditActionCropStatusScreen(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
} else if (item.activityTypeName == "ACTIVE_TYPE_UPDATE_ENV") {
Get.to(EditActionEnvironmentUpdate(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
} else if (item.activityTypeName ==
"ACTIVE_TYPE_PESTS_INVESTIGATION") {
Get.to(EditActionDiseaseScreen(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
} else if (item.activityTypeName == "ACTIVE_TYPE_USE_WATER") {
Get.to(EditActionUseWaterScreen(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
} else if (item.activityTypeName == "ACTIVE_TYPE_HARVEST") {
Get.to(EditActionHarvestScreen(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
} else if (item.activityTypeName == "ACTIVE_TYPE_PACKING") {
Get.to(EditActionPackingScreen(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
} else if (item.activityTypeName == "ACTIVE_TYPE_SELL") {
Get.to(EditActionSellScreen(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
} else if (item.activityTypeName == "ACTIVE_TYPE_END") {
Get.to(EditActionEndScreen(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
} else if (item.activityTypeName == "ACTIVE_TYPE_STATUS_GROW") {
Get.to(EditActionPlantScreen(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
} else if (item.activityTypeName == "ACTIVE_TYPE_MANURING") {
Get.to(EditActionDungScreen(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
} else if (item.activityTypeName == "ACTIVE_TYPE_SPRAY") {
Get.to(EditActionSprayingScreen(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
} else if (item.activityTypeName == "ACTIVE_TYPE_PROCESS") {
Get.to(EditActionHarvestProcessScreen(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
} else {
Get.to(EditActionOtherScreen(
cropId: item.cropId,
activityId: item.id,
isEdit: true,
));
}
});
}
bool get wantKeepAlive => true;
}

class ActionType {
Widget listScreen;
String actionName;
ActionType(String actionName, Widget listScreen) {
String icon;
ActionType(String actionName, Widget listScreen, String icon) {
this.actionName = actionName;
this.listScreen = listScreen;
this.icon = icon;
}
}

+ 11
- 0
lib/utils/const_assets.dart View File

@@ -3,4 +3,15 @@ class AppAssets {
static const logo = baseAssets + 'logo.png';
static const logoWithSlogan = baseAssets + 'logoWithSlogan.png';
static const tempImage = baseAssets + 'tempImage.png';
static const icActionNursery = baseAssets + 'icActionNursery.png';
static const icActionCropStatus = baseAssets + 'icActionCropStatus.png';
static const icActionDisease = baseAssets + 'icActionDisease.png';
static const icActionDung = baseAssets + 'icActionDung.png';
static const icActionEnd = baseAssets + 'icActionEnd.png';
static const icActionEnvironment = baseAssets + 'icActionEnvironment.png';
static const icActionHarvest = baseAssets + 'icActionHarvest.png';
static const icActionOther = baseAssets + 'icActionOther.png';
static const icActionPlant = baseAssets + 'icActionPlant.png';
static const icActionSpraying = baseAssets + 'icActionSpraying.png';
static const icActionUseWater = baseAssets + 'icActionUseWater.png';
}

Loading…
Cancel
Save