Material3やCasual Game Toolkitを試すにはFlutter3が必要なので、Flutter2からアップグレードしました。
対応前のFlutterバージョン
Flutterをアップグレード
3.0.3に上げてしばらくしたら3.0.4が出ていたので2回アップグレードしました。
特に問題なく完了。
パッケージをアップグレード
アプリで使っているパッケージをアップグレードします。
アプリのプロジェクトディレクトリ直下※で行います。
※私の環境の場合、「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について言っているようです。
パッケージのバージョンを上げたらでなくなりました。
もう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!
コメント