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
2020-07-05 14:05:43 +0200
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
5e5f65c94ecd4f980cb13fbaaf4160f26bcdc823
5e5f65c9
2 parents
3b8c9a48
da642212
Merge branch 'pr/29'
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
10 deletions
example/lib/main.dart
example/lib/modals/modal_inside_modal.dart
example/pubspec.lock
lib/src/bottom_sheet.dart
example/lib/main.dart
View file @
5e5f65c
...
...
@@ -112,6 +112,7 @@ class _MyHomePageState extends State<MyHomePage> {
child:
SafeArea
(
bottom:
false
,
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
stretch
,
mainAxisSize:
MainAxisSize
.
min
,
children:
<
Widget
>[
ListTile
(
...
...
@@ -119,6 +120,7 @@ class _MyHomePageState extends State<MyHomePage> {
onTap:
()
=>
Navigator
.
of
(
context
).
push
(
MaterialWithModalsPageRoute
(
builder:
(
context
)
=>
CupertinoSharePage
()))),
section
(
'STYLES'
),
ListTile
(
title:
Text
(
'Material fit'
),
onTap:
()
=>
showMaterialModalBottomSheet
(
...
...
@@ -164,6 +166,7 @@ class _MyHomePageState extends State<MyHomePage> {
builder:
(
context
,
scrollController
)
=>
ModalFit
(
scrollController:
scrollController
),
)),
section
(
'COMPLEX CASES'
),
ListTile
(
title:
Text
(
'Cupertino Small Modal forced to expand'
),
onTap:
()
=>
showCupertinoModalBottomSheet
(
...
...
@@ -174,6 +177,17 @@ class _MyHomePageState extends State<MyHomePage> {
ModalFit
(
scrollController:
scrollController
),
)),
ListTile
(
title:
Text
(
'Reverse list'
),
onTap:
()
=>
showBarModalBottomSheet
(
expand:
true
,
context:
context
,
backgroundColor:
Colors
.
transparent
,
builder:
(
context
,
scrollController
)
=>
ModalInsideModal
(
scrollController:
scrollController
,
reverse:
true
),
)),
ListTile
(
title:
Text
(
'Cupertino Modal inside modal'
),
onTap:
()
=>
showCupertinoModalBottomSheet
(
expand:
true
,
...
...
@@ -222,4 +236,13 @@ class _MyHomePageState extends State<MyHomePage> {
),
);
}
Widget
section
(
String
title
)
{
return
Padding
(
padding:
EdgeInsets
.
fromLTRB
(
16
,
20
,
16
,
8
),
child:
Text
(
title
,
style:
Theme
.
of
(
context
).
textTheme
.
caption
,
));
}
}
...
...
example/lib/modals/modal_inside_modal.dart
View file @
5e5f65c
...
...
@@ -4,8 +4,10 @@ import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
class
ModalInsideModal
extends
StatelessWidget
{
final
ScrollController
scrollController
;
final
bool
reverse
;
const
ModalInsideModal
({
Key
key
,
this
.
scrollController
})
:
super
(
key:
key
);
const
ModalInsideModal
({
Key
key
,
this
.
scrollController
,
this
.
reverse
=
false
})
:
super
(
key:
key
);
@override
Widget
build
(
BuildContext
context
)
{
...
...
@@ -16,6 +18,7 @@ class ModalInsideModal extends StatelessWidget {
child:
SafeArea
(
bottom:
false
,
child:
ListView
(
reverse:
reverse
,
shrinkWrap:
true
,
controller:
scrollController
,
physics:
ClampingScrollPhysics
(),
...
...
@@ -24,7 +27,7 @@ class ModalInsideModal extends StatelessWidget {
tiles:
List
.
generate
(
100
,
(
index
)
=>
ListTile
(
title:
Text
(
'Item'
),
title:
Text
(
'Item
$index
'
),
onTap:
()
=>
showCupertinoModalBottomSheet
(
expand:
true
,
isDismissible:
false
,
...
...
@@ -32,7 +35,7 @@ class ModalInsideModal extends StatelessWidget {
backgroundColor:
Colors
.
transparent
,
builder:
(
context
,
scrollController
)
=>
ModalInsideModal
(
scrollController:
scrollController
),
scrollController:
scrollController
,
reverse:
reverse
),
)),
)).
toList
(),
),
...
...
example/pubspec.lock
View file @
5e5f65c
...
...
@@ -106,7 +106,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.
5
"
version: "0.1.
6
"
path:
dependency: transitive
description:
...
...
lib/src/bottom_sheet.dart
View file @
5e5f65c
...
...
@@ -69,6 +69,8 @@ class ModalBottomSheet extends StatefulWidget {
/// the top bound.
final
bool
bounce
;
// Force the widget to fill the maximum size of the viewport
// or if false it will fit to the content of the widget
final
bool
expanded
;
final
WidgetWithChildBuilder
containerBuilder
;
...
...
@@ -242,9 +244,17 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
DateTime
_startTime
;
void
_handleScrollUpdate
(
ScrollNotification
notification
)
{
if
(
notification
.
metrics
.
pixels
<=
notification
.
metrics
.
minScrollExtent
)
{
if
(!
_scrollController
.
hasClients
)
return
;
final
scrollPosition
=
_scrollController
.
position
;
final
isScrollReversed
=
scrollPosition
.
axisDirection
==
AxisDirection
.
down
;
final
offset
=
isScrollReversed
?
scrollPosition
.
pixels
:
scrollPosition
.
maxScrollExtent
-
scrollPosition
.
pixels
;
if
(
offset
<=
0
)
{
//Check if scrollController is used
if
(!
_scrollController
.
hasClients
)
return
;
// Check if listener is same from scrollController.
// TODO: Improve the way it checks if it the same view controller
// Use PrimaryScrollController
...
...
@@ -264,12 +274,13 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
_startTime
=
null
;
return
;
}
// Otherwise the calculate the velocity with a VelocityTracker
DragUpdateDetails
dragDetails
;
// Otherwise the calculate the velocity with a VelocityTracker
if
(
_velocityTracker
==
null
)
{
_velocityTracker
=
VelocityTracker
();
_startTime
=
DateTime
.
now
();
}
DragUpdateDetails
dragDetails
;
if
(
notification
is
ScrollUpdateNotification
)
{
dragDetails
=
notification
.
dragDetails
;
}
...
...
@@ -278,8 +289,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
}
if
(
dragDetails
!=
null
)
{
final
duration
=
_startTime
.
difference
(
DateTime
.
now
());
final
offset
=
Offset
(
0
,
notification
.
metrics
.
pixels
);
_velocityTracker
.
addPosition
(
duration
,
offset
);
_velocityTracker
.
addPosition
(
duration
,
Offset
(
0
,
offset
));
_handleDragUpdate
(
dragDetails
.
primaryDelta
);
}
else
if
(
isDragging
)
{
final
velocity
=
_velocityTracker
.
getVelocity
().
pixelsPerSecond
.
dy
;
...
...
Please
register
or
login
to post a comment