11import 'package:flutter/material.dart' ;
2+ import 'dart:async' ;
23
34class GFBottomSheet extends StatefulWidget {
45 GFBottomSheet ({
@@ -71,7 +72,6 @@ class _GFBottomSheetState extends State<GFBottomSheet>
7172
7273 void _onVerticalDragEnd (data) {
7374 _setSmoothness ();
74-
7575 if (isDragDirectionUp && widget.controller.value) {
7676 _showBottomSheet ();
7777 } else if (! isDragDirectionUp && ! widget.controller.value) {
@@ -90,81 +90,106 @@ class _GFBottomSheetState extends State<GFBottomSheet>
9090 @override
9191 void initState () {
9292 super .initState ();
93+ position = widget.minContentHeight;
9394 widget.controller.value = showBottomSheet;
9495 _controllerListener = () {
9596 widget.controller.value ? _showBottomSheet () : _hideBottomSheet ();
9697 };
9798 widget.controller.addListener (_controllerListener);
9899 }
99100
101+ StreamController <double > controller = StreamController .broadcast ();
102+ double position;
103+
104+
100105 @override
101106 Widget build (BuildContext context) {
102-
103- final BottomSheetThemeData bottomSheetTheme = Theme .of (context).bottomSheetTheme;
104- final double elevation = widget.elevation ?? bottomSheetTheme.elevation ?? 0 ;
107+ final BottomSheetThemeData bottomSheetTheme =
108+ Theme .of (context).bottomSheetTheme;
109+ final double elevation =
110+ widget.elevation ?? bottomSheetTheme.elevation ?? 0 ;
105111
106112 final Widget bottomSheet = Column (
107- mainAxisSize: MainAxisSize .min,
108- children: < Widget > [
109- widget.stickyHeader == null
110- ? Container ()
111- : GestureDetector (
112- onVerticalDragUpdate: _onVerticalDragUpdate,
113- onVerticalDragEnd: _onVerticalDragEnd,
114- onTap: _onTap,
115- child: widget.stickyHeader,
116- ),
117- AnimatedBuilder (
118- animation: widget.controller,
119- builder: (_, Widget child) => AnimatedContainer (
120- curve: Curves .easeOut,
121- duration: Duration (milliseconds: widget.controller.smoothness),
122- height: widget.controller.height,
123- child: GestureDetector (
124- onVerticalDragUpdate: _onVerticalDragUpdate,
125- onVerticalDragEnd: _onVerticalDragEnd,
126- onTap: _onTap,
127- child: widget.contentBody,
128- ),
129- ),
130- ),
113+ mainAxisSize: MainAxisSize .min,
114+ children: < Widget > [
115+ widget.stickyHeader == null
116+ ? Container ()
117+ : GestureDetector (
118+ onVerticalDragUpdate: _onVerticalDragUpdate,
119+ onVerticalDragEnd: _onVerticalDragEnd,
120+ onTap: _onTap,
121+ child: widget.stickyHeader,
122+ ),
123+
124+
131125 StreamBuilder (
132- stream: controller.stream,
133- builder: (context,snapshot) => GestureDetector (
134- onVerticalDragUpdate: (DragUpdateDetails details){
135- position = MediaQuery .of (context).size.height- details.globalPosition.dy;
136- position.isNegative ? Navigator .pop (context) : controller.add (position);
137- },
138- behavior: HitTestBehavior .translucent,
139- child:
140- Container (
141- color: Colors .red,
142- height: snapshot.hasData ? snapshot.data : 100.0 ,
143- width: double .infinity,
144- child: Text ('Child' ),
145- )),
126+ stream: controller.stream,
127+ builder: (context, snapshot) => GestureDetector (
128+ onVerticalDragUpdate: (DragUpdateDetails details){
129+ position = MediaQuery .of (context).size.height - details.globalPosition.dy;
130+ print ('fff' );
131+
132+ if (position >= widget.maxContentHeight){
133+ print ('max' );
134+ position = widget.maxContentHeight;
135+ }else if (position <= widget.minContentHeight){
136+ print ('min' );
137+ position = widget.minContentHeight;
138+ _hideBottomSheet ();
139+ }
140+ controller.add (position);
141+
142+ },
143+ onVerticalDragEnd: _onVerticalDragEnd,
144+ onTap: _onTap,
145+ behavior: HitTestBehavior .translucent,
146+ child: Container (
147+ color: Colors .red,
148+ height: snapshot.hasData ? snapshot.data : widget.maxContentHeight* 0.3 ,
149+ width: double .infinity,
150+ child: Text ('jk' ),
151+ )
146152 ),
147- widget.stickyFooter != null
148- ? AnimatedBuilder (
149- animation: widget.controller,
150- builder: (_, Widget child) => AnimatedContainer (
151- curve: Curves .easeOut,
152- duration:
153- Duration (milliseconds: widget.controller.smoothness),
154- height: widget.controller.height != widget.minContentHeight
155- ? widget.stickyFooterHeight
156- : 0.0 ,
157- child: GestureDetector (
158- onVerticalDragUpdate: _onVerticalDragUpdate,
159- onVerticalDragEnd: _onVerticalDragEnd,
160- onTap: _onTap,
161- child: widget.stickyFooter,
162- ),
163- ),
164- )
165- : Container (),
166- ],
167- );
153+ ),
154+
155+ // AnimatedBuilder(
156+ // animation: widget.controller,
157+ // builder: (_, Widget child) =>
158+ // AnimatedContainer(
159+ // curve: Curves.easeOut,
160+ // duration: Duration(milliseconds: widget.controller.smoothness),
161+ // height: widget.controller.height,
162+ // child: GestureDetector(
163+ // onVerticalDragUpdate: _onVerticalDragUpdate,
164+ // onVerticalDragEnd: _onVerticalDragEnd,
165+ // onTap: _onTap,
166+ // child: widget.contentBody
167+ // ),
168+ // ),
169+ // ),
170+
171+ widget.stickyFooter != null
172+ ? AnimatedBuilder (
173+ animation: widget.controller,
174+ builder: (_, Widget child) => AnimatedContainer (
175+ curve: Curves .easeOut,
176+ duration: Duration (
177+ milliseconds: widget.controller.smoothness),
178+ height: widget.controller.height !=
179+ widget.minContentHeight
180+ ? widget.stickyFooterHeight
181+ : 0.0 ,
182+ child: GestureDetector (
183+ onVerticalDragUpdate: _onVerticalDragUpdate,
184+ onVerticalDragEnd: _onVerticalDragEnd,
185+ onTap: _onTap,
186+ child: widget.stickyFooter,
187+ ),
188+ ),
189+ )
190+ : Container (),
191+ ],
192+ );
168193 return Material (
169194 elevation: elevation,
170195 child: bottomSheet,
@@ -188,7 +213,6 @@ class _GFBottomSheetState extends State<GFBottomSheet>
188213 void _setSmoothness () {
189214 widget.controller.smoothness = 500 ;
190215 }
191-
192216}
193217
194218class GFBottomSheetController extends ValueNotifier <bool > {
0 commit comments