|
- import 'package:farm_tpf/authentication/authentication.dart';
- import 'package:farm_tpf/presentation/screens/notification/sc_notification.dart';
- import 'package:farm_tpf/presentation/screens/profile/sc_update_profile.dart';
- import 'package:farm_tpf/utils/const_color.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_bloc/flutter_bloc.dart';
-
- class HomeDrawer extends StatefulWidget {
- const HomeDrawer(
- {Key key,
- this.screenIndex,
- this.iconAnimationController,
- this.callBackIndex})
- : super(key: key);
-
- final AnimationController iconAnimationController;
- final DrawerIndex screenIndex;
- final Function(DrawerIndex) callBackIndex;
-
- @override
- _HomeDrawerState createState() => _HomeDrawerState();
- }
-
- class _HomeDrawerState extends State<HomeDrawer> {
- List<DrawerList> drawerList;
- @override
- void initState() {
- setdDrawerListArray();
- super.initState();
- }
-
- void setdDrawerListArray() {
- drawerList = <DrawerList>[
- DrawerList(
- index: DrawerIndex.ScanBarcode,
- labelName: "Quét mã QR",
- icon: Icon(Icons.scanner)),
- DrawerList(
- index: DrawerIndex.Home,
- labelName: 'Danh sách lô',
- icon: Icon(Icons.home),
- ),
- DrawerList(
- index: DrawerIndex.ControlDevice,
- labelName: 'Điều khiển thiết bị',
- icon: Icon(Icons.device_hub),
- )
- ];
- }
-
- @override
- Widget build(BuildContext context) {
- return Container(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.stretch,
- mainAxisAlignment: MainAxisAlignment.start,
- children: <Widget>[
- Container(
- width: double.infinity,
- padding: const EdgeInsets.only(top: 45.0),
- child: Container(
- padding: const EdgeInsets.all(16.0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.start,
- children: <Widget>[
- AnimatedBuilder(
- animation: widget.iconAnimationController,
- builder: (BuildContext context, Widget child) {
- return ScaleTransition(
- scale: AlwaysStoppedAnimation<double>(
- 1.0 - (widget.iconAnimationController.value) * 0.2),
- child: RotationTransition(
- turns: AlwaysStoppedAnimation<double>(Tween<double>(
- begin: 0.0, end: 24.0)
- .animate(CurvedAnimation(
- parent: widget.iconAnimationController,
- curve: Curves.fastOutSlowIn))
- .value /
- 360),
- child: Container(
- height: 100,
- width: 100,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(120),
- border: Border.all(
- width: 0.35, color: COLOR_CONST.DEFAULT),
- ),
- child: ClipRRect(
- borderRadius:
- const BorderRadius.all(Radius.circular(10.0)),
- child: FlutterLogo(
- size: 10,
- ),
- ),
- ),
- ),
- );
- },
- ),
- Padding(
- padding: const EdgeInsets.only(top: 8, left: 20),
- child: Text(
- 'Võ Phước Đại',
- style: TextStyle(
- fontWeight: FontWeight.w600,
- color: COLOR_CONST.GRAY1,
- fontSize: 18,
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- const SizedBox(
- height: 4,
- ),
- Divider(
- height: 1,
- color: COLOR_CONST.GRAY1,
- ),
- Expanded(
- child: ListView.builder(
- physics: const BouncingScrollPhysics(),
- padding: const EdgeInsets.all(0.0),
- itemCount: drawerList.length,
- itemBuilder: (BuildContext context, int index) {
- return inkwell(drawerList[index]);
- },
- ),
- ),
- Divider(
- height: 1,
- color: COLOR_CONST.GRAY1,
- ),
- Column(
- children: <Widget>[
- ListTile(
- title: Text(
- 'Thông báo',
- style: TextStyle(
- fontWeight: FontWeight.w600,
- fontSize: 16,
- ),
- textAlign: TextAlign.left,
- ),
- leading: Icon(
- Icons.notifications,
- color: Colors.black,
- ),
- onTap: () {
- Navigator.of(context).push(
- MaterialPageRoute(builder: (_) => NotificationScreen()));
- },
- ),
- SizedBox(
- height: 2.0,
- ),
- ListTile(
- title: Text(
- 'Cài đặt',
- style: TextStyle(
- fontWeight: FontWeight.w600,
- fontSize: 16,
- ),
- textAlign: TextAlign.left,
- ),
- leading: Icon(
- Icons.settings,
- color: Colors.black,
- ),
- onTap: () {
- Navigator.of(context).push(
- MaterialPageRoute(builder: (_) => UpdateProfileScreen()));
- },
- ),
- SizedBox(
- height: 2.0,
- ),
- ListTile(
- title: Text(
- 'Đăng xuất',
- style: TextStyle(
- fontWeight: FontWeight.w600,
- fontSize: 16,
- ),
- textAlign: TextAlign.left,
- ),
- leading: Icon(
- Icons.power_settings_new,
- color: Colors.red,
- ),
- onTap: () {
- _clickSignOut();
- },
- ),
- SizedBox(
- height: MediaQuery.of(context).padding.bottom,
- )
- ],
- ),
- ],
- ),
- );
- }
-
- Widget inkwell(DrawerList listData) {
- return Material(
- color: Colors.white,
- child: InkWell(
- splashColor: Colors.grey.withOpacity(0.1),
- highlightColor: Colors.transparent,
- onTap: () {
- navigationtoScreen(listData.index);
- },
- child: Stack(
- children: <Widget>[
- Container(
- padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
- child: Row(
- children: <Widget>[
- Container(
- width: 6.0,
- height: 46.0,
- ),
- const Padding(
- padding: EdgeInsets.all(4.0),
- ),
- listData.isAssetsImage
- ? Container(
- width: 24,
- height: 24,
- child: Image.asset(listData.imageName,
- color: widget.screenIndex == listData.index
- ? COLOR_CONST.DEFAULT
- : COLOR_CONST.BLACK),
- )
- : Icon(listData.icon.icon,
- color: widget.screenIndex == listData.index
- ? COLOR_CONST.DEFAULT
- : COLOR_CONST.BLACK),
- const Padding(
- padding: EdgeInsets.all(4.0),
- ),
- Text(
- listData.labelName,
- style: TextStyle(
- fontWeight: FontWeight.w500,
- fontSize: 16,
- color: widget.screenIndex == listData.index
- ? COLOR_CONST.DEFAULT
- : COLOR_CONST.BLACK,
- ),
- textAlign: TextAlign.left,
- ),
- ],
- ),
- ),
- widget.screenIndex == listData.index
- ? AnimatedBuilder(
- animation: widget.iconAnimationController,
- builder: (BuildContext context, Widget child) {
- return Transform(
- transform: Matrix4.translationValues(
- (MediaQuery.of(context).size.width * 0.75 - 64) *
- (1.0 -
- widget.iconAnimationController.value -
- 1.0),
- 0.0,
- 0.0),
- child: Padding(
- padding: EdgeInsets.only(top: 8, bottom: 8),
- child: Container(
- width:
- MediaQuery.of(context).size.width * 0.75 - 64,
- height: 46,
- decoration: BoxDecoration(
- color: COLOR_CONST.DEFAULT.withOpacity(0.2),
- borderRadius: new BorderRadius.only(
- topLeft: Radius.circular(0),
- topRight: Radius.circular(28),
- bottomLeft: Radius.circular(0),
- bottomRight: Radius.circular(28),
- ),
- ),
- ),
- ),
- );
- },
- )
- : const SizedBox()
- ],
- ),
- ),
- );
- }
-
- Future<void> navigationtoScreen(DrawerIndex indexScreen) async {
- widget.callBackIndex(indexScreen);
- }
-
- _clickSignOut() {
- context.bloc<AuthenticationBloc>().add(AuthenticationLogoutRequested());
- }
- }
-
- enum DrawerIndex { ScanBarcode, Home, ControlDevice }
-
- class DrawerList {
- DrawerList({
- this.isAssetsImage = false,
- this.labelName = '',
- this.icon,
- this.index,
- this.imageName = '',
- });
-
- String labelName;
- Icon icon;
- bool isAssetsImage;
- String imageName;
- DrawerIndex index;
- }
|