@@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
4
4
5
5
class DrawerUserController extends StatefulWidget {
6
6
const DrawerUserController ({
7
- Key key,
7
+ Key ? key,
8
8
this .drawerWidth = 250 ,
9
9
this .onDrawerCall,
10
10
this .screenView,
@@ -15,63 +15,63 @@ class DrawerUserController extends StatefulWidget {
15
15
}) : super (key: key);
16
16
17
17
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;
24
24
25
25
@override
26
26
_DrawerUserControllerState createState () => _DrawerUserControllerState ();
27
27
}
28
28
29
29
class _DrawerUserControllerState extends State <DrawerUserController > with TickerProviderStateMixin {
30
- ScrollController scrollController;
31
- AnimationController iconAnimationController;
32
- AnimationController animationController;
30
+ ScrollController ? scrollController;
31
+ AnimationController ? iconAnimationController;
32
+ AnimationController ? animationController;
33
33
34
34
double scrolloffset = 0.0 ;
35
35
36
36
@override
37
37
void initState () {
38
38
animationController = AnimationController (duration: const Duration (milliseconds: 2000 ), vsync: this );
39
39
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);
41
41
scrollController = ScrollController (initialScrollOffset: widget.drawerWidth);
42
- scrollController
42
+ scrollController!
43
43
..addListener (() {
44
- if (scrollController.offset <= 0 ) {
44
+ if (scrollController! .offset <= 0 ) {
45
45
if (scrolloffset != 1.0 ) {
46
46
setState (() {
47
47
scrolloffset = 1.0 ;
48
48
try {
49
- widget.drawerIsOpen (true );
49
+ widget.drawerIsOpen ! (true );
50
50
} catch (_) {}
51
51
});
52
52
}
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 ,
56
56
duration: const Duration (milliseconds: 0 ), curve: Curves .fastOutSlowIn);
57
57
} else {
58
58
if (scrolloffset != 0.0 ) {
59
59
setState (() {
60
60
scrolloffset = 0.0 ;
61
61
try {
62
- widget.drawerIsOpen (false );
62
+ widget.drawerIsOpen ! (false );
63
63
} catch (_) {}
64
64
});
65
65
}
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);
67
67
}
68
68
});
69
- WidgetsBinding .instance.addPostFrameCallback ((_) => getInitState ());
69
+ WidgetsBinding .instance? .addPostFrameCallback ((_) => getInitState ());
70
70
super .initState ();
71
71
}
72
72
73
73
Future <bool > getInitState () async {
74
- scrollController.jumpTo (
74
+ scrollController? .jumpTo (
75
75
widget.drawerWidth,
76
76
);
77
77
return true ;
@@ -96,18 +96,18 @@ class _DrawerUserControllerState extends State<DrawerUserController> with Ticker
96
96
//we divided first drawer Width with HomeDrawer and second full-screen Width with all home screen, we called screen View
97
97
height: MediaQuery .of (context).size.height,
98
98
child: AnimatedBuilder (
99
- animation: iconAnimationController,
100
- builder: (BuildContext context, Widget child) {
99
+ animation: iconAnimationController! ,
100
+ builder: (BuildContext context, Widget ? child) {
101
101
return Transform (
102
102
//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 ),
104
104
child: HomeDrawer (
105
105
screenIndex: widget.screenIndex == null ? DrawerIndex .HOME : widget.screenIndex,
106
106
iconAnimationController: iconAnimationController,
107
107
callBackIndex: (DrawerIndex indexType) {
108
108
onDrawerClick ();
109
109
try {
110
- widget.onDrawerCall (indexType);
110
+ widget.onDrawerCall ! (indexType);
111
111
} catch (e) {}
112
112
},
113
113
),
@@ -155,8 +155,8 @@ class _DrawerUserControllerState extends State<DrawerUserController> with Ticker
155
155
child: widget.menuView != null
156
156
? widget.menuView
157
157
: AnimatedIcon (
158
- icon: widget.animatedIconData != null ? widget.animatedIconData : AnimatedIcons .arrow_menu,
159
- progress: iconAnimationController),
158
+ icon: widget.animatedIconData ?? AnimatedIcons .arrow_menu,
159
+ progress: iconAnimationController! ),
160
160
),
161
161
onTap: () {
162
162
FocusScope .of (context).requestFocus (FocusNode ());
@@ -179,14 +179,14 @@ class _DrawerUserControllerState extends State<DrawerUserController> with Ticker
179
179
180
180
void onDrawerClick () {
181
181
//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 (
184
184
0.0 ,
185
185
duration: const Duration (milliseconds: 400 ),
186
186
curve: Curves .fastOutSlowIn,
187
187
);
188
188
} else {
189
- scrollController.animateTo (
189
+ scrollController? .animateTo (
190
190
widget.drawerWidth,
191
191
duration: const Duration (milliseconds: 400 ),
192
192
curve: Curves .fastOutSlowIn,
0 commit comments