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:51:07 +0200
Browse Files
Options
Browse Files
Download
Plain Diff
Committed by
GitHub
2020-07-05 14:51:07 +0200
Commit
200f2082cda9bd803d95aa49ca475b916a793b77
200f2082
2 parents
7b9122ad
36b502aa
Merge pull request #36 from jamesblasco/nested_scroll
Nested scroll
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
93 additions
and
64 deletions
example/lib/main.dart
example/lib/modals/modal_with_nested_scroll.dart
lib/src/bottom_sheet.dart
lib/src/bottom_sheets/cupertino_bottom_sheet.dart
pubspec.lock
example/lib/main.dart
View file @
200f208
...
...
@@ -11,6 +11,7 @@ import 'modals/modal_fit.dart';
import
'modals/modal_inside_modal.dart'
;
import
'modals/modal_will_scope.dart'
;
import
'modals/modal_with_navigator.dart'
;
import
'modals/modal_with_nested_scroll.dart'
;
import
'modals/modal_with_scroll.dart'
;
import
'examples/cupertino_share.dart'
;
...
...
@@ -219,7 +220,7 @@ class _MyHomePageState extends State<MyHomePage> {
scrollController:
scrollController
),
)),
ListTile
(
title:
Text
(
'
Cupertino
Modal with WillPopScope'
),
title:
Text
(
'Modal with WillPopScope'
),
onTap:
()
=>
showCupertinoModalBottomSheet
(
expand:
true
,
context:
context
,
...
...
@@ -228,6 +229,15 @@ class _MyHomePageState extends State<MyHomePage> {
ModalWillScope
(
scrollController:
scrollController
),
)),
ListTile
(
title:
Text
(
'Modal with Nested Scroll'
),
onTap:
()
=>
showCupertinoModalBottomSheet
(
expand:
true
,
context:
context
,
builder:
(
context
,
scrollController
)
=>
NestedScrollModal
(
scrollController:
scrollController
),
)),
],
),
),
...
...
example/lib/modals/modal_with_nested_scroll.dart
0 → 100644
View file @
200f208
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/material.dart'
;
class
NestedScrollModal
extends
StatelessWidget
{
final
ScrollController
scrollController
;
const
NestedScrollModal
({
Key
key
,
this
.
scrollController
})
:
super
(
key:
key
);
@override
Widget
build
(
BuildContext
context
)
{
return
NestedScrollView
(
physics:
ScrollPhysics
(
parent:
PageScrollPhysics
()),
headerSliverBuilder:
(
BuildContext
context
,
bool
innerBoxIsScrolled
)
{
return
<
Widget
>[
SliverList
(
delegate:
SliverChildListDelegate
(
[
Container
(
height:
300
,
color:
Colors
.
blue
),
],
),
),
];
},
body:
ListView
.
builder
(
controller:
scrollController
,
itemBuilder:
(
context
,
index
)
{
return
Container
(
height:
100
,
color:
index
.
isOdd
?
Colors
.
green
:
Colors
.
orange
,
);
},
itemCount:
12
,
));
}
}
...
...
lib/src/bottom_sheet.dart
View file @
200f208
...
...
@@ -244,17 +244,19 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
DateTime
_startTime
;
void
_handleScrollUpdate
(
ScrollNotification
notification
)
{
final
scrollPosition
=
_scrollController
.
position
;
if
(
scrollPosition
.
axis
==
Axis
.
horizontal
)
return
;
//Check if scrollController is used
if
(!
_scrollController
.
hasClients
)
return
;
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
...
...
lib/src/bottom_sheets/cupertino_bottom_sheet.dart
View file @
200f208
...
...
@@ -84,6 +84,7 @@ Future<T> showCupertinoModalBottomSheet<T>({
Radius
topRadius
=
_default_top_radius
,
Duration
duration
,
RouteSettings
settings
,
Color
transitionBackgroundColor
,
})
async
{
assert
(
context
!=
null
);
assert
(
builder
!=
null
);
...
...
@@ -121,6 +122,7 @@ Future<T> showCupertinoModalBottomSheet<T>({
previousRouteAnimationCurve:
previousRouteAnimationCurve
,
duration:
duration
,
settings:
settings
,
transitionBackgroundColor:
transitionBackgroundColor
??
Colors
.
black
));
return
result
;
}
...
...
@@ -129,6 +131,10 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> {
final
Radius
topRadius
;
final
Curve
previousRouteAnimationCurve
;
// Background color behind all routes
// Black by default
final
Color
transitionBackgroundColor
;
CupertinoModalBottomSheetRoute
({
ScrollWidgetBuilder
builder
,
WidgetWithChildBuilder
containerBuilder
,
...
...
@@ -145,6 +151,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> {
@required
bool
expanded
,
Duration
duration
,
RouteSettings
settings
,
this
.
transitionBackgroundColor
,
this
.
topRadius
=
_default_top_radius
,
this
.
previousRouteAnimationCurve
,
})
:
assert
(
expanded
!=
null
),
...
...
@@ -199,6 +206,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> {
body:
child
,
animationCurve:
previousRouteAnimationCurve
,
topRadius:
topRadius
,
backgroundColor:
transitionBackgroundColor
??
Colors
.
black
,
);
}
}
...
...
@@ -207,6 +215,7 @@ class _CupertinoModalTransition extends StatelessWidget {
final
Animation
<
double
>
secondaryAnimation
;
final
Radius
topRadius
;
final
Curve
animationCurve
;
final
Color
backgroundColor
;
final
Widget
body
;
...
...
@@ -215,6 +224,7 @@ class _CupertinoModalTransition extends StatelessWidget {
@required
this
.
secondaryAnimation
,
@required
this
.
body
,
@required
this
.
topRadius
,
this
.
backgroundColor
=
Colors
.
black
,
this
.
animationCurve
,
})
:
super
(
key:
key
);
...
...
@@ -246,7 +256,7 @@ class _CupertinoModalTransition extends StatelessWidget {
:
(
1
-
progress
)
*
startRoundCorner
+
progress
*
topRadius
.
x
;
return
Stack
(
children:
<
Widget
>[
Container
(
color:
Colors
.
black
),
Container
(
color:
backgroundColor
),
Transform
.
translate
(
offset:
Offset
(
0
,
yOffset
),
child:
Transform
.
scale
(
...
...
@@ -266,6 +276,7 @@ class _CupertinoModalTransition extends StatelessWidget {
class
_CupertinoScaffold
extends
InheritedWidget
{
final
AnimationController
animation
;
final
Radius
topRadius
;
@override
...
...
@@ -288,10 +299,14 @@ class CupertinoScaffold extends StatefulWidget {
final
Widget
body
;
final
Radius
topRadius
;
final
Color
transitionBackgroundColor
;
const
CupertinoScaffold
(
{
Key
key
,
this
.
body
,
this
.
topRadius
=
_default_top_radius
})
:
super
(
key:
key
);
const
CupertinoScaffold
({
Key
key
,
this
.
body
,
this
.
topRadius
=
_default_top_radius
,
this
.
transitionBackgroundColor
=
Colors
.
black
,
})
:
super
(
key:
key
);
@override
State
<
StatefulWidget
>
createState
()
=>
_CupertinoScaffoldState
();
...
...
@@ -376,6 +391,7 @@ class _CupertinoScaffoldState extends State<CupertinoScaffold>
secondaryAnimation:
animationController
,
body:
widget
.
body
,
topRadius:
widget
.
topRadius
,
backgroundColor:
widget
.
transitionBackgroundColor
,
),
);
}
...
...
pubspec.lock
View file @
200f208
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
async:
dependency: transitive
description:
...
...
@@ -29,6 +15,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
charcode:
dependency: transitive
description:
...
...
@@ -36,27 +29,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
c
ollection
:
c
lock
:
dependency: transitive
description:
name: c
ollection
name: c
lock
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.12"
convert:
version: "1.0.1"
collection:
dependency: transitive
description:
name: co
nvert
name: co
llection
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
crypto:
version: "1.14.13"
fake_async:
dependency: transitive
description:
name:
crypto
name:
fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "
2.1.4
"
version: "
1.1.0
"
flutter:
dependency: "direct main"
description: flutter
...
...
@@ -67,20 +60,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.12"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.
6
"
version: "0.12.
8
"
meta:
dependency: transitive
description:
...
...
@@ -94,28 +80,14 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.
6.4
"
version: "1.
7.0
"
pedantic:
dependency: "direct dev"
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0+1"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
version: "1.9.0"
sky_engine:
dependency: transitive
description: flutter
...
...
@@ -162,7 +134,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.1
5
"
version: "0.2.1
7
"
typed_data:
dependency: transitive
description:
...
...
@@ -177,13 +149,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.6.1"
sdks:
dart: ">=2.
6.0
<3.0.0"
dart: ">=2.
9.0-14.0.dev
<3.0.0"
flutter: ">=1.12.0 <2.0.0"
...
...
Please
register
or
login
to post a comment