Flutter recommends against splitting up a long build method into smaller methods, as Flutter uses the build method to optimize building its widget tree.
I'm curious whether this affects a FutureBuilder widget's builder function too. On the one hand, I'm thinking that builder is already a function by its nature, so it should be alright to split off into a separate method inside the parent widget, like so:
class MyWidgetState extends State<MyWidget> {
@override
Widget build(BuildContext context) {
Future future = MyFuture();
return Scaffold(
body: FutureBuilder(
future: future,
builder: myBuilderMethod,
));
}
Widget myBuilderMethod(BuildContext builder, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
...
}
}
}
On the other hand, I'm not entirely sure how Flutter builds its widget tree here, so I'm scared I might be incurring some performance penalties compared to the standard inline version:
class MyWidgetState extends State<MyWidget> {
@override
Widget build(BuildContext context) {
Future future = MyFuture();
return Scaffold(
body: FutureBuilder(
future: future,
builder: (context, snapshot) {
if (snapshot.hasData) {
...
}
},
));
}
}
Is it alright performance-wise to split off my builder method as shown in my first example?