Which one is better approach for initialize flutter widget properties?
can someone explain which approach is better and why.
First one
having const constructor and initialize properties in build method.
class CustomStatusBar extends StatelessWidget {
const CustomStatusBar({
Key? key,
required this.report,
}) : super(key: key);
final Report report;
@override
Widget build(BuildContext context) {
final int open = report.open;
final int finished = report.finished;
final int terminated = report.terminated;
final int total = open + finished + terminated;
return MyWidget();
}
}
Second one
having Non-cost constructor and initialize properties in constructor.
class CustomStatusBar extends StatelessWidget {
CustomStatusBar({
Key? key,
required this.report,
}) :
open = report.open,
finished = report.finished,
terminated = report.terminated,
total = report.open + report.finished + report.terminated,
super(key: key);
final Report report;
final int open;
final int finished;
final int terminated;
final int total;
@override
Widget build(BuildContext context) {
return MyWidget();
}
}