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 11:24:58 +0200
Browse Files
Options
Browse Files
Download
Plain Diff
Committed by
GitHub
2020-07-05 11:24:58 +0200
Commit
3b8c9a482fdb17bdc77f59111219035dd4df02bc
3b8c9a48
2 parents
05c9e531
d7728be0
Merge pull request #22 from jamesblasco/small_bug_fixes
Small bug fixes
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
11 deletions
example/lib/modals/modal_inside_modal.dart
lib/src/bottom_sheet.dart
example/lib/modals/modal_inside_modal.dart
View file @
3b8c9a4
...
...
@@ -18,7 +18,7 @@ class ModalInsideModal extends StatelessWidget {
child:
ListView
(
shrinkWrap:
true
,
controller:
scrollController
,
physics:
Bounc
ingScrollPhysics
(),
physics:
Clamp
ingScrollPhysics
(),
children:
ListTile
.
divideTiles
(
context:
context
,
tiles:
List
.
generate
(
...
...
lib/src/bottom_sheet.dart
View file @
3b8c9a4
...
...
@@ -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
(
...
...
Please
register
or
login
to post a comment