Jaime Blasco

Use PrimaryScrollController

@@ -53,8 +53,8 @@ class CupertinoSharePage extends StatelessWidget { @@ -53,8 +53,8 @@ class CupertinoSharePage extends StatelessWidget {
53 expand: true, 53 expand: true,
54 context: context, 54 context: context,
55 backgroundColor: Colors.transparent, 55 backgroundColor: Colors.transparent,
56 - builder: (context, scrollController) =>  
57 - PhotoShareBottomSheet(scrollController: scrollController), 56 + builder: (context) =>
  57 + PhotoShareBottomSheet(),
58 ); 58 );
59 }, 59 },
60 ), 60 ),
@@ -73,9 +73,9 @@ class CupertinoSharePage extends StatelessWidget { @@ -73,9 +73,9 @@ class CupertinoSharePage extends StatelessWidget {
73 } 73 }
74 74
75 class PhotoShareBottomSheet extends StatelessWidget { 75 class PhotoShareBottomSheet extends StatelessWidget {
76 - final ScrollController scrollController;  
77 76
78 - const PhotoShareBottomSheet({Key key, this.scrollController}) 77 +
  78 + const PhotoShareBottomSheet({Key key})
79 : super(key: key); 79 : super(key: key);
80 80
81 @override 81 @override
@@ -92,7 +92,7 @@ class PhotoShareBottomSheet extends StatelessWidget { @@ -92,7 +92,7 @@ class PhotoShareBottomSheet extends StatelessWidget {
92 appBar: appBar(context), 92 appBar: appBar(context),
93 body: CustomScrollView( 93 body: CustomScrollView(
94 physics: ClampingScrollPhysics(), 94 physics: ClampingScrollPhysics(),
95 - controller: scrollController, 95 + primary: true,
96 slivers: <Widget>[ 96 slivers: <Widget>[
97 SliverSafeArea( 97 SliverSafeArea(
98 bottom: false, 98 bottom: false,
@@ -50,11 +50,9 @@ class MyApp extends StatelessWidget { @@ -50,11 +50,9 @@ class MyApp extends StatelessWidget {
50 expand: true, 50 expand: true,
51 context: context, 51 context: context,
52 backgroundColor: Colors.transparent, 52 backgroundColor: Colors.transparent,
53 - builder: (context, scrollController) =>  
54 - Stack( 53 + builder: (context) => Stack(
55 children: <Widget>[ 54 children: <Widget>[
56 - ModalWithScroll(  
57 - scrollController: scrollController), 55 + ModalWithScroll(),
58 Positioned( 56 Positioned(
59 height: 40, 57 height: 40,
60 left: 40, 58 left: 40,
@@ -130,8 +128,7 @@ class _MyHomePageState extends State<MyHomePage> { @@ -130,8 +128,7 @@ class _MyHomePageState extends State<MyHomePage> {
130 expand: false, 128 expand: false,
131 context: context, 129 context: context,
132 backgroundColor: Colors.transparent, 130 backgroundColor: Colors.transparent,
133 - builder: (context, scrollController) =>  
134 - ModalFit(scrollController: scrollController), 131 + builder: (context) => ModalFit(),
135 )), 132 )),
136 ListTile( 133 ListTile(
137 title: Text('Bar Modal'), 134 title: Text('Bar Modal'),
@@ -139,9 +136,7 @@ class _MyHomePageState extends State<MyHomePage> { @@ -139,9 +136,7 @@ class _MyHomePageState extends State<MyHomePage> {
139 expand: true, 136 expand: true,
140 context: context, 137 context: context,
141 backgroundColor: Colors.transparent, 138 backgroundColor: Colors.transparent,
142 - builder: (context, scrollController) =>  
143 - ModalInsideModal(  
144 - scrollController: scrollController), 139 + builder: (context) => ModalInsideModal(),
145 )), 140 )),
146 ListTile( 141 ListTile(
147 title: Text('Avatar Modal'), 142 title: Text('Avatar Modal'),
@@ -149,16 +144,13 @@ class _MyHomePageState extends State<MyHomePage> { @@ -149,16 +144,13 @@ class _MyHomePageState extends State<MyHomePage> {
149 expand: true, 144 expand: true,
150 context: context, 145 context: context,
151 backgroundColor: Colors.transparent, 146 backgroundColor: Colors.transparent,
152 - builder: (context, scrollController) =>  
153 - ModalInsideModal(  
154 - scrollController: scrollController), 147 + builder: (context) => ModalInsideModal(),
155 )), 148 )),
156 ListTile( 149 ListTile(
157 title: Text('Float Modal'), 150 title: Text('Float Modal'),
158 onTap: () => showFloatingModalBottomSheet( 151 onTap: () => showFloatingModalBottomSheet(
159 context: context, 152 context: context,
160 - builder: (context, scrollController) =>  
161 - ModalFit(scrollController: scrollController), 153 + builder: (context) => ModalFit(),
162 )), 154 )),
163 ListTile( 155 ListTile(
164 title: Text('Cupertino Modal fit'), 156 title: Text('Cupertino Modal fit'),
@@ -166,8 +158,7 @@ class _MyHomePageState extends State<MyHomePage> { @@ -166,8 +158,7 @@ class _MyHomePageState extends State<MyHomePage> {
166 expand: false, 158 expand: false,
167 context: context, 159 context: context,
168 backgroundColor: Colors.transparent, 160 backgroundColor: Colors.transparent,
169 - builder: (context, scrollController) =>  
170 - ModalFit(scrollController: scrollController), 161 + builder: (context) => ModalFit(),
171 )), 162 )),
172 section('COMPLEX CASES'), 163 section('COMPLEX CASES'),
173 ListTile( 164 ListTile(
@@ -176,8 +167,7 @@ class _MyHomePageState extends State<MyHomePage> { @@ -176,8 +167,7 @@ class _MyHomePageState extends State<MyHomePage> {
176 expand: true, 167 expand: true,
177 context: context, 168 context: context,
178 backgroundColor: Colors.transparent, 169 backgroundColor: Colors.transparent,
179 - builder: (context, scrollController) =>  
180 - ModalFit(scrollController: scrollController), 170 + builder: (context) => ModalFit(),
181 )), 171 )),
182 ListTile( 172 ListTile(
183 title: Text('Reverse list'), 173 title: Text('Reverse list'),
@@ -185,10 +175,8 @@ class _MyHomePageState extends State<MyHomePage> { @@ -185,10 +175,8 @@ class _MyHomePageState extends State<MyHomePage> {
185 expand: true, 175 expand: true,
186 context: context, 176 context: context,
187 backgroundColor: Colors.transparent, 177 backgroundColor: Colors.transparent,
188 - builder: (context, scrollController) =>  
189 - ModalInsideModal(  
190 - scrollController: scrollController,  
191 - reverse: true), 178 + builder: (context) =>
  179 + ModalInsideModal(reverse: true),
192 )), 180 )),
193 ListTile( 181 ListTile(
194 title: Text('Cupertino Modal inside modal'), 182 title: Text('Cupertino Modal inside modal'),
@@ -196,9 +184,7 @@ class _MyHomePageState extends State<MyHomePage> { @@ -196,9 +184,7 @@ class _MyHomePageState extends State<MyHomePage> {
196 expand: true, 184 expand: true,
197 context: context, 185 context: context,
198 backgroundColor: Colors.transparent, 186 backgroundColor: Colors.transparent,
199 - builder: (context, scrollController) =>  
200 - ModalInsideModal(  
201 - scrollController: scrollController), 187 + builder: (context) => ModalInsideModal(),
202 )), 188 )),
203 ListTile( 189 ListTile(
204 title: Text('Cupertino Modal with inside navigation'), 190 title: Text('Cupertino Modal with inside navigation'),
@@ -206,9 +192,7 @@ class _MyHomePageState extends State<MyHomePage> { @@ -206,9 +192,7 @@ class _MyHomePageState extends State<MyHomePage> {
206 expand: true, 192 expand: true,
207 context: context, 193 context: context,
208 backgroundColor: Colors.transparent, 194 backgroundColor: Colors.transparent,
209 - builder: (context, scrollController) =>  
210 - ModalWithNavigator(  
211 - scrollController: scrollController), 195 + builder: (context) => ModalWithNavigator(),
212 )), 196 )),
213 ListTile( 197 ListTile(
214 title: 198 title:
@@ -217,9 +201,8 @@ class _MyHomePageState extends State<MyHomePage> { @@ -217,9 +201,8 @@ class _MyHomePageState extends State<MyHomePage> {
217 expand: true, 201 expand: true,
218 context: context, 202 context: context,
219 backgroundColor: Colors.transparent, 203 backgroundColor: Colors.transparent,
220 - builder: (context, scrollController) =>  
221 - ComplexModal(  
222 - scrollController: scrollController), 204 + builder: (context) =>
  205 + ComplexModal(),
223 )), 206 )),
224 ListTile( 207 ListTile(
225 title: Text('Modal with WillPopScope'), 208 title: Text('Modal with WillPopScope'),
@@ -227,18 +210,16 @@ class _MyHomePageState extends State<MyHomePage> { @@ -227,18 +210,16 @@ class _MyHomePageState extends State<MyHomePage> {
227 expand: true, 210 expand: true,
228 context: context, 211 context: context,
229 backgroundColor: Colors.transparent, 212 backgroundColor: Colors.transparent,
230 - builder: (context, scrollController) =>  
231 - ModalWillScope(  
232 - scrollController: scrollController), 213 + builder: (context) =>
  214 + ModalWillScope(),
233 )), 215 )),
234 ListTile( 216 ListTile(
235 title: Text('Modal with Nested Scroll'), 217 title: Text('Modal with Nested Scroll'),
236 onTap: () => showCupertinoModalBottomSheet( 218 onTap: () => showCupertinoModalBottomSheet(
237 expand: true, 219 expand: true,
238 context: context, 220 context: context,
239 - builder: (context, scrollController) =>  
240 - NestedScrollModal(  
241 - scrollController: scrollController), 221 + builder: (context) =>
  222 + NestedScrollModal(),
242 )), 223 )),
243 SizedBox( 224 SizedBox(
244 height: 60, 225 height: 60,
@@ -69,7 +69,7 @@ class AvatarBottomSheet extends StatelessWidget { @@ -69,7 +69,7 @@ class AvatarBottomSheet extends StatelessWidget {
69 69
70 Future<T> showAvatarModalBottomSheet<T>({ 70 Future<T> showAvatarModalBottomSheet<T>({
71 @required BuildContext context, 71 @required BuildContext context,
72 - @required ScrollWidgetBuilder builder, 72 + @required WidgetBuilder builder,
73 Color backgroundColor, 73 Color backgroundColor,
74 double elevation, 74 double elevation,
75 ShapeBorder shape, 75 ShapeBorder shape,
@@ -27,7 +27,7 @@ class FloatingModal extends StatelessWidget { @@ -27,7 +27,7 @@ class FloatingModal extends StatelessWidget {
27 27
28 Future<T> showFloatingModalBottomSheet<T>({ 28 Future<T> showFloatingModalBottomSheet<T>({
29 @required BuildContext context, 29 @required BuildContext context,
30 - @required ScrollWidgetBuilder builder, 30 + @required WidgetBuilder builder,
31 Color backgroundColor, 31 Color backgroundColor,
32 }) async { 32 }) async {
33 final result = await showCustomModalBottomSheet( 33 final result = await showCustomModalBottomSheet(
@@ -2,12 +2,13 @@ import 'package:flutter/cupertino.dart'; @@ -2,12 +2,13 @@ import 'package:flutter/cupertino.dart';
2 import 'package:flutter/material.dart'; 2 import 'package:flutter/material.dart';
3 3
4 class ComplexModal extends StatelessWidget { 4 class ComplexModal extends StatelessWidget {
5 - final ScrollController scrollController;  
6 5
7 - const ComplexModal({Key key, this.scrollController}) : super(key: key); 6 +
  7 + const ComplexModal({Key key}) : super(key: key);
8 8
9 @override 9 @override
10 Widget build(BuildContext context) { 10 Widget build(BuildContext context) {
  11 + final scrollController = PrimaryScrollController.of(context);
11 return Material( 12 return Material(
12 child: WillPopScope( 13 child: WillPopScope(
13 onWillPop: () async { 14 onWillPop: () async {
@@ -46,6 +47,7 @@ class ComplexModal extends StatelessWidget { @@ -46,6 +47,7 @@ class ComplexModal extends StatelessWidget {
46 bottom: false, 47 bottom: false,
47 child: ListView( 48 child: ListView(
48 shrinkWrap: true, 49 shrinkWrap: true,
  50 +
49 controller: scrollController, 51 controller: scrollController,
50 children: ListTile.divideTiles( 52 children: ListTile.divideTiles(
51 context: context, 53 context: context,
@@ -2,9 +2,9 @@ import 'package:flutter/cupertino.dart'; @@ -2,9 +2,9 @@ import 'package:flutter/cupertino.dart';
2 import 'package:flutter/material.dart'; 2 import 'package:flutter/material.dart';
3 3
4 class ModalFit extends StatelessWidget { 4 class ModalFit extends StatelessWidget {
5 - final ScrollController scrollController;  
6 5
7 - const ModalFit({Key key, this.scrollController}) : super(key: key); 6 +
  7 + const ModalFit({Key key}) : super(key: key);
8 8
9 @override 9 @override
10 Widget build(BuildContext context) { 10 Widget build(BuildContext context) {
@@ -3,14 +3,13 @@ import 'package:flutter/material.dart'; @@ -3,14 +3,13 @@ import 'package:flutter/material.dart';
3 import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; 3 import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
4 4
5 class ModalInsideModal extends StatelessWidget { 5 class ModalInsideModal extends StatelessWidget {
6 - final ScrollController scrollController;  
7 final bool reverse; 6 final bool reverse;
8 7
9 - const ModalInsideModal({Key key, this.scrollController, this.reverse = false})  
10 - : super(key: key); 8 + const ModalInsideModal({Key key, this.reverse = false}) : super(key: key);
11 9
12 @override 10 @override
13 Widget build(BuildContext context) { 11 Widget build(BuildContext context) {
  12 + final scrollController = PrimaryScrollController.of(context);
14 return Material( 13 return Material(
15 child: CupertinoPageScaffold( 14 child: CupertinoPageScaffold(
16 navigationBar: CupertinoNavigationBar( 15 navigationBar: CupertinoNavigationBar(
@@ -33,10 +32,8 @@ class ModalInsideModal extends StatelessWidget { @@ -33,10 +32,8 @@ class ModalInsideModal extends StatelessWidget {
33 isDismissible: false, 32 isDismissible: false,
34 context: context, 33 context: context,
35 backgroundColor: Colors.transparent, 34 backgroundColor: Colors.transparent,
36 - builder: (context, scrollController) =>  
37 - ModalInsideModal(  
38 - scrollController: scrollController,  
39 - reverse: reverse), 35 + builder: (context) =>
  36 + ModalInsideModal(reverse: reverse),
40 )), 37 )),
41 )).toList(), 38 )).toList(),
42 ), 39 ),
@@ -2,9 +2,9 @@ import 'package:flutter/cupertino.dart'; @@ -2,9 +2,9 @@ import 'package:flutter/cupertino.dart';
2 import 'package:flutter/material.dart'; 2 import 'package:flutter/material.dart';
3 3
4 class ModalWillScope extends StatelessWidget { 4 class ModalWillScope extends StatelessWidget {
5 - final ScrollController scrollController;  
6 5
7 - const ModalWillScope({Key key, this.scrollController}) : super(key: key); 6 +
  7 + const ModalWillScope({Key key}) : super(key: key);
8 8
9 @override 9 @override
10 Widget build(BuildContext context) { 10 Widget build(BuildContext context) {
@@ -2,12 +2,13 @@ import 'package:flutter/cupertino.dart'; @@ -2,12 +2,13 @@ import 'package:flutter/cupertino.dart';
2 import 'package:flutter/material.dart'; 2 import 'package:flutter/material.dart';
3 3
4 class ModalWithNavigator extends StatelessWidget { 4 class ModalWithNavigator extends StatelessWidget {
5 - final ScrollController scrollController;  
6 5
7 - const ModalWithNavigator({Key key, this.scrollController}) : super(key: key); 6 +
  7 + const ModalWithNavigator({Key key}) : super(key: key);
8 8
9 @override 9 @override
10 Widget build(BuildContext context) { 10 Widget build(BuildContext context) {
  11 + final scrollController = PrimaryScrollController.of(context);
11 return Material( 12 return Material(
12 child: Navigator( 13 child: Navigator(
13 onGenerateRoute: (_) => MaterialPageRoute( 14 onGenerateRoute: (_) => MaterialPageRoute(
@@ -2,12 +2,12 @@ import 'package:flutter/cupertino.dart'; @@ -2,12 +2,12 @@ import 'package:flutter/cupertino.dart';
2 import 'package:flutter/material.dart'; 2 import 'package:flutter/material.dart';
3 3
4 class NestedScrollModal extends StatelessWidget { 4 class NestedScrollModal extends StatelessWidget {
5 - final ScrollController scrollController; 5 + const NestedScrollModal({Key key}) : super(key: key);
6 6
7 - const NestedScrollModal({Key key, this.scrollController}) : super(key: key);  
8 7
9 @override 8 @override
10 Widget build(BuildContext context) { 9 Widget build(BuildContext context) {
  10 + final scrollController = PrimaryScrollController.of(context);
11 return NestedScrollView( 11 return NestedScrollView(
12 controller: ScrollController(), 12 controller: ScrollController(),
13 physics: ScrollPhysics(parent: PageScrollPhysics()), 13 physics: ScrollPhysics(parent: PageScrollPhysics()),
@@ -2,12 +2,11 @@ import 'package:flutter/cupertino.dart'; @@ -2,12 +2,11 @@ import 'package:flutter/cupertino.dart';
2 import 'package:flutter/material.dart'; 2 import 'package:flutter/material.dart';
3 3
4 class ModalWithScroll extends StatelessWidget { 4 class ModalWithScroll extends StatelessWidget {
5 - final ScrollController scrollController;  
6 -  
7 - const ModalWithScroll({Key key, this.scrollController}) : super(key: key); 5 + const ModalWithScroll({Key key}) : super(key: key);
8 6
9 @override 7 @override
10 Widget build(BuildContext context) { 8 Widget build(BuildContext context) {
  9 + final scrollController = PrimaryScrollController.of(context);
11 return Material( 10 return Material(
12 child: CupertinoPageScaffold( 11 child: CupertinoPageScaffold(
13 navigationBar: CupertinoNavigationBar( 12 navigationBar: CupertinoNavigationBar(
@@ -21,9 +21,6 @@ const double _minFlingVelocity = 500.0; @@ -21,9 +21,6 @@ const double _minFlingVelocity = 500.0;
21 const double _closeProgressThreshold = 0.6; 21 const double _closeProgressThreshold = 0.6;
22 const double _willPopThreshold = 0.8; 22 const double _willPopThreshold = 0.8;
23 23
24 -typedef ScrollWidgetBuilder = Widget Function(  
25 - BuildContext context, ScrollController controller);  
26 -  
27 typedef WidgetWithChildBuilder = Widget Function( 24 typedef WidgetWithChildBuilder = Widget Function(
28 BuildContext context, Animation<double> animation, Widget child); 25 BuildContext context, Animation<double> animation, Widget child);
29 26
@@ -51,10 +48,10 @@ class ModalBottomSheet extends StatefulWidget { @@ -51,10 +48,10 @@ class ModalBottomSheet extends StatefulWidget {
51 this.scrollController, 48 this.scrollController,
52 this.expanded, 49 this.expanded,
53 @required this.onClosing, 50 @required this.onClosing,
54 - @required this.builder, 51 + @required this.child,
55 }) : assert(enableDrag != null), 52 }) : assert(enableDrag != null),
56 assert(onClosing != null), 53 assert(onClosing != null),
57 - assert(builder != null), 54 + assert(child != null),
58 super(key: key); 55 super(key: key);
59 56
60 /// The animation controller that controls the bottom sheet's entrance and 57 /// The animation controller that controls the bottom sheet's entrance and
@@ -96,7 +93,7 @@ class ModalBottomSheet extends StatefulWidget { @@ -96,7 +93,7 @@ class ModalBottomSheet extends StatefulWidget {
96 93
97 /// A builder for the contents of the sheet. 94 /// A builder for the contents of the sheet.
98 /// 95 ///
99 - final ScrollWidgetBuilder builder; 96 + final Widget child;
100 97
101 /// If true, the bottom sheet can be dragged up and down and dismissed by 98 /// If true, the bottom sheet can be dragged up and down and dismissed by
102 /// swiping downwards. 99 /// swiping downwards.
@@ -131,7 +128,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> @@ -131,7 +128,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
131 with TickerProviderStateMixin { 128 with TickerProviderStateMixin {
132 final GlobalKey _childKey = GlobalKey(debugLabel: 'BottomSheet child'); 129 final GlobalKey _childKey = GlobalKey(debugLabel: 'BottomSheet child');
133 130
134 - ScrollController _scrollController; 131 + ScrollController get _scrollController => widget.scrollController;
135 132
136 AnimationController _bounceDragController; 133 AnimationController _bounceDragController;
137 134
@@ -260,6 +257,9 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> @@ -260,6 +257,9 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
260 //Check if scrollController is used 257 //Check if scrollController is used
261 if (!_scrollController.hasClients) return; 258 if (!_scrollController.hasClients) return;
262 259
  260 + if (_scrollController !=
  261 + Scrollable.of(notification.context).widget.controller) return;
  262 +
263 final scrollPosition = _scrollController.position; 263 final scrollPosition = _scrollController.position;
264 264
265 if (scrollPosition.axis == Axis.horizontal) return; 265 if (scrollPosition.axis == Axis.horizontal) return;
@@ -270,14 +270,6 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> @@ -270,14 +270,6 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
270 : scrollPosition.maxScrollExtent - scrollPosition.pixels; 270 : scrollPosition.maxScrollExtent - scrollPosition.pixels;
271 271
272 if (offset <= 0) { 272 if (offset <= 0) {
273 - // Check if listener is same from scrollController.  
274 - // TODO: Improve the way it checks if it the same view controller  
275 - // Use PrimaryScrollController  
276 - if (_scrollController.position.pixels != notification.metrics.pixels &&  
277 - !(_scrollController.position.pixels == 0 &&  
278 - notification.metrics.pixels >= 0)) {  
279 - return;  
280 - }  
281 // Clamping Scroll Physics end with a ScrollEndNotification with a DragEndDetail class 273 // Clamping Scroll Physics end with a ScrollEndNotification with a DragEndDetail class
282 // while Bouncing Scroll Physics or other physics that Overflow don't return a drag end info 274 // while Bouncing Scroll Physics or other physics that Overflow don't return a drag end info
283 275
@@ -323,7 +315,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> @@ -323,7 +315,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
323 animationCurve = _defaultCurve; 315 animationCurve = _defaultCurve;
324 _bounceDragController = 316 _bounceDragController =
325 AnimationController(vsync: this, duration: Duration(milliseconds: 300)); 317 AnimationController(vsync: this, duration: Duration(milliseconds: 300));
326 - _scrollController = widget.scrollController ?? ScrollController(); 318 +
327 // Todo: Check if we can remove scroll Controller 319 // Todo: Check if we can remove scroll Controller
328 super.initState(); 320 super.initState();
329 } 321 }
@@ -335,8 +327,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> @@ -335,8 +327,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
335 curve: Curves.easeOutSine, 327 curve: Curves.easeOutSine,
336 ); 328 );
337 329
338 - var child = widget.builder(context, _scrollController);  
339 - 330 + var child = widget.child;
340 if (widget.containerBuilder != null) { 331 if (widget.containerBuilder != null) {
341 child = widget.containerBuilder( 332 child = widget.containerBuilder(
342 context, 333 context,
@@ -394,8 +385,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> @@ -394,8 +385,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
394 child: RepaintBoundary(child: child), 385 child: RepaintBoundary(child: child),
395 ); 386 );
396 387
397 - return PrimaryScrollStatusBarHandler(  
398 - scrollController: _scrollController, child: child); 388 + return PrimaryScrollStatusBarHandler(child: child);
399 } 389 }
400 } 390 }
401 391
@@ -14,7 +14,6 @@ class _ModalBottomSheet<T> extends StatefulWidget { @@ -14,7 +14,6 @@ class _ModalBottomSheet<T> extends StatefulWidget {
14 this.route, 14 this.route,
15 this.secondAnimationController, 15 this.secondAnimationController,
16 this.bounce = false, 16 this.bounce = false,
17 - this.scrollController,  
18 this.expanded = false, 17 this.expanded = false,
19 this.enableDrag = true, 18 this.enableDrag = true,
20 this.animationCurve, 19 this.animationCurve,
@@ -28,7 +27,6 @@ class _ModalBottomSheet<T> extends StatefulWidget { @@ -28,7 +27,6 @@ class _ModalBottomSheet<T> extends StatefulWidget {
28 final bool enableDrag; 27 final bool enableDrag;
29 final AnimationController secondAnimationController; 28 final AnimationController secondAnimationController;
30 final Curve animationCurve; 29 final Curve animationCurve;
31 - final ScrollController scrollController;  
32 30
33 @override 31 @override
34 _ModalBottomSheetState<T> createState() => _ModalBottomSheetState<T>(); 32 _ModalBottomSheetState<T> createState() => _ModalBottomSheetState<T>();
@@ -54,6 +52,8 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { @@ -54,6 +52,8 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
54 return null; 52 return null;
55 } 53 }
56 54
  55 + ScrollController _scrollController;
  56 +
57 @override 57 @override
58 void initState() { 58 void initState() {
59 widget.route.animation.addListener(updateController); 59 widget.route.animation.addListener(updateController);
@@ -63,6 +63,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { @@ -63,6 +63,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
63 @override 63 @override
64 void dispose() { 64 void dispose() {
65 widget.route.animation.removeListener(updateController); 65 widget.route.animation.removeListener(updateController);
  66 + _scrollController?.dispose();
66 super.dispose(); 67 super.dispose();
67 } 68 }
68 69
@@ -74,7 +75,11 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { @@ -74,7 +75,11 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
74 Widget build(BuildContext context) { 75 Widget build(BuildContext context) {
75 assert(debugCheckHasMediaQuery(context)); 76 assert(debugCheckHasMediaQuery(context));
76 77
77 - return AnimatedBuilder( 78 + return PrimaryScrollController(
  79 + controller: PrimaryScrollController.of(context) ??
  80 + (_scrollController ??= ScrollController()),
  81 + child: Builder(
  82 + builder: (context) => AnimatedBuilder(
78 animation: widget.route._animationController, 83 animation: widget.route._animationController,
79 builder: (BuildContext context, Widget child) { 84 builder: (BuildContext context, Widget child) {
80 // Disable the initial animation when accessible navigation is on so 85 // Disable the initial animation when accessible navigation is on so
@@ -99,14 +104,17 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { @@ -99,14 +104,17 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
99 Navigator.of(context).pop(); 104 Navigator.of(context).pop();
100 } 105 }
101 }, 106 },
102 - builder: widget.route.builder, 107 + child: child,
103 enableDrag: widget.enableDrag, 108 enableDrag: widget.enableDrag,
104 bounce: widget.bounce, 109 bounce: widget.bounce,
105 - scrollController: widget.scrollController, 110 + scrollController: PrimaryScrollController.of(context),
106 animationCurve: widget.animationCurve, 111 animationCurve: widget.animationCurve,
107 ), 112 ),
108 ); 113 );
109 }, 114 },
  115 + child: widget.route.builder(context),
  116 + ),
  117 + ),
110 ); 118 );
111 } 119 }
112 } 120 }
@@ -132,7 +140,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> { @@ -132,7 +140,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> {
132 super(settings: settings); 140 super(settings: settings);
133 141
134 final WidgetWithChildBuilder containerBuilder; 142 final WidgetWithChildBuilder containerBuilder;
135 - final ScrollWidgetBuilder builder; 143 + final WidgetBuilder builder;
136 final bool expanded; 144 final bool expanded;
137 final bool bounce; 145 final bool bounce;
138 final Color modalBarrierColor; 146 final Color modalBarrierColor;
@@ -183,7 +191,6 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> { @@ -183,7 +191,6 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> {
183 route: this, 191 route: this,
184 secondAnimationController: secondAnimationController, 192 secondAnimationController: secondAnimationController,
185 expanded: expanded, 193 expanded: expanded,
186 - scrollController: scrollController,  
187 bounce: bounce, 194 bounce: bounce,
188 enableDrag: enableDrag, 195 enableDrag: enableDrag,
189 animationCurve: animationCurve, 196 animationCurve: animationCurve,
@@ -212,7 +219,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> { @@ -212,7 +219,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> {
212 /// Shows a modal material design bottom sheet. 219 /// Shows a modal material design bottom sheet.
213 Future<T> showCustomModalBottomSheet<T>({ 220 Future<T> showCustomModalBottomSheet<T>({
214 @required BuildContext context, 221 @required BuildContext context,
215 - @required ScrollWidgetBuilder builder, 222 + @required WidgetBuilder builder,
216 @required WidgetWithChildBuilder containerWidget, 223 @required WidgetWithChildBuilder containerWidget,
217 Color backgroundColor, 224 Color backgroundColor,
218 double elevation, 225 double elevation,
@@ -226,7 +233,6 @@ Future<T> showCustomModalBottomSheet<T>({ @@ -226,7 +233,6 @@ Future<T> showCustomModalBottomSheet<T>({
226 bool useRootNavigator = false, 233 bool useRootNavigator = false,
227 bool isDismissible = true, 234 bool isDismissible = true,
228 bool enableDrag = true, 235 bool enableDrag = true,
229 - ScrollController scrollController,  
230 Duration duration, 236 Duration duration,
231 }) async { 237 }) async {
232 assert(context != null); 238 assert(context != null);
@@ -71,7 +71,7 @@ class BarBottomSheet extends StatelessWidget { @@ -71,7 +71,7 @@ class BarBottomSheet extends StatelessWidget {
71 71
72 Future<T> showBarModalBottomSheet<T>({ 72 Future<T> showBarModalBottomSheet<T>({
73 @required BuildContext context, 73 @required BuildContext context,
74 - @required ScrollWidgetBuilder builder, 74 + @required WidgetBuilder builder,
75 Color backgroundColor, 75 Color backgroundColor,
76 double elevation, 76 double elevation,
77 ShapeBorder shape, 77 ShapeBorder shape,
@@ -67,7 +67,7 @@ class _CupertinoBottomSheetContainer extends StatelessWidget { @@ -67,7 +67,7 @@ class _CupertinoBottomSheetContainer extends StatelessWidget {
67 67
68 Future<T> showCupertinoModalBottomSheet<T>({ 68 Future<T> showCupertinoModalBottomSheet<T>({
69 @required BuildContext context, 69 @required BuildContext context,
70 - @required ScrollWidgetBuilder builder, 70 + @required WidgetBuilder builder,
71 Color backgroundColor, 71 Color backgroundColor,
72 double elevation, 72 double elevation,
73 ShapeBorder shape, 73 ShapeBorder shape,
@@ -137,7 +137,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> { @@ -137,7 +137,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> {
137 final Color transitionBackgroundColor; 137 final Color transitionBackgroundColor;
138 138
139 CupertinoModalBottomSheetRoute({ 139 CupertinoModalBottomSheetRoute({
140 - ScrollWidgetBuilder builder, 140 + WidgetBuilder builder,
141 WidgetWithChildBuilder containerBuilder, 141 WidgetWithChildBuilder containerBuilder,
142 String barrierLabel, 142 String barrierLabel,
143 double elevation, 143 double elevation,
@@ -317,7 +317,7 @@ class CupertinoScaffold extends StatefulWidget { @@ -317,7 +317,7 @@ class CupertinoScaffold extends StatefulWidget {
317 317
318 static Future<T> showCupertinoModalBottomSheet<T>({ 318 static Future<T> showCupertinoModalBottomSheet<T>({
319 @required BuildContext context, 319 @required BuildContext context,
320 - @required ScrollWidgetBuilder builder, 320 + @required WidgetBuilder builder,
321 Curve animationCurve, 321 Curve animationCurve,
322 Curve previousRouteAnimationCurve, 322 Curve previousRouteAnimationCurve,
323 Color backgroundColor, 323 Color backgroundColor,
@@ -5,7 +5,7 @@ import 'dart:async'; @@ -5,7 +5,7 @@ import 'dart:async';
5 /// Shows a modal material design bottom sheet. 5 /// Shows a modal material design bottom sheet.
6 Future<T> showMaterialModalBottomSheet<T>({ 6 Future<T> showMaterialModalBottomSheet<T>({
7 @required BuildContext context, 7 @required BuildContext context,
8 - @required ScrollWidgetBuilder builder, 8 + @required WidgetBuilder builder,
9 Color backgroundColor, 9 Color backgroundColor,
10 double elevation, 10 double elevation,
11 ShapeBorder shape, 11 ShapeBorder shape,
@@ -4,30 +4,23 @@ import 'package:flutter/widgets.dart'; @@ -4,30 +4,23 @@ import 'package:flutter/widgets.dart';
4 /// scroll to the top when tapped on the status bar 4 /// scroll to the top when tapped on the status bar
5 /// 5 ///
6 class PrimaryScrollStatusBarHandler extends StatefulWidget { 6 class PrimaryScrollStatusBarHandler extends StatefulWidget {
7 - final ScrollController scrollController;  
8 final Widget child; 7 final Widget child;
9 8
10 - const PrimaryScrollStatusBarHandler(  
11 - {Key key, this.child, this.scrollController})  
12 - : super(key: key); 9 + const PrimaryScrollStatusBarHandler({Key key, this.child}) : super(key: key);
  10 +
13 @override 11 @override
14 _PrimaryScrollWidgetState createState() => _PrimaryScrollWidgetState(); 12 _PrimaryScrollWidgetState createState() => _PrimaryScrollWidgetState();
15 } 13 }
16 14
17 class _PrimaryScrollWidgetState extends State<PrimaryScrollStatusBarHandler> { 15 class _PrimaryScrollWidgetState extends State<PrimaryScrollStatusBarHandler> {
18 - ScrollController controller;  
19 -  
20 @override 16 @override
21 void initState() { 17 void initState() {
22 - controller = widget.scrollController ?? ScrollController();  
23 super.initState(); 18 super.initState();
24 } 19 }
25 20
26 @override 21 @override
27 Widget build(BuildContext context) { 22 Widget build(BuildContext context) {
28 - return PrimaryScrollController(  
29 - controller: controller,  
30 - child: Stack( 23 + return Stack(
31 fit: StackFit.expand, 24 fit: StackFit.expand,
32 children: [ 25 children: [
33 widget.child, 26 widget.child,
@@ -46,13 +39,12 @@ class _PrimaryScrollWidgetState extends State<PrimaryScrollStatusBarHandler> { @@ -46,13 +39,12 @@ class _PrimaryScrollWidgetState extends State<PrimaryScrollStatusBarHandler> {
46 ), 39 ),
47 ), 40 ),
48 ], 41 ],
49 - ),  
50 ); 42 );
51 } 43 }
52 44
53 void _handleStatusBarTap(BuildContext context) { 45 void _handleStatusBarTap(BuildContext context) {
54 final controller = PrimaryScrollController.of(context); 46 final controller = PrimaryScrollController.of(context);
55 - if (controller.hasClients) { 47 + if (controller != null && controller.hasClients) {
56 controller.animateTo( 48 controller.animateTo(
57 0.0, 49 0.0,
58 duration: const Duration(milliseconds: 300), 50 duration: const Duration(milliseconds: 300),