MethodChannelFlutterMultiDisplay class

An implementation of FlutterMultiDisplayPlatform that uses method channels.

This class provides the Android implementation of the flutter_multi_display plugin using Flutter's method channel mechanism for communication between Dart and native Kotlin/Java code.

Method Channel Communication

This implementation communicates with the native Android plugin via the flutter_multi_display/shared_state method channel. It sends method calls to native code and receives responses asynchronously.

Supported Methods

The following methods are invoked on the native side:

  • getPlatformVersion: Gets the Android version
  • updateState: Updates shared state
  • getState: Retrieves state for a type
  • getAllState: Retrieves all states
  • clearState: Clears state for a type
  • setupMultiDisplay: Initializes multi-display

Testing

The methodChannel field is exposed with @visibleForTesting to allow unit tests to mock the method channel behavior.

Example test:

test('getPlatformVersion returns correct value', () async {
  const channel = MethodChannel('flutter_multi_display/shared_state');
  TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
      .setMockMethodCallHandler(channel, (call) async {
    if (call.method == 'getPlatformVersion') {
      return 'Android 11';
    }
    return null;
  });

  final platform = MethodChannelFlutterMultiDisplay();
  expect(await platform.getPlatformVersion(), 'Android 11');
});
Inheritance

Properties

hashCode int
The hash code for this object.
no setterinherited
methodChannel MethodChannel
The method channel used to interact with the native platform.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clearState(String type) Future<void>
Clears the shared state for a specific type.
override
getAllState() Future<Map<String, dynamic>>
Retrieves all shared states across all types.
override
getPlatformVersion() Future<String?>
Gets the platform version from the native Android platform.
override
getState(String type) Future<Map<String, dynamic>?>
Retrieves the shared state for a specific type.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setupMultiDisplay(List<String> entrypoints, {bool portBased = false}) Future<void>
Initializes the multi-display functionality with the specified configuration.
override
toString() String
A string representation of this object.
inherited
updateState(String type, Map<String, dynamic>? state) Future<void>
Updates the shared state for a specific type.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited