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
ba4a11da
Unverified
Commit
ba4a11da
authored
Jan 19, 2024
by
Qun Cheng
Committed by
GitHub
Jan 19, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `showDragHandle` to `showBottomSheet` (#141754)
parent
3563372f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
43 deletions
+78
-43
bottom_sheet.dart
packages/flutter/lib/src/material/bottom_sheet.dart
+2
-0
scaffold.dart
packages/flutter/lib/src/material/scaffold.dart
+7
-0
bottom_sheet_test.dart
packages/flutter/test/material/bottom_sheet_test.dart
+69
-43
No files found.
packages/flutter/lib/src/material/bottom_sheet.dart
View file @
ba4a11da
...
...
@@ -1333,6 +1333,7 @@ PersistentBottomSheetController showBottomSheet({
Clip
?
clipBehavior
,
BoxConstraints
?
constraints
,
bool
?
enableDrag
,
bool
?
showDragHandle
,
AnimationController
?
transitionAnimationController
,
})
{
assert
(
debugCheckHasScaffold
(
context
));
...
...
@@ -1345,6 +1346,7 @@ PersistentBottomSheetController showBottomSheet({
clipBehavior:
clipBehavior
,
constraints:
constraints
,
enableDrag:
enableDrag
,
showDragHandle:
showDragHandle
,
transitionAnimationController:
transitionAnimationController
,
);
}
...
...
packages/flutter/lib/src/material/scaffold.dart
View file @
ba4a11da
...
...
@@ -2306,6 +2306,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
Clip
?
clipBehavior
,
BoxConstraints
?
constraints
,
bool
?
enableDrag
,
bool
?
showDragHandle
,
bool
shouldDisposeAnimationController
=
true
,
})
{
assert
(()
{
...
...
@@ -2380,6 +2381,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
key:
bottomSheetKey
,
animationController:
animationController
,
enableDrag:
enableDrag
??
!
isPersistent
,
showDragHandle:
showDragHandle
,
onClosing:
()
{
if
(
_currentBottomSheet
==
null
)
{
return
;
...
...
@@ -2481,6 +2483,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
Clip
?
clipBehavior
,
BoxConstraints
?
constraints
,
bool
?
enableDrag
,
bool
?
showDragHandle
,
AnimationController
?
transitionAnimationController
,
})
{
assert
(()
{
...
...
@@ -2508,6 +2511,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
clipBehavior:
clipBehavior
,
constraints:
constraints
,
enableDrag:
enableDrag
,
showDragHandle:
showDragHandle
,
shouldDisposeAnimationController:
transitionAnimationController
==
null
,
);
});
...
...
@@ -3133,6 +3137,7 @@ class _StandardBottomSheet extends StatefulWidget {
super
.
key
,
required
this
.
animationController
,
this
.
enableDrag
=
true
,
this
.
showDragHandle
,
required
this
.
onClosing
,
required
this
.
onDismissed
,
required
this
.
builder
,
...
...
@@ -3147,6 +3152,7 @@ class _StandardBottomSheet extends StatefulWidget {
final
AnimationController
animationController
;
// we control it, but it must be disposed by whoever created it.
final
bool
enableDrag
;
final
bool
?
showDragHandle
;
final
VoidCallback
?
onClosing
;
final
VoidCallback
?
onDismissed
;
final
VoidCallback
?
onDispose
;
...
...
@@ -3252,6 +3258,7 @@ class _StandardBottomSheetState extends State<_StandardBottomSheet> {
child:
BottomSheet
(
animationController:
widget
.
animationController
,
enableDrag:
widget
.
enableDrag
,
showDragHandle:
widget
.
showDragHandle
,
onDragStart:
_handleDragStart
,
onDragEnd:
_handleDragEnd
,
onClosing:
widget
.
onClosing
!,
...
...
packages/flutter/test/material/bottom_sheet_test.dart
View file @
ba4a11da
...
...
@@ -1194,26 +1194,64 @@ void main() {
});
testWidgets
(
'Drag handle color can take MaterialStateProperty'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
ScaffoldState
>
scaffoldKey
=
GlobalKey
<
ScaffoldState
>();
const
Color
defaultColor
=
Colors
.
blue
;
const
Color
hoveringColor
=
Colors
.
green
;
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
.
light
().
copyWith
(
bottomSheetTheme:
BottomSheetThemeData
(
dragHandleColor:
MaterialStateColor
.
resolveWith
((
Set
<
MaterialState
>
states
)
{
if
(
states
.
contains
(
MaterialState
.
hovered
))
{
return
hoveringColor
;
}
return
defaultColor
;
}),
Future
<
void
>
checkDragHandleAndColors
()
async
{
await
tester
.
pump
();
// bottom sheet show animation starts
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// animation done
final
Finder
dragHandle
=
find
.
bySemanticsLabel
(
'Dismiss'
);
expect
(
tester
.
getSize
(
dragHandle
),
const
Size
(
48
,
48
),
);
final
Offset
center
=
tester
.
getCenter
(
dragHandle
);
final
Offset
edge
=
tester
.
getTopLeft
(
dragHandle
)
-
const
Offset
(
1
,
1
);
// Shows default drag handle color
final
TestGesture
gesture
=
await
tester
.
createGesture
(
kind:
PointerDeviceKind
.
mouse
,
pointer:
1
);
await
gesture
.
addPointer
(
location:
edge
);
await
tester
.
pump
();
BoxDecoration
boxDecoration
=
tester
.
widget
<
Container
>(
find
.
descendant
(
of:
dragHandle
,
matching:
find
.
byWidgetPredicate
((
Widget
widget
)
=>
widget
is
Container
&&
widget
.
decoration
!=
null
),
)).
decoration
!
as
BoxDecoration
;
expect
(
boxDecoration
.
color
,
defaultColor
);
// Shows hovering drag handle color
await
gesture
.
moveTo
(
center
);
await
tester
.
pump
();
boxDecoration
=
tester
.
widget
<
Container
>(
find
.
descendant
(
of:
dragHandle
,
matching:
find
.
byWidgetPredicate
((
Widget
widget
)
=>
widget
is
Container
&&
widget
.
decoration
!=
null
),
)).
decoration
!
as
BoxDecoration
;
expect
(
boxDecoration
.
color
,
hoveringColor
);
await
gesture
.
removePointer
();
}
Widget
buildScaffold
(
GlobalKey
scaffoldKey
)
{
return
MaterialApp
(
theme:
ThemeData
.
light
().
copyWith
(
bottomSheetTheme:
BottomSheetThemeData
(
dragHandleColor:
MaterialStateColor
.
resolveWith
((
Set
<
MaterialState
>
states
)
{
if
(
states
.
contains
(
MaterialState
.
hovered
))
{
return
hoveringColor
;
}
return
defaultColor
;
}),
),
),
),
home:
Scaffold
(
key:
scaffoldKey
,
body:
const
Center
(
child:
Text
(
'body'
)),
),
));
home:
Scaffold
(
key:
scaffoldKey
,
body:
const
Center
(
child:
Text
(
'body'
)),
),
);
}
GlobalKey
<
ScaffoldState
>
scaffoldKey
=
GlobalKey
<
ScaffoldState
>();
await
tester
.
pumpWidget
(
buildScaffold
(
scaffoldKey
));
showModalBottomSheet
<
void
>(
context:
scaffoldKey
.
currentContext
!,
...
...
@@ -1223,36 +1261,24 @@ void main() {
},
);
await
tester
.
pump
();
// bottom sheet show animation starts
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// animation done
await
checkDragHandleAndColors
();
final
Finder
dragHandle
=
find
.
bySemanticsLabel
(
'Dismiss'
);
expect
(
tester
.
getSize
(
dragHandle
),
const
Size
(
48
,
48
),
);
final
Offset
center
=
tester
.
getCenter
(
dragHandle
);
final
Offset
edge
=
tester
.
getTopLeft
(
dragHandle
)
-
const
Offset
(
1
,
1
);
await
tester
.
pumpWidget
(
Container
());
// Reset
scaffoldKey
=
GlobalKey
<
ScaffoldState
>();
await
tester
.
pumpWidget
(
buildScaffold
(
scaffoldKey
));
// Shows default drag handle color
final
TestGesture
gesture
=
await
tester
.
createGesture
(
kind:
PointerDeviceKind
.
mouse
,
pointer:
1
);
await
gesture
.
addPointer
(
location:
edge
);
await
tester
.
pump
();
BoxDecoration
boxDecoration
=
tester
.
widget
<
Container
>(
find
.
descendant
(
of:
dragHandle
,
matching:
find
.
byWidgetPredicate
((
Widget
widget
)
=>
widget
is
Container
&&
widget
.
decoration
!=
null
),
)).
decoration
!
as
BoxDecoration
;
expect
(
boxDecoration
.
color
,
defaultColor
);
// Shows hovering drag handle color
await
gesture
.
moveTo
(
center
);
await
tester
.
pump
();
boxDecoration
=
tester
.
widget
<
Container
>(
find
.
descendant
(
of:
dragHandle
,
matching:
find
.
byWidgetPredicate
((
Widget
widget
)
=>
widget
is
Container
&&
widget
.
decoration
!=
null
),
)).
decoration
!
as
BoxDecoration
;
scaffoldKey
.
currentState
!.
showBottomSheet
((
_
)
{
return
Builder
(
builder:
(
BuildContext
context
)
{
return
const
SizedBox
(
height:
200.0
,
child:
Text
(
'Bottom Sheet'
),
);
},
);
},
showDragHandle:
true
);
expect
(
boxDecoration
.
color
,
hoveringColor
);
await
checkDragHandleAndColors
(
);
});
testWidgets
(
'showModalBottomSheet does not use root Navigator by default'
,
(
WidgetTester
tester
)
async
{
...
...
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