По какой-то причине не могу использовать flutter_bloc

Итак, я использую Android Studio 4.2.1.

Я могу создать новый проект Flutter и запустить его.

Кстати, по ходу дела я создал несколько обучающих приложений.

Но по какой-то причине, если я импортирую 'package: flutter_bloc / flutter_bloc.dart';, он задыхается.

Вот вывод консоли:

Запуск lib / main.dart на I3312 в режиме отладки ... Запуск задачи Gradle 'assemblyDebug' ... ../../development/flutter/.pub-cache/hosted/pub.dartlang.org/bloc-7.0. 0 / lib / src / bloc.dart: 96: 28: Ошибка: тип аргумента «Событие» не может быть назначен типу параметра «Объект», поскольку «Событие» допускает значение NULL, а «Объект» - нет.

  • «Объект» происходит от «dart: core». наблюдатель.onEvent (это, событие); ^

ОШИБКА: сбой при сборке за исключением.

Вот оскорбительный код от bloc.dart:

  /// A great spot to add logging/analytics at the individual [Bloc] level.
  ///
  /// **Note: `super.onEvent` should always be called first.**
  /// ```dart
  /// @override
  /// void onEvent(Event event) {
  ///   // Always call super.onEvent with the current event
  ///   super.onEvent(event);
  ///
  ///   // Custom onEvent logic goes here
  /// }
  /// ```
  ///
  /// See also:
  ///
  /// * [BlocObserver.onEvent] for observing events globally.
  ///
  @protected
  @mustCallSuper
  void onEvent(Event event) {
    // ignore: invalid_use_of_protected_member
    observer.onEvent(this, event);
  }

Любой загружаемый мной проект, в котором используется flutter_bloc, имеет ту или иную ошибку.

У меня есть ощущение, что это связано с нулевой безопасностью, но я не знаю.

ваше здоровье

редактировать; добавлен pubspec.yaml

name: simple_bloc
description: A new Flutter project.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev


version: 1.0.0+1

environment:
#  sdk:  ">=2.7.0 <=2.10.0"
  sdk: ">=2.7.0 <=3.0.0"

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  flutter_bloc: ^7.0.0


dev_dependencies:
  flutter_test:
    sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

person SpeedyVV    schedule 14.05.2021    source источник
comment
мне кажется, что вы используете старую версию flutter_bloc с dart 2.12 (она же нулевая безопасность). Не могли бы вы опубликовать свой pubspec.yaml   -  person croxx5f    schedule 15.05.2021
comment
Добавил в исходный пост. - Благодарность   -  person SpeedyVV    schedule 15.05.2021
comment
Кстати ... Я только что установил Android Studio на свой ПК с Windows, и он там работает. Итак, очевидно, что я сделал что-то с окружающей средой на своем Mac.   -  person SpeedyVV    schedule 15.05.2021


Ответы (1)


Пытался переустановить Android Studio, но ничего не вышло.

Наконец попробовал ПОЛНОСТЬЮ удалить AndroidStudio и любую другую папку Android, com.google на моем Mac ...

Переустановил Android Studio, Flutter SDK и Android SDK.

Это сработало, но это была PITA!

person SpeedyVV    schedule 15.05.2021