I’m studying platters by myself. When I enter the code like below, it says to use const grammar like the attached picture, how can I add it without errors?
class MyHomePage extends StatelessWidget {
final String title; //
MyHomePage({required this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
title,
),
),
body: Center(
// child: Image.asset('images/tree.jpg'),
child: Text(
'Hello, Text Widget',
style: TextStyle(
fontSize: 25,
color: Colors.purple,
),
),
),
);
}
}
Please give me answer bro…
I’m begginner
3
Answers
It is just warring/suggestion message for better practice , you can add
const
before centerBut if you read something inside the Center widget, it cant be const.
Find more about dart.
do this way,
or
It is good practise to use const keyword, when you know, it not going to change during compile time. In your case add it in Center() widget .