Jaime Blasco
Committed by GitHub

Merge pull request #22 from jamesblasco/small_bug_fixes

Small bug fixes
... ... @@ -18,7 +18,7 @@ class ModalInsideModal extends StatelessWidget {
child: ListView(
shrinkWrap: true,
controller: scrollController,
physics: BouncingScrollPhysics(),
physics: ClampingScrollPhysics(),
children: ListTile.divideTiles(
context: context,
tiles: List.generate(
... ...
... ... @@ -13,7 +13,7 @@ import 'package:flutter/widgets.dart';
const Duration _bottomSheetDuration = Duration(milliseconds: 400);
const double _minFlingVelocity = 500.0;
const double _closeProgressThreshold = 0.5;
const double _closeProgressThreshold = 0.6;
const double _willPopThreshold = 0.8;
typedef ScrollWidgetBuilder = Widget Function(
... ... @@ -243,14 +243,30 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
void _handleScrollUpdate(ScrollNotification notification) {
if (notification.metrics.pixels <= notification.metrics.minScrollExtent) {
//Check if listener is same from scrollController
if (!_scrollController.hasClients) return;
if (_scrollController.position.pixels != notification.metrics.pixels) {
// Check if listener is same from scrollController.
// TODO: Improve the way it checks if it the same view controller
// Use PrimaryScrollController
if (_scrollController.position.pixels != notification.metrics.pixels &&
!(_scrollController.position.pixels == 0 &&
notification.metrics.pixels >= 0)) {
return;
}
// Clamping Scroll Physics end with a ScrollEndNotification with a DragEndDetail class
// while Bouncing Scroll Physics or other physics that Overflow don't return a drag end info
// We use the velocity from DragEndDetail in case it is available
if (notification is ScrollEndNotification &&
notification.dragDetails != null) {
_handleDragEnd(notification.dragDetails.primaryVelocity);
_velocityTracker = null;
_startTime = null;
return;
}
// Otherwise the calculate the velocity with a VelocityTracker
DragUpdateDetails dragDetails;
if (notification is ScrollStartNotification) {
if (_velocityTracker == null) {
_velocityTracker = VelocityTracker();
_startTime = DateTime.now();
}
... ... @@ -262,11 +278,13 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
}
if (dragDetails != null) {
final duration = _startTime.difference(DateTime.now());
final offset = Offset(0, _scrollController.offset);
final offset = Offset(0, notification.metrics.pixels);
_velocityTracker.addPosition(duration, offset);
_handleDragUpdate(dragDetails.primaryDelta);
} else if (isDragging) {
final velocity = _velocityTracker.getVelocity().pixelsPerSecond.dy;
_velocityTracker = null;
_startTime = null;
_handleDragEnd(velocity);
}
}
... ... @@ -285,7 +303,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
Widget build(BuildContext context) {
final bounceAnimation = CurvedAnimation(
parent: _bounceDragController,
curve: widget.animationCurve ?? Curves.easeOutSine,
curve: Curves.easeOutSine,
);
var child = widget.builder(context, _scrollController);
... ... @@ -299,17 +317,17 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
}
// Todo: Add curved Animation when push and pop without gesture
/* final Animation<double> containerAnimation = CurvedAnimation(
final Animation<double> containerAnimation = CurvedAnimation(
parent: widget.animationController,
curve: Curves.easeOut,
);*/
curve: widget.animationCurve ?? Curves.linear,
);
return AnimatedBuilder(
animation: widget.animationController,
builder: (context, _) => ClipRect(
child: CustomSingleChildLayout(
delegate: _ModalBottomSheetLayout(
widget.animationController.value, widget.expanded),
containerAnimation.value, widget.expanded),
child: !widget.enableDrag
? child
: KeyedSubtree(
... ...