ScaffoldMessenger.showSnackBar was called, but there are currently no descendant Scaffolds to present to. 'package:flutter/src/material/scaffold.dart': Failed assertion: line 289 pos 7: '_scaffolds.isNotEmpty'
fica dando este erro
Meu Codigo: import 'package:flutter/material.dart';
class FormScreen extends StatefulWidget { const FormScreen({Key? key}) : super(key: key);
@override State createState() => _FormScreenState(); }
class _FormScreenState extends State { TextEditingController usernameController = TextEditingController(); TextEditingController passwordController = TextEditingController(); final _formKey = GlobalKey();
@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: Text('Login'), ), body: Form( key: _formKey, child: Center( child: SingleChildScrollView( child: Container( height: 650, width: 375, decoration: BoxDecoration( color: Colors.black12, border: Border.all(color: Colors.black, width: 2), borderRadius: BorderRadius.circular(8), ), child: Column( children: [ Padding( padding: const EdgeInsets.all(8.0), child: TextFormField(
textAlign: TextAlign.center,
controller: usernameController,
validator: (value) {
if (value!.isEmpty && value != 'Victor') {
return 'Username Errado';
}
return null;
},
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Username',
fillColor: Colors.white70,
filled: true
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
textAlign: TextAlign.center,
controller: passwordController,
validator: (value) {
if (value!.isEmpty && value != '123') {
return 'Username Errado';
}
return null;
},
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Passoword',
fillColor: Colors.white70,
filled: true),
),
),
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Teste'))
);
}
},
child: Text('Adicionar'))
],
),
),
),
),
)),
);
} }