How to make the examples work

The examples of the book don’t work with the current versions of Flutter. Until 3.10 you could patch around and get things going but as of 3.13 there’s no way.

See the issues and output with the current version, and a section on how to run the examples with the Flutter SDK current at the publishing date of the booking.

Took me a long time, maybe this helps others.

Current version of Flutter

Flutter (Channel stable, 3.13.7, on Arch Linux 6.5.6-arch2-1, locale de_DE.UTF-8)

Project build through make clean get build-runner is failing:

Because every version of component_library from path depends on intl ^0.17.0 and every version of flutter_localizations from sdk depends on intl 0.18.1, component_library from path is incompatible with  
 flutter_localizations from sdk.  
So, because wonder_words depends on both flutter_localizations from sdk and component_library from path, version solving failed.

Add to pubspec.yaml:

dependency_overrides:
  intl: ^0.18.1

Project build through make clean get build-runner is passing.

Various errors in Android Studio

  • component_library/example
    → Delete
  • main.dart
    • The type of ‘_favQsApi’ can’t be inferred because it depends on itself through the cycle: _favQsApi, _userRepository.
    • The type of ‘_userRepository’ can’t be inferred because it depends on itself through the cycle: _favQsApi, _userRepository.
    • The type of ‘_routerDelegate’ can’t be inferred because it depends on itself through the cycle: _routerDelegate.
      → Add type to declarations
  • ‘SearchBar’ isn’t a function. in quote_list
    → Change import 'package:flutter/material.dart' hide SearchBar;
  • test packages with errors
    → Delete

Launching fails with

Launching lib/main.dart on sdk gphone64 x86 64 in debug mode...
Upgrading build.gradle
Conflict detected between Android Studio Java version and Gradle version, upgrading Gradle version from 6.7 to 7.6.1.
Upgrading gradle-wrapper.properties
Running Gradle task 'assembleDebug'...
Warning: The plugin integration_test requires Android SDK version 33.
For more information about build configuration, see https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
One or more plugins require a higher Android SDK version.
Fix this issue by adding the following to /mnt/Development/flutter/projects/others/rwf-materials/08-deep-linking/projects/starter/android/app/build.gradle:
android {
  compileSdkVersion 33
  ...
}


/home/user/.pub-cache/hosted/pub.dev/sliver_tools-0.2.6/lib/src/sliver_stack.dart:282:55: Error: A value of type 'RenderObject?' can't be assigned to a variable of type 'AbstractNode?'.
 - 'RenderObject' is from 'package:flutter/src/rendering/object.dart' ('../../../../../../sdk/flutter/packages/flutter/lib/src/rendering/object.dart').
 - 'AbstractNode' is from 'package:flutter/src/foundation/node.dart' ('../../../../../../sdk/flutter/packages/flutter/lib/src/foundation/node.dart').
      final AbstractNode? targetParent = renderObject.parent;
                                                      ^
/home/user/.pub-cache/hosted/pub.dev/sliver_tools-0.2.6/lib/src/sliver_stack.dart:283:54: Error: The method 'markNeedsLayout' isn't defined for the class 'AbstractNode?'.
 - 'AbstractNode' is from 'package:flutter/src/foundation/node.dart' ('../../../../../../sdk/flutter/packages/flutter/lib/src/foundation/node.dart').
Try correcting the name to the name of an existing method, or defining a method named 'markNeedsLayout'.
      if (targetParent is RenderObject) targetParent.markNeedsLayout();
                                                     ^^^^^^^^^^^^^^^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* Where:
Script '/mnt/Development/flutter/sdk/flutter/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy' line: 1297

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/mnt/Development/flutter/sdk/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 27s
Exception: Gradle task assembleDebug failed with exit code 1

Everything goes downhill from here: There’s no way to make the app running again without recreating the project.

Version of the time of publishing

Flutter (Channel stable, 3.3.0, on Arch Linux 6.5.6-arch2-1, locale de_DE.UTF-8) via Flutter SDK archive

Add to makefile:

JAVA_HOME := /usr/lib/jvm/java-11-openjdk  
FLUTTER_BIN := /mnt/Development/flutter/projects/others/rwf-materials/sdk/flutter/bin  
PATH := /usr/bin:$(FLUTTER_BIN)

Project build through make clean get build-runner is passing.

Set Flutter SDK in Android Studio: Languages → Flutter → Flutter SDK path

Set Java in Run Configuration through Environment variable JAVA_HOME=/usr/lib/jvm/java-11-openjdk

Still various compile errors in Android Studio, affects test and component_library/example.
→ Delete

App runs in emulator despite reporting deprecation warnings:

Launching lib/main.dart on sdk gphone64 x86 64 in debug mode...
Running Gradle task 'assembleDebug'...
Note: /mnt/Development/flutter/projects/others/rwf-materials/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-4.2.1/android/src/main/java/com/it_nomads/fluttersecurestorage/FlutterSecureStoragePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /mnt/Development/flutter/projects/others/rwf-materials/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_remote_config-2.0.11/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /mnt/Development/flutter/projects/others/rwf-materials/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_analytics-9.1.12/android/src/main/java/io/flutter/plugins/firebase/analytics/FlutterFirebaseAnalyticsPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /mnt/Development/flutter/projects/others/rwf-materials/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_dynamic_links-4.3.1/android/src/main/java/io/flutter/plugins/firebase/dynamiclinks/FlutterFirebaseDynamicLinksPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
✓  Built build/app/outputs/flutter-apk/app-debug.apk.
Installing build/app/outputs/flutter-apk/app.apk...
...

Actually you can run book’s projects without it’s recreating on the up-to-date version of Flutter 3.13.6.

Here is a complete list of fixes you need to make after opening a clean starter project in the code editor (tested on Windows 11 22H2 and VS Code 1.83.1):

  1. As suggested in this post add explicit FavQsApi and RoutemasterDelegate types to the main file:
lib\main.dart

line 79
late final _favQsApi = FavQsApi(
→ (change to)
late final FavQsApi _favQsApi = FavQsApi(

line 91
late final _routerDelegate = RoutemasterDelegate(
→
late final RoutemasterDelegate _routerDelegate = RoutemasterDelegate(
  1. Update the intl package version for two local packages:
packages\component_library\pubspec.yaml
packages\features\profile_menu\pubspec.yaml

intl: ^0.17.0
→ 
intl: ^0.18.1
  1. Bump infinite_scroll_pagination package version since it uses outdate sliver_tools package:
packages\features\quote_list\pubspec.yaml

infinite_scroll_pagination: ^4.0.0-dev.1
→
infinite_scroll_pagination: ^4.0.0
  1. Update gradle and google-services versions to build the project correctly:
android\build.gradle

classpath 'com.android.tools.build:gradle:4.1.0'
→
classpath 'com.android.tools.build:gradle:7.4.1'

classpath 'com.google.gms:google-services:4.3.10'
→
classpath 'com.google.gms:google-services:4.3.14'
  1. Raise compileSdkVersion to current value:
android\app\build.gradle

line 31
compileSdkVersion 31
→
compileSdkVersion 33
  1. All dependencies in monitoring package need to be updated—replace whole dependencies section with the following (leave dev_dependencies as is):
packages\monitoring\pubspec.yaml

dependencies:
  …
→
dependencies:
  flutter:
    sdk: flutter
  firebase_core: ^2.17.0
  firebase_crashlytics: ^3.3.7
  firebase_dynamic_links: ^5.3.7
  firebase_analytics: ^10.5.1
  firebase_remote_config: ^4.2.7
  1. As discussed here rename (with F2 button) SearchBar class with something different to avoid a name collision:
packages\component_library\lib\src\search_bar.dart

line 4
SearchBar
→
AppSearchBar
  1. Finally you can get packages:
    make get

On Windows you may need to use Git Bash terminal instead of default PowerShell to run this command successfully—here are the details.

That’s all! Now you can build and run projects without problems (after fixing all the suggested in the book’s chapter issues of course if you have opened a starter project).

2 Likes

I’d really prefer running the examples with a current version. The suggestions partially reflect what I tried to do.

I’ve compiled the steps into the makefile, so that they can be applied through make patch-for-current-flutter:

patch-for-current-flutter:	patch-main \
	patch-searchbar \
	patch-package-intl \
	patch-package-infinite-scroll \
	patch-monitoring \
	patch-android-gradle \
	patch-android-app-compile

patch-main:
	sed -i 's/late final _favQsApi/late final FavQsApi _favQsApi/' lib/main.dart
	sed -i 's/late final _userRepository/late final UserRepository _userRepository/' lib/main.dart
	sed -i 's/late final _routerDelegate/late final RoutemasterDelegate _routerDelegate/' lib/main.dart

patch-searchbar:
	sed -i 's/SearchBar/AppSearchBar/g' packages/component_library/lib/src/search_bar.dart
	sed -i 's/child: SearchBar/child: AppSearchBar/' packages/features/quote_list/lib/src/quote_list_screen.dart

patch-package-intl:
	sed -i 's/intl: ^0.17.0/intl: ^0.18.1/' packages/component_library/pubspec.yaml
	sed -i 's/intl: ^0.17.0/intl: ^0.18.1/' packages/features/profile_menu/pubspec.yaml

patch-package-infinite-scroll:
	sed -i 's/infinite_scroll_pagination: ^4.0.0-dev.1/infinite_scroll_pagination: ^4.0.0/' packages/features/quote_list/pubspec.yaml

patch-monitoring:
	sed -i 's/firebase_core: ^1.19.1/firebase_core: ^2.17.0/' packages/monitoring/pubspec.yaml
	sed -i 's/firebase_crashlytics: ^2.8.4/firebase_crashlytics: ^3.3.7/' packages/monitoring/pubspec.yaml
	sed -i 's/firebase_dynamic_links: ^4.3.1/firebase_dynamic_links: ^5.3.7/' packages/monitoring/pubspec.yaml
	sed -i 's/firebase_analytics: ^9.1.12/firebase_analytics: ^10.5.1/' packages/monitoring/pubspec.yaml
	sed -i 's/firebase_remote_config: ^2.0.11/firebase_remote_config: ^4.2.7/' packages/monitoring/pubspec.yaml

However the modifications are not working for me. When trying to run the patched example 07 in Android Studio, I’m getting following build error:

Launching lib/main.dart on sdk gphone64 x86 64 in debug mode...
Upgrading build.gradle
Conflict detected between Android Studio Java version and Gradle version, upgrading Gradle version from 6.7 to 7.6.1.
Upgrading gradle-wrapper.properties
Running Gradle task 'assembleDebug'...
/home/wolkenschieber/.pub-cache/hosted/pub.dev/file-6.1.2/lib/src/interface/file.dart:15:16: Error: The method 'File.create' has fewer named arguments than those of overridden method 'File.create'.
  Future<File> create({bool recursive = false});
               ^
org-dartlang-sdk:///third_party/dart/sdk/lib/io/file.dart:232:16: Context: This is the overridden method ('create').
  Future<File> create({bool recursive = false, bool exclusive = false});
               ^
/home/wolkenschieber/.pub-cache/hosted/pub.dev/file-6.1.2/lib/src/interface/file.dart:15:16: Error: The method 'File.create' doesn't have the named parameter 'exclusive' of overridden method 'File.create'.
  Future<File> create({bool recursive = false});
               ^
org-dartlang-sdk:///third_party/dart/sdk/lib/io/file.dart:232:16: Context: This is the overridden method ('create').
  Future<File> create({bool recursive = false, bool exclusive = false});
               ^
/home/wolkenschieber/.pub-cache/hosted/pub.dev/file-6.1.2/lib/src/forwarding/forwarding_file.dart:22:8: Error: The method 'ForwardingFile.createSync' has fewer named arguments than those of overridden method 'File.createSync'.
  void createSync({bool recursive = false}) =>
       ^
org-dartlang-sdk:///third_party/dart/sdk/lib/io/file.dart:248:8: Context: This is the overridden method ('createSync').
  void createSync({bool recursive = false, bool exclusive = false});
       ^
/home/wolkenschieber/.pub-cache/hosted/pub.dev/file-6.1.2/lib/src/forwarding/forwarding_file.dart:22:8: Error: The method 'ForwardingFile.createSync' doesn't have the named parameter 'exclusive' of overridden method 'File.createSync'.
  void createSync({bool recursive = false}) =>
       ^
org-dartlang-sdk:///third_party/dart/sdk/lib/io/file.dart:248:8: Context: This is the overridden method ('createSync').
  void createSync({bool recursive = false, bool exclusive = false});
       ^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* Where:
Script '/mnt/Development/flutter/sdk/flutter/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy' line: 1297

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/mnt/Development/flutter/sdk/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 59s
Exception: Gradle task assembleDebug failed with exit code 1

When preparing the project through make clean patch-for-current-flutter get build-runner, the command fails with

Failed to build build_runner:build_runner:
/home/wolkenschieber/.pub-cache/hosted/pub.dev/watcher-1.0.2/lib/src/constructable_file_system_event.dart:7:57: Error: The class 'FileSystemEvent' can't be extended, implemented, or mixed in outside of its library because it's a sealed class.
abstract class _ConstructableFileSystemEvent implements FileSystemEvent {
                                                        ^
/home/wolkenschieber/.pub-cache/hosted/pub.dev/matcher-0.12.10/lib/src/error_matchers.dart:14:33: Error: 'CastError' isn't a type.
const isCastError = TypeMatcher<CastError>();
                                ^^^^^^^^^
/home/wolkenschieber/.pub-cache/hosted/pub.dev/matcher-0.12.10/lib/src/error_matchers.dart:21:49: Error: 'CyclicInitializationError' isn't a type.
const isCyclicInitializationError = TypeMatcher<CyclicInitializationError>();
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^
/home/wolkenschieber/.pub-cache/hosted/pub.dev/matcher-0.12.10/lib/src/error_matchers.dart:33:39: Error: 'NullThrownError' isn't a type.
const isNullThrownError = TypeMatcher<NullThrownError>();
                                      ^^^^^^^^^^^^^^^
/home/wolkenschieber/.pub-cache/hosted/pub.dev/build_runner-2.0.5/lib/src/build_script_generate/bootstrap.dart:76:40: Error: Method not found: 'NullThrownError'.
      final error = e[0] as Object? ?? NullThrownError();

Thank you very much. Your answer resolves the issue.