Closed AhmedNourJamalElDin closed 4 years ago
I would suggest you using if statement inside the tree instead of using it in build methods. Like this:
Widget build(BuildContext context) {
return SeparatedColumn(
children: [
Text("Hello"),
if(shouldBuildWorldText)
_buildWorldText(),
],
);
}
Widget _buildWorldText() {
return Text("World");
}
This way is much more efficient and _buildWorldText
won't be called unless condition is true.
Hint: Don't use methods for building widgets because it will refresh all widgets inside that method even tho they don't need refreshing. You can read more at: https://blog.codemagic.io/how-to-improve-the-performance-of-your-flutter-app./
Thanks for sharing this useful article.
I'm aware of the issues, but I'm literally having the second one where I have my widgets splitted:
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
HeaderWidget(),
MainWidget(),
FooterWidget(),
],
),
),
);
}
}
but I want to hide or show the footer based on backend flag. if the backend returned "showFooter = false" I would like to hide the footer.
Do you suggest or recommend any better way to do so?
Hi,
Is it possible to filter out all null values?
To reproduce:
Now it throws an exception by flutter where null values are not allowed.