Skip to content

Commit a7a3023

Browse files
committed
GFBottomSheet testing done
1 parent 7c20721 commit a7a3023

File tree

2 files changed

+108
-112
lines changed

2 files changed

+108
-112
lines changed

example/lib/main_temp.dart

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateM
4545
String searchData;
4646
final TextEditingController _searchController = TextEditingController();
4747
int groupValue = 0;
48-
GFBottomSheeetController _controller = GFBottomSheeetController();
48+
GFBottomSheetController _controller = GFBottomSheetController();
4949

5050
@override
5151
void initState() {
@@ -86,6 +86,26 @@ class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateM
8686
);
8787
}
8888

89+
void _modalBottomSheetMenu(){
90+
showModalBottomSheet(
91+
context: context,
92+
elevation: 10,
93+
builder: (builder) => Container(
94+
height: 350,
95+
color: Colors.transparent,
96+
child: Container(
97+
decoration: const BoxDecoration(
98+
color: Colors.white,
99+
borderRadius: BorderRadius.only(
100+
topLeft: Radius.circular(10),
101+
topRight: Radius.circular(10))),
102+
child: const Center(
103+
child: Text('This is a modal sheet'),
104+
)),
105+
)
106+
);
107+
}
108+
89109

90110
@override
91111
Widget build(BuildContext context) => Scaffold(
@@ -130,6 +150,7 @@ class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateM
130150
bottomSheet: GFBottomSheet(
131151
controller: _controller,
132152
maxHeight: 200,
153+
elevation: 10,
133154
smoothness: GFSmoothness.HIGH,
134155
stickyHeader: Container(
135156
decoration: BoxDecoration(
@@ -154,16 +175,19 @@ class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateM
154175
),
155176
stickyFooter: Container(
156177
color: Theme.of(context).primaryColor,
157-
height: 50,
178+
height: 100,
158179
child: const Center(
159180
child: Text('I am Footer!'),
160181
),
161182
),
183+
// stickyFooterHeight: 50,
162184
),
163185
floatingActionButton: FloatingActionButton(
164186
child: const Icon(Icons.stars),
165187
onPressed: () {
166-
_controller.isOpened ? _controller.hide() : _controller.show();
188+
// _persistentBottomSheet();
189+
// _modalBottomSheetMenu();
190+
_controller.isBottomSheetOpened ? _controller.hideBottomSheet() : _controller.showBottomSheet();
167191
}),
168192
);
169193
}
Lines changed: 81 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
11
import 'dart:async';
2+
import 'dart:js';
23
import 'package:flutter/material.dart';
34
import 'package:getwidget/smoothness/gf_smoothness.dart';
45

56

67
class GFBottomSheet extends StatefulWidget {
8+
9+
GFBottomSheet({
10+
Key key,
11+
@required this.stickyHeader,
12+
@required this.contentBody,
13+
this.stickyFooter,
14+
this.controller,
15+
this.minHeight = 0,
16+
this.maxHeight = 300,
17+
this.elevation = 0.0,
18+
this.smoothness = GFSmoothness.MEDIUM,
19+
this.stickyFooterHeight,
20+
}) : assert(elevation >= 0.0),
21+
assert(minHeight >= 0.0),
22+
super(key: key) {
23+
controller.height = minHeight;
24+
controller.smoothness = smoothness;
25+
controller == null ? controller = GFBottomSheetController() : Container();
26+
}
27+
728
// This controls the minimum height of the body. Must be greater or equal of
829
// 0. By default is 0
930
final double minHeight;
1031

1132
// This controls the minimum height of the body. By default is 500
1233
final double maxHeight;
1334

14-
// This is the content that will be hided of your bottomSheet. You can fit any
15-
// widget. This parameter is required
16-
final Widget contentBody;
17-
1835
// This is the header of your bottomSheet. This widget is the swipeable area
1936
// where user will interact. This parameter is required
2037
final Widget stickyHeader;
2138

39+
// This is the content that will be hided of your bottomSheet. You can fit any
40+
// widget. This parameter is required
41+
final Widget contentBody;
42+
2243
final Widget stickyFooter;
2344

2445
// This property is the elevation of the bottomSheet. Must be greater or equal
@@ -29,29 +50,15 @@ class GFBottomSheet extends StatefulWidget {
2950
// from the app and don't depend of user's interaction.
3051
// can hide and show methods plus have isOpened variable
3152
// to check widget visibility on a screen
32-
GFBottomSheeetController controller;
53+
GFBottomSheetController controller;
3354

55+
/// default medium
3456
final int smoothness;
3557

36-
GFBottomSheet({
37-
Key key,
38-
@required this.stickyHeader,
39-
@required this.contentBody,
40-
this.stickyFooter,
41-
this.controller,
42-
this.minHeight = 0,
43-
this.maxHeight = 300,
44-
this.elevation = 0.0,
45-
this.smoothness = GFSmoothness.MEDIUM,
46-
}) : assert(elevation >= 0.0),
47-
assert(minHeight >= 0.0),
48-
super(key: key) {
49-
if (controller == null) {
50-
this.controller = GFBottomSheeetController();
51-
}
52-
this.controller.height = this.minHeight;
53-
this.controller.Smoothness = smoothness;
54-
}
58+
// default false
59+
final double stickyFooterHeight;
60+
61+
5562

5663
@override
5764
_GFBottomSheetState createState() => _GFBottomSheetState();
@@ -74,17 +81,17 @@ class _GFBottomSheetState extends State<GFBottomSheet> with TickerProviderState
7481
_setUsersSmoothness();
7582

7683
if (isDragDirectionUp && widget.controller.value) {
77-
_show();
84+
_showBottomSheet();
7885
} else if (!isDragDirectionUp && !widget.controller.value) {
79-
_hide();
86+
_hideBottomSheet();
8087
} else {
8188
widget.controller.value = isDragDirectionUp;
8289
}
8390
}
8491

8592
void _onTap() {
86-
final bool isOpened = widget.controller.height == widget.maxHeight;
87-
widget.controller.value = !isOpened;
93+
final bool isBottomSheetOpened = widget.controller.height == widget.maxHeight;
94+
widget.controller.value = !isBottomSheetOpened;
8895
}
8996

9097
Function _controllerListener;
@@ -94,7 +101,7 @@ class _GFBottomSheetState extends State<GFBottomSheet> with TickerProviderState
94101
super.initState();
95102
widget.controller.value = showBottomSheet;
96103
_controllerListener = () {
97-
widget.controller.value ? _show() : _hide();
104+
widget.controller.value ? _showBottomSheet() : _hideBottomSheet();
98105
};
99106
widget.controller.addListener(_controllerListener);
100107
}
@@ -108,50 +115,51 @@ class _GFBottomSheetState extends State<GFBottomSheet> with TickerProviderState
108115
onVerticalDragUpdate: _onVerticalDragUpdate,
109116
onVerticalDragEnd: _onVerticalDragEnd,
110117
onTap: _onTap,
111-
child: Container(
112-
decoration: widget.elevation > 0
113-
? BoxDecoration(boxShadow: [
114-
BoxShadow(
115-
color: Colors.black54,
116-
blurRadius: widget.elevation,
117-
),
118-
])
119-
: null,
120-
width: MediaQuery
121-
.of(context)
122-
.size
123-
.width,
124-
child: widget.stickyHeader,
125-
),
118+
child: widget.stickyHeader,
126119
),
127120
AnimatedBuilder(
128-
animation: widget.controller,
129-
builder: (_, Widget child) =>
130-
AnimatedContainer(
131-
curve: Curves.easeOut,
132-
duration: Duration(milliseconds: widget.controller.Smoothness),
133-
height: widget.controller.height,
134-
child: GestureDetector(
135-
onVerticalDragUpdate: _onVerticalDragUpdate,
136-
onVerticalDragEnd: _onVerticalDragEnd,
137-
onTap: _onTap,
138-
child: widget.contentBody,
121+
animation: widget.controller,
122+
builder: (_, Widget child) =>
123+
AnimatedContainer(
124+
curve: Curves.easeOut,
125+
duration: Duration(milliseconds: widget.controller.smoothness),
126+
height: widget.controller.height,
127+
child: GestureDetector(
128+
onVerticalDragUpdate: _onVerticalDragUpdate,
129+
onVerticalDragEnd: _onVerticalDragEnd,
130+
onTap: _onTap,
131+
child: widget.contentBody,
132+
),
139133
),
140-
),
141134
),
142-
widget.controller.height == 0
143-
? widget.stickyFooter
144-
: Container()
135+
widget.stickyFooter != null ? AnimatedBuilder(
136+
animation: widget.controller,
137+
builder: (_, Widget child) =>
138+
AnimatedContainer(
139+
curve: Curves.easeOut,
140+
duration: Duration(milliseconds: widget.controller.smoothness),
141+
height: widget.controller.height != widget.minHeight ? widget.stickyFooterHeight : 0.0,
142+
child: GestureDetector(
143+
onVerticalDragUpdate: _onVerticalDragUpdate,
144+
onVerticalDragEnd: _onVerticalDragEnd,
145+
onTap: _onTap,
146+
child: widget.stickyFooter,
147+
),
148+
),
149+
) : Container(),
145150
],
146151
);
147-
return bottomSheet;
152+
return Material(
153+
elevation: widget.elevation,
154+
child: bottomSheet,
155+
);
148156
}
149157

150-
void _hide() {
158+
void _hideBottomSheet() {
151159
widget.controller.height = widget.minHeight;
152160
}
153161

154-
void _show() {
162+
void _showBottomSheet() {
155163
widget.controller.height = widget.maxHeight;
156164
}
157165

@@ -162,76 +170,40 @@ class _GFBottomSheetState extends State<GFBottomSheet> with TickerProviderState
162170
}
163171

164172
void _setUsersSmoothness() {
165-
widget.controller.Smoothness = widget.smoothness;
173+
widget.controller.smoothness = widget.smoothness;
166174
}
167175

168176
void _setNativeSmoothness() {
169-
widget.controller.Smoothness = widget.smoothness;
177+
widget.controller.smoothness = widget.smoothness;
170178
}
171179
}
172180

173-
class GFBottomSheeetController extends ValueNotifier<bool> {
174-
// SolidBloc _bloc = SolidBloc();
181+
class GFBottomSheetController extends ValueNotifier<bool> {
182+
183+
GFBottomSheetController() : super(false);
175184

176-
// This is the current height of the bottomSheet's body
185+
// This is the current height of the GFBottomSheet's contentBody
177186
double _height;
178187

179188
// This is the current smoothness of the bottomSheet
180-
int Smoothness;
189+
int smoothness;
181190

182-
GFBottomSheeetController() : super(false);
183-
184-
// // Returns the value of the height as stream
185-
// Stream<double> get heightStream => _bloc.height;
186-
//
187-
// // Returns the value of the visibility as stream
188-
// Stream<bool> get isOpenStream => _bloc.isOpen;
189-
190-
// This method sets the value of the height using streams
191+
// This method sets the value of the height
191192
set height(double value) {
192193
_height = value;
193-
// _bloc.dispatch(value);
194194
}
195195

196196
// Returns the value of the height
197197
double get height => _height;
198198

199199
// Returns if the solid bottom sheet is opened or not
200-
bool get isOpened => value;
200+
bool get isBottomSheetOpened => value;
201201

202202
// Updates the visibility value to false
203-
void hide() => value = false;
203+
void hideBottomSheet() => value = false;
204204

205205
// Updates the visibility value to true
206-
void show() => value = true;
206+
void showBottomSheet() => value = true;
207207

208-
@override
209-
void dispose() {
210-
// _bloc.dispose();
211-
super.dispose();
212-
}
213208
}
214209

215-
//class SolidBloc {
216-
// StreamController<double> _heightController =
217-
// StreamController<double>.broadcast();
218-
// Stream<double> get height => _heightController.stream;
219-
// Sink<double> get _heightSink => _heightController.sink;
220-
//
221-
// StreamController<bool> _visibilityController =
222-
// StreamController<bool>.broadcast();
223-
// Stream<bool> get isOpen => _visibilityController.stream;
224-
// Sink<bool> get _visibilitySink => _visibilityController.sink;
225-
//
226-
// // Adds new values to streams
227-
// void dispatch(double value) {
228-
// _heightSink.add(value);
229-
// _visibilitySink.add(value > 0);
230-
// }
231-
//
232-
// // Closes streams
233-
// void dispose() {
234-
// _heightController.close();
235-
// _visibilityController.close();
236-
// }
237-
//}

0 commit comments

Comments
 (0)