I have a class:
class Foo {
void bar() {}
}
And I'm using it like this:
Widget build() {
late Foo foo;
return Column(
children: [
ElevatedButton(
onPressed: foo.bar, // Error:
child: Text('Use'),
),
ElevatedButton(
onPressed: () => foo = Foo(), // Assigning foo here
child: Text('Initialize'),
),
],
);
}
The late local variable 'foo' is definitely unassigned at this point. (Documentation)
As you can see I'm using the late
keyword to give a hint to the analyzer that I'll be instantiating later, but I still see an error, why?
Note: I'm NOT looking for solutions on HOW to make it work but rather WHY it's not working?