native_kit_platform_interface 0.1.1
native_kit_platform_interface: ^0.1.1 copied to clipboard
Platform interface and Pigeon contract for native_kit, the federated plugin that invokes true OS-native UI, pickers, scanners and system sheets.
native_kit_platform_interface example #
Apps should depend on native_kit.
This package is useful when you implement a new platform or want to fake the
native layer in tests.
Faking native UI in tests #
Every Pigeon host API is a plain class, so tests can extend it and inject the
fake through PigeonNativeKitPlatform:
import 'package:flutter_test/flutter_test.dart';
import 'package:native_kit/native_kit.dart';
import 'package:native_kit_platform_interface/native_kit_platform_interface.dart';
class FakeOverlays extends OverlaysHostApi {
@override
Future<AlertResultDto?> showAlert(AlertRequestDto request) async =>
AlertResultDto(actionId: 'delete', textValues: <String>[]);
}
void main() {
test('confirms deletion', () async {
NativeKitPlatform.instance = PigeonNativeKitPlatform(overlays: FakeOverlays());
final NativeAlertResult? result = await NativeKit.showAlert(title: 'Delete?');
expect(result?.actionId, 'delete');
});
}
Implementing a platform #
Extend PigeonNativeKitPlatform (or NativeKitPlatform) and register it:
class NativeKitMyPlatform extends PigeonNativeKitPlatform {
static void registerWith() {
NativeKitPlatform.instance = NativeKitMyPlatform();
}
}
The native side implements the six host APIs generated from
pigeons/native_kit_api.dart (OverlaysHostApi, ValuePickersHostApi,
ZeroPermPickersHostApi, VisionMediaHostApi, SystemUtilitiesHostApi,
SecurityHardwareHostApi).