How to Solve No Material Widget Found In Flutter ?

· 3 min read
How to Solve No Material Widget In Flutter
How to Solve No Material Widget In Flutter

Generally When a user wraps a widget without a Material Widget then the user gets an error that states that No Material Widget Found So in this article we will go through How to Solve No Material Widget Found In Flutter?

How to Solve No Material Widget Found In Flutter?

As the error says Material Widget, you can either directly include one, or use a widget that contains Material itself, such as a Card Widget, Dialog Widget, Drawer, or Scaffold Widget.

It will make it easy to add other material widgets to your app later, such as an AppBar Widget, Drawer, or FloatingActionButton Widget.

Consider a code snippet like the below:

@override
Widget build(BuildContext context) {
  return new Scaffold(
    body: new Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        new TextField(
            controller: _controller,
            decoration: new InputDecoration(
                hintText: 'Type something',
            ),
        ),
        new RaisedButton(
            onPressed: () {
              showDialog(
                  context: context,
                  child: new AlertDialog(
                      title: new Text('What you typed'),
                      content: new Text(_controller.text),
                  ),
              );
            },
            child: new Text('DONE'),
        ),
      ],
    ),
  );
}

Put all widgets inside a Scaffold Widget, like this:

    import 'package:flutter/material.dart';

    void main() => runApp(MyApp());

    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Demo',
          //home: MyWidget(), --> do not do this !!!
          home: Home() --> this will wrap it in Scaffold
        );
      }
    }

    class Home extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            appBar: AppBar(
              title: Text('Demo'),
            ),
            body: MyWidget()); --> put your widget here
      }
    }

class MyWidget extends StatefulWidget {
...

Conclusion:

In this article, We have been through How to Call Method in One Stateful Widget From Another Stateful Widget In Flutter ??

Thanks for being with us on a Flutter Journey !!!

Keep Learning !!! Keep Fluttering !!!

FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

FlutterAgency.com is one of the most popular online portal dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge on Flutter.

Leave a Reply