Skip to content

Commit c3fbcc1

Browse files
committed
expanded content body implemented
1 parent 0f21bb3 commit c3fbcc1

2 files changed

Lines changed: 290 additions & 64 deletions

File tree

example/lib/main_temp.dart

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
import 'package:flutter/cupertino.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter/widgets.dart';
4+
import 'package:getwidget/getwidget.dart';
5+
6+
final List<String> imageList = [
7+
'https://cdn.pixabay.com/photo/2017/12/03/18/04/christmas-balls-2995437_960_720.jpg',
8+
'https://cdn.pixabay.com/photo/2017/12/13/00/23/christmas-3015776_960_720.jpg',
9+
'https://cdn.pixabay.com/photo/2019/12/19/10/55/christmas-market-4705877_960_720.jpg',
10+
'https://cdn.pixabay.com/photo/2019/12/20/00/03/road-4707345_960_720.jpg',
11+
'https://cdn.pixabay.com/photo/2019/12/22/04/18/x-mas-4711785__340.jpg',
12+
'https://cdn.pixabay.com/photo/2016/11/22/07/09/spruce-1848543__340.jpg',
13+
'https://cdn.pixabay.com/photo/2017/12/03/18/04/christmas-balls-2995437_960_720.jpg',
14+
'https://cdn.pixabay.com/photo/2017/12/13/00/23/christmas-3015776_960_720.jpg',
15+
];
16+
17+
void main() => runApp(MyApp());
18+
19+
class MyApp extends StatelessWidget {
20+
@override
21+
Widget build(BuildContext context) => MaterialApp(
22+
title: 'GetWidget Example',
23+
theme: ThemeData(
24+
primarySwatch: Colors.blue,
25+
),
26+
debugShowCheckedModeBanner: false,
27+
home: const MyHomePage(title: 'GetWidget Example'),
28+
);
29+
}
30+
31+
class MyHomePage extends StatefulWidget {
32+
const MyHomePage({Key key, this.title}) : super(key: key);
33+
34+
final String title;
35+
36+
@override
37+
_MyHomePageState createState() => _MyHomePageState();
38+
}
39+
40+
class _MyHomePageState extends State<MyHomePage>
41+
with SingleTickerProviderStateMixin {
42+
final _scaffoldKey = new GlobalKey<ScaffoldState>();
43+
TabController tabController;
44+
final _ratingController = TextEditingController();
45+
bool check = false;
46+
String searchData;
47+
final TextEditingController _searchController = TextEditingController();
48+
int groupValue = 0;
49+
final GFBottomSheetController _controller = GFBottomSheetController();
50+
double foo = 100.0;
51+
52+
@override
53+
void initState() {
54+
super.initState();
55+
_ratingController.text = '4.5';
56+
tabController = TabController(length: 6, initialIndex: 3, vsync: this);
57+
}
58+
59+
@override
60+
void dispose() {
61+
tabController.dispose();
62+
super.dispose();
63+
}
64+
65+
bool switchValue = true;
66+
bool showToast = false;
67+
68+
List list = [
69+
'Flutter',
70+
'React',
71+
'Ionic',
72+
'Xamarin',
73+
'Flutter2',
74+
'React2',
75+
'Ionic2',
76+
'Xamarin2',
77+
];
78+
79+
void _persistentBottomSheet() {
80+
_scaffoldKey.currentState.showBottomSheet((context) => Container(
81+
color: Colors.redAccent,
82+
height: 250,
83+
child: const Center(
84+
child: Text('Hey! guys , this is a persistent bottom sheet'),
85+
),
86+
));
87+
}
88+
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+
@override
109+
Widget build(BuildContext context) => Scaffold(
110+
key: _scaffoldKey,
111+
appBar: GFAppBar(
112+
backgroundColor: Colors.blueGrey,
113+
title: const Text('UI Kit'),
114+
centerTitle: true,
115+
),
116+
body: SingleChildScrollView(
117+
child: Column(
118+
mainAxisAlignment: MainAxisAlignment.start,
119+
crossAxisAlignment: CrossAxisAlignment.center,
120+
children: [
121+
Container(
122+
height: 10,
123+
),
124+
Radio(
125+
value: 0,
126+
groupValue: groupValue,
127+
onChanged: (val) {
128+
setState(() {
129+
groupValue = val;
130+
});
131+
},
132+
),
133+
Radio(
134+
value: 1,
135+
groupValue: groupValue,
136+
onChanged: (val) {
137+
setState(() {
138+
groupValue = val;
139+
});
140+
},
141+
),
142+
// Expanded(child: SizedBox.expand(
143+
// child: DraggableScrollableSheet(
144+
// builder: (BuildContext context, ScrollController scrollController) => Container(
145+
// color: Colors.blue[100],
146+
// child: ListView.builder(
147+
// controller: scrollController,
148+
// itemCount: 25,
149+
// itemBuilder: (BuildContext context, int index) => ListTile(title: Text('Item $index')),
150+
// ),
151+
// ),
152+
// ),
153+
// ),)
154+
],
155+
),
156+
),
157+
bottomSheet: GFBottomSheet(
158+
controller: _controller,
159+
// minContentHeight: 100,
160+
maxContentHeight: 500,
161+
// elevation: 10,
162+
stickyHeader: Container(
163+
decoration: BoxDecoration(
164+
borderRadius: BorderRadius.circular(10),
165+
color: Colors.tealAccent),
166+
height: 50,
167+
child: const Center(
168+
child: Text('Swipe me!'),
169+
),
170+
),
171+
contentBody: Container(
172+
child: ListView(
173+
children: const [
174+
Text('fhj'),
175+
Text('fhj'),
176+
Text('fhj'),
177+
Text('fhj'),
178+
Text('fhj'),
179+
Text('fhj'),
180+
],
181+
),
182+
),
183+
stickyFooter: Container(
184+
color: Theme.of(context).primaryColor,
185+
height: 100,
186+
child: const Center(
187+
child: Text('I am Footer!'),
188+
),
189+
),
190+
stickyFooterHeight: 50,
191+
),
192+
floatingActionButton: FloatingActionButton(
193+
child: const Icon(Icons.stars),
194+
onPressed: () {
195+
// _persistentBottomSheet();
196+
// _modalBottomSheetMenu();
197+
_controller.isBottomSheetOpened
198+
? _controller.hideBottomSheet()
199+
: _controller.showBottomSheet();
200+
}),
201+
);
202+
}

lib/components/bottom_sheet/gf_bottom_sheet.dart

Lines changed: 88 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'dart:async';
23

34
class 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

194218
class GFBottomSheetController extends ValueNotifier<bool> {

0 commit comments

Comments
 (0)