Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No material widget found textfield widgets require a material widget ancestor

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 material widget ancestor

 import 'package:flutter/material.dart';   Widget LoginPage() {     return new Container(       height: MediaQuery.of(context).size.height,       decoration: BoxDecoration(         color: Colors.white,         image: DecorationImage(           colorFilter: new ColorFilter.mode(               Colors.black.withOpacity(0.05), BlendMode.dstATop),           image: AssetImage('assets/images/mountains.jpg'),           fit: BoxFit.cover,         ),       ),       child: new Column(         children: <Widget>[           Container(             padding: EdgeInsets.all(120.0),             child: Center(               child: Icon(                 Icons.headset_mic,                 color: Colors.redAccent,                 size: 50.0,               ),             ),           ),           new Row(             children: <Widget>[               new Expanded(                 child: new Padding(                   padding: const EdgeInsets.only(left: 40.0),                   child: new Text(                     "EMAIL",                     style: TextStyle(                       fontWeight: FontWeight.bold,                       color: Colors.redAccent,                       fontSize: 15.0,                     ),                   ),                 ),               ),             ],           ),           new Container(             width: MediaQuery.of(context).size.width,             margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),             alignment: Alignment.center,             decoration: BoxDecoration(               border: Border(                 bottom: BorderSide(                     color: Colors.redAccent,                     width: 0.5,                     style: BorderStyle.solid),               ),             ),             padding: const EdgeInsets.only(left: 0.0, right: 10.0),             child: new Row(               crossAxisAlignment: CrossAxisAlignment.center,               mainAxisAlignment: MainAxisAlignment.start,               children: <Widget>[                 new Expanded(                   child: TextField(                     obscureText: true,                     textAlign: TextAlign.left,                     decoration: InputDecoration(                       border: InputBorder.none,                       hintText: '[email protected]',                       hintStyle: TextStyle(color: Colors.grey),                     ),                   ),                 ),               ],             ),           ),           Divider(             height: 24.0,           ),           new Row(             children: <Widget>[               new Expanded(                 child: new Padding(                   padding: const EdgeInsets.only(left: 40.0),                   child: new Text(                     "PASSWORD",                     style: TextStyle(                       fontWeight: FontWeight.bold,                       color: Colors.redAccent,                       fontSize: 15.0,                     ),                   ),                 ),               ),             ],           ),           new Container(             width: MediaQuery.of(context).size.width,             margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),             alignment: Alignment.center,             decoration: BoxDecoration(               border: Border(                 bottom: BorderSide(                     color: Colors.redAccent,                     width: 0.5,                     style: BorderStyle.solid),               ),             ),             padding: const EdgeInsets.only(left: 0.0, right: 10.0),             child: new Row(               crossAxisAlignment: CrossAxisAlignment.center,               mainAxisAlignment: MainAxisAlignment.start,               children: <Widget>[                 new Expanded(                   child: TextField(                     obscureText: true,                     textAlign: TextAlign.left,                     decoration: InputDecoration(                       border: InputBorder.none,                       hintText: '*********',                       hintStyle: TextStyle(color: Colors.grey),                     ),                   ),                 ),               ],             ),           ),           Divider(             height: 24.0,           ),           new Row(             mainAxisAlignment: MainAxisAlignment.end,             children: <Widget>[               Padding(                 padding: const EdgeInsets.only(right: 20.0),                 child: new FlatButton(                   child: new Text(                     "Forgot Password?",                     style: TextStyle(                       fontWeight: FontWeight.bold,                       color: Colors.redAccent,                       fontSize: 15.0,                     ),                     textAlign: TextAlign.end,                   ),                   onPressed: () => {},                 ),               ),             ],           ),           new Container(             width: MediaQuery.of(context).size.width,             margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 20.0),             alignment: Alignment.center,             child: new Row(               children: <Widget>[                 new Expanded(                   child: new FlatButton(                     shape: new RoundedRectangleBorder(                       borderRadius: new BorderRadius.circular(30.0),                     ),                     color: Colors.redAccent,                     onPressed: () => {},                     child: new Container(                       padding: const EdgeInsets.symmetric(                         vertical: 20.0,                         horizontal: 20.0,                       ),                       child: new Row(                         mainAxisAlignment: MainAxisAlignment.center,                         children: <Widget>[                           new Expanded(                             child: Text(                               "LOGIN",                               textAlign: TextAlign.center,                               style: TextStyle(                                   color: Colors.white,                                   fontWeight: FontWeight.bold),                             ),                           ),                         ],                       ),                     ),                   ),                 ),               ],             ),           ),           new Container(             width: MediaQuery.of(context).size.width,             margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 20.0),             alignment: Alignment.center,             child: Row(               children: <Widget>[                 new Expanded(                   child: new Container(                     margin: EdgeInsets.all(8.0),                     decoration: BoxDecoration(border: Border.all(width: 0.25)),                   ),                 ),                 Text(                   "OR CONNECT WITH",                   style: TextStyle(                     color: Colors.grey,                     fontWeight: FontWeight.bold,                   ),                 ),                 new Expanded(                   child: new Container(                     margin: EdgeInsets.all(8.0),                     decoration: BoxDecoration(border: Border.all(width: 0.25)),                   ),                 ),               ],             ),           ),           new Container(             width: MediaQuery.of(context).size.width,             margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 20.0),             child: new Row(               children: <Widget>[                 new Expanded(                   child: new Container(                     margin: EdgeInsets.only(right: 8.0),                     alignment: Alignment.center,                     child: new Row(                       children: <Widget>[                         new Expanded(                           child: new FlatButton(                             shape: new RoundedRectangleBorder(                               borderRadius: new BorderRadius.circular(30.0),                             ),                             color: Color(0Xff3B5998),                             onPressed: () => {},                             child: new Container(                               child: new Row(                                 mainAxisAlignment: MainAxisAlignment.center,                                 children: <Widget>[                                   new Expanded(                                     child: new FlatButton(                                       padding: EdgeInsets.only(                                         top: 20.0,                                         bottom: 20.0,                                       ),                                       child: new Row(                                         mainAxisAlignment:                                         MainAxisAlignment.spaceEvenly,                                         children: <Widget>[                                           Icon(                                             const IconData(0xea90,                                                 fontFamily: 'icomoon'),                                             color: Colors.white,                                             size: 15.0,                                           ),                                           Text(                                             "FACEBOOK",                                             textAlign: TextAlign.center,                                             style: TextStyle(                                                 color: Colors.white,                                                 fontWeight: FontWeight.bold),                                           ),                                         ],                                       ),                                     ),                                   ),                                 ],                               ),                             ),                           ),                         ),                       ],                     ),                   ),                 ),                 new Expanded(                   child: new Container(                     margin: EdgeInsets.only(left: 8.0),                     alignment: Alignment.center,                     child: new Row(                       children: <Widget>[                         new Expanded(                           child: new FlatButton(                             shape: new RoundedRectangleBorder(                               borderRadius: new BorderRadius.circular(30.0),                             ),                             color: Color(0Xffdb3236),                             onPressed: () => {},                             child: new Container(                               child: new Row(                                 mainAxisAlignment: MainAxisAlignment.center,                                 children: <Widget>[                                   new Expanded(                                     child: new FlatButton(                                       padding: EdgeInsets.only(                                         top: 20.0,                                         bottom: 20.0,                                       ),                                       child: new Row(                                         mainAxisAlignment:                                         MainAxisAlignment.spaceEvenly,                                         children: <Widget>[                                           Icon(                                             const IconData(0xea88,                                                 fontFamily: 'icomoon'),                                             color: Colors.white,                                             size: 15.0,                                           ),                                           Text(                                             "GOOGLE",                                             textAlign: TextAlign.center,                                             style: TextStyle(                                                 color: Colors.white,                                                 fontWeight: FontWeight.bold),                                           ),                                         ],                                       ),                                     ),                                   ),                                 ],                               ),                             ),                           ),                         ),                       ],                     ),                   ),                 ),               ],             ),           )         ],       ),     );   } 

enter image description here

Does anyone know how to resolve it ?

like image 225
N Sharma Avatar asked Aug 09 '18 17:08

N Sharma


People also ask

How to solve No Material widget found?

Wrap your widget with Material() to escape this error. In this way, you can solve the "No Material widget found" error on Flutter App.

What is a material widget?

A convenience widget that wraps a number of widgets that are commonly required for applications implementing Material Design.

How do you use TextField in flutter?

In Flutter, this can be done using TextEditingController . First, create a TextEditingController and set it as a controller property of your TextField widget. In this example, I have added an extra Button and Text widget which will show the added text when you click the “Show Text” button.


1 Answers

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*) } 
like image 137
Dinesh Balasubramanian Avatar answered Sep 19 '22 04:09

Dinesh Balasubramanian