This Exception was cause by using the context of Scaffold widget instead of Child widget in the widget Tree. We handle this exception by two ways Option1) Using Builder widget Option1) By Using Scaffold key
Scaffold(
appBar: AppBar(
title: Text('Builder Widget'),
),
body: Builder(
builder: (context) =>
Center(
child: RaisedButton(
color: Colors.pink,
textColor: Colors.white,
onPressed: () {
final snackBar = SnackBar(content: Text('Flutter SnackBar'));
Scaffold.of(context).showSnackBar(snackBar);
},
child: Text('Display SnackBar'),
),
),
),
);
GlobalKey<ScaffoldState>_scaffoldKey=GlobalKey();
Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: Text('Builder Widget'),
),
body: Center(
child: RaisedButton(
color: Colors.pink,
textColor: Colors.white,
onPressed: () {
final snackBar = SnackBar(content: Text('Flutter SnackBar'));
_scaffoldKey.currentState.showSnackBar(snackBar);
},
child: Text('Display SnackBar'),
),
),
),
How to remove Yellow lines under Text Widgets in Flutter?
How to Close Flutter application Programmatically?
How to make a widget Center vertically inside a SingleChildScrollView
How to create Gradient background for AppBar in Flutter
How can i use hexadecimal color code in Flutter?
Flutter - Vertical Divider - How to add Vertical Divider?
How do i make circular icon Inside Button ?
Fix Flutter Bottom Overflowed Error in Your App - RRutors
How to remove debug banner in flutter?
How to copy text from Text Widget flutter?
How to make shadow for Container widget Flutter?
How to handle the code after showDialog is dismissed in Flutter?
How do I open a web browser (URL) from my Flutter code?
Flutter Questions and Answers
How can i get document id in Flutter Firestore?
How to create Toast in Flutter?
What corresponds to Intent in Flutter?
How does Flutter load images?
How to set the TextFormField/TextField border color
How to deactivate back button in flutter?
How to check the given value is a number or not in dart?
How do I supply/set an initial value to a text field in Flutter ?
Fix Navigator Context Issue in Flutter with RRutors
How to place a listview inside a SingleChildScrollView but prevent them from scrolling separately?
How to find the Screen orientation in flutter
Fix MissingPluginException Error in Flutter with RRutors
Fix Scaffold.of() Called Without Scaffold Exception - RRutors
Fix Flutter Null Safety Issue with RRutors
Can we use Container color and decoration properties at once?
How do we save the data in browser's cookies using the Flutter web?
How to change the application launcher icon on Flutter?
OS Error: A required privilege is not held by the client errno = 1314
How to navigate to new screen without back screen
How to change package name in flutter?
How do i change the OutlineInputBorder color?
How do i make CachedNetwork image as rounded circle in flutter?
How to display snackbar infinite duration in a flutter application
Vertical Divider is Not Showing in my Flutter Application
Fix MediaQuery.of() Error in Flutter with RRutors Guide
What is Flutter?