Skip to content

Commit 61c4a1b

Browse files
authored
Merge pull request #41 from alex-melnyk/quickfix/disable_gestures_wont_work
#39 gesture issue fix
2 parents df47bd6 + 7a56e51 commit 61c4a1b

File tree

6 files changed

+202
-158
lines changed

6 files changed

+202
-158
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.3.4
2+
3+
* Hot reload + state update support added.
4+
* Added RepaintBoundary for additional performance.
5+
* Removed IgnorePointer and added disabling drag events on GestureDetector.
6+
17
## 1.3.3
28

39
* Disable with IgnorePointer widget added.

example/pubspec.lock

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ packages:
55
dependency: transitive
66
description:
77
name: characters
8-
url: "https://pub.dartlang.org"
8+
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
9+
url: "https://pub.dev"
910
source: hosted
10-
version: "1.2.0"
11+
version: "1.2.1"
1112
collection:
1213
dependency: transitive
1314
description:
1415
name: collection
15-
url: "https://pub.dartlang.org"
16+
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
17+
url: "https://pub.dev"
1618
source: hosted
17-
version: "1.15.0"
19+
version: "1.17.0"
1820
flutter:
1921
dependency: "direct main"
2022
description: flutter
@@ -26,39 +28,44 @@ packages:
2628
path: ".."
2729
relative: true
2830
source: path
29-
version: "1.3.3"
31+
version: "1.3.4"
32+
js:
33+
dependency: transitive
34+
description:
35+
name: js
36+
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
37+
url: "https://pub.dev"
38+
source: hosted
39+
version: "0.6.5"
3040
material_color_utilities:
3141
dependency: transitive
3242
description:
3343
name: material_color_utilities
34-
url: "https://pub.dartlang.org"
44+
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
45+
url: "https://pub.dev"
3546
source: hosted
36-
version: "0.1.3"
47+
version: "0.2.0"
3748
meta:
3849
dependency: transitive
3950
description:
4051
name: meta
41-
url: "https://pub.dartlang.org"
52+
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
53+
url: "https://pub.dev"
4254
source: hosted
43-
version: "1.7.0"
55+
version: "1.8.0"
4456
sky_engine:
4557
dependency: transitive
4658
description: flutter
4759
source: sdk
4860
version: "0.0.99"
49-
typed_data:
50-
dependency: transitive
51-
description:
52-
name: typed_data
53-
url: "https://pub.dartlang.org"
54-
source: hosted
55-
version: "1.3.0"
5661
vector_math:
5762
dependency: transitive
5863
description:
5964
name: vector_math
60-
url: "https://pub.dartlang.org"
65+
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
66+
url: "https://pub.dev"
6167
source: hosted
62-
version: "2.1.1"
68+
version: "2.1.4"
6369
sdks:
64-
dart: ">=2.14.0 <3.0.0"
70+
dart: ">=2.17.0-0 <3.0.0"
71+
flutter: ">=3.7.3"

example/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ publish_to: 'none'
44

55
environment:
66
sdk: ">=2.7.0 <3.0.0"
7+
flutter: 3.7.3
78

89
dependencies:
910
flutter:

lib/src/widget.dart

Lines changed: 140 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -64,32 +64,153 @@ class AdvancedDrawer extends StatefulWidget {
6464
}
6565

6666
class _AdvancedDrawerState extends State<AdvancedDrawer>
67-
with SingleTickerProviderStateMixin {
68-
late final AdvancedDrawerController _controller;
69-
late final AnimationController _animationController;
70-
late final Animation<double> _drawerScaleAnimation;
71-
late final Animation<Offset> _childSlideAnimation;
72-
late final Animation<double> _childScaleAnimation;
73-
late final Animation<Decoration> _childDecorationAnimation;
67+
with TickerProviderStateMixin {
68+
final _spareController = AdvancedDrawerController();
69+
70+
late AnimationController _spareAnimationController;
71+
late AnimationController _animationController;
72+
73+
late Animation<double> _drawerScaleAnimation;
74+
late Animation<Offset> _childSlideAnimation;
75+
late Animation<double> _childScaleAnimation;
76+
late Animation<Decoration> _childDecorationAnimation;
77+
7478
late double _offsetValue;
7579
late Offset _freshPosition;
80+
7681
bool _captured = false;
7782
Offset? _startPosition;
7883

7984
@override
8085
void initState() {
8186
super.initState();
8287

83-
_controller = widget.controller ?? AdvancedDrawerController();
84-
_controller.addListener(_handleControllerChanged);
88+
_initControllers();
89+
}
90+
91+
@override
92+
void didUpdateWidget(covariant AdvancedDrawer oldWidget) {
93+
_initControllers();
94+
95+
super.didUpdateWidget(oldWidget);
96+
}
97+
98+
@override
99+
Widget build(BuildContext context) {
100+
return Material(
101+
color: widget.backdropColor,
102+
child: GestureDetector(
103+
onHorizontalDragStart:
104+
widget.disabledGestures ? null : _handleDragStart,
105+
onHorizontalDragUpdate:
106+
widget.disabledGestures ? null : _handleDragUpdate,
107+
onHorizontalDragEnd: widget.disabledGestures ? null : _handleDragEnd,
108+
onHorizontalDragCancel:
109+
widget.disabledGestures ? null : _handleDragCancel,
110+
child: Container(
111+
color: Colors.transparent,
112+
child: Stack(
113+
children: [
114+
Align(
115+
alignment: widget.rtlOpening
116+
? Alignment.centerRight
117+
: Alignment.centerLeft,
118+
child: FractionallySizedBox(
119+
widthFactor: widget.openRatio,
120+
child: ScaleTransition(
121+
scale: _drawerScaleAnimation,
122+
alignment: widget.rtlOpening
123+
? Alignment.centerLeft
124+
: Alignment.centerRight,
125+
child: RepaintBoundary(
126+
child: widget.drawer,
127+
),
128+
),
129+
),
130+
),
131+
SlideTransition(
132+
position: _childSlideAnimation,
133+
textDirection:
134+
widget.rtlOpening ? TextDirection.rtl : TextDirection.ltr,
135+
child: ScaleTransition(
136+
scale: _childScaleAnimation,
137+
child: Builder(
138+
builder: (_) {
139+
final childStack = Stack(
140+
children: [
141+
RepaintBoundary(child: widget.child),
142+
ValueListenableBuilder<AdvancedDrawerValue>(
143+
valueListenable: _controller,
144+
builder: (_, value, __) {
145+
if (!value.visible) {
146+
return const SizedBox();
147+
}
148+
149+
return Material(
150+
color: Colors.transparent,
151+
child: InkWell(
152+
onTap: _controller.hideDrawer,
153+
highlightColor: Colors.transparent,
154+
child: Container(),
155+
),
156+
);
157+
},
158+
),
159+
],
160+
);
161+
162+
if (widget.animateChildDecoration &&
163+
widget.childDecoration != null) {
164+
return AnimatedBuilder(
165+
animation: _childDecorationAnimation,
166+
builder: (_, child) {
167+
return Container(
168+
clipBehavior: Clip.antiAlias,
169+
decoration: _childDecorationAnimation.value,
170+
child: child,
171+
);
172+
},
173+
child: childStack,
174+
);
175+
}
176+
177+
return Container(
178+
clipBehavior: widget.childDecoration != null
179+
? Clip.antiAlias
180+
: Clip.none,
181+
decoration: widget.childDecoration,
182+
child: childStack,
183+
);
184+
},
185+
),
186+
),
187+
),
188+
],
189+
),
190+
),
191+
),
192+
);
193+
}
194+
195+
AdvancedDrawerController get _controller {
196+
return widget.controller ?? _spareController;
197+
}
198+
199+
void _initControllers() {
200+
_controller
201+
..removeListener(_handleControllerChanged)
202+
..addListener(_handleControllerChanged);
203+
204+
_spareAnimationController = AnimationController(
205+
vsync: this,
206+
value: _controller.value.visible ? 1 : 0,
207+
);
85208

86-
_animationController = widget.animationController ??
87-
AnimationController(
88-
vsync: this,
89-
value: _controller.value.visible ? 1 : 0,
90-
);
209+
_animationController =
210+
widget.animationController ?? _spareAnimationController;
91211

92-
_animationController.duration = widget.animationDuration;
212+
_animationController.reverseDuration =
213+
_animationController.duration = widget.animationDuration;
93214

94215
final parentAnimation = widget.animationCurve == null
95216
? _animationController
@@ -119,101 +240,6 @@ class _AdvancedDrawerState extends State<AdvancedDrawer>
119240
).animate(parentAnimation);
120241
}
121242

122-
@override
123-
Widget build(BuildContext context) {
124-
return Material(
125-
color: widget.backdropColor,
126-
child: IgnorePointer(
127-
ignoring: widget.disabledGestures,
128-
child: GestureDetector(
129-
onHorizontalDragStart: _handleDragStart,
130-
onHorizontalDragUpdate: _handleDragUpdate,
131-
onHorizontalDragEnd: _handleDragEnd,
132-
onHorizontalDragCancel: _handleDragCancel,
133-
child: Container(
134-
color: Colors.transparent,
135-
child: Stack(
136-
children: [
137-
Align(
138-
alignment: widget.rtlOpening
139-
? Alignment.centerRight
140-
: Alignment.centerLeft,
141-
child: FractionallySizedBox(
142-
widthFactor: widget.openRatio,
143-
child: ScaleTransition(
144-
scale: _drawerScaleAnimation,
145-
alignment: widget.rtlOpening
146-
? Alignment.centerLeft
147-
: Alignment.centerRight,
148-
child: widget.drawer,
149-
),
150-
),
151-
),
152-
SlideTransition(
153-
position: _childSlideAnimation,
154-
textDirection:
155-
widget.rtlOpening ? TextDirection.rtl : TextDirection.ltr,
156-
child: ScaleTransition(
157-
scale: _childScaleAnimation,
158-
child: Builder(
159-
builder: (_) {
160-
final childStack = Stack(
161-
children: [
162-
widget.child,
163-
ValueListenableBuilder<AdvancedDrawerValue>(
164-
valueListenable: _controller,
165-
builder: (_, value, __) {
166-
if (!value.visible) {
167-
return const SizedBox();
168-
}
169-
170-
return Material(
171-
color: Colors.transparent,
172-
child: InkWell(
173-
onTap: _controller.hideDrawer,
174-
highlightColor: Colors.transparent,
175-
child: Container(),
176-
),
177-
);
178-
},
179-
),
180-
],
181-
);
182-
183-
if (widget.animateChildDecoration &&
184-
widget.childDecoration != null) {
185-
return AnimatedBuilder(
186-
animation: _childDecorationAnimation,
187-
builder: (_, child) {
188-
return Container(
189-
clipBehavior: Clip.antiAlias,
190-
decoration: _childDecorationAnimation.value,
191-
child: child,
192-
);
193-
},
194-
child: childStack,
195-
);
196-
}
197-
198-
return Container(
199-
clipBehavior: widget.childDecoration != null
200-
? Clip.antiAlias
201-
: Clip.none,
202-
decoration: widget.childDecoration,
203-
child: childStack,
204-
);
205-
},
206-
),
207-
),
208-
),
209-
],
210-
),
211-
),
212-
),
213-
),
214-
);
215-
}
216-
217243
void _handleControllerChanged() {
218244
_controller.value.visible
219245
? _animationController.forward()
@@ -266,15 +292,11 @@ class _AdvancedDrawerState extends State<AdvancedDrawer>
266292

267293
@override
268294
void dispose() {
269-
_controller.removeListener(_handleControllerChanged);
295+
_spareController
296+
..removeListener(_handleControllerChanged)
297+
..dispose();
270298

271-
if (widget.controller == null) {
272-
_controller.dispose();
273-
}
274-
275-
if (widget.animationController == null) {
276-
_animationController.dispose();
277-
}
299+
_spareAnimationController.dispose();
278300

279301
super.dispose();
280302
}

0 commit comments

Comments
 (0)