Reputation: 9
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
Upvotes: 1
Views: 144
Reputation: 37
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
backgroundColor: Colors.yellowAccent,
appBar: AppBar(
title: const Text('I am Rich'),
),
),
)
);
}
In your code const is creating problem here i have solve the error
If you dont use const it will work fine but it will show warning if you dont want any warning then use const before text widget
Upvotes: 1
Reputation: 21
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.
Upvotes: 1
Reputation: 801
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
Upvotes: 1