Search code examples
flutterdart

A function body must be provided. Try adding a function body


image

I wrote it myself because statefulwidget didn't automatically create the pattern and out of 7 different errors I just couldn't fix this

import 'package:flutter/material.dart';

class NaberMain extends StatefulWidget {
  NaberMain({Key key}) : super(key: key)

  // ignore: empty_constructor_bodies
  @override 
  _NaberMainState createState() => _NaberMainState();
}

class _NaberMainState extends State<NaberMain> {
  @override
  Widget build(BuildContext context) {
    return Container(
    );
  }
}

Solution

  • You have a missing semi-colon after super(key: key). Add the semi-colon.

    class NaberMain extends StatefulWidget {
      NaberMain({Key key}) : super(key: key); //This is the semi-colon.
    
      @override 
      _NaberMainState createState() => _NaberMainState();
    }
    
    class _NaberMainState extends State<NaberMain> {
      @override
      Widget build(BuildContext context) {
        return Container(
        );
      }
    }