I am trying to show snackbar on button click but due to some reasons facing an error message below.
Unhandled Exception: Scaffold.of() called with a context that does not contain a Scaffold.
Am I missing anything?
Code
class SignIn extends StatefulWidget {
@override
_SignInState createState() {
return _SignInState();
}
}
class _SignInState extends State<SignIn> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Hello",
home: Scaffold(
body: Center(
child: ListView(shrinkWrap: true, children: <Widget>[
Center(
child: Form(
key: _formKey,
child: Column(children: <Widget>[
Container(
child: Column(
children: <Widget>[
Container(
child: Row(
children: <Widget>[
ElevatedButton(
child: Text("Login"),
onPressed: () {
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text("Hello there!"),
),
);
})
],
),
)
],
),
)
]),
))
]))));
}
}