11import 'dart:async' ;
22import 'package:flutter/material.dart' ;
3+ import 'package:getwidget/smoothness/gf_smoothness.dart' ;
4+
35
46class GFBottomSheet extends StatefulWidget {
57 // This controls the minimum height of the body. Must be greater or equal of
@@ -19,10 +21,6 @@ class GFBottomSheet extends StatefulWidget {
1921
2022 final Widget stickyFooter;
2123
22- // This property defines how 'smooth' or fast will be the animation. Low is
23- // the slowest velocity and high is the fastest. By default is medium.
24- final Smoothness smoothness;
25-
2624 // This property is the elevation of the bottomSheet. Must be greater or equal
2725 // to 0. By default is 0.
2826 final double elevation;
@@ -33,30 +31,33 @@ class GFBottomSheet extends StatefulWidget {
3331 // to check widget visibility on a screen
3432 SolidController controller;
3533
34+ final int smoothness;
35+
3636 GFBottomSheet ({
3737 Key key,
3838 @required this .stickyHeader,
3939 @required this .contentBody,
4040 this .stickyFooter,
4141 this .controller,
4242 this .minHeight = 0 ,
43- this .maxHeight = 500 ,
43+ this .maxHeight = 300 ,
4444 this .elevation = 0.0 ,
45- this .smoothness = Smoothness .medium ,
45+ this .smoothness = GFSmoothness . MEDIUM ,
4646 }) : assert (elevation >= 0.0 ),
4747 assert (minHeight >= 0.0 ),
4848 super (key: key) {
4949 if (controller == null ) {
5050 this .controller = SolidController ();
5151 }
52- this .controller.smoothness = smoothness;
52+ this .controller.height = this .minHeight;
53+ this .controller.Smoothness = smoothness;
5354 }
5455
5556 @override
5657 _GFBottomSheetState createState () => _GFBottomSheetState ();
5758}
5859
59- class _GFBottomSheetState extends State <GFBottomSheet > {
60+ class _GFBottomSheetState extends State <GFBottomSheet > with TickerProviderStateMixin {
6061 bool isDragDirectionUp;
6162 bool showOnAppear = false ;
6263
@@ -87,10 +88,17 @@ class _GFBottomSheetState extends State<GFBottomSheet> {
8788 }
8889
8990 Function _controllerListener;
91+ AnimationController _controller;
9092
9193 @override
9294 void initState () {
9395 super .initState ();
96+ // _controller = AnimationController(
97+ // vsync: this,
98+ // lowerBound: 0.0,
99+ // upperBound: 1.0,
100+ // );
101+ // _controller.addStatusListener(_controllerListener);
94102 widget.controller.value = showOnAppear;
95103 _controllerListener = () {
96104 widget.controller.value ? _show () : _hide ();
@@ -99,7 +107,8 @@ class _GFBottomSheetState extends State<GFBottomSheet> {
99107 }
100108
101109 @override
102- Widget build (BuildContext context) => Column (
110+ Widget build (BuildContext context) {
111+ final Widget bottomSheet = Column (
103112 mainAxisSize: MainAxisSize .min,
104113 children: < Widget > [
105114 GestureDetector (
@@ -115,36 +124,46 @@ class _GFBottomSheetState extends State<GFBottomSheet> {
115124 ),
116125 ])
117126 : null ,
118- width: MediaQuery .of (context).size.width,
127+ width: MediaQuery
128+ .of (context)
129+ .size
130+ .width,
119131 child: widget.stickyHeader,
120132 ),
121133 ),
122134 StreamBuilder <double >(
123135 stream: widget.controller.heightStream,
124136 initialData: widget.controller.height,
125- builder: (_, snapshot) => AnimatedContainer (
126- curve: Curves .easeOut,
127- duration:
128- Duration (milliseconds: widget.controller.smoothness.value),
129- height: snapshot.data,
130- child: GestureDetector (
131- onVerticalDragUpdate: _onVerticalDragUpdate,
132- onVerticalDragEnd: _onVerticalDragEnd,
133- onTap: _onTap,
134- child: widget.contentBody,
137+ builder: (_, snapshot) =>
138+ AnimatedContainer (
139+ curve: Curves .easeOut,
140+ duration:
141+ Duration (milliseconds: widget.controller.Smoothness ),
142+ height: snapshot.data,
143+ child: GestureDetector (
144+ onVerticalDragUpdate: _onVerticalDragUpdate,
145+ onVerticalDragEnd: _onVerticalDragEnd,
146+ onTap: _onTap,
147+ child: widget.contentBody,
148+ ),
135149 ),
136- ),
137150 ),
138- widget.controller.height == widget.maxHeight ? widget.stickyFooter : Container ()
151+ widget.controller.height == widget.maxHeight
152+ ? widget.stickyFooter
153+ : Container ()
139154 ],
140155 );
156+ return bottomSheet;
157+ }
141158
142159 void _hide () {
143160 widget.controller.height = widget.minHeight;
161+ print ('hhhhhhhhhhhh ${ widget .controller .height == widget .maxHeight }' );
144162 }
145163
146164 void _show () {
147165 widget.controller.height = widget.maxHeight;
166+ print ('sssssssss ${ widget .controller .height == widget .maxHeight }' );
148167 }
149168
150169 @override
@@ -154,43 +173,22 @@ class _GFBottomSheetState extends State<GFBottomSheet> {
154173 }
155174
156175 void _setUsersSmoothness () {
157- widget.controller.smoothness = widget.smoothness;
176+ widget.controller.Smoothness = widget.smoothness;
158177 }
159178
160179 void _setNativeSmoothness () {
161- widget.controller.smoothness = Smoothness . withValue ( 5 ) ;
180+ widget.controller.Smoothness = widget.smoothness ;
162181 }
163182}
164183
165- class Smoothness {
166- final int _value;
167-
168- Smoothness ._() : _value = 0 ;
169-
170- const Smoothness ._low () : _value = 100 ;
171-
172- const Smoothness ._medium () : _value = 250 ;
173-
174- const Smoothness ._high () : _value = 500 ;
175-
176- const Smoothness ._withValue (int value) : _value = value;
177-
178- static const Smoothness low = Smoothness ._low ();
179- static const Smoothness medium = Smoothness ._medium ();
180- static const Smoothness high = Smoothness ._high ();
181- static Smoothness withValue (int value) => Smoothness ._withValue (value);
182-
183- int get value => _value;
184- }
185-
186184class SolidController extends ValueNotifier <bool > {
187185 SolidBloc _bloc = SolidBloc ();
188186
189187 // This is the current height of the bottomSheet's body
190188 double _height;
191189
192190 // This is the current smoothness of the bottomSheet
193- Smoothness smoothness ;
191+ int Smoothness ;
194192
195193 SolidController () : super (false );
196194
0 commit comments