Flutter_cached_network_image: Support NNBD

Created on 20 Nov 2020  路  17Comments  路  Source: Baseflow/flutter_cached_network_image

馃悰 Bug Report

Currently using Non Nullable for flutter, all other dependencies work fine except for cached_network_image. Now I'm getting a long list of errors and the app cannot run nor build.

Here is the long list of errors I'm getting:
`
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/compat.dart:1:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite_common/src/compat.dart';
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/sqflite_import.dart:5:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite_common/src/compat.dart' show SqfliteOptions;
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/constant.dart:1:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite_common/src/constant.dart';
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/utils.dart:1:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite_common/src/utils.dart';
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/utils/utils.dart:1:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite_common/utils/utils.dart';
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/sqlite_api.dart:1:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite_common/sqlite_api.dart';
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/sqflite_import.dart:18:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite_common/src/factory_mixin.dart'
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/sqflite_import.dart:8:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite_common/src/database.dart' // ignore: implementation_imports
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/sqflite_import.dart:12:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite_common/src/database_mixin.dart' // ignore: implementation_imports
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/sqflite_import.dart:16:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite_common/src/exception.dart'
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/sqflite_import.dart:20:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite_common/src/factory.dart' show SqfliteDatabaseFactory;
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/sqflite_import.dart:21:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite_common/src/mixin/constant.dart'
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/sqflite_import.dart:32:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite_common/src/mixin/factory.dart'
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/sql_builder.dart:1:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite_common/src/sql_builder.dart';
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/sqflite.dart:13:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite/src/compat.dart';
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/sqflite.dart:16:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'sqlite_api.dart';

../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/sql.dart:5:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite/src/sql_builder.dart'
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/sqflite.dart:12:1: Error: Null safe libraries are not allowed to export declarations from of opt-out libraries.
export 'package:sqflite/sql.dart' show ConflictAlgorithm;
^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/sqflite.dart:70:17: Error: Optional parameter 'duration' should have a default value because its type 'Duration' doesn't allow null.

  • 'Duration' is from 'dart:core'.
    {Duration duration, void Function() callback}) {
    ^^^^^^^^
    ../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/sqflite.dart:70:43: Error: Optional parameter 'callback' should have a default value because its type 'void Function()' doesn't allow null.
    {Duration duration, void Function() callback}) {
    ^^^^^^^^
    ../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/sqflite.dart:128:10: Error: Optional parameter 'version' should have a default value because its type 'int' doesn't allow null.
    {int version,
    ^^^^^^^
    ../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/sqflite.dart:129:27: Error: Optional parameter 'onConfigure' should have a default value because its type 'FutureOr Function(Database)' doesn't allow null.
  • 'Database' is from 'package:sqflite_common/sqlite_api.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite_common-1.0.2+1/lib/sqlite_api.dart').
    OnDatabaseConfigureFn onConfigure,
    ^^^^^^^^^^^
    ../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/sqflite.dart:130:24: Error: Optional parameter 'onCreate' should have a default value because its type 'FutureOr Function(Database, int)' doesn't allow null.
  • 'Database' is from 'package:sqflite_common/sqlite_api.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite_common-1.0.2+1/lib/sqlite_api.dart').
    OnDatabaseCreateFn onCreate,
    ^^^^^^^^
    ../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/sqflite.dart:131:31: Error: Optional parameter 'onUpgrade' should have a default value because its type 'FutureOr Function(Database, int, int)' doesn't allow null.
  • 'Database' is from 'package:sqflite_common/sqlite_api.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite_common-1.0.2+1/lib/sqlite_api.dart').
    OnDatabaseVersionChangeFn onUpgrade,
    ^^^^^^^^^
    ../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/sqflite.dart:132:31: Error: Optional parameter 'onDowngrade' should have a default value because its type 'FutureOr Function(Database, int, int)' doesn't allow null.
  • 'Database' is from 'package:sqflite_common/sqlite_api.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite_common-1.0.2+1/lib/sqlite_api.dart').
    OnDatabaseVersionChangeFn onDowngrade,
    ^^^^^^^^^^^
    ../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/sqflite.dart:133:22: Error: Optional parameter 'onOpen' should have a default value because its type 'FutureOr Function(Database)' doesn't allow null.
  • 'Database' is from 'package:sqflite_common/sqlite_api.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite_common-1.0.2+1/lib/sqlite_api.dart').
    OnDatabaseOpenFn onOpen,
    ^^^^^^
    ../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/factory_impl.dart:10:24: Error: Field '_databaseFactory' should be initialized because its type 'SqfliteDatabaseFactory' doesn't allow null.
  • 'SqfliteDatabaseFactory' is from 'package:sqflite_common/src/factory.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite_common-1.0.2+1/lib/src/factory.dart').
    SqfliteDatabaseFactory _databaseFactory;
    ^^^^^^^^^^^^^^^^
    ../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/factory_impl.dart:42:30: Error: The value 'null' can't be assigned to a variable of type 'SqfliteDatabaseFactory' because 'SqfliteDatabaseFactory' is not nullable.
  • 'SqfliteDatabaseFactory' is from 'package:sqflite_common/src/factory.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite_common-1.0.2+1/lib/src/factory.dart').
    sqfliteDatabaseFactory = null;

../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/factory_impl.dart:53:5: Warning: Operand of null-aware operation '??=' has type 'SqfliteDatabaseFactory' which excludes null.

  • 'SqfliteDatabaseFactory' is from 'package:sqflite_common/src/factory.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite_common-1.0.2+1/lib/src/factory.dart').
    _databaseFactory ??= SqfliteDatabaseFactoryImpl();
    ^
    ../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/factory_impl.dart:67:5: Warning: Operand of null-aware operation '??=' has type 'SqfliteDatabaseFactory' which excludes null.
  • 'SqfliteDatabaseFactory' is from 'package:sqflite_common/src/factory.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite_common-1.0.2+1/lib/src/factory.dart').
    _databaseFactory ??= SqfliteDatabaseFactoryImpl();
    ^
    ../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.2+1/lib/src/sqflite_impl.dart:17:13: Error: A value of type 'Future' can't be returned from a function with return type 'Future' because 'T?' is nullable and 'T' isn't.
  • 'Future' is from 'dart:async'.
    channel.invokeMethod(method, arguments);

FAILURE: Build failed with an exception.

  • Where:
    Script '/../flutter_tools/gradle/flutter.gradle' line: 900

  • What went wrong:
    Execution failed for task ':app:compileFlutterBuildDevDebug'.

    Process 'command '/../flutter/bin/flutter'' finished with non-zero exit value 1
    `

Expected behavior

App should run without errors like it did prior to making the non nullable change.

Reproduction steps

In pubspec.yaml:
`environment:
sdk: ">=2.10.0 <3.0.0"

dependencies:
cached_network_image: ^2.3.3`

Added analysis_options.yaml:
analyzer: enable-experiment: - non-nullable

In my launch.json for VS code, I added the args
"--enable-experiment=non-nullable", "--no-sound-null-safety",

Configuration

Version: 1.x
Version 2.3.3

Platform:

  • [x] :iphone: iOS
  • [x] :robot: Android

Most helpful comment

I wanted to migrate this lib, but it still needs flutter_cache_manager to migrate first.
I've gone and done that instead: https://github.com/Baseflow/flutter_cache_manager/pull/278.

All 17 comments

I didn't have a look at it yet, but seeing your errors it looks like sqflite will need to migrate first. Looks like that is going to beta soon: https://github.com/tekartik/sqflite/issues/529

Thanks for the heads up, I just saw they released today 2.0.0-nullsafety.1 as a prelease

OctoImage is almost migrated: https://github.com/Baseflow/octo_image/pull/16. That's waiting for some packages that should have an update soon.

@renefloor octo_image has now migrated to nnbd (1.0.0-nullsafety.1). It would be great if this package could also be migrated soon. I can help if needed.

I wanted to migrate this lib, but it still needs flutter_cache_manager to migrate first.
I've gone and done that instead: https://github.com/Baseflow/flutter_cache_manager/pull/278.

It looks like flutter_cache_manager is now migrated to null safety.

Does someone have time to migrate this library?

I can try to migrate this package as I've just migrated mine :) But looks like octo_image package also needs to be migrated. Anyone want to try?

@bartektartanus octo_image is already migrated: https://pub.dev/packages/octo_image/versions/1.0.0-nullsafety.1

@jlubeck Indeed! My bad. :) Ok, I've started this migration.

Code seems to look fine now, but I'm struggling with tests. I have some troubles with mockito and migrating the mocks. Now the mocks needs to be generated by build_runner with annotation @GenerateMocks. Looks like it does not work with mixins yet. So I can't generate mock for ImageCacheManager.
Will try again tomorrow and submit my work in progress MR.

Ok, PR is ready, but it's still WIP. Maybe someone with better knowledge of this package and mockito will rewrite tests?

Why is the version 3.0.0-nullsafety on pub.dev not showing the null safety badge?

The null safety badge will appear only once a stable version is released.

Please, can you re-check it? Because other plugins on pub.dev has also a pre-released version WITH the null safety badge. If I can help you somehow let me know. 馃槑馃憤

@rlazom I've only ever seen the Null Safety badge for stable nullsafe releases (if you found a counter example, I would be interested if you could say which one). Though I don't think it's a problem, it's actually a motivation to get a stable release out soon ;-)

@ryanheise this is my pre-release package with the badge https://pub.dev/packages/flutter_widget_from_html_core/versions/0.6.0-rc.2021030401

Screen Shot 2021-03-11 at 09 13 47

Maybe it is a bug in pub.dev, but I would point out that the Dart migration guide provided specific recommendations for null safety prereleases and it's possible that things aren't behaving correctly unless you follow those recommendations.

In this case, a nullsafe prerelease should be named something like 0.6.0-nullsafety.0 (where the 0 gets incremented for each successive prerelease version).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BerndWessels picture BerndWessels  路  6Comments

gunhansancar picture gunhansancar  路  3Comments

yossefEl picture yossefEl  路  4Comments

srburton picture srburton  路  6Comments

love-bkpp picture love-bkpp  路  5Comments