You need to sign in or sign up before continuing.
Rafał Dziuryk

Fix PageView horizontal scroll

Add PageView Sample
@@ -13,6 +13,7 @@ import 'modals/modal_will_scope.dart'; @@ -13,6 +13,7 @@ import 'modals/modal_will_scope.dart';
13 import 'modals/modal_with_navigator.dart'; 13 import 'modals/modal_with_navigator.dart';
14 import 'modals/modal_with_nested_scroll.dart'; 14 import 'modals/modal_with_nested_scroll.dart';
15 import 'modals/modal_with_scroll.dart'; 15 import 'modals/modal_with_scroll.dart';
  16 +import 'modals/modal_with_page_view.dart';
16 17
17 import 'examples/cupertino_share.dart'; 18 import 'examples/cupertino_share.dart';
18 19
@@ -240,6 +241,15 @@ class _MyHomePageState extends State<MyHomePage> { @@ -240,6 +241,15 @@ class _MyHomePageState extends State<MyHomePage> {
240 NestedScrollModal( 241 NestedScrollModal(
241 scrollController: scrollController), 242 scrollController: scrollController),
242 )), 243 )),
  244 + ListTile(
  245 + title: Text('Modal with PageView'),
  246 + onTap: () => showBarModalBottomSheet(
  247 + expand: true,
  248 + context: context,
  249 + builder: (context, scrollController) =>
  250 + ModalWithPageView(
  251 + scrollController: scrollController),
  252 + )),
243 SizedBox( 253 SizedBox(
244 height: 60, 254 height: 60,
245 ) 255 )
  1 +import 'package:flutter/material.dart';
  2 +
  3 +class ModalWithPageView extends StatelessWidget {
  4 + final ScrollController scrollController;
  5 +
  6 + const ModalWithPageView({Key key, this.scrollController}) : super(key: key);
  7 +
  8 + @override
  9 + Widget build(BuildContext context) {
  10 + return Material(
  11 + child: Scaffold(
  12 + appBar: AppBar(
  13 + leading: Container(), title: Text('Modal With Page View')),
  14 + body: SafeArea(
  15 + bottom: false,
  16 + child: PageView(
  17 + children: List.generate(2, (index) => ListView(
  18 + shrinkWrap: true,
  19 + controller: scrollController,
  20 + children: ListTile.divideTiles(
  21 + context: context,
  22 + tiles: List.generate(
  23 + 100,
  24 + (index) => ListTile(
  25 + title: Text('Item'),
  26 + )),
  27 + ).toList(),
  28 + )),
  29 + ),
  30 + ),
  31 + ),
  32 + );
  33 + }
  34 +}
@@ -259,6 +259,8 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> @@ -259,6 +259,8 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
259 void _handleScrollUpdate(ScrollNotification notification) { 259 void _handleScrollUpdate(ScrollNotification notification) {
260 //Check if scrollController is used 260 //Check if scrollController is used
261 if (!_scrollController.hasClients) return; 261 if (!_scrollController.hasClients) return;
  262 + //Check if there is more than 1 attached ScrollController e.g. swiping page in PageView
  263 + if (_scrollController.positions.length > 1) return;
262 264
263 final scrollPosition = _scrollController.position; 265 final scrollPosition = _scrollController.position;
264 266
@@ -305,7 +307,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> @@ -305,7 +307,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
305 if (dragDetails != null) { 307 if (dragDetails != null) {
306 final duration = _startTime.difference(DateTime.now()); 308 final duration = _startTime.difference(DateTime.now());
307 _velocityTracker.addPosition(duration, Offset(0, offset)); 309 _velocityTracker.addPosition(duration, Offset(0, offset));
308 - _handleDragUpdate(dragDetails.primaryDelta); 310 + _handleDragUpdate(dragDetails.delta.dy);
309 } else if (isDragging) { 311 } else if (isDragging) {
310 final velocity = _velocityTracker.getVelocity().pixelsPerSecond.dy; 312 final velocity = _velocityTracker.getVelocity().pixelsPerSecond.dy;
311 _velocityTracker = null; 313 _velocityTracker = null;
@@ -365,7 +367,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> @@ -365,7 +367,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
365 delegate: _CustomBottomSheetLayout(bounceAnimation.value), 367 delegate: _CustomBottomSheetLayout(bounceAnimation.value),
366 child: GestureDetector( 368 child: GestureDetector(
367 onVerticalDragUpdate: (details) { 369 onVerticalDragUpdate: (details) {
368 - _handleDragUpdate(details.primaryDelta); 370 + _handleDragUpdate(details.delta.dy);
369 }, 371 },
370 onVerticalDragEnd: (details) { 372 onVerticalDragEnd: (details) {
371 _handleDragEnd(details.primaryVelocity); 373 _handleDragEnd(details.primaryVelocity);