Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
ab5dfe1d
Unverified
Commit
ab5dfe1d
authored
Oct 15, 2021
by
Casey Rogers
Committed by
GitHub
Oct 15, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
s/extent/size/ (#91775)
parent
3ece170c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
76 deletions
+76
-76
draggable_scrollable_sheet.dart
...s/flutter/lib/src/widgets/draggable_scrollable_sheet.dart
+76
-76
No files found.
packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart
View file @
ab5dfe1d
...
...
@@ -282,111 +282,111 @@ class DraggableScrollableNotification extends Notification with ViewportNotifica
///
/// The ScrollPosition knows the number of pixels a user wants to move the sheet.
///
/// The [current
Extent
] will never be null.
/// The [current
Size
] will never be null.
/// The [availablePixels] will never be null, but may be `double.infinity`.
class
_DraggableSheetExtent
{
_DraggableSheetExtent
({
required
this
.
min
Extent
,
required
this
.
max
Extent
,
required
this
.
min
Size
,
required
this
.
max
Size
,
required
this
.
snap
,
required
this
.
snapSizes
,
required
this
.
initial
Extent
,
required
this
.
on
Extent
Changed
,
ValueNotifier
<
double
>?
current
Extent
,
required
this
.
initial
Size
,
required
this
.
on
Size
Changed
,
ValueNotifier
<
double
>?
current
Size
,
bool
?
hasChanged
,
})
:
assert
(
min
Extent
!=
null
),
assert
(
max
Extent
!=
null
),
assert
(
initial
Extent
!=
null
),
assert
(
min
Extent
>=
0
),
assert
(
max
Extent
<=
1
),
assert
(
min
Extent
<=
initialExtent
),
assert
(
initial
Extent
<=
maxExtent
),
_current
Extent
=
(
currentExtent
??
ValueNotifier
<
double
>(
initialExtent
))
..
addListener
(
on
Extent
Changed
),
})
:
assert
(
min
Size
!=
null
),
assert
(
max
Size
!=
null
),
assert
(
initial
Size
!=
null
),
assert
(
min
Size
>=
0
),
assert
(
max
Size
<=
1
),
assert
(
min
Size
<=
initialSize
),
assert
(
initial
Size
<=
maxSize
),
_current
Size
=
(
currentSize
??
ValueNotifier
<
double
>(
initialSize
))
..
addListener
(
on
Size
Changed
),
availablePixels
=
double
.
infinity
,
hasChanged
=
hasChanged
??
false
;
final
double
min
Extent
;
final
double
max
Extent
;
final
double
min
Size
;
final
double
max
Size
;
final
bool
snap
;
final
List
<
double
>
snapSizes
;
final
double
initial
Extent
;
final
ValueNotifier
<
double
>
_current
Extent
;
final
VoidCallback
on
Extent
Changed
;
final
double
initial
Size
;
final
ValueNotifier
<
double
>
_current
Size
;
final
VoidCallback
on
Size
Changed
;
double
availablePixels
;
// Used to disable snapping until the extent has changed. We do this because
// we don't want to snap away from the initial extent.
// Used to disable snapping until the user interacts with the sheet. We set
// this to false on initialization and after programmatic interaction with the
// sheet to prevent snapping away from the initial size and after animateTo/jumpTo.
bool
hasChanged
;
bool
get
isAtMin
=>
min
Extent
>=
_currentExtent
.
value
;
bool
get
isAtMax
=>
max
Extent
<=
_currentExtent
.
value
;
bool
get
isAtMin
=>
min
Size
>=
_currentSize
.
value
;
bool
get
isAtMax
=>
max
Size
<=
_currentSize
.
value
;
set
current
Extent
(
double
value
)
{
set
current
Size
(
double
value
)
{
assert
(
value
!=
null
);
hasChanged
=
true
;
_current
Extent
.
value
=
value
.
clamp
(
minExtent
,
maxExtent
);
_current
Size
.
value
=
value
.
clamp
(
minSize
,
maxSize
);
}
double
get
current
Extent
=>
_currentExtent
.
value
;
double
get
currentPixels
=>
extentToPixels
(
_currentExtent
.
value
);
double
get
current
Size
=>
_currentSize
.
value
;
double
get
currentPixels
=>
sizeToPixels
(
_currentSize
.
value
);
double
get
additionalMin
Extent
=>
isAtMin
?
0.0
:
1.0
;
double
get
additionalMax
Extent
=>
isAtMax
?
0.0
:
1.0
;
List
<
double
>
get
pixelSnapSizes
=>
snapSizes
.
map
(
extent
ToPixels
).
toList
();
double
get
additionalMin
Size
=>
isAtMin
?
0.0
:
1.0
;
double
get
additionalMax
Size
=>
isAtMax
?
0.0
:
1.0
;
List
<
double
>
get
pixelSnapSizes
=>
snapSizes
.
map
(
size
ToPixels
).
toList
();
/// The scroll position gets inputs in terms of pixels, but the
extent
is
/// The scroll position gets inputs in terms of pixels, but the
size
is
/// expected to be expressed as a number between 0..1.
void
addPixelDelta
(
double
delta
,
BuildContext
context
)
{
if
(
availablePixels
==
0
)
{
return
;
}
update
Extent
(
currentExtent
+
pixelsToExtent
(
delta
),
context
);
update
Size
(
currentSize
+
pixelsToSize
(
delta
),
context
);
}
/// Set the extent to the new value. [newExtent] should be a number between
/// 0..1.
void
updateExtent
(
double
newExtent
,
BuildContext
context
)
{
currentExtent
=
newExtent
;
/// Set the size to the new value. [newSize] should be a number between 0..1.
void
updateSize
(
double
newSize
,
BuildContext
context
)
{
currentSize
=
newSize
;
DraggableScrollableNotification
(
minExtent:
min
Extent
,
maxExtent:
max
Extent
,
extent:
current
Extent
,
initialExtent:
initial
Extent
,
minExtent:
min
Size
,
maxExtent:
max
Size
,
extent:
current
Size
,
initialExtent:
initial
Size
,
context:
context
,
).
dispatch
(
context
);
}
double
pixelsTo
Extent
(
double
pixels
)
{
return
pixels
/
availablePixels
*
max
Extent
;
double
pixelsTo
Size
(
double
pixels
)
{
return
pixels
/
availablePixels
*
max
Size
;
}
double
extent
ToPixels
(
double
extent
)
{
return
extent
/
max
Extent
*
availablePixels
;
double
size
ToPixels
(
double
extent
)
{
return
extent
/
max
Size
*
availablePixels
;
}
void
dispose
()
{
_current
Extent
.
removeListener
(
onExtent
Changed
);
_current
Size
.
removeListener
(
onSize
Changed
);
}
_DraggableSheetExtent
copyWith
({
required
double
min
Extent
,
required
double
max
Extent
,
required
double
min
Size
,
required
double
max
Size
,
required
bool
snap
,
required
List
<
double
>
snapSizes
,
required
double
initial
Extent
,
required
VoidCallback
on
Extent
Changed
,
required
double
initial
Size
,
required
VoidCallback
on
Size
Changed
,
})
{
return
_DraggableSheetExtent
(
min
Extent:
minExtent
,
max
Extent:
maxExtent
,
min
Size:
minSize
,
max
Size:
maxSize
,
snap:
snap
,
snapSizes:
snapSizes
,
initial
Extent:
initialExtent
,
on
ExtentChanged:
onExtent
Changed
,
initial
Size:
initialSize
,
on
SizeChanged:
onSize
Changed
,
// Use the possibly updated initialExtent if the user hasn't dragged yet.
current
Extent
:
ValueNotifier
<
double
>(
hasChanged
?
_current
Extent
.
value
.
clamp
(
minExtent
,
maxExtent
)
:
initial
Extent
),
current
Size
:
ValueNotifier
<
double
>(
hasChanged
?
_current
Size
.
value
.
clamp
(
minSize
,
maxSize
)
:
initial
Size
),
hasChanged:
hasChanged
,
);
}
...
...
@@ -400,12 +400,12 @@ class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> {
void
initState
()
{
super
.
initState
();
_extent
=
_DraggableSheetExtent
(
min
Extent
:
widget
.
minChildSize
,
max
Extent
:
widget
.
maxChildSize
,
min
Size
:
widget
.
minChildSize
,
max
Size
:
widget
.
maxChildSize
,
snap:
widget
.
snap
,
snapSizes:
_impliedSnapSizes
(),
initial
Extent
:
widget
.
initialChildSize
,
on
ExtentChanged:
_setExtent
,
initial
Size
:
widget
.
initialChildSize
,
on
SizeChanged:
_setSize
,
);
_scrollController
=
_DraggableScrollableSheetScrollController
(
extent:
_extent
);
}
...
...
@@ -455,11 +455,11 @@ class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> {
);
}
_extent
.
hasChanged
=
false
;
_extent
.
_current
Extent
.
value
=
_extent
.
initialExtent
;
_extent
.
_current
Size
.
value
=
_extent
.
initialSize
;
}
}
void
_set
Extent
()
{
void
_set
Size
()
{
setState
(()
{
// _extent has been updated when this is called.
});
...
...
@@ -471,7 +471,7 @@ class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> {
builder:
(
BuildContext
context
,
BoxConstraints
constraints
)
{
_extent
.
availablePixels
=
widget
.
maxChildSize
*
constraints
.
biggest
.
height
;
final
Widget
sheet
=
FractionallySizedBox
(
heightFactor:
_extent
.
current
Extent
,
heightFactor:
_extent
.
current
Size
,
alignment:
Alignment
.
bottomCenter
,
child:
widget
.
builder
(
context
,
_scrollController
),
);
...
...
@@ -490,12 +490,12 @@ class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> {
void
_replaceExtent
()
{
_extent
.
dispose
();
_extent
=
_extent
.
copyWith
(
min
Extent
:
widget
.
minChildSize
,
max
Extent
:
widget
.
maxChildSize
,
min
Size
:
widget
.
minChildSize
,
max
Size
:
widget
.
maxChildSize
,
snap:
widget
.
snap
,
snapSizes:
_impliedSnapSizes
(),
initial
Extent
:
widget
.
initialChildSize
,
on
ExtentChanged:
_setExtent
,
initial
Size
:
widget
.
initialChildSize
,
on
SizeChanged:
_setSize
,
);
// Modify the existing scroll controller instead of replacing it so that
// developers listening to the controller do not have to rebuild their listeners.
...
...
@@ -584,7 +584,7 @@ class _DraggableScrollableSheetScrollController extends ScrollController {
/// This class is a concrete subclass of [ScrollPosition] logic that handles a
/// single [ScrollContext], such as a [Scrollable]. An instance of this class
/// manages [ScrollActivity] instances, which changes the
/// [_DraggableSheetExtent.current
Extent
] or visible content offset in the
/// [_DraggableSheetExtent.current
Size
] or visible content offset in the
/// [Scrollable]'s [Viewport]
///
/// See also:
...
...
@@ -624,13 +624,13 @@ class _DraggableScrollableSheetScrollPosition
}
@override
bool
applyContentDimensions
(
double
minScroll
Extent
,
double
maxScrollExtent
)
{
// We need to provide some extra
extent
if we haven't yet reached the max or
// min
extents. Otherwise, a list with fewer children than the extent
of
bool
applyContentDimensions
(
double
minScroll
Size
,
double
maxScrollSize
)
{
// We need to provide some extra
size
if we haven't yet reached the max or
// min
sizes. Otherwise, a list with fewer children than the size
of
// the available space will get stuck.
return
super
.
applyContentDimensions
(
minScroll
Extent
-
extent
.
additionalMinExtent
,
maxScroll
Extent
+
extent
.
additionalMaxExtent
,
minScroll
Size
-
extent
.
additionalMinSize
,
maxScroll
Size
+
extent
.
additionalMaxSize
,
);
}
...
...
@@ -649,7 +649,7 @@ class _DraggableScrollableSheetScrollPosition
bool
get
_isAtSnapSize
{
return
extent
.
snapSizes
.
any
(
(
double
snapSize
)
{
return
(
extent
.
current
Extent
-
snapSize
).
abs
()
<=
extent
.
pixelsToExtent
(
physics
.
tolerance
.
distance
);
return
(
extent
.
current
Size
-
snapSize
).
abs
()
<=
extent
.
pixelsToSize
(
physics
.
tolerance
.
distance
);
},
);
}
...
...
@@ -803,7 +803,7 @@ class _ResetNotifier extends ChangeNotifier {
class
_InheritedResetNotifier
extends
InheritedNotifier
<
_ResetNotifier
>
{
/// Creates an [InheritedNotifier] that the [DraggableScrollableSheet] will
/// listen to for an indication that it should
change its extent
.
/// listen to for an indication that it should
reset itself back to [DraggableScrollableSheet.initialChildSize]
.
///
/// The [child] and [notifier] properties must not be null.
const
_InheritedResetNotifier
({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment