Unverified Commit c84b1047 authored by NikolajHarderNota's avatar NikolajHarderNota Committed by GitHub

modal bottom sheet barrier label (#126431)

Adds barrierLabel as optional param in showModalBottomSheet

Fixes #83180
parent 4341ed42
......@@ -1152,6 +1152,9 @@ class _BottomSheetSuspendedCurve extends ParametricCurve<double> {
/// Returns a `Future` that resolves to the value (if any) that was passed to
/// [Navigator.pop] when the modal bottom sheet was closed.
///
/// The 'barrierLabel' parameter can be used to set a custom barrierlabel.
/// Will default to modalBarrierDismissLabel of context if not set.
///
/// {@tool dartpad}
/// This example demonstrates how to use [showModalBottomSheet] to display a
/// bottom sheet that obscures the content behind it when a user taps a button.
......@@ -1184,6 +1187,7 @@ Future<T?> showModalBottomSheet<T>({
required BuildContext context,
required WidgetBuilder builder,
Color? backgroundColor,
String? barrierLabel,
double? elevation,
ShapeBorder? shape,
Clip? clipBehavior,
......@@ -1208,7 +1212,7 @@ Future<T?> showModalBottomSheet<T>({
builder: builder,
capturedThemes: InheritedTheme.capture(from: context, to: navigator.context),
isScrollControlled: isScrollControlled,
barrierLabel: localizations.scrimLabel,
barrierLabel: barrierLabel ?? localizations.scrimLabel,
barrierOnTapHint: localizations.scrimOnTapHint(localizations.bottomSheetLabel),
backgroundColor: backgroundColor,
elevation: elevation,
......
......@@ -1999,6 +1999,58 @@ void main() {
});
});
group('showModalBottomSheet modalBarrierDismissLabel', () {
testWidgets('Verify that modalBarrierDismissLabel is used if provided',
(WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
const String customLabel = 'custom label';
await tester.pumpWidget(MaterialApp(
home: Scaffold(
key: scaffoldKey,
body: const Center(child: Text('body')),
),
));
showModalBottomSheet<void>(
barrierLabel: 'custom label',
context: scaffoldKey.currentContext!,
builder: (BuildContext context) {
return const Text('BottomSheet');
},
);
await tester.pump();
await tester.pump(const Duration(seconds: 1));
final ModalBarrier modalBarrier =
tester.widget(find.byType(ModalBarrier).last);
expect(modalBarrier.semanticsLabel, customLabel);
});
testWidgets('Verify that modalBarrierDismissLabel from context is used if barrierLabel is not provided',
(WidgetTester tester) async {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
await tester.pumpWidget(MaterialApp(
home: Scaffold(
key: scaffoldKey,
body: const Center(child: Text('body')),
),
));
showModalBottomSheet<void>(
context: scaffoldKey.currentContext!,
builder: (BuildContext context) {
return const Text('BottomSheet');
},
);
await tester.pump();
await tester.pump(const Duration(seconds: 1));
final ModalBarrier modalBarrier =
tester.widget(find.byType(ModalBarrier).last);
expect(modalBarrier.semanticsLabel, MaterialLocalizations.of(scaffoldKey.currentContext!).scrimLabel);
});
});
}
class _TestPage extends StatelessWidget {
......
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