After migrating flutter code to null-safety, mock objects not accepting `any`

When assigning the Mock object, it needs to be of the Mock object type, not the BaseClass. @GenerateMocks(MockSpec<ITransactionRepository>(as: #MockTransactionRepository), ) void main() { …. ITransactionRepository baseObject = MockTransactionRepository(); // wrong MockTransactionRepository mockObject = MockTransactionRepository(); // right when(baseObject.method(any)); // results in compile error when(mockObject.method(any)); // OK … } Source: https://github.com/dart-lang/mockito/issues/364

The argument type ‘Function’ can’t be assigned to the parameter type ‘void Function()?’ after null safety

Change your code to accept a VoidCallback instead of Function for the onPressed. By the way VoidCallback is just shorthand for void Function() so you could also define it as final void Function() onPressed; Updated code: class DrawerItem extends StatelessWidget { final String text; final VoidCallback onPressed; const DrawerItem({Key key, this.text, this.onPressed}) : super(key: key); … Read more

How to enable Null-Safety in Flutter?

Null safety is no longer an experiment as of Dart 2.12. It is now easy to enable. Enabling null safety Starting with the first Dart 2.12 versions, types will be non-nullable by default. So you just need to change your SDK constraint: environment: sdk: “>=2.12.0 <3.0.0″ Learn more about “Enabling null safety” on dart.dev.

The default ‘List’ constructor isn’t available when null safety is enabled. Try using a list literal, ‘List.filled’ or ‘List.generate’

Short answer: Instead of the pre-null-safety operations var foo = List<int>(); // Now error var bar = List<int>(n); // Now error var baz = List<int>(0); // Now error use the following: var foo = <int>[]; // Always the recommended way. var bar = List.filled(1, 0); // Not filled with `null`s. var baz = List<int>.empty(); Long … Read more

Non-nullable instance field must be initialized

(Your code was fine before Dart 2.12, null safety) With null safety, Dart doesn’t know if you actually assigned a value to count. Dart initializes objects in two phases, and Dart expects all member variables to already be initialized when the constructor’s body executes. Because your members are non-nullable and haven’t been initialized to non-null … Read more

What is Null Safety in Dart?

1. Null safety / non-nullable (by default) The null safety / non-nullable (by default), short NNBD, feature can currently be found at nullsafety.dartpad.dev. Keep in mind that you can read the full spec here and full roadmap here. Now, sound null safety has also been officially announced for Dart. 2.1. What does non-nullable by default … Read more

The parameter can’t have a value of ‘null’ because of its type in Dart

Why The reason this happens is because with null safety enabled, your non-nullable parameter factor or key cannot be null. In the function and the constructor, these values might be null when the function is called without the named parameter: calculate() or Foo(). However because the types (int and Key) are non-nullable, this is invalid … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)