Skip to content

Commit 6c5a649

Browse files
Merge branch 'master' into master
2 parents 467f16c + 07dcb4d commit 6c5a649

File tree

13 files changed

+220
-34
lines changed

13 files changed

+220
-34
lines changed

example/pubspec.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

lib/components/accordian/gf_accordian.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ class _GFAccordionState extends State<GFAccordion>
9797
showAccordion = widget.showAccordion;
9898
animationController = AnimationController(
9999
duration: const Duration(seconds: 2),
100-
vsync: this,
101100
);
102101
controller = AnimationController(
103-
vsync: this,
104102
duration: const Duration(milliseconds: 300),
105103
);
106104
offset = Tween(

lib/components/alert/gf_alert.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class _GFAlertState extends State<GFAlert> with TickerProviderStateMixin {
6868
void initState() {
6969
animationController = AnimationController(
7070
duration: const Duration(milliseconds: 300),
71-
vsync: this,
7271
);
7372
animation = CurvedAnimation(
7473
parent: animationController,

lib/components/animation/gf_animation.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ class _GFAnimationState extends State<GFAnimation>
118118
if (widget.type == GFAnimationType.rotateTransition) {
119119
controller = widget.controller ??
120120
AnimationController(
121-
duration: widget.duration ?? const Duration(seconds: 2),
122-
vsync: this);
121+
duration: widget.duration ?? const Duration(seconds: 2));
123122
animation = widget.turnsAnimation ??
124123
Tween<double>(begin: 0, end: 20).animate(controller);
125124
if (widget.turnsAnimation == null) {
@@ -128,7 +127,6 @@ class _GFAnimationState extends State<GFAnimation>
128127
} else if (widget.type == GFAnimationType.scaleTransition) {
129128
controller = widget.controller ??
130129
AnimationController(
131-
vsync: this,
132130
duration: widget.duration ?? const Duration(seconds: 2));
133131
animation = widget.scaleAnimation ??
134132
CurvedAnimation(
@@ -137,7 +135,6 @@ class _GFAnimationState extends State<GFAnimation>
137135
} else if (widget.type == GFAnimationType.slideTransition) {
138136
controller = AnimationController(
139137
duration: widget.duration ?? const Duration(seconds: 2),
140-
vsync: this,
141138
)..repeat(reverse: true);
142139
offsetAnimation = Tween<Offset>(
143140
begin: Offset.zero,
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
import 'package:flutter/material.dart';
2+
3+
class GFBottomSheet extends StatefulWidget {
4+
GFBottomSheet({
5+
Key key,
6+
@required this.stickyHeader,
7+
@required this.contentBody,
8+
this.stickyFooter,
9+
this.controller,
10+
this.minContentHeight = 0,
11+
this.maxContentHeight = 300,
12+
this.elevation = 0.0,
13+
this.stickyFooterHeight,
14+
}) : assert(elevation >= 0.0),
15+
assert(minContentHeight >= 0.0),
16+
super(key: key) {
17+
controller.height = minContentHeight;
18+
controller.smoothness = 500;
19+
// controller == null ? controller = GFBottomSheetController() : Container();
20+
}
21+
22+
/// [minContentHeight] controls the minimum height of the content body.
23+
/// It Must be greater or equal to 0. Default value is 0.
24+
final double minContentHeight;
25+
26+
/// [maxContentHeight] controls the maximum height of the content body.
27+
/// It Must be greater or equal to 0. Default value is 300.
28+
final double maxContentHeight;
29+
30+
/// [stickyHeader] is the header of GFBottomSheet.
31+
/// User can interact by swiping or tapping the [stickyHeader]
32+
final Widget stickyHeader;
33+
34+
/// [contentBody] is the body of GFBottomSheet.
35+
/// User can interact by tapping the [contentBody]
36+
final Widget contentBody;
37+
38+
/// [stickyFooter] is the footer of GFBottomSheet.
39+
/// User can interact by swiping or tapping the [stickyFooter]
40+
final Widget stickyFooter;
41+
42+
/// [stickyFooterHeight] defines the height of GFBottokSheet footer.
43+
final double stickyFooterHeight;
44+
45+
/// [elevation] controls shadow below the GFBottomSheet material.
46+
/// Must be greater or equalto 0. Default value is 0.
47+
final double elevation;
48+
49+
/// [controller] used to control GFBottomSheet behavior like hide/show
50+
final GFBottomSheetController controller;
51+
52+
@override
53+
_GFBottomSheetState createState() => _GFBottomSheetState();
54+
}
55+
56+
class _GFBottomSheetState extends State<GFBottomSheet>
57+
with TickerProviderStateMixin {
58+
bool isDragDirectionUp;
59+
bool showBottomSheet = false;
60+
Function _controllerListener;
61+
62+
void _onVerticalDragUpdate(data) {
63+
_setNativeSmoothness();
64+
if (((widget.controller.height - data.delta.dy) >
65+
widget.minContentHeight) &&
66+
((widget.controller.height - data.delta.dy) <
67+
widget.maxContentHeight)) {
68+
isDragDirectionUp = data.delta.dy <= 0;
69+
widget.controller.height -= data.delta.dy;
70+
}
71+
}
72+
73+
void _onVerticalDragEnd(data) {
74+
_setUsersSmoothness();
75+
76+
if (isDragDirectionUp && widget.controller.value) {
77+
_showBottomSheet();
78+
} else if (!isDragDirectionUp && !widget.controller.value) {
79+
_hideBottomSheet();
80+
} else {
81+
widget.controller.value = isDragDirectionUp;
82+
}
83+
}
84+
85+
void _onTap() {
86+
final bool isBottomSheetOpened =
87+
widget.controller.height == widget.maxContentHeight;
88+
widget.controller.value = !isBottomSheetOpened;
89+
}
90+
91+
@override
92+
void initState() {
93+
super.initState();
94+
widget.controller.value = showBottomSheet;
95+
_controllerListener = () {
96+
widget.controller.value ? _showBottomSheet() : _hideBottomSheet();
97+
};
98+
widget.controller.addListener(_controllerListener);
99+
}
100+
101+
@override
102+
Widget build(BuildContext context) {
103+
final Widget bottomSheet = Column(
104+
mainAxisSize: MainAxisSize.min,
105+
children: <Widget>[
106+
widget.stickyHeader == null
107+
? Container()
108+
: GestureDetector(
109+
onVerticalDragUpdate: _onVerticalDragUpdate,
110+
onVerticalDragEnd: _onVerticalDragEnd,
111+
onTap: _onTap,
112+
child: widget.stickyHeader,
113+
),
114+
AnimatedBuilder(
115+
animation: widget.controller,
116+
builder: (_, Widget child) => AnimatedContainer(
117+
curve: Curves.easeOut,
118+
duration: Duration(milliseconds: widget.controller.smoothness),
119+
height: widget.controller.height,
120+
child: GestureDetector(
121+
onVerticalDragUpdate: _onVerticalDragUpdate,
122+
onVerticalDragEnd: _onVerticalDragEnd,
123+
onTap: _onTap,
124+
child: widget.contentBody,
125+
),
126+
),
127+
),
128+
widget.stickyFooter != null
129+
? AnimatedBuilder(
130+
animation: widget.controller,
131+
builder: (_, Widget child) => AnimatedContainer(
132+
curve: Curves.easeOut,
133+
duration:
134+
Duration(milliseconds: widget.controller.smoothness),
135+
height: widget.controller.height != widget.minContentHeight
136+
? widget.stickyFooterHeight
137+
: 0.0,
138+
child: GestureDetector(
139+
onVerticalDragUpdate: _onVerticalDragUpdate,
140+
onVerticalDragEnd: _onVerticalDragEnd,
141+
onTap: _onTap,
142+
child: widget.stickyFooter,
143+
),
144+
),
145+
)
146+
: Container(),
147+
],
148+
);
149+
return Material(
150+
elevation: widget.elevation,
151+
child: bottomSheet,
152+
);
153+
}
154+
155+
void _hideBottomSheet() {
156+
widget.controller.height = widget.minContentHeight;
157+
}
158+
159+
void _showBottomSheet() {
160+
widget.controller.height = widget.maxContentHeight;
161+
}
162+
163+
@override
164+
void dispose() {
165+
widget.controller.removeListener(_controllerListener);
166+
super.dispose();
167+
}
168+
169+
void _setUsersSmoothness() {
170+
widget.controller.smoothness = 500;
171+
}
172+
173+
void _setNativeSmoothness() {
174+
widget.controller.smoothness = 500;
175+
}
176+
}
177+
178+
class GFBottomSheetController extends ValueNotifier<bool> {
179+
GFBottomSheetController() : super(false);
180+
181+
/// Defines the height of the GFBottomSheet's contentBody
182+
double _height;
183+
184+
/// Defines the drag animation smoothness of the GFBottomSheet
185+
int smoothness;
186+
187+
// ignore: unnecessary_getters_setters
188+
set height(double value) => _height = value;
189+
190+
// ignore: unnecessary_getters_setters
191+
double get height => _height;
192+
193+
bool get isBottomSheetOpened => value;
194+
195+
void hideBottomSheet() => value = false;
196+
void showBottomSheet() => value = true;
197+
}

lib/components/carousel/gf_items_carousel.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class _GFItemsCarouselState extends State<GFItemsCarousel>
8383
offset = 0;
8484
animationController = AnimationController(
8585
duration: const Duration(milliseconds: dragAnimationDuration),
86-
vsync: this,
8786
);
8887
Future.delayed(Duration.zero, () {
8988
setState(() {
@@ -133,7 +132,6 @@ class _GFItemsCarouselState extends State<GFItemsCarousel>
133132

134133
animationController = AnimationController(
135134
duration: const Duration(milliseconds: dragAnimationDuration),
136-
vsync: this,
137135
);
138136

139137
final Tween tween =
@@ -165,7 +163,6 @@ class _GFItemsCarouselState extends State<GFItemsCarousel>
165163
final double endAnimation = size * (offset / size).round().toDouble();
166164
animationController = AnimationController(
167165
duration: const Duration(milliseconds: shiftAnimationDuration),
168-
vsync: this,
169166
);
170167
final Tween tween = Tween<double>(begin: beginAnimation, end: endAnimation);
171168
final Animation animation = tween.animate(animationController);

lib/components/loader/gf_loader.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ class _GFLoaderState extends State<GFLoader>
7171
void initState() {
7272
super.initState();
7373

74-
controller = AnimationController(duration: widget.duration, vsync: this);
74+
controller = AnimationController(
75+
duration: widget.duration,
76+
);
7577

7678
loaderanimation1 = Tween<double>(begin: 0, end: 1).animate(
7779
CurvedAnimation(

lib/components/progress_bar/gf_progress_bar.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ class _GFProgressBarState extends State<GFProgressBar>
130130
super.initState();
131131
if (widget.animation) {
132132
_animationController = AnimationController(
133-
vsync: this,
134133
duration: Duration(milliseconds: widget.animationDuration));
135134
_animation =
136135
Tween(begin: 0, end: widget.percentage).animate(_animationController)
@@ -146,7 +145,6 @@ class _GFProgressBarState extends State<GFProgressBar>
146145

147146
if (widget.animation) {
148147
circularAnimationController = AnimationController(
149-
vsync: this,
150148
duration: Duration(milliseconds: widget.animationDuration));
151149
circularAnimation = Tween(begin: 0, end: widget.percentage)
152150
.animate(circularAnimationController)

lib/components/shimmer/gf_shimmer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class _GFShimmerState extends State<GFShimmer>
6565
void initState() {
6666
super.initState();
6767
_count = 0;
68-
_controller = AnimationController(vsync: this, duration: widget.duration)
68+
_controller = AnimationController(duration: widget.duration)
6969
..addStatusListener((AnimationStatus status) {
7070
if (status != AnimationStatus.completed) {
7171
return;

lib/components/toast/gf_toast.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ class _GFToastState extends State<GFToast> with TickerProviderStateMixin {
7171
void initState() {
7272
animationController = AnimationController(
7373
duration: widget.duration,
74-
vsync: this,
7574
);
7675
animation = CurvedAnimation(
7776
parent: animationController,
@@ -81,7 +80,6 @@ class _GFToastState extends State<GFToast> with TickerProviderStateMixin {
8180
if (mounted) {
8281
animationController.forward();
8382
fadeanimationController = AnimationController(
84-
vsync: this,
8583
duration: widget.animationDuration,
8684
)..addListener(() => setState(() {}));
8785
fadeanimation = Tween<double>(

0 commit comments

Comments
 (0)