Unverified Commit ba4a11da authored by Qun Cheng's avatar Qun Cheng Committed by GitHub

Add `showDragHandle` to `showBottomSheet` (#141754)

parent 3563372f
...@@ -1333,6 +1333,7 @@ PersistentBottomSheetController showBottomSheet({ ...@@ -1333,6 +1333,7 @@ PersistentBottomSheetController showBottomSheet({
Clip? clipBehavior, Clip? clipBehavior,
BoxConstraints? constraints, BoxConstraints? constraints,
bool? enableDrag, bool? enableDrag,
bool? showDragHandle,
AnimationController? transitionAnimationController, AnimationController? transitionAnimationController,
}) { }) {
assert(debugCheckHasScaffold(context)); assert(debugCheckHasScaffold(context));
...@@ -1345,6 +1346,7 @@ PersistentBottomSheetController showBottomSheet({ ...@@ -1345,6 +1346,7 @@ PersistentBottomSheetController showBottomSheet({
clipBehavior: clipBehavior, clipBehavior: clipBehavior,
constraints: constraints, constraints: constraints,
enableDrag: enableDrag, enableDrag: enableDrag,
showDragHandle: showDragHandle,
transitionAnimationController: transitionAnimationController, transitionAnimationController: transitionAnimationController,
); );
} }
......
...@@ -2306,6 +2306,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto ...@@ -2306,6 +2306,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
Clip? clipBehavior, Clip? clipBehavior,
BoxConstraints? constraints, BoxConstraints? constraints,
bool? enableDrag, bool? enableDrag,
bool? showDragHandle,
bool shouldDisposeAnimationController = true, bool shouldDisposeAnimationController = true,
}) { }) {
assert(() { assert(() {
...@@ -2380,6 +2381,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto ...@@ -2380,6 +2381,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
key: bottomSheetKey, key: bottomSheetKey,
animationController: animationController, animationController: animationController,
enableDrag: enableDrag ?? !isPersistent, enableDrag: enableDrag ?? !isPersistent,
showDragHandle: showDragHandle,
onClosing: () { onClosing: () {
if (_currentBottomSheet == null) { if (_currentBottomSheet == null) {
return; return;
...@@ -2481,6 +2483,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto ...@@ -2481,6 +2483,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
Clip? clipBehavior, Clip? clipBehavior,
BoxConstraints? constraints, BoxConstraints? constraints,
bool? enableDrag, bool? enableDrag,
bool? showDragHandle,
AnimationController? transitionAnimationController, AnimationController? transitionAnimationController,
}) { }) {
assert(() { assert(() {
...@@ -2508,6 +2511,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto ...@@ -2508,6 +2511,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin, Resto
clipBehavior: clipBehavior, clipBehavior: clipBehavior,
constraints: constraints, constraints: constraints,
enableDrag: enableDrag, enableDrag: enableDrag,
showDragHandle: showDragHandle,
shouldDisposeAnimationController: transitionAnimationController == null, shouldDisposeAnimationController: transitionAnimationController == null,
); );
}); });
...@@ -3133,6 +3137,7 @@ class _StandardBottomSheet extends StatefulWidget { ...@@ -3133,6 +3137,7 @@ class _StandardBottomSheet extends StatefulWidget {
super.key, super.key,
required this.animationController, required this.animationController,
this.enableDrag = true, this.enableDrag = true,
this.showDragHandle,
required this.onClosing, required this.onClosing,
required this.onDismissed, required this.onDismissed,
required this.builder, required this.builder,
...@@ -3147,6 +3152,7 @@ class _StandardBottomSheet extends StatefulWidget { ...@@ -3147,6 +3152,7 @@ class _StandardBottomSheet extends StatefulWidget {
final AnimationController animationController; // we control it, but it must be disposed by whoever created it. final AnimationController animationController; // we control it, but it must be disposed by whoever created it.
final bool enableDrag; final bool enableDrag;
final bool? showDragHandle;
final VoidCallback? onClosing; final VoidCallback? onClosing;
final VoidCallback? onDismissed; final VoidCallback? onDismissed;
final VoidCallback? onDispose; final VoidCallback? onDispose;
...@@ -3252,6 +3258,7 @@ class _StandardBottomSheetState extends State<_StandardBottomSheet> { ...@@ -3252,6 +3258,7 @@ class _StandardBottomSheetState extends State<_StandardBottomSheet> {
child: BottomSheet( child: BottomSheet(
animationController: widget.animationController, animationController: widget.animationController,
enableDrag: widget.enableDrag, enableDrag: widget.enableDrag,
showDragHandle: widget.showDragHandle,
onDragStart: _handleDragStart, onDragStart: _handleDragStart,
onDragEnd: _handleDragEnd, onDragEnd: _handleDragEnd,
onClosing: widget.onClosing!, onClosing: widget.onClosing!,
......
...@@ -1194,26 +1194,64 @@ void main() { ...@@ -1194,26 +1194,64 @@ void main() {
}); });
testWidgets('Drag handle color can take MaterialStateProperty', (WidgetTester tester) async { testWidgets('Drag handle color can take MaterialStateProperty', (WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
const Color defaultColor=Colors.blue; const Color defaultColor=Colors.blue;
const Color hoveringColor=Colors.green; const Color hoveringColor=Colors.green;
await tester.pumpWidget(MaterialApp( Future<void> checkDragHandleAndColors() async {
theme: ThemeData.light().copyWith( await tester.pump(); // bottom sheet show animation starts
bottomSheetTheme: BottomSheetThemeData( await tester.pump(const Duration(seconds: 1)); // animation done
dragHandleColor: MaterialStateColor.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.hovered)) { final Finder dragHandle = find.bySemanticsLabel('Dismiss');
return hoveringColor; expect(
} tester.getSize(dragHandle),
return defaultColor; 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(
home: Scaffold( key: scaffoldKey,
key: scaffoldKey, body: const Center(child: Text('body')),
body: const Center(child: Text('body')), ),
), );
)); }
GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
await tester.pumpWidget(buildScaffold(scaffoldKey));
showModalBottomSheet<void>( showModalBottomSheet<void>(
context: scaffoldKey.currentContext!, context: scaffoldKey.currentContext!,
...@@ -1223,36 +1261,24 @@ void main() { ...@@ -1223,36 +1261,24 @@ void main() {
}, },
); );
await tester.pump(); // bottom sheet show animation starts await checkDragHandleAndColors();
await tester.pump(const Duration(seconds: 1)); // animation done
final Finder dragHandle = find.bySemanticsLabel('Dismiss'); await tester.pumpWidget(Container()); // Reset
expect( scaffoldKey = GlobalKey<ScaffoldState>();
tester.getSize(dragHandle), await tester.pumpWidget(buildScaffold(scaffoldKey));
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 scaffoldKey.currentState!.showBottomSheet((_) {
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1); return Builder(
await gesture.addPointer(location: edge); builder: (BuildContext context) {
await tester.pump(); return const SizedBox(
BoxDecoration boxDecoration=tester.widget<Container>(find.descendant( height: 200.0,
of: dragHandle, child: Text('Bottom Sheet'),
matching: find.byWidgetPredicate((Widget widget) => widget is Container && widget.decoration != null), );
)).decoration! as BoxDecoration; },
expect(boxDecoration.color, defaultColor); );
}, showDragHandle: true);
// 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 checkDragHandleAndColors();
}); });
testWidgets('showModalBottomSheet does not use root Navigator by default', (WidgetTester tester) async { testWidgets('showModalBottomSheet does not use root Navigator by default', (WidgetTester tester) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment