Jaime Blasco
Committed by GitHub

Merge pull request #57 from DenDos/master

Add closeProgressThreshold parameter
... ... @@ -52,6 +52,7 @@ showMaterialModalBottomSheet(
|AnimationController secondAnimation| The `secondAnimation` parameter allows you to provide an animation controller that will be used to animate push/pop of the modal route. Using this param is advised against and will be probably removed in future versions |
|bool bounce = false| The `bounce` parameter specifies if the bottom sheet can go beyond the top boundary while dragging |
|Duration duration = const Duration(milliseconds: 400)| The `duration` of modal opening |
|double closeProgressThreshold = 0.6| The `closeProgressThreshold` specifies when the bottom sheet will be dismissed when user drags it. |
#### Material params
... ...
... ... @@ -42,6 +42,7 @@ class ModalBottomSheet extends StatefulWidget {
/// Creates a bottom sheet.
const ModalBottomSheet({
Key key,
this.closeProgressThreshold,
this.animationController,
this.animationCurve,
this.enableDrag = true,
... ... @@ -57,6 +58,10 @@ class ModalBottomSheet extends StatefulWidget {
assert(builder != null),
super(key: key);
/// The closeProgressThreshold parameter
/// specifies when the bottom sheet will be dismissed when user drags it.
final double closeProgressThreshold;
/// The animation controller that controls the bottom sheet's entrance and
/// exit animations.
///
... ... @@ -152,7 +157,8 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
widget.animationController.value < _willPopThreshold;
bool get hasReachedCloseThreshold =>
widget.animationController.value < _closeProgressThreshold;
widget.animationController.value <
(widget.closeProgressThreshold ?? _closeProgressThreshold);
void _close() {
isDragging = false;
... ...
... ... @@ -11,6 +11,7 @@ const Duration _bottomSheetDuration = Duration(milliseconds: 400);
class _ModalBottomSheet<T> extends StatefulWidget {
const _ModalBottomSheet({
Key key,
this.closeProgressThreshold,
this.route,
this.secondAnimationController,
this.bounce = false,
... ... @@ -22,6 +23,7 @@ class _ModalBottomSheet<T> extends StatefulWidget {
assert(enableDrag != null),
super(key: key);
final double closeProgressThreshold;
final ModalBottomSheetRoute<T> route;
final bool expanded;
final bool bounce;
... ... @@ -85,6 +87,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
label: _getRouteLabel(),
explicitChildNodes: true,
child: ModalBottomSheet(
closeProgressThreshold: widget.closeProgressThreshold,
expanded: widget.route.expanded,
containerBuilder: widget.route.containerBuilder,
animationController: widget.route._animationController,
... ... @@ -113,6 +116,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
class ModalBottomSheetRoute<T> extends PopupRoute<T> {
ModalBottomSheetRoute({
this.closeProgressThreshold,
this.containerBuilder,
this.builder,
this.scrollController,
... ... @@ -131,6 +135,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> {
assert(enableDrag != null),
super(settings: settings);
final double closeProgressThreshold;
final WidgetWithChildBuilder containerBuilder;
final ScrollWidgetBuilder builder;
final bool expanded;
... ... @@ -180,6 +185,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> {
context: context,
// removeTop: true,
child: _ModalBottomSheet<T>(
closeProgressThreshold: closeProgressThreshold,
route: this,
secondAnimationController: secondAnimationController,
expanded: expanded,
... ...
... ... @@ -75,6 +75,7 @@ Future<T> showBarModalBottomSheet<T>({
Color backgroundColor,
double elevation,
ShapeBorder shape,
double closeProgressThreshold,
Clip clipBehavior,
Color barrierColor = Colors.black87,
bool bounce = true,
... ... @@ -99,6 +100,7 @@ Future<T> showBarModalBottomSheet<T>({
.push(ModalBottomSheetRoute<T>(
builder: builder,
bounce: bounce,
closeProgressThreshold: closeProgressThreshold,
containerBuilder: (_, __, child) => BarBottomSheet(
child: child,
control: topControl,
... ...
... ... @@ -70,6 +70,7 @@ Future<T> showCupertinoModalBottomSheet<T>({
@required ScrollWidgetBuilder builder,
Color backgroundColor,
double elevation,
double closeProgressThreshold,
ShapeBorder shape,
Clip clipBehavior,
Color barrierColor,
... ... @@ -110,6 +111,7 @@ Future<T> showCupertinoModalBottomSheet<T>({
),
secondAnimationController: secondAnimation,
expanded: expand,
closeProgressThreshold: closeProgressThreshold,
barrierLabel: barrierLabel,
elevation: elevation,
bounce: bounce,
... ... @@ -139,6 +141,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> {
CupertinoModalBottomSheetRoute({
ScrollWidgetBuilder builder,
WidgetWithChildBuilder containerBuilder,
double closeProgressThreshold,
String barrierLabel,
double elevation,
ShapeBorder shape,
... ... @@ -160,6 +163,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> {
assert(isDismissible != null),
assert(enableDrag != null),
super(
closeProgressThreshold: closeProgressThreshold,
scrollController: scrollController,
containerBuilder: containerBuilder,
builder: builder,
... ... @@ -318,6 +322,7 @@ class CupertinoScaffold extends StatefulWidget {
static Future<T> showCupertinoModalBottomSheet<T>({
@required BuildContext context,
@required ScrollWidgetBuilder builder,
double closeProgressThreshold,
Curve animationCurve,
Curve previousRouteAnimationCurve,
Color backgroundColor,
... ... @@ -345,6 +350,7 @@ class CupertinoScaffold extends StatefulWidget {
final topRadius = CupertinoScaffold.of(context).topRadius;
final result = await Navigator.of(context, rootNavigator: useRootNavigator)
.push(CupertinoModalBottomSheetRoute<T>(
closeProgressThreshold: closeProgressThreshold,
builder: builder,
secondAnimationController: CupertinoScaffold.of(context).animation,
containerBuilder: (context, _, child) => _CupertinoBottomSheetContainer(
... ...
... ... @@ -6,6 +6,7 @@ import 'dart:async';
Future<T> showMaterialModalBottomSheet<T>({
@required BuildContext context,
@required ScrollWidgetBuilder builder,
double closeProgressThreshold,
Color backgroundColor,
double elevation,
ShapeBorder shape,
... ... @@ -31,6 +32,7 @@ Future<T> showMaterialModalBottomSheet<T>({
final result = await Navigator.of(context, rootNavigator: useRootNavigator)
.push(ModalBottomSheetRoute<T>(
builder: builder,
closeProgressThreshold: closeProgressThreshold,
containerBuilder: _materialContainerBuilder(
context,
backgroundColor: backgroundColor,
... ...