Issue
I have this widget in Flutter that represents a simple loading:
class Loading extends StatelessWidget {
const Loading({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Material(
child: Center(
child: CircularProgressIndicator(),
),
);
}
}
I'm using IntelliJ on version 2021.2.1 and I've been getting this warning at various times while building code in flutter:
To solve this lint problem you can just add the reserved word const
after the return statement, leaving the code as follows:
class Loading extends StatelessWidget {
const Loading({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const Material(
child: Center(
child: CircularProgressIndicator(),
),
);
}
}
How does this really change to flutter? Is it a significant change? If not very significant is there a way to disable these warnings in IntelliJ? Because I think them quite boring.
Solution
It will prevent the Widget from being rebuild when its parent is rebuilt, as you already know that it will not change ever. Thus, only needing to build it once, you gain performance by making it a const
.
Answered By - Tim Jacobs Answer Checked By - Marie Seifert (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.