@@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
44
55class DrawerUserController extends StatefulWidget {
66 const DrawerUserController ({
7- Key key,
7+ Key ? key,
88 this .drawerWidth = 250 ,
99 this .onDrawerCall,
1010 this .screenView,
@@ -15,63 +15,63 @@ class DrawerUserController extends StatefulWidget {
1515 }) : super (key: key);
1616
1717 final double drawerWidth;
18- final Function (DrawerIndex ) onDrawerCall;
19- final Widget screenView;
20- final Function (bool ) drawerIsOpen;
21- final AnimatedIconData animatedIconData;
22- final Widget menuView;
23- final DrawerIndex screenIndex;
18+ final Function (DrawerIndex )? onDrawerCall;
19+ final Widget ? screenView;
20+ final Function (bool )? drawerIsOpen;
21+ final AnimatedIconData ? animatedIconData;
22+ final Widget ? menuView;
23+ final DrawerIndex ? screenIndex;
2424
2525 @override
2626 _DrawerUserControllerState createState () => _DrawerUserControllerState ();
2727}
2828
2929class _DrawerUserControllerState extends State <DrawerUserController > with TickerProviderStateMixin {
30- ScrollController scrollController;
31- AnimationController iconAnimationController;
32- AnimationController animationController;
30+ ScrollController ? scrollController;
31+ AnimationController ? iconAnimationController;
32+ AnimationController ? animationController;
3333
3434 double scrolloffset = 0.0 ;
3535
3636 @override
3737 void initState () {
3838 animationController = AnimationController (duration: const Duration (milliseconds: 2000 ), vsync: this );
3939 iconAnimationController = AnimationController (vsync: this , duration: const Duration (milliseconds: 0 ));
40- iconAnimationController..animateTo (1.0 , duration: const Duration (milliseconds: 0 ), curve: Curves .fastOutSlowIn);
40+ iconAnimationController? ..animateTo (1.0 , duration: const Duration (milliseconds: 0 ), curve: Curves .fastOutSlowIn);
4141 scrollController = ScrollController (initialScrollOffset: widget.drawerWidth);
42- scrollController
42+ scrollController!
4343 ..addListener (() {
44- if (scrollController.offset <= 0 ) {
44+ if (scrollController! .offset <= 0 ) {
4545 if (scrolloffset != 1.0 ) {
4646 setState (() {
4747 scrolloffset = 1.0 ;
4848 try {
49- widget.drawerIsOpen (true );
49+ widget.drawerIsOpen ! (true );
5050 } catch (_) {}
5151 });
5252 }
53- iconAnimationController.animateTo (0.0 , duration: const Duration (milliseconds: 0 ), curve: Curves .fastOutSlowIn);
54- } else if (scrollController.offset > 0 && scrollController.offset < widget.drawerWidth.floor ()) {
55- iconAnimationController.animateTo ((scrollController.offset * 100 / (widget.drawerWidth)) / 100 ,
53+ iconAnimationController? .animateTo (0.0 , duration: const Duration (milliseconds: 0 ), curve: Curves .fastOutSlowIn);
54+ } else if (scrollController! .offset > 0 && scrollController! .offset < widget.drawerWidth.floor ()) {
55+ iconAnimationController? .animateTo ((scrollController! .offset * 100 / (widget.drawerWidth)) / 100 ,
5656 duration: const Duration (milliseconds: 0 ), curve: Curves .fastOutSlowIn);
5757 } else {
5858 if (scrolloffset != 0.0 ) {
5959 setState (() {
6060 scrolloffset = 0.0 ;
6161 try {
62- widget.drawerIsOpen (false );
62+ widget.drawerIsOpen ! (false );
6363 } catch (_) {}
6464 });
6565 }
66- iconAnimationController.animateTo (1.0 , duration: const Duration (milliseconds: 0 ), curve: Curves .fastOutSlowIn);
66+ iconAnimationController? .animateTo (1.0 , duration: const Duration (milliseconds: 0 ), curve: Curves .fastOutSlowIn);
6767 }
6868 });
69- WidgetsBinding .instance.addPostFrameCallback ((_) => getInitState ());
69+ WidgetsBinding .instance? .addPostFrameCallback ((_) => getInitState ());
7070 super .initState ();
7171 }
7272
7373 Future <bool > getInitState () async {
74- scrollController.jumpTo (
74+ scrollController? .jumpTo (
7575 widget.drawerWidth,
7676 );
7777 return true ;
@@ -96,18 +96,18 @@ class _DrawerUserControllerState extends State<DrawerUserController> with Ticker
9696 //we divided first drawer Width with HomeDrawer and second full-screen Width with all home screen, we called screen View
9797 height: MediaQuery .of (context).size.height,
9898 child: AnimatedBuilder (
99- animation: iconAnimationController,
100- builder: (BuildContext context, Widget child) {
99+ animation: iconAnimationController! ,
100+ builder: (BuildContext context, Widget ? child) {
101101 return Transform (
102102 //transform we use for the stable drawer we, not need to move with scroll view
103- transform: Matrix4 .translationValues (scrollController.offset, 0.0 , 0.0 ),
103+ transform: Matrix4 .translationValues (scrollController! .offset, 0.0 , 0.0 ),
104104 child: HomeDrawer (
105105 screenIndex: widget.screenIndex == null ? DrawerIndex .HOME : widget.screenIndex,
106106 iconAnimationController: iconAnimationController,
107107 callBackIndex: (DrawerIndex indexType) {
108108 onDrawerClick ();
109109 try {
110- widget.onDrawerCall (indexType);
110+ widget.onDrawerCall ! (indexType);
111111 } catch (e) {}
112112 },
113113 ),
@@ -155,8 +155,8 @@ class _DrawerUserControllerState extends State<DrawerUserController> with Ticker
155155 child: widget.menuView != null
156156 ? widget.menuView
157157 : AnimatedIcon (
158- icon: widget.animatedIconData != null ? widget.animatedIconData : AnimatedIcons .arrow_menu,
159- progress: iconAnimationController),
158+ icon: widget.animatedIconData ?? AnimatedIcons .arrow_menu,
159+ progress: iconAnimationController! ),
160160 ),
161161 onTap: () {
162162 FocusScope .of (context).requestFocus (FocusNode ());
@@ -179,14 +179,14 @@ class _DrawerUserControllerState extends State<DrawerUserController> with Ticker
179179
180180 void onDrawerClick () {
181181 //if scrollcontroller.offset != 0.0 then we set to closed the drawer(with animation to offset zero position) if is not 1 then open the drawer
182- if (scrollController.offset != 0.0 ) {
183- scrollController.animateTo (
182+ if (scrollController! .offset != 0.0 ) {
183+ scrollController? .animateTo (
184184 0.0 ,
185185 duration: const Duration (milliseconds: 400 ),
186186 curve: Curves .fastOutSlowIn,
187187 );
188188 } else {
189- scrollController.animateTo (
189+ scrollController? .animateTo (
190190 widget.drawerWidth,
191191 duration: const Duration (milliseconds: 400 ),
192192 curve: Curves .fastOutSlowIn,
0 commit comments