Describes the API System Channels for using platform-specific functions from Flutter.
First of all, basically I don't recommend using this API </ font>. This API is used a lot inside the Flutter Framework, but since it is an intermediate layer API as shown below, it is highly likely that it will change in future version upgrades.
If you look at the [Source Code] of SystemChannels (https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/services/system_channels.dart), the contents use MethodChannel, EventChannel, etc. You can see that. Please refer to here for Method Channel and Event Channel.
Several types are available for each application. The list is shown below.
type | function | Higher Flutter Service |
---|---|---|
lifecycle | life cycle | widget |
navigation | navigation | widget, system_chrome |
system | unknown….hereUsed in, but virtually nothing | widget |
accessibility | Accessibility(Text reading etc.) | PlatformViews, Semantics |
platform | System setting(Screen rotation,End etc.) | SemanticsService,RouteNotificationMessages etc. |
platform_views | Platform-specific view operations | AndroidView, UiKitView |
skia | Graphics | - |
keyEvent | Key input | RawKeyEvent |
textInput | Text input | TextInput, AndroidView, UiKitView |
lifecycle
Life cycle listener
SystemChannels.lifecycle.setMessageHandler((message){
print('<SystemChannels.lifecycle> $message');
/*
AppLifecycleState.paused
AppLifecycleState.inactive
AppLifecycleState.resumed
AppLifecycleState.suspending
AppLifecycleState.detached
*/
return Future<String>.value();
});
navigation
Navigation operation listener
SystemChannels.navigation.setMethodCallHandler((call) {
print('<SystemChannels.navigation> ${call.method} (${call.arguments})');
/*
popRoute
pushRoute
*/
return Future<dynamic>.value();
});
system It can't be used for anything, it's not used, and you can ignore it.
For the time being, set only the callback
SystemChannels.system.setMessageHandler((message) {
print('<SystemChannels.system> $message');
return Future<dynamic>.value();
});
accessibility
Text-to-speech sample
SemanticsService.announce('Hello world', TextDirection.ltr)
The Flutter Framework internal implementation of is below.
Dart
final AnnounceSemanticsEvent event = AnnounceSemanticsEvent('Hello world', TextDirection.ltr);
SystemChannels.accessibility.send(event.toMap());
platform
Exit the app
SystemNavigator.pop()
The Flutter Framework internal implementation of is below.
Exit the app
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
platform_views
It is used in flutter_web, so please refer to it.
Create a view like this
final Map<String, dynamic> args = <String, dynamic>{
'id': 1,
'viewType': 'Create WebView',
};
SystemChannels.platform_views.invokeMethod('create', args);
skia
Skia cache size setting. There is no other function, and now I can only do this ...
const maxBytes = 4 * 1024 * 1024;
SystemChannels.skia.invokeMethod('setResourceCacheMaxBytes', maxBytes);
keyEvent
Key input listener
SystemChannels.keyEvent.setMessageHandler((message) {
print('<SystemChannels.keyEvent> $message');
return Future<dynamic>.value();
});
textInput
Keyboard display ON/OFF
SystemChannels.textInput.invokeMethod('TextInput.show');
SystemChannels.textInput.invokeMethod('TextInput.hide');
Recommended Posts