在 flutter 中使用 notifier 1.0.2 插件后的错误信息

error message after using notifier 1.0.2 plugin in flutter

我在 flutter 中寻找 Broadcast receiver 的替代品,然后我得到了一个插件 notifier 1.0.2 添加到我的 pubspec.yaml 后收到一条错误消息,如

Because every version of notifier depends on synchronized ^1.5.3+2 and sqflite 1.2.0 depends on synchronized >=2.0.2 <4.0.0, notifier is incompatible with sqflite 1.2.0.

So, because Bluis depends on both sqflite 1.2.0 and notifier 1.0.2, version solving failed.
pub get failed (1; So, because Bluis depends on both sqflite 1.2.0 and notifier 1.0.2, version solving failed.)
Process finished with exit code 1

这是我的 pubspec.yaml

name: Bluis
description: A new Flutter project.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.2.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  rxdart: ^0.22.3
  http: ^0.12.0+1
  toast: ^0.1.5
  sqflite: 1.2.0
  intl: ^0.16.0
  geolocator: ^5.1.4+2
  flutter_compass: ^0.3.4
  url_launcher: ^5.2.5
  permission_handler: ^4.0.0
  camera: ^0.5.2+1
  video_player: ^0.10.0
  path_provider: ^1.1.0
  path: ^1.6.2
  e2e: ^0.2.0
  esys_flutter_share: ^1.0.2
  shared_preferences: ^0.5.4+5
  connectivity: ^0.4.5+3
  uuid: ^2.0.4
  logger: ^0.6.0
  event_bus: ^1.1.0
  location: ^2.3.4
  dio: ^3.0.8
  recase: ^3.0.0
  flutter_map:
    git:
      url: git://github.com/okaxaki/flutter_map.git
      ref: fix/support-flutter-1.10



dev_dependencies:
  flutter_test:
    sdk: flutter
  notifier: 1.0.2

# 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

  # To add assets to your application, add an assets section, like this:
  assets:
    - assets/images/
    - assets/locale/localization_en.json
    - assets/locale/localization_hi.json
    - assets/locale/localization_or.json

我使用 event bus

解决了我的目的
  1. 创建事件总线
    EventBus eventBus = EventBus();

  2. 定义事件(用构造函数创建一个 class 事件名称)
    class UserLoggedInEvent { User user; UserLoggedInEvent(this.user); }

  3. 注册监听器(监听你的事件)
    eventBus.on<UserLoggedInEvent>().listen((event) { // All events are of type UserLoggedInEvent (or subtypes of it). print(event.user); });

  4. 启动您的活动
    User myUser = User('Mickey'); eventBus.fire(UserLoggedInEvent(myUser));

  5. 取消所有活动
    eventBus.cancel();