Material3やCasual Game Toolkitを試すにはFlutter3が必要なので、Flutter2からアップグレードしました。
対応前のFlutterバージョン
flutter 2.10.5
%flutter --version
Flutter 2.10.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 5464c5bac7 (2 months ago) • 2022-04-18 09:55:37 -0700
Engine • revision 57d3bac3dd
Tools • Dart 2.16.2 • DevTools 2.9.2
Flutterをアップグレード
3.0.3に上げてしばらくしたら3.0.4が出ていたので2回アップグレードしました。
特に問題なく完了。
flutter 2.10.5 → 3.0.3
% flutter upgrade --force
Upgrading Flutter to 3.0.3 from 2.10.5 in /Users/takeshitsuji/flutter...
Downloading Darwin arm64 Dart SDK from Flutter engine ffe7b86a1e5b5cb63c8385ae1adc759e372ee8f4...
〜
Flutter 3.0.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 676cefaaff (6 days ago) • 2022-06-22 11:34:49 -0700
Engine • revision ffe7b86a1e
Tools • Dart 2.17.5 • DevTools 2.12.2
Running flutter doctor...
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.3, on macOS 12.4 21F79 darwin-arm (Rosetta), locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.68.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
• No issues found!
flutter 3.0.3 → 3.0.4
% flutter upgrade --force
Upgrading Flutter to 3.0.4 from 3.0.3 in /Users/takeshitsuji/flutter...
Downloading Darwin arm64 Dart SDK from Flutter engine 6ba2af10bb05c88a2731482cedf2cfd11cf5af0b...
〜
Flutter 3.0.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 85684f9300 (31 hours ago) • 2022-06-30 13:22:47 -0700
Engine • revision 6ba2af10bb
Tools • Dart 2.17.5 • DevTools 2.12.2
Running flutter doctor...
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.4, on macOS 12.4 21F79 darwin-arm, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.68.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
• No issues found!
パッケージをアップグレード
アプリで使っているパッケージをアップグレードします。
アプリのプロジェクトディレクトリ直下※で行います。
※私の環境の場合、「raiki_anime」の部分です。
raiki_anime% flutter pub upgrade
Resolving dependencies...
app_review 2.1.1+1
app_tracking_transparency 2.0.2+4
〜
Changed 51 dependencies!
20 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.
Flutter3でアプリをビルド
次にアプリをビルドしてみます。
raiki_anime%flutter clean
raiki_anime%flutter run
Running "flutter pub get" in raiki_anime... 1,034ms
Launching lib/main.dart on iPhone 13 mini in debug mode...
Upgrading Info.plist
Running pod install... 1,439ms
Running Xcode build...
└─Compiling, linking and signing... 6.7s
Xcode build done. 30.0s
〜
flutter: [LifeCycle][HomePage] initState.
一応アプリは起動しましたが、実行時にいくつかのワーニングがでました。
../../../.pub-cache/hosted/pub.dartlang.org/scrollable_positioned_list-0.2.3/lib/src/scrollable_positioned_list.dart:439:24: Warning: Operand of null-aware operation
'!' has type 'SchedulerBinding' which excludes null.
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart' ('../../../flutter/packages/flutter/lib/src/scheduler/binding.dart').
SchedulerBinding.instance!.addPostFrameCallback((_) {
^
../../../.pub-cache/hosted/pub.dartlang.org/scrollable_positioned_list-0.2.3/lib/src/scrollable_positioned_list.dart:486:26: Warning: Operand of null-aware operation
'!' has type 'SchedulerBinding' which excludes null.
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart' ('../../../flutter/packages/flutter/lib/src/scheduler/binding.dart').
SchedulerBinding.instance!.addPostFrameCallback((_) {
^
../../../.pub-cache/hosted/pub.dartlang.org/scrollable_positioned_list-0.2.3/lib/src/positioned_list.dart:312:24: Warning: Operand of null-aware operation '!' has
type 'SchedulerBinding' which excludes null.
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart' ('../../../flutter/packages/flutter/lib/src/scheduler/binding.dart').
SchedulerBinding.instance!.addPostFrameCallback((_) {
^
scrollable_positioned_listパッケージで、Null Safetyについて言っているようです。
パッケージのバージョンを上げたらでなくなりました。
pubspec.yaml
scrollable_positioned_list: ^0.3.2
#scrollable_positioned_list: ^0.2.0-nullsafety.0
もう1個のワーニング。
lib/widgets/anime_list_item_widget.dart:57:20: Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../flutter/packages/flutter/lib/src/widgets/binding.dart').
WidgetsBinding.instance?.addPostFrameCallback((_) {
こちらもNull Safetyで、以下の修正で出なくなりました。
//WidgetsBinding.instance?.addPostFrameCallback((_) {
WidgetsBinding.instance.addPostFrameCallback((_) {
Flutterとパッケージのアップグレード、アプリのビルドまで特に大きな問題なく完了できました。
Material3やCasual Game Toolkitを試していこうと思います。
(おまけ)flutter lintのバージョンアップ
Flutter3でflutter createを使って生成されたアプリは、自動的にv2.0のlintsセットが有効にされるそうです。
既存のアプリ、パッケージ、プラグインは 以下を実行することで、v2.0に移行することができます。
自動修正コマンドも用意されていて親切ですが、全て自動とはいかない場合は手動で修正が必要とのことです。
%flutter pub upgrade --major-versions flutter_lints # flutter_lintsのバージョンアップ
%dart fix --apply # lint警告の自動修正
私はflutter_lintsではなくpedantic_monoを使っていたので、今回公式のflutter_lintsに移行しました。
特にlintのエラーは出ていないようなので、ワーニングをボチボチ消していこうと思います。
% git diff pubspec.yaml
diff --git a/pubspec.yaml b/pubspec.yaml
- pedantic_mono: any
+ flutter_lints: ^2.0.1
% git diff analysis_options.yaml
diff --git a/analysis_options.yaml b/analysis_options.yaml
index c6d040c..839cc64 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -1,2 +1,29 @@
-# https://pub.dev/packages/pedantic_mono
-include: package:pedantic_mono/analysis_options.yaml
\ No newline at end of file
+# This file configures the analyzer, which statically analyzes Dart code to
+# check for errors, warnings, and lints.
+#
+# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
+# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
+# invoked from the command line by running `flutter analyze`.
+
+# The following line activates a set of recommended lints for Flutter apps,
+# packages, and plugins designed to encourage good coding practices.
+include: package:flutter_lints/flutter.yaml
+
+linter:
+ # The lint rules applied to this project can be customized in the
+ # section below to disable rules from the `package:flutter_lints/flutter.yaml`
+ # included above or to enable additional rules. A list of all available lints
+ # and their documentation is published at
+ # https://dart-lang.github.io/linter/lints/index.html.
+ #
+ # Instead of disabling a lint rule for the entire project in the
+ # section below, it can also be suppressed for a single line of code
+ # or a specific dart file by using the `// ignore: name_of_lint` and
+ # `// ignore_for_file: name_of_lint` syntax on the line or in the file
+ # producing the lint.
+ rules:
+ # avoid_print: false # Uncomment to disable the `avoid_print` rule
+ # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
+
+# Additional information about this file can be found at
+# https://dart.dev/guides/language/analysis-options
参考記事

Flutter2からFlutter3に更新する

What’s new in Flutter 3
Deep dive into our latest release, including macOS and Linux stable, performance improvements, and more!
コメント