Unverified Commit 4fa5fe5f authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Remove nullOk from Scaffold.of and ScaffoldMessenger.of, create maybeOf for both (#68908)

parent e5f7726c
...@@ -487,11 +487,11 @@ class _AppBarState extends State<AppBar> { ...@@ -487,11 +487,11 @@ class _AppBarState extends State<AppBar> {
static const Color _defaultShadowColor = Color(0xFF000000); static const Color _defaultShadowColor = Color(0xFF000000);
void _handleDrawerButton() { void _handleDrawerButton() {
Scaffold.of(context)!.openDrawer(); Scaffold.of(context).openDrawer();
} }
void _handleDrawerButtonEnd() { void _handleDrawerButtonEnd() {
Scaffold.of(context)!.openEndDrawer(); Scaffold.of(context).openEndDrawer();
} }
@override @override
...@@ -500,7 +500,7 @@ class _AppBarState extends State<AppBar> { ...@@ -500,7 +500,7 @@ class _AppBarState extends State<AppBar> {
assert(debugCheckHasMaterialLocalizations(context)); assert(debugCheckHasMaterialLocalizations(context));
final ThemeData? theme = Theme.of(context); final ThemeData? theme = Theme.of(context);
final AppBarTheme appBarTheme = AppBarTheme.of(context); final AppBarTheme appBarTheme = AppBarTheme.of(context);
final ScaffoldState? scaffold = Scaffold.of(context, nullOk: true); final ScaffoldState? scaffold = Scaffold.maybeOf(context);
final ModalRoute<dynamic>? parentRoute = ModalRoute.of(context); final ModalRoute<dynamic>? parentRoute = ModalRoute.of(context);
final bool hasDrawer = scaffold?.hasDrawer ?? false; final bool hasDrawer = scaffold?.hasDrawer ?? false;
......
...@@ -737,7 +737,7 @@ PersistentBottomSheetController<T> showBottomSheet<T>({ ...@@ -737,7 +737,7 @@ PersistentBottomSheetController<T> showBottomSheet<T>({
assert(builder != null); assert(builder != null);
assert(debugCheckHasScaffold(context)); assert(debugCheckHasScaffold(context));
return Scaffold.of(context)!.showBottomSheet<T>( return Scaffold.of(context).showBottomSheet<T>(
builder, builder,
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
elevation: elevation, elevation: elevation,
......
...@@ -204,16 +204,34 @@ class ScaffoldMessenger extends StatefulWidget { ...@@ -204,16 +204,34 @@ class ScaffoldMessenger extends StatefulWidget {
/// ``` /// ```
/// {@end-tool} /// {@end-tool}
/// ///
/// If there is no [ScaffoldMessenger] in scope, then this will return null. /// If there is no [ScaffoldMessenger] in scope, then this will assert in
/// debug mode, and throw an exception in release mode.
///
/// See also: /// See also:
/// ///
/// * [maybeOf], which is a similar function but will return null instead of
/// throwing if there is no [ScaffoldMessenger] ancestor.
/// * [debugCheckHasScaffoldMessenger], which asserts that the given context /// * [debugCheckHasScaffoldMessenger], which asserts that the given context
/// has a [ScaffoldMessenger] ancestor. /// has a [ScaffoldMessenger] ancestor.
static ScaffoldMessengerState? of(BuildContext context, { bool nullOk = false }) { static ScaffoldMessengerState of(BuildContext context) {
assert(nullOk != null);
assert(context != null); assert(context != null);
assert(debugCheckHasScaffoldMessenger(context));
assert(nullOk || debugCheckHasScaffoldMessenger(context)); final _ScaffoldMessengerScope scope = context.dependOnInheritedWidgetOfExactType<_ScaffoldMessengerScope>()!;
return scope._scaffoldMessengerState;
}
/// The state from the closest instance of this class that encloses the given
/// context, if any.
///
/// Will return null if a [ScaffoldMessenger] is not found in the given context.
///
/// See also:
///
/// * [of], which is a similar function, except that it will throw an
/// exception if a [ScaffoldMessenger] is not found in the given context.
static ScaffoldMessengerState? maybeOf(BuildContext context) {
assert(context != null);
final _ScaffoldMessengerScope? scope = context.dependOnInheritedWidgetOfExactType<_ScaffoldMessengerScope>(); final _ScaffoldMessengerScope? scope = context.dependOnInheritedWidgetOfExactType<_ScaffoldMessengerScope>();
return scope?._scaffoldMessengerState; return scope?._scaffoldMessengerState;
...@@ -1755,7 +1773,11 @@ class Scaffold extends StatefulWidget { ...@@ -1755,7 +1773,11 @@ class Scaffold extends StatefulWidget {
/// By default, the drag gesture is enabled. /// By default, the drag gesture is enabled.
final bool endDrawerEnableOpenDragGesture; final bool endDrawerEnableOpenDragGesture;
/// The state from the closest instance of this class that encloses the given context. /// Finds the [ScaffoldState] from the closest instance of this class that
/// encloses the given context.
///
/// If no instance of this class encloses the given context, will cause an
/// assert in debug mode, and throw an exception in release mode.
/// ///
/// {@tool dartpad --template=freeform} /// {@tool dartpad --template=freeform}
/// Typical usage of the [Scaffold.of] function is to call it from within the /// Typical usage of the [Scaffold.of] function is to call it from within the
...@@ -1892,12 +1914,11 @@ class Scaffold extends StatefulWidget { ...@@ -1892,12 +1914,11 @@ class Scaffold extends StatefulWidget {
/// [ScaffoldState] rather than using the [Scaffold.of] function. /// [ScaffoldState] rather than using the [Scaffold.of] function.
/// ///
/// If there is no [Scaffold] in scope, then this will throw an exception. /// If there is no [Scaffold] in scope, then this will throw an exception.
/// To return null if there is no [Scaffold], then pass `nullOk: true`. /// To return null if there is no [Scaffold], use [maybeOf] instead.
static ScaffoldState? of(BuildContext context, { bool nullOk = false }) { static ScaffoldState of(BuildContext context) {
assert(nullOk != null);
assert(context != null); assert(context != null);
final ScaffoldState? result = context.findAncestorStateOfType<ScaffoldState>(); final ScaffoldState? result = context.findAncestorStateOfType<ScaffoldState>();
if (nullOk || result != null) if (result != null)
return result; return result;
throw FlutterError.fromParts(<DiagnosticsNode>[ throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary( ErrorSummary(
...@@ -1927,6 +1948,22 @@ class Scaffold extends StatefulWidget { ...@@ -1927,6 +1948,22 @@ class Scaffold extends StatefulWidget {
]); ]);
} }
/// Finds the [ScaffoldState] from the closest instance of this class that
/// encloses the given context.
///
/// If no instance of this class encloses the given context, will return null.
/// To throw an exception instead, use [of] instead of this function.
///
/// See also:
///
/// * [of], a similar function to this one that throws if no instance
/// encloses the given context. Also includes some sample code in its
/// documentation.
static ScaffoldState? maybeOf(BuildContext context) {
assert(context != null);
return context.findAncestorStateOfType<ScaffoldState>();
}
/// Returns a [ValueListenable] for the [ScaffoldGeometry] for the closest /// Returns a [ValueListenable] for the [ScaffoldGeometry] for the closest
/// [Scaffold] ancestor of the given context. /// [Scaffold] ancestor of the given context.
/// ///
...@@ -2714,7 +2751,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -2714,7 +2751,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
void didChangeDependencies() { void didChangeDependencies() {
// nullOk is valid here since both the Scaffold and ScaffoldMessenger are // nullOk is valid here since both the Scaffold and ScaffoldMessenger are
// currently available for managing SnackBars. // currently available for managing SnackBars.
final ScaffoldMessengerState? _currentScaffoldMessenger = ScaffoldMessenger.of(context, nullOk: true); final ScaffoldMessengerState? _currentScaffoldMessenger = ScaffoldMessenger.maybeOf(context);
// If our ScaffoldMessenger has changed, unregister with the old one first. // If our ScaffoldMessenger has changed, unregister with the old one first.
if (_scaffoldMessenger != null && if (_scaffoldMessenger != null &&
(_currentScaffoldMessenger == null || _scaffoldMessenger != _currentScaffoldMessenger)) { (_currentScaffoldMessenger == null || _scaffoldMessenger != _currentScaffoldMessenger)) {
...@@ -3304,7 +3341,7 @@ class _StandardBottomSheetState extends State<_StandardBottomSheet> { ...@@ -3304,7 +3341,7 @@ class _StandardBottomSheetState extends State<_StandardBottomSheet> {
bool extentChanged(DraggableScrollableNotification notification) { bool extentChanged(DraggableScrollableNotification notification) {
final double extentRemaining = 1.0 - notification.extent; final double extentRemaining = 1.0 - notification.extent;
final ScaffoldState scaffold = Scaffold.of(context)!; final ScaffoldState scaffold = Scaffold.of(context);
if (extentRemaining < _kBottomSheetDominatesPercentage) { if (extentRemaining < _kBottomSheetDominatesPercentage) {
scaffold._floatingActionButtonVisibilityValue = extentRemaining * _kBottomSheetDominatesPercentage * 10; scaffold._floatingActionButtonVisibilityValue = extentRemaining * _kBottomSheetDominatesPercentage * 10;
scaffold.showBodyScrim(true, math.max( scaffold.showBodyScrim(true, math.max(
......
...@@ -123,7 +123,7 @@ class _SnackBarActionState extends State<SnackBarAction> { ...@@ -123,7 +123,7 @@ class _SnackBarActionState extends State<SnackBarAction> {
_haveTriggeredAction = true; _haveTriggeredAction = true;
}); });
widget.onPressed(); widget.onPressed();
Scaffold.of(context)!.hideCurrentSnackBar(reason: SnackBarClosedReason.action); Scaffold.of(context).hideCurrentSnackBar(reason: SnackBarClosedReason.action);
} }
@override @override
...@@ -529,14 +529,14 @@ class _SnackBarState extends State<SnackBar> { ...@@ -529,14 +529,14 @@ class _SnackBarState extends State<SnackBar> {
container: true, container: true,
liveRegion: true, liveRegion: true,
onDismiss: () { onDismiss: () {
Scaffold.of(context)!.removeCurrentSnackBar(reason: SnackBarClosedReason.dismiss); Scaffold.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.dismiss);
}, },
child: Dismissible( child: Dismissible(
key: const Key('dismissible'), key: const Key('dismissible'),
direction: DismissDirection.down, direction: DismissDirection.down,
resizeDuration: null, resizeDuration: null,
onDismissed: (DismissDirection direction) { onDismissed: (DismissDirection direction) {
Scaffold.of(context)!.removeCurrentSnackBar(reason: SnackBarClosedReason.swipe); Scaffold.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.swipe);
}, },
child: snackBar, child: snackBar,
), ),
......
...@@ -647,7 +647,7 @@ void main() { ...@@ -647,7 +647,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return FloatingActionButton( return FloatingActionButton(
onPressed: () { onPressed: () {
ScaffoldMessenger.of(context)!.showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Snacky!')), const SnackBar(content: Text('Snacky!')),
); );
}, },
......
...@@ -355,7 +355,7 @@ void main() { ...@@ -355,7 +355,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context)!.showBottomSheet<void>((BuildContext context) { Scaffold.of(context).showBottomSheet<void>((BuildContext context) {
return Container( return Container(
key: sheetKey, key: sheetKey,
color: Colors.blue[500], color: Colors.blue[500],
...@@ -1900,7 +1900,7 @@ void main() { ...@@ -1900,7 +1900,7 @@ void main() {
MaterialApp( MaterialApp(
home: Builder( home: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
Scaffold.of(context)!.showBottomSheet<void>((BuildContext context) { Scaffold.of(context).showBottomSheet<void>((BuildContext context) {
return Container(); return Container();
}); });
return Container(); return Container();
...@@ -2033,7 +2033,7 @@ void main() { ...@@ -2033,7 +2033,7 @@ void main() {
}); });
}); });
testWidgets('ScaffoldMessenger.of can return null', (WidgetTester tester) async { testWidgets('ScaffoldMessenger.maybeOf can return null if not found', (WidgetTester tester) async {
ScaffoldMessengerState? scaffoldMessenger; ScaffoldMessengerState? scaffoldMessenger;
const Key tapTarget = Key('tap-target'); const Key tapTarget = Key('tap-target');
await tester.pumpWidget(Directionality( await tester.pumpWidget(Directionality(
...@@ -2045,7 +2045,7 @@ void main() { ...@@ -2045,7 +2045,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
scaffoldMessenger = ScaffoldMessenger.of(context, nullOk: true); scaffoldMessenger = ScaffoldMessenger.maybeOf(context);
}, },
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
child: Container( child: Container(
...@@ -2064,7 +2064,7 @@ void main() { ...@@ -2064,7 +2064,7 @@ void main() {
expect(scaffoldMessenger, isNull); expect(scaffoldMessenger, isNull);
}); });
testWidgets('ScaffoldMessenger.of will assert if !nullOk', (WidgetTester tester) async { testWidgets('ScaffoldMessenger.of will assert if not found', (WidgetTester tester) async {
const Key tapTarget = Key('tap-target'); const Key tapTarget = Key('tap-target');
final List<dynamic> exceptions = <dynamic>[]; final List<dynamic> exceptions = <dynamic>[];
......
...@@ -17,7 +17,7 @@ void main() { ...@@ -17,7 +17,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context)!.showSnackBar(const SnackBar( Scaffold.of(context).showSnackBar(const SnackBar(
content: Text(helloSnackBar), content: Text(helloSnackBar),
duration: Duration(seconds: 2), duration: Duration(seconds: 2),
)); ));
...@@ -62,7 +62,7 @@ void main() { ...@@ -62,7 +62,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(const SnackBar( ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text(helloSnackBar), content: Text(helloSnackBar),
duration: Duration(seconds: 2), duration: Duration(seconds: 2),
)); ));
...@@ -108,7 +108,7 @@ void main() { ...@@ -108,7 +108,7 @@ void main() {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
snackBarCount += 1; snackBarCount += 1;
Scaffold.of(context)!.showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
content: Text('bar$snackBarCount'), content: Text('bar$snackBarCount'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
)); ));
...@@ -183,7 +183,7 @@ void main() { ...@@ -183,7 +183,7 @@ void main() {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
snackBarCount += 1; snackBarCount += 1;
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('bar$snackBarCount'), content: Text('bar$snackBarCount'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
)); ));
...@@ -260,7 +260,7 @@ void main() { ...@@ -260,7 +260,7 @@ void main() {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
snackBarCount += 1; snackBarCount += 1;
lastController = Scaffold.of(context)!.showSnackBar(SnackBar( lastController = Scaffold.of(context).showSnackBar(SnackBar(
content: Text('bar$snackBarCount'), content: Text('bar$snackBarCount'),
duration: Duration(seconds: time), duration: Duration(seconds: time),
)); ));
...@@ -346,7 +346,7 @@ void main() { ...@@ -346,7 +346,7 @@ void main() {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
snackBarCount += 1; snackBarCount += 1;
lastController = ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( lastController = ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('bar$snackBarCount'), content: Text('bar$snackBarCount'),
duration: Duration(seconds: time), duration: Duration(seconds: time),
)); ));
...@@ -430,7 +430,7 @@ void main() { ...@@ -430,7 +430,7 @@ void main() {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
snackBarCount += 1; snackBarCount += 1;
Scaffold.of(context)!.showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
content: Text('bar$snackBarCount'), content: Text('bar$snackBarCount'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
)); ));
...@@ -475,7 +475,7 @@ void main() { ...@@ -475,7 +475,7 @@ void main() {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
snackBarCount += 1; snackBarCount += 1;
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('bar$snackBarCount'), content: Text('bar$snackBarCount'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
)); ));
...@@ -518,7 +518,7 @@ void main() { ...@@ -518,7 +518,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context)!.showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction( action: SnackBarAction(
...@@ -557,7 +557,7 @@ void main() { ...@@ -557,7 +557,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction( action: SnackBarAction(
...@@ -598,7 +598,7 @@ void main() { ...@@ -598,7 +598,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context)!.showSnackBar( Scaffold.of(context).showSnackBar(
SnackBar( SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
...@@ -640,7 +640,7 @@ void main() { ...@@ -640,7 +640,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context)!.showSnackBar( Scaffold.of(context).showSnackBar(
SnackBar( SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
...@@ -678,7 +678,7 @@ void main() { ...@@ -678,7 +678,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context)!.showSnackBar( Scaffold.of(context).showSnackBar(
SnackBar( SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
margin: const EdgeInsets.all(padding), margin: const EdgeInsets.all(padding),
...@@ -724,7 +724,7 @@ void main() { ...@@ -724,7 +724,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context)!.showSnackBar( Scaffold.of(context).showSnackBar(
const SnackBar( const SnackBar(
content: Text('I am a snack bar.'), content: Text('I am a snack bar.'),
behavior: SnackBarBehavior.floating, behavior: SnackBarBehavior.floating,
...@@ -771,7 +771,7 @@ void main() { ...@@ -771,7 +771,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
const SnackBar( const SnackBar(
content: Text('I am a snack bar.'), content: Text('I am a snack bar.'),
behavior: SnackBarBehavior.floating, behavior: SnackBarBehavior.floating,
...@@ -812,7 +812,7 @@ void main() { ...@@ -812,7 +812,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
const SnackBar( const SnackBar(
content: Text('I am a snack bar.'), content: Text('I am a snack bar.'),
padding: EdgeInsets.all(padding), padding: EdgeInsets.all(padding),
...@@ -856,7 +856,7 @@ void main() { ...@@ -856,7 +856,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
width: width, width: width,
...@@ -894,7 +894,7 @@ void main() { ...@@ -894,7 +894,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
...@@ -946,7 +946,7 @@ void main() { ...@@ -946,7 +946,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () { }), action: SnackBarAction(label: 'ACTION', onPressed: () { }),
...@@ -1001,7 +1001,7 @@ void main() { ...@@ -1001,7 +1001,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
...@@ -1052,7 +1052,7 @@ void main() { ...@@ -1052,7 +1052,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
...@@ -1106,7 +1106,7 @@ void main() { ...@@ -1106,7 +1106,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
...@@ -1164,7 +1164,7 @@ void main() { ...@@ -1164,7 +1164,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
...@@ -1207,7 +1207,7 @@ void main() { ...@@ -1207,7 +1207,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('snack'), content: const Text('snack'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction( action: SnackBarAction(
...@@ -1285,7 +1285,7 @@ void main() { ...@@ -1285,7 +1285,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context)!.showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
content: const Text('snack'), content: const Text('snack'),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
action: SnackBarAction( action: SnackBarAction(
...@@ -1327,7 +1327,7 @@ void main() { ...@@ -1327,7 +1327,7 @@ void main() {
key: scaffoldKey, key: scaffoldKey,
body: GestureDetector( body: GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('snack'), content: const Text('snack'),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
action: SnackBarAction( action: SnackBarAction(
...@@ -1369,7 +1369,7 @@ void main() { ...@@ -1369,7 +1369,7 @@ void main() {
body: Builder(builder: (BuildContext context) { body: Builder(builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context)!.showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
content: const Text('snack'), content: const Text('snack'),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
action: SnackBarAction( action: SnackBarAction(
...@@ -1411,7 +1411,7 @@ void main() { ...@@ -1411,7 +1411,7 @@ void main() {
key: scaffoldKey, key: scaffoldKey,
body: GestureDetector( body: GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('snack'), content: const Text('snack'),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
action: SnackBarAction( action: SnackBarAction(
...@@ -1450,7 +1450,7 @@ void main() { ...@@ -1450,7 +1450,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(const SnackBar( ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text(helloSnackBar), content: Text(helloSnackBar),
)); ));
}, },
...@@ -1499,7 +1499,7 @@ void main() { ...@@ -1499,7 +1499,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context)!.showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
content: const Text('test'), content: const Text('test'),
action: SnackBarAction(label: 'foo', onPressed: () { }), action: SnackBarAction(label: 'foo', onPressed: () { }),
)); ));
...@@ -1547,7 +1547,7 @@ void main() { ...@@ -1547,7 +1547,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('test'), content: const Text('test'),
action: SnackBarAction(label: 'foo', onPressed: () { }), action: SnackBarAction(label: 'foo', onPressed: () { }),
)); ));
...@@ -1594,7 +1594,7 @@ void main() { ...@@ -1594,7 +1594,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('hello'), content: const Text('hello'),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
onVisible: () { onVisible: () {
...@@ -1631,14 +1631,14 @@ void main() { ...@@ -1631,14 +1631,14 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('hello'), content: const Text('hello'),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
onVisible: () { onVisible: () {
called += 1; called += 1;
}, },
)); ));
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('hello 2'), content: const Text('hello 2'),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
onVisible: () { onVisible: () {
...@@ -1747,7 +1747,7 @@ void main() { ...@@ -1747,7 +1747,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
...@@ -1847,7 +1847,7 @@ void main() { ...@@ -1847,7 +1847,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
...@@ -1953,7 +1953,7 @@ void main() { ...@@ -1953,7 +1953,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context)!.showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
content: const Text('Some content'), content: const Text('Some content'),
behavior: SnackBarBehavior.fixed, behavior: SnackBarBehavior.fixed,
action: SnackBarAction( action: SnackBarAction(
...@@ -1990,7 +1990,7 @@ void main() { ...@@ -1990,7 +1990,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context)!.showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
content: const Text('Some content'), content: const Text('Some content'),
behavior: SnackBarBehavior.floating, behavior: SnackBarBehavior.floating,
action: SnackBarAction( action: SnackBarAction(
...@@ -2042,7 +2042,7 @@ void main() { ...@@ -2042,7 +2042,7 @@ void main() {
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
key: snackTarget, key: snackTarget,
onPressed: () async { onPressed: () async {
ScaffoldMessenger.of(context)!.showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
const SnackBar( const SnackBar(
content: Text(snackBarText), content: Text(snackBarText),
), ),
......
...@@ -71,7 +71,7 @@ void main() { ...@@ -71,7 +71,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text(text), content: const Text(text),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
...@@ -109,7 +109,7 @@ void main() { ...@@ -109,7 +109,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text(text), content: const Text(text),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: action, onPressed: () {}), action: SnackBarAction(label: action, onPressed: () {}),
...@@ -153,7 +153,7 @@ void main() { ...@@ -153,7 +153,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
elevation: elevation, elevation: elevation,
shape: shape, shape: shape,
...@@ -200,7 +200,7 @@ void main() { ...@@ -200,7 +200,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
...@@ -242,7 +242,7 @@ void main() { ...@@ -242,7 +242,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context)!.showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
......
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