3

I created a new plugin with

flutter create --template plugin alfalfa

which generates lib/alfalfa.dart containing

import 'dart:async';

import 'package:flutter/services.dart';

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

  //...
}

I want to add an EventChannel so Java and Objective-C code can call back to the Dart code. I don't know what the name of the EventChannel should be.

final EventChannel _eventChannel =
    const EventChannel("com.rollingfields.alfalfa/events");

or

final EventChannel _eventChannel =
    const EventChannel("alfalfa/events");

or something else? Is there a convention?

If the better option for the EventChannel is the name including the reverse domain, should I rename the generated MethodChannel to be com.rollingfields.alfalfa?

Ted Henry
  • 1,442
  • 1
  • 14
  • 34

1 Answers1

6

When in doubt, check the flutter plugins repo. The connectivity plugin uses:

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

  @visibleForTesting
  static const EventChannel eventChannel = EventChannel(
    'plugins.flutter.io/connectivity_status',
  );

so, certainly one example of good practice. So, perhaps com.rollingfields/alfalfa and com.rollingfields/alfalfa_events

Richard Heap
  • 48,344
  • 9
  • 130
  • 112
  • Thank you, Richard! (How strange they didn't use the standard reverse domain name convention for namespacing.) – Ted Henry May 07 '19 at 01:21