命名 Flutter 插件 EventChannel

Ted*_*nry 3 flutter flutter-plugin flutter-platform-channel

我创建了一个新插件

flutter create --template plugin alfalfa
Run Code Online (Sandbox Code Playgroud)

其生成lib/alfalfa.dart包含

import 'dart:async';

import 'package:flutter/services.dart';

class Alfalfa {
  static const MethodChannel _channel =
      const MethodChannel('alfalfa');

  //...
}
Run Code Online (Sandbox Code Playgroud)

我想添加一个EventChannel这样Java和Objective-C代码可以回调到Dart代码。我不知道该叫什么名字EventChannel

final EventChannel _eventChannel =
    const EventChannel("com.rollingfields.alfalfa/events");
Run Code Online (Sandbox Code Playgroud)

或者

final EventChannel _eventChannel =
    const EventChannel("alfalfa/events");
Run Code Online (Sandbox Code Playgroud)

或者是其他东西?有约定吗?

如果更好的选择EventChannel是包含反向域的名称,我应该将生成的名称重命名MethodChannel为吗com.rollingfields.alfalfa

Ric*_*eap 6

如有疑问,请检查 flutter 插件存储库。连接插件使用:

  @visibleForTesting
  static const MethodChannel methodChannel = MethodChannel(
    'plugins.flutter.io/connectivity',
  );

  @visibleForTesting
  static const EventChannel eventChannel = EventChannel(
    'plugins.flutter.io/connectivity_status',
  );
Run Code Online (Sandbox Code Playgroud)

因此,这无疑是良好实践的一个例子。所以,也许com.rollingfields/alfalfacom.rollingfields/alfalfa_events