ScaffoldMessenger (Widget of the Week)

Flutter · 155K views · 2022 · 1:57

Open on YouTube

Web developmentSoftware (other)tutorial

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about showing SnackBars across navigation or from stateless widgets, since it demonstrates the ScaffoldMessenger approach.

Recommended by 0 people across 0 different months, 2023 to 2023.

What it is

A under-two-minute Flutter 'Widget of the Week' episode from the official Flutter channel explaining ScaffoldMessenger, the widget that lets apps show SnackBars reliably even as users navigate between screens. It includes a short code example using a global key.

What people said

Cites Ake · 2023-01 · Stack Overflow · on “FlutterError No ScaffoldMessenger widget found”

FlutterError (No ScaffoldMessenger widget found. MyApp widgets require a ScaffoldMessenger widget ancestor. The specific widget that could not find a ScaffoldMessenger ancestor was: MyApp The ancestors of this widget were: _InheritedProviderScope<UserProvider?> ChangeNotifierProvider _NestedHook MultiProvider [root] Typically, the ScaffoldMessenger widget is introduced by the MaterialApp at the top of your application widget tree.) Error this section void showSnackBar(BuildContext context, String text) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text(text), ), ); } import 'dart:io'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; vo

Cites A. Rokbi · 2023-02 · Stack Overflow · on “How could use SnackBars within the Scaffold in stateless widget?”

I found the answer from the youtube video [this video] as the following: import 'package:flutter/material.dart'; void main() => runApp(MyApp()); final _scaffoldkey = GlobalKey<ScaffoldMessengerState>(); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( scaffoldMessengerKey: _scaffoldkey, home: Scaffold( appBar: AppBar( actions: <Widget>[ IconButton( splashRadius: 18, icon: const Icon(Icons.thumb_up), tooltip: 'Like the app', onPressed: () { final SnackBar snackBar = SnackBar( duration: const Duration(seconds: 1), content: const Text('Registered as you like the application.'), action: SnackBarAction( label: 'Undo', on

Cites Cristian Beckert · 2023-03 · Stack Overflow · on “Show a snackbar after navigate in Flutter”

For anyone having this issue in 2023, after scaffoldKey.currentState.showSnackBar() (where scaffoldKey = GlobalKey<ScaffoldState>() ) got deprecated, and Flutter introduced ScaffoldMessenger.of(context).showSnackBar(Snackbar(content: Text(''))) which supports displaying the Snackbar on every screen even after navigation, make sure the screen you're navigating to has a Scaffold . My problem was that the screen I was returning to didn't had a scaffold. It was just returning the Material() widget as it was the Splash screen of the application. You can also use a global key if necessary, like so: final _scaffoldKey = GlobalKey<ScaffoldMessengerState>(); then using it as mentioned in previous com