Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
modal_bottom_sheet
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jaime Blasco
2022-03-09 11:16:45 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
bb309e897cecfbd9486c5bdf4c47d52db9401217
bb309e89
1 parent
e98cc9c3
fix: analyzer warnings
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
99 additions
and
175 deletions
analysis_options.yaml
example/lib/examples/cupertino_share.dart
example/lib/modals/circular_modal.dart
example/lib/modals/floating_modal.dart
example/lib/modals/modal_fit.dart
example/lib/modals/modal_simple.dart
example/lib/modals/modal_with_nested_scroll.dart
example/lib/web_frame.dart
lib/src/bottom_sheet.dart
lib/src/bottom_sheet_route.dart
lib/src/bottom_sheets/bar_bottom_sheet.dart
lib/src/bottom_sheets/cupertino_bottom_sheet.dart
lib/src/bottom_sheets/material_bottom_sheet.dart
lib/src/material_with_modal_page_route.dart
lib/src/utils/bottom_sheet_suspended_curve.dart
lib/src/utils/modal_scroll_controller.dart
lib/src/utils/scroll_to_top_status_bar.dart
analysis_options.yaml
View file @
bb309e8
include
:
package:pedantic/analysis_options.yaml
enable-experiment
:
-
extension-methods
\ No newline at end of file
example/lib/examples/cupertino_share.dart
View file @
bb309e8
...
...
@@ -149,27 +149,28 @@ class PhotoShareBottomSheet extends StatelessWidget {
margin:
EdgeInsets
.
symmetric
(
horizontal:
4
),
child:
Column
(
children:
<
Widget
>[
if
(
app
.
imageUrl
!=
null
)
Material
(
child:
ClipRRect
(
child:
Container
(
height:
60
,
width:
60
,
decoration:
BoxDecoration
(
image:
DecorationImage
(
image:
AssetImage
(
app
.
imageUrl
!),
fit:
BoxFit
.
cover
),
color:
Colors
.
white
,
borderRadius:
BorderRadius
.
circular
(
15
)),
if
(
app
.
imageUrl
!=
null
)
Material
(
child:
ClipRRect
(
child:
Container
(
height:
60
,
width:
60
,
decoration:
BoxDecoration
(
image:
DecorationImage
(
image:
AssetImage
(
app
.
imageUrl
!),
fit:
BoxFit
.
cover
),
color:
Colors
.
white
,
borderRadius:
BorderRadius
.
circular
(
15
)),
),
),
shape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
15
)),
elevation:
12
,
shadowColor:
Colors
.
black12
,
),
shape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
15
)),
elevation:
12
,
shadowColor:
Colors
.
black12
,
),
SizedBox
(
height:
8
),
Text
(
app
.
title
,
...
...
@@ -185,62 +186,62 @@ class PhotoShareBottomSheet extends StatelessWidget {
),
),
SliverPadding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
18
,
vertical:
6
),
sliver:
SliverList
(
delegate:
SliverChildListDelegate
.
fixed
(
List
<
Widget
>.
from
(
actions
.
map
(
(
action
)
=>
Container
(
padding:
EdgeInsets
.
symmetric
(
vertical:
16
,
horizontal:
16
),
child:
Text
(
action
.
title
,
style:
CupertinoTheme
.
of
(
context
)
.
textTheme
.
textStyle
,
)),
)).
addItemInBetween
(
Divider
(
height:
1
,
))),
)),
padding:
EdgeInsets
.
symmetric
(
horizontal:
18
,
vertical:
6
),
sliver:
SliverList
(
delegate:
SliverChildListDelegate
.
fixed
(
List
<
Widget
>.
from
(
actions
.
map
(
(
action
)
=>
Container
(
padding:
EdgeInsets
.
symmetric
(
vertical:
16
,
horizontal:
16
),
child:
Text
(
action
.
title
,
style:
CupertinoTheme
.
of
(
context
)
.
textTheme
.
textStyle
,
)),
)).
addItemInBetween
(
Divider
(
height:
1
,
))),
)),
SliverPadding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
18
,
vertical:
6
),
sliver:
SliverList
(
delegate:
SliverChildListDelegate
.
fixed
(
List
<
Widget
>.
from
(
actions1
.
map
(
(
action
)
=>
Container
(
padding:
EdgeInsets
.
symmetric
(
vertical:
16
,
horizontal:
16
),
child:
Text
(
action
.
title
,
style:
CupertinoTheme
.
of
(
context
)
.
textTheme
.
textStyle
,
)),
)).
addItemInBetween
(
Divider
(
height:
1
,
))),
)
),
padding:
EdgeInsets
.
symmetric
(
horizontal:
18
,
vertical:
6
),
sliver:
SliverList
(
delegate:
SliverChildListDelegate
.
fixed
(
List
<
Widget
>.
from
(
actions1
.
map
(
(
action
)
=>
Container
(
padding:
EdgeInsets
.
symmetric
(
vertical:
16
,
horizontal:
16
),
child:
Text
(
action
.
title
,
style:
CupertinoTheme
.
of
(
context
)
.
textTheme
.
textStyle
,
)),
)).
addItemInBetween
(
Divider
(
height:
1
,
))),
)),
SliverPadding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
18
,
vertical:
4
),
sliver:
SliverList
(
delegate:
SliverChildListDelegate
.
fixed
(
List
<
Widget
>.
from
(
actions2
.
map
(
(
action
)
=>
Container
(
padding:
EdgeInsets
.
symmetric
(
vertical:
16
,
horizontal:
16
),
child:
Text
(
action
.
title
,
style:
CupertinoTheme
.
of
(
context
)
.
textTheme
.
textStyle
,
)),
)).
addItemInBetween
(
Divider
(
height:
1
,
))),
)
),
padding:
EdgeInsets
.
symmetric
(
horizontal:
18
,
vertical:
4
),
sliver:
SliverList
(
delegate:
SliverChildListDelegate
.
fixed
(
List
<
Widget
>.
from
(
actions2
.
map
(
(
action
)
=>
Container
(
padding:
EdgeInsets
.
symmetric
(
vertical:
16
,
horizontal:
16
),
child:
Text
(
action
.
title
,
style:
CupertinoTheme
.
of
(
context
)
.
textTheme
.
textStyle
,
)),
)).
addItemInBetween
(
Divider
(
height:
1
,
))),
)),
SliverSafeArea
(
top:
false
,
sliver:
SliverPadding
(
...
...
@@ -268,19 +269,19 @@ class PhotoShareBottomSheet extends StatelessWidget {
margin:
EdgeInsets
.
symmetric
(
horizontal:
4
),
child:
Column
(
children:
<
Widget
>[
if
(
person
.
imageUrl
!=
null
)
Material
(
child:
CircleAvatar
(
backgroundImage:
AssetImage
(
person
.
imageUrl
!,
if
(
person
.
imageUrl
!=
null
)
Material
(
child:
CircleAvatar
(
backgroundImage:
AssetImage
(
person
.
imageUrl
!,
),
radius:
30
,
backgroundColor:
Colors
.
white
,
),
radius:
30
,
backgroundColor:
Colors
.
white
,
shape:
CircleBorder
(),
elevation:
12
,
shadowColor:
Colors
.
black12
,
),
shape:
CircleBorder
(),
elevation:
12
,
shadowColor:
Colors
.
black12
,
),
SizedBox
(
height:
8
),
Text
(
person
.
title
,
...
...
example/lib/modals/circular_modal.dart
View file @
bb309e8
...
...
@@ -2,14 +2,14 @@ import 'dart:math';
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:modal_bottom_sheet/modal_bottom_sheet.dart'
;
class
AvatarBottomSheet
extends
StatelessWidget
{
final
Widget
child
;
final
Animation
<
double
>
animation
;
const
AvatarBottomSheet
({
Key
?
key
,
required
this
.
child
,
required
this
.
animation
})
const
AvatarBottomSheet
(
{
Key
?
key
,
required
this
.
child
,
required
this
.
animation
})
:
super
(
key:
key
);
@override
...
...
@@ -83,12 +83,6 @@ Future<T?> showAvatarModalBottomSheet<T>({
bool
enableDrag
=
true
,
Duration
?
duration
,
})
async
{
assert
(
context
!=
null
);
assert
(
builder
!=
null
);
assert
(
expand
!=
null
);
assert
(
useRootNavigator
!=
null
);
assert
(
isDismissible
!=
null
);
assert
(
enableDrag
!=
null
);
assert
(
debugCheckHasMediaQuery
(
context
));
assert
(
debugCheckHasMaterialLocalizations
(
context
));
final
result
=
await
Navigator
.
of
(
context
,
rootNavigator:
useRootNavigator
)
...
...
example/lib/modals/floating_modal.dart
View file @
bb309e8
import
'package:flutter/material.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:modal_bottom_sheet/modal_bottom_sheet.dart'
;
class
FloatingModal
extends
StatelessWidget
{
...
...
example/lib/modals/modal_fit.dart
View file @
bb309e8
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/material.dart'
;
class
ModalFit
extends
StatelessWidget
{
...
...
example/lib/modals/modal_simple.dart
View file @
bb309e8
...
...
@@ -2,8 +2,6 @@ import 'package:flutter/cupertino.dart';
import
'package:flutter/material.dart'
;
class
SimpleModal
extends
StatelessWidget
{
const
SimpleModal
({
Key
?
key
})
:
super
(
key:
key
);
@override
...
...
example/lib/modals/modal_with_nested_scroll.dart
View file @
bb309e8
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/material.dart'
;
import
'package:modal_bottom_sheet/modal_bottom_sheet.dart'
;
...
...
example/lib/web_frame.dart
View file @
bb309e8
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:url_launcher/url_launcher.dart'
;
class
WebFrame
extends
StatelessWidget
{
...
...
lib/src/bottom_sheet.dart
View file @
bb309e8
...
...
@@ -3,12 +3,8 @@
// found in the LICENSE file.
import
'dart:async'
;
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/gestures.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:modal_bottom_sheet/src/utils/scroll_to_top_status_bar.dart'
;
import
'package:modal_bottom_sheet/src/utils/bottom_sheet_suspended_curve.dart'
;
...
...
@@ -49,10 +45,7 @@ class ModalBottomSheet extends StatefulWidget {
required
this
.
expanded
,
required
this
.
onClosing
,
required
this
.
child
,
})
:
assert
(
enableDrag
!=
null
),
assert
(
onClosing
!=
null
),
assert
(
child
!=
null
),
super
(
key:
key
);
})
:
super
(
key:
key
);
/// The closeProgressThreshold parameter
/// specifies when the bottom sheet will be dismissed when user drags it.
...
...
@@ -488,5 +481,4 @@ PointerDeviceKind defaultPointerDeviceKind(BuildContext context) {
case
TargetPlatform
.
fuchsia
:
return
PointerDeviceKind
.
unknown
;
}
return
PointerDeviceKind
.
unknown
;
}
...
...
lib/src/bottom_sheet_route.dart
View file @
bb309e8
import
'dart:async'
;
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:modal_bottom_sheet/src/utils/modal_scroll_controller.dart'
;
import
'../modal_bottom_sheet.dart'
;
...
...
@@ -19,9 +16,7 @@ class _ModalBottomSheet<T> extends StatefulWidget {
this
.
expanded
=
false
,
this
.
enableDrag
=
true
,
this
.
animationCurve
,
})
:
assert
(
expanded
!=
null
),
assert
(
enableDrag
!=
null
),
super
(
key:
key
);
})
:
super
(
key:
key
);
final
double
?
closeProgressThreshold
;
final
ModalBottomSheetRoute
<
T
>
route
;
...
...
@@ -143,10 +138,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> {
this
.
animationCurve
,
this
.
duration
,
RouteSettings
?
settings
,
})
:
assert
(
expanded
!=
null
),
assert
(
isDismissible
!=
null
),
assert
(
enableDrag
!=
null
),
super
(
settings:
settings
);
})
:
super
(
settings:
settings
);
final
double
?
closeProgressThreshold
;
final
WidgetWithChildBuilder
?
containerBuilder
;
...
...
@@ -247,13 +239,6 @@ Future<T?> showCustomModalBottomSheet<T>({
Duration
?
duration
,
RouteSettings
?
settings
,
})
async
{
assert
(
context
!=
null
);
assert
(
builder
!=
null
);
assert
(
containerWidget
!=
null
);
assert
(
expand
!=
null
);
assert
(
useRootNavigator
!=
null
);
assert
(
isDismissible
!=
null
);
assert
(
enableDrag
!=
null
);
assert
(
debugCheckHasMediaQuery
(
context
));
assert
(
debugCheckHasMaterialLocalizations
(
context
));
final
hasMaterialLocalizations
=
...
...
lib/src/bottom_sheets/bar_bottom_sheet.dart
View file @
bb309e8
...
...
@@ -90,12 +90,6 @@ Future<T?> showBarModalBottomSheet<T>({
Duration
?
duration
,
RouteSettings
?
settings
,
})
async
{
assert
(
context
!=
null
);
assert
(
builder
!=
null
);
assert
(
expand
!=
null
);
assert
(
useRootNavigator
!=
null
);
assert
(
isDismissible
!=
null
);
assert
(
enableDrag
!=
null
);
assert
(
debugCheckHasMediaQuery
(
context
));
assert
(
debugCheckHasMaterialLocalizations
(
context
));
final
result
=
await
Navigator
.
of
(
context
,
rootNavigator:
useRootNavigator
)
...
...
lib/src/bottom_sheets/cupertino_bottom_sheet.dart
View file @
bb309e8
...
...
@@ -5,8 +5,6 @@
import
'dart:async'
;
import
'package:flutter/cupertino.dart'
show
CupertinoTheme
,
CupertinoApp
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/gestures.dart'
;
import
'package:flutter/material.dart'
show
Colors
,
...
...
@@ -17,12 +15,12 @@ import 'package:flutter/services.dart';
import
'package:flutter/widgets.dart'
;
import
'../../modal_bottom_sheet.dart'
;
import
'../bottom_sheet_route.dart'
;
const
double
_kPreviousPageVisibleOffset
=
10
;
const
Radius
_kDefaultTopRadius
=
Radius
.
circular
(
12
);
const
BoxShadow
_kDefaultBoxShadow
=
BoxShadow
(
blurRadius:
10
,
color:
Colors
.
black12
,
spreadRadius:
5
);
const
BoxShadow
_kDefaultBoxShadow
=
BoxShadow
(
blurRadius:
10
,
color:
Colors
.
black12
,
spreadRadius:
5
);
/// Cupertino Bottom Sheet Container
///
...
...
@@ -43,14 +41,13 @@ class _CupertinoBottomSheetContainer extends StatelessWidget {
this
.
shadow
,
})
:
super
(
key:
key
);
@override
Widget
build
(
BuildContext
context
)
{
final
topSafeAreaPadding
=
MediaQuery
.
of
(
context
).
padding
.
top
;
final
topPadding
=
_kPreviousPageVisibleOffset
+
topSafeAreaPadding
;
final
_shadow
=
shadow
??
_kDefaultBoxShadow
;
BoxShadow
(
blurRadius:
10
,
color:
Colors
.
black12
,
spreadRadius:
5
);
BoxShadow
(
blurRadius:
10
,
color:
Colors
.
black12
,
spreadRadius:
5
);
final
_backgroundColor
=
backgroundColor
??
CupertinoTheme
.
of
(
context
).
scaffoldBackgroundColor
;
return
Padding
(
...
...
@@ -95,11 +92,6 @@ Future<T?> showCupertinoModalBottomSheet<T>({
Color
?
transitionBackgroundColor
,
BoxShadow
?
shadow
,
})
async
{
assert
(
context
!=
null
);
assert
(
builder
!=
null
);
assert
(
expand
!=
null
);
assert
(
useRootNavigator
!=
null
);
assert
(
enableDrag
!=
null
);
assert
(
debugCheckHasMediaQuery
(
context
));
final
hasMaterialLocalizations
=
Localizations
.
of
<
MaterialLocalizations
>(
context
,
MaterialLocalizations
)
!=
...
...
@@ -144,7 +136,6 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> {
final
Curve
?
previousRouteAnimationCurve
;
final
BoxShadow
?
boxShadow
;
// Background color behind all routes
...
...
@@ -173,10 +164,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> {
this
.
transitionBackgroundColor
,
this
.
topRadius
=
_kDefaultTopRadius
,
this
.
previousRouteAnimationCurve
,
})
:
assert
(
expanded
!=
null
),
assert
(
isDismissible
!=
null
),
assert
(
enableDrag
!=
null
),
super
(
})
:
super
(
closeProgressThreshold:
closeProgressThreshold
,
scrollController:
scrollController
,
containerBuilder:
containerBuilder
,
...
...
@@ -201,8 +189,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> {
Widget
child
,
)
{
final
paddingTop
=
MediaQuery
.
of
(
context
).
padding
.
top
;
final
distanceWithScale
=
(
paddingTop
+
_kPreviousPageVisibleOffset
)
*
0.9
;
final
distanceWithScale
=
(
paddingTop
+
_kPreviousPageVisibleOffset
)
*
0.9
;
final
offsetY
=
secondaryAnimation
.
value
*
(
paddingTop
-
distanceWithScale
);
final
scale
=
1
-
secondaryAnimation
.
value
/
10
;
return
AnimatedBuilder
(
...
...
@@ -237,7 +224,6 @@ class _CupertinoModalTransition extends StatelessWidget {
final
Radius
topRadius
;
final
Curve
?
animationCurve
;
final
Color
backgroundColor
;
final
BoxShadow
?
boxShadow
;
final
Widget
body
;
...
...
@@ -248,7 +234,6 @@ class _CupertinoModalTransition extends StatelessWidget {
required
this
.
topRadius
,
this
.
backgroundColor
=
Colors
.
black
,
this
.
animationCurve
,
this
.
boxShadow
,
})
:
super
(
key:
key
);
@override
...
...
@@ -355,11 +340,6 @@ class CupertinoScaffold extends StatefulWidget {
RouteSettings
?
settings
,
BoxShadow
?
shadow
,
})
async
{
assert
(
context
!=
null
);
assert
(
builder
!=
null
);
assert
(
expand
!=
null
);
assert
(
useRootNavigator
!=
null
);
assert
(
enableDrag
!=
null
);
assert
(
debugCheckHasMediaQuery
(
context
));
final
isCupertinoApp
=
context
.
findAncestorWidgetOfExactType
<
CupertinoApp
>()
!=
null
;
...
...
lib/src/bottom_sheets/material_bottom_sheet.dart
View file @
bb309e8
...
...
@@ -22,12 +22,6 @@ Future<T?> showMaterialModalBottomSheet<T>({
Duration
?
duration
,
RouteSettings
?
settings
,
})
async
{
assert
(
context
!=
null
);
assert
(
builder
!=
null
);
assert
(
expand
!=
null
);
assert
(
useRootNavigator
!=
null
);
assert
(
isDismissible
!=
null
);
assert
(
enableDrag
!=
null
);
assert
(
debugCheckHasMediaQuery
(
context
));
assert
(
debugCheckHasMaterialLocalizations
(
context
));
final
result
=
await
Navigator
.
of
(
context
,
rootNavigator:
useRootNavigator
)
...
...
lib/src/material_with_modal_page_route.dart
View file @
bb309e8
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'../modal_bottom_sheet.dart'
;
...
...
@@ -15,10 +14,7 @@ class MaterialWithModalsPageRoute<T> extends MaterialPageRoute<T> {
RouteSettings
?
settings
,
bool
maintainState
=
true
,
bool
fullscreenDialog
=
false
,
})
:
assert
(
builder
!=
null
),
assert
(
maintainState
!=
null
),
assert
(
fullscreenDialog
!=
null
),
super
(
})
:
super
(
settings:
settings
,
fullscreenDialog:
fullscreenDialog
,
builder:
builder
,
...
...
lib/src/utils/bottom_sheet_suspended_curve.dart
View file @
bb309e8
...
...
@@ -30,8 +30,7 @@ class BottomSheetSuspendedCurve extends Curve {
const
BottomSheetSuspendedCurve
(
this
.
startingPoint
,
{
this
.
curve
=
Curves
.
easeOutCubic
,
})
:
assert
(
startingPoint
!=
null
),
assert
(
curve
!=
null
);
});
/// The progress value at which [curve] should begin.
///
...
...
lib/src/utils/modal_scroll_controller.dart
View file @
bb309e8
...
...
@@ -16,8 +16,7 @@ class ModalScrollController extends InheritedWidget {
Key
?
key
,
required
this
.
controller
,
required
Widget
child
,
})
:
assert
(
controller
!=
null
),
super
(
})
:
super
(
key:
key
,
child:
PrimaryScrollController
(
controller:
controller
,
...
...
lib/src/utils/scroll_to_top_status_bar.dart
View file @
bb309e8
...
...
@@ -50,7 +50,7 @@ class _ScrollToTopStatusBarState extends State<ScrollToTopStatusBarHandler> {
void
_handleStatusBarTap
(
BuildContext
context
)
{
final
controller
=
widget
.
scrollController
;
if
(
controller
!=
null
&&
controller
.
hasClients
)
{
if
(
controller
.
hasClients
)
{
controller
.
animateTo
(
0.0
,
duration:
const
Duration
(
milliseconds:
300
),
...
...
Please
register
or
login
to post a comment