skip to Main Content
import 'package:flutter/material.dart';

void main() {
runApp(
const MaterialApp(

  home: Scaffold(
    backgroundColor: Colors.yellowAccent,
    appBar: AppBar(
        title: Text('I am Rich'),
    ),
  ),
)

);
}

I’m starting to study a new course on Flutter and get a warning saying "The constructor being called is not a constructor" Can somebody tell me why is that? It only appears when I add the Text Widget… What’s wrong here? thank you in advance. I’m a total beginner

2

Answers


  1. void main() {
      runApp(
        MaterialApp(
          home: Scaffold(
            backgroundColor: Colors.yellowAccent,
            appBar: AppBar(
              title: Text('I am Rich'),
            ),
          ),
        )
      );
    }
    

    you should remove the const keyword in front of the MaterialApp, because AppBar() is not a const constructor

    Login or Signup to reply.
  2. home: Scaffold(
        backgroundColor: Colors.yellowAccent,
        appBar: AppBar(
          title: const Text('I am Rich'),
        ),
      ),
    

    You should add const keyword before your Text Widget. Because you have added static text in Text Widget.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search