flutter 3.0升级项目后出现如下错误。
Syncing files to device iPhone 13 Pro Max...
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/another_transformer_page_view-1.1.0/lib/src/another_transformer_page_view.dart:519:22: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
WidgetsBinding.instance!.addPostFrameCallback(_onGetSize);
^
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/another_transformer_page_view-1.1.0/lib/src/another_transformer_page_view.dart:537:22: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
WidgetsBinding.instance!.addPostFrameCallback(_onGetSize);
^
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_login-3.2.0/lib/src/widgets/animated_text.dart:57:20: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
WidgetsBinding.instance!.addPostFrameCallback((_) {
^
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/awesome_select-5.2.0/lib/src/widget.dart:1547:58: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
MediaQueryData.fromWindow(WidgetsBinding.instance!.window);
^
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/awesome_select-5.2.0/lib/src/text_error.dart:99:20: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
WidgetsBinding.instance!.addPostFrameCallback((_) {
这是 flutter 的错误吗?任何人都可以向 flutter 报告此情况吗?我不知道要向 flutter 团队报告这个问题。
This Warning bug is resolved. see my comment in correct answer I have written ( if you are a mac user goto finder -> press goto button by swift+cmd+G -> past all 6 files I have mentioned or you find an error and replace [root-name] with your root directory name.
最佳答案
'WidgetsBinding.instance' getter 曾经是可为 null 的类型。在新的更新中,它更改为不可为空。因此,现在旧软件包在更新后会显示这一点,因为它们在那里使用了 null 感知运算符。它将在新版本中修复。现在,您可以从日志中显示的行中删除空感知运算符,重建后将不再有警告。
关于Flutter 3.0 显示错误 : WidgetsBinding. instance!.addPostFrameCallback((_) => widget.onReady.call());,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72298737/