flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.3k stars 27.52k forks source link

Why is FormFieldValidator's value nullable? #87782

Open Albert221 opened 3 years ago

Albert221 commented 3 years ago

https://github.com/flutter/flutter/blob/40e8620a27f1a608d4df232936a168f134d64d7c/packages/flutter/lib/src/widgets/form.dart#L279-L285

I find it less convenient to use ! operator as I don't see a case when the value would be null for a field.

I'd be grateful for an explanation :)

LefebvreIlyas commented 3 years ago

Another question: Why doesn't FormFieldState override didUpdateWidget ? Is it an oversight?

LefebvreIlyas commented 3 years ago

Hello Albert, the value could be null for a tristate checkbox (true, false, null) or for a Dropdown for example .

LefebvreIlyas commented 3 years ago

But generic can take a type like String?. The developer could then explicitly specify that the type is nullable.