Flutter: операнд операции с нулевым значением '!' имеет тип WidgetsBinding, который исключает нуль

Я запускаю свое приложение флаттера (Flutter 3.0 и dart sdk 2.17.0.

Но теперь я нашел здесь предупреждение, как это -

      /usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_navigation/src/router_report.dart:53:22: Warning: Operand of null-aware
operation '!' has type 'WidgetsBinding' which excludes null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart'
 ('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/widgets/bindi
 ng.dart').
      WidgetsBinding.instance!.addPostFrameCallback((_) {
                     ^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_navigation/src/snackbar/snackbar.dart:452:22: Warning: Operand of
null-aware operation '!' has type 'SchedulerBinding' which excludes null.
 - 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
 ('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
 ding.dart').
    SchedulerBinding.instance!.addPostFrameCallback(
                     ^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_navigation/src/extension_navigation.dart:357:24: Warning: Operand of
null-aware operation '!' has type 'SchedulerBinding' which excludes null.
 - 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
 ('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
 ding.dart').
      SchedulerBinding.instance!.addPostFrameCallback((_) {
                       ^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_navigation/src/extension_navigation.dart:468:24: Warning: Operand of
null-aware operation '!' has type 'SchedulerBinding' which excludes null.
 - 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
 ('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
 ding.dart').
      SchedulerBinding.instance!.addPostFrameCallback((_) {
                       ^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_state_manager/src/simple/get_controllers.dart:90:20: Warning: Operand
of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart'
 ('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/widgets/bindi
 ng.dart').
    WidgetsBinding.instance!.addObserver(this);
                   ^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_state_manager/src/simple/get_controllers.dart:96:20: Warning: Operand
of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart'
 ('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/widgets/bindi
 ng.dart').
    WidgetsBinding.instance!.removeObserver(this);
                   ^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_state_manager/src/rx_flutter/rx_notifier.dart:130:22: Warning: Operand
of null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
 - 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
 ('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
 ding.dart').
    SchedulerBinding.instance?.addPostFrameCallback((_) => onReady());
                     ^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_state_manager/src/rx_flutter/rx_disposable.dart:20:22: Warning: Operand
of null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
 - 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
 ('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
 ding.dart').
    SchedulerBinding.instance?.addPostFrameCallback((_) => onReady());
                     ^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/flutte
r_easyloading-3.0.3/lib/src/widgets/overlay_entry.dart:35:26: Warning: Operand of
null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
 - 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
 ('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
 ding.dart').
    if (SchedulerBinding.instance?.schedulerPhase ==
                         ^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/flutte
r_easyloading-3.0.3/lib/src/widgets/overlay_entry.dart:37:24: Warning: Operand of
null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
 - 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
 ('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
 ding.dart').
      SchedulerBinding.instance?.addPostFrameCallback((_) {
                       ^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/flutte
r_easyloading-3.0.3/lib/src/widgets/container.dart:64:24: Warning: Operand of
null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
 - 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
 ('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
 ding.dart').
      SchedulerBinding.instance?.schedulerPhase ==
                       ^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/flutte
r_easyloading-3.0.3/lib/src/widgets/container.dart:101:24: Warning: Operand of
null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
 - 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
 ('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
 ding.dart').
      SchedulerBinding.instance?.addPostFrameCallback((_) => completer
                       ^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/flutte
r_easyloading-3.0.3/lib/src/widgets/container.dart:112:24: Warning: Operand of
null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
 - 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
 ('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
 ding.dart').
      SchedulerBinding.instance?.addPostFrameCallback((_) => completer
                       ^
Syncing files to device iPhone SE (3rd generation)...              805ms

В чем проблема. Это не отображается в предыдущей версии флаттера.

1 ответ

Во флаттере 3.0

      SchedulerBinding.instance!.addPostFrameCallback(...);

стал

      SchedulerBinding.instance.addPostFrameCallback(...);

похоже, что в пакете привязок закодированы некоторые Schedulerbindings, и их необходимо обновить.

Вы можете скопировать пакет локально и изменить код внутри этого пакета.

Или измените зависимости... или дождитесь обновления этого пакета и вернитесь к Flutter 2.10.5.

Вы можете прочитать об изменениях во Flutter 3.0 здесь

Я использую инструмент для изменения версий Flutter Sidekick , вы можете выбрать разные версии Flutter для разных проектов.

Другие вопросы по тегам