Flutter 状态管理 provider的使用和封装
2020-09-18 12:10:17
问题1:I'm learning Dart and see the following idiom a lot:
someFuture.then((_) => someFunc());
I have also seen code like:
someOtherFuture.then(() => someOtherFunc());
Is there a functional difference between these two examples? A.k.a., What does passing _
as a parameter to a Dart function do?
This is particularly confusing given Dart's use of _
as a prefix for declaring private functions.
_
typically because you plan to not use it and throw it away. For example you can use the name x
or foo
instead. The difference between (_)
and ()
is simple in that one function takes an argument and the other doesn't. null
, for clarity? Just to save typing? And, won't the function be a little surprised when it tries to use the unassigned, untyped variable? Or, am I missing something?null
is a keyword and can't be used as a variable name. 3) Yes, It saves typing and also gives a low profile look. 4) No, _
is an assigned variable. No surprises here.