missing concrete implementation of state.build

Viewed 18794

I am getting this error in Dart: "Missing concrete implementation of "state.build""

The first method is the following:

class MyHomePage extends StatefulWidget {
  // String titleInput;
  // String amountInput;
  @override
  MyHomePageState createState() => MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> {
  final List<Transaction> _userTransactions = [
    // Transaction(
    //   id: "t1",
    //   title: "New Shoes",
    //   amount: 69.99,
    //   date: DateTime.now(),
    // ),
    // Transaction(
    //   id: "t2",
    //   title: "Weekly Groceries",
    //   amount: 16.53,
    //   date: DateTime.now(),
    // ),
  ];

Does anyone knows what this error means and how to solve it?

Thank you.

5 Answers

You need to add a build method to the State of your widget, this method describes the part of the user interface represented by your widget, e.g., (add this to the MyHomePageState)

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child:
            Container(
              height: 200,
              width: 100,
              color:  Colors.yellow,
        ),
      ),
    );
  }

Check the curly brace that closes the class where the Widget build method is found. You might just have closed it in the wrong place.

This was the case for me.

So make sure your build method is within the curly braces that enclose the class

class _LandingPageState extends State<LandingPage> {
    Widget build(BuildContext context) {
    ...
}

All the Stateful widgets and Stateless widgets should have build method.

@override
Widget build(BuildContext context) {
    return Container(
       ...
    );
}

If you want to use it without build do not extend the class with State, use it like

class YourClassName {
}

Goto the definitation of State<T> class and see what are the abstract methods. You will find build() method as the only abstract method i.e. a method without body. So when yu are inheriting from State<MyHomePage>, you must override the build() and give a body; basically you will create your Widgets inside the build() method.

So to fix the error add the below code to your class:

class MyHomePageState extends State<MyHomePage> {
   @override
   Widget build(BuildContext context) {
      return Scaffold( // Your Widget
         ...
      );
   }
}

Just check

@override
Widget build( Buildcontext context)
{ 
return Container();
}

Check spelling of build

reason : As u extend your class with stateless or statefull widget , U use overiding method to over ride the pre defined method which is already written in parent class which is state less/full class

Related