Issue I started seeing this error in my DropdownButton after migrating to null safety. DropdownButton<String>( value: myValue, onChanged: (String string) { // Error print(string); }, items: [ DropdownMenuItem( value: ‘foo’, child: Text(‘Foo’), ), DropdownMenuItem( value: ‘bar’, child: Text(‘Bar’), ), ],
Continue readingTag: dart
Why snapshot.data returns null in FutureBuilder?
Issue void main() { FutureBuilder<bool>( future: f(), builder: (_, AsyncSnapshot<bool> snapshot) { bool data = snapshot.data; // Error return Container(); }, ); } Future<bool> f() async => true; I used bool in all the places and hence my snapshot.data should
Continue readingFlow analysis doesn't work when using setState
Issue void f() { String string; setState(() { string = fooCondition ? ‘foo’ : ‘bar’; }); string.toUpperCase(); // Error } If I remove the setState condition, the flow analysis work! I could put my setState below (blank setState(() {}) but
Continue readingWhat's the difference between ? and ! in collections like Map, List and Set?
Issue What’s the difference between ? and ! when used in a collection in Dart? Say, I have: var list = [1, 2]; Now, I can either use print(list?[0]); // prints 1 or print(list![0]); // also prints 1 Both of
Continue readingShorthand of checking the nullability of a bool variable used in an if condition
Issue Future<bool?> f() async => true; void main() async { final proceed = await f(); if (proceed) {…} // Error if (proceed != null && proceed) {…} // Works but too verbose } Is there any shorthand or a better
Continue readingHow to do a multi check for null values after Dart null safety?
Issue int? foo, bar, baz; bool get allGood => foo != null && bar != null && baz != null; void f1() { if (allGood) { print(‘${foo.abs()} ${bar.abs()} ${baz.abs()}}’); // Error } } void f2() { if (allGood) { print(‘${foo.ceil()}
Continue readingThe parameter 'firebaseFirestore' can't have a value of 'null' because of its type, but the implicit default value is 'null' in flutter
Issue I declared two variables of type FirebaseFirestore and FireBaseAuth, and now i am facing an error of null safety. I am using a constructor in my class, and passing them as paraeters, with getting an error of – The
Continue readingretrofit_generator:retrofit crash after upgrade to Null Safe version on Flutter
Issue I am trying to upgrade my Flutter app to be Null Safe and I encountered a problem with the retrofit code generator. So I have a RestAPI abstract class declared like this: @RestApi(baseUrl: ApiConsts.authBaseURL) abstract class IAuthApi { factory
Continue readingError: 'split' can't be unconditionally invoked because the receiver can be 'null'
Issue Android Studio throws this following NullSafety error on split in Flutter. The method ‘split’ can’t be unconditionally invoked because the receiver can be ‘null’. Try making the call conditional (using ‘?.’) or adding a null check to the target
Continue readingThe initializer type 'AuthRepository?' can't be assigned to the field type 'AuthRepository' in flutter
Issue The error is coming on line 6 (in the first code snippet or the main code part), on authRepository part. The main code – class AuthBloc extends Bloc<AuthEvent, AuthState> { final AuthRepository _authRepository; var v; AuthBloc({ @required AuthRepository? authRepository
Continue reading