Unverified Commit 135bb5d4 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Remove deprecated Scaffold SnackBar API (#98549)

parent 1cf5c740
...@@ -122,7 +122,7 @@ class _SnackBarActionState extends State<SnackBarAction> { ...@@ -122,7 +122,7 @@ class _SnackBarActionState extends State<SnackBarAction> {
_haveTriggeredAction = true; _haveTriggeredAction = true;
}); });
widget.onPressed(); widget.onPressed();
Scaffold.of(context).hideCurrentSnackBar(reason: SnackBarClosedReason.action); ScaffoldMessenger.of(context).hideCurrentSnackBar(reason: SnackBarClosedReason.action);
} }
@override @override
...@@ -583,14 +583,14 @@ class _SnackBarState extends State<SnackBar> { ...@@ -583,14 +583,14 @@ class _SnackBarState extends State<SnackBar> {
container: true, container: true,
liveRegion: true, liveRegion: true,
onDismiss: () { onDismiss: () {
Scaffold.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.dismiss); ScaffoldMessenger.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.dismiss);
}, },
child: Dismissible( child: Dismissible(
key: const Key('dismissible'), key: const Key('dismissible'),
direction: widget.dismissDirection, direction: widget.dismissDirection,
resizeDuration: null, resizeDuration: null,
onDismissed: (DismissDirection direction) { onDismissed: (DismissDirection direction) {
Scaffold.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.swipe); ScaffoldMessenger.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.swipe);
}, },
child: snackBar, child: snackBar,
), ),
......
...@@ -263,8 +263,10 @@ void main() { ...@@ -263,8 +263,10 @@ void main() {
), ),
), ),
)); ));
// The Scaffold should assert we still have an ancestor ScaffoldMessenger in // Tap SnackBarAction to dismiss.
// order to dismiss the SnackBar from the ScaffoldMessenger. // The SnackBarAction should assert we still have an ancestor
// ScaffoldMessenger in order to dismiss the SnackBar from the
// Scaffold.
await tester.tap(find.text('Test')); await tester.tap(find.text('Test'));
FlutterError.onError = oldHandler; FlutterError.onError = oldHandler;
...@@ -286,11 +288,67 @@ void main() { ...@@ -286,11 +288,67 @@ void main() {
expect(error.toStringDeep(), equalsIgnoringHashCodes( expect(error.toStringDeep(), equalsIgnoringHashCodes(
'FlutterError\n' 'FlutterError\n'
' No ScaffoldMessenger widget found.\n' ' No ScaffoldMessenger widget found.\n'
' Scaffold widgets require a ScaffoldMessenger widget ancestor.\n' ' SnackBarAction widgets require a ScaffoldMessenger widget\n'
' ancestor.\n'
' The specific widget that could not find a ScaffoldMessenger\n' ' The specific widget that could not find a ScaffoldMessenger\n'
' ancestor was:\n' ' ancestor was:\n'
' Scaffold-[LabeledGlobalKey<ScaffoldState>#00829]\n' ' SnackBarAction\n'
' The ancestors of this widget were:\n' ' The ancestors of this widget were:\n'
' TextButtonTheme\n'
' Padding\n'
' Row\n'
' Padding\n'
' MediaQuery\n'
' Padding\n'
' SafeArea\n'
' FadeTransition\n'
' IconTheme\n'
' IconTheme\n'
' _InheritedCupertinoTheme\n'
' CupertinoTheme\n'
' _InheritedTheme\n'
' Theme\n'
' DefaultTextStyle\n'
' AnimatedDefaultTextStyle\n'
' _InkFeatures-[GlobalKey#00000 ink renderer]\n'
' NotificationListener<LayoutChangedNotification>\n'
' PhysicalModel\n'
' AnimatedPhysicalModel\n'
' Material\n'
' FractionalTranslation\n'
' SlideTransition\n'
' Listener\n'
' _GestureSemantics\n'
' RawGestureDetector\n'
' GestureDetector\n'
" Dismissible-[<'dismissible'>]\n"
' Semantics\n'
' Align\n'
' AnimatedBuilder\n'
' ClipRect\n'
' KeyedSubtree-[GlobalKey#00000]\n'
' _EffectiveTickerMode\n'
' TickerMode\n'
' Offstage\n'
' SizedBox\n'
' Hero\n'
' SnackBar-[#00000]\n'
' MediaQuery\n'
' LayoutId-[<_ScaffoldSlot.snackBar>]\n'
' CustomMultiChildLayout\n'
' AnimatedBuilder\n'
' DefaultTextStyle\n'
' AnimatedDefaultTextStyle\n'
' _InkFeatures-[GlobalKey#00000 ink renderer]\n'
' NotificationListener<LayoutChangedNotification>\n'
' PhysicalModel\n'
' AnimatedPhysicalModel\n'
' Material\n'
' _ScrollMetricsNotificationObserverScope\n'
' NotificationListener<ScrollMetricsNotification>\n'
' ScrollMetricsNotificationObserver\n'
' _ScaffoldScope\n'
' Scaffold-[LabeledGlobalKey<ScaffoldState>#00000]\n'
' MediaQuery\n' ' MediaQuery\n'
' Directionality\n' ' Directionality\n'
' [root]\n' ' [root]\n'
......
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