Hi I am trying to build a login screen in flutter but I am getting below error when opening it.
No material widget found textfield widgets require a mater
Error states that TextField widgets require a Material widget ancestor. Simply wrapping your whole loginWidget into Scaffold
will solve the problem.
Widget LoginPage() {
return new Scaffold(body: *your whole code*)
}
Just wrap your widget with Material like this:
@override
Widget build(BuildContext context) {
return Material(
child: YourAwesomeWidget(),
}
Wrap the code with Scaffold. it works
Wrap the loginpage function with a Scaffold or a MaterialApp
Widget LoginPage() {
return new Scaffold(
body: Container(
*the rest of your code*
),
);
}
or
Widget LoginPage() {
return new MaterialApp(
home: Container(
*the rest of your code*
),
);
}
I encountered your same problem. Always remember to enter Scaffold remembering that it must be included as a parent who creates the page, inside it after, you will insert all the widgets you want, but Scaffold after MaterialApp is the second component that must be added if you are creating a new page.
Since most of the widget asks for material widget as their parent widget
its a good practice you should use Material()
or Scaffold()
widget on top of the widget tree and then continue your code.
@override
Widget build(BuildContext context) {
return Material(
child: body(),
}
OR
@override
Widget build(BuildContext context) {
return Scaffold(
child: body(),
}