适用于安卓和 IOS 的 Flutter 插件,可处理常见的本机任务
sabian_native_common
Common native functions for flutter
Handles common native tasks for Android and IOS.
All permissions related tasks like camera,notifications are handled for you so you only need to focus on the tasks at hand
Usage example:
final _platform = SabianNativeCommon();
void _takePicture(BuildContext context) {
_platform.media.takePicture().then((payload) {
_setCurrentImage(payload.images!.first);
print("Success");
}).onError((error, stackTrace) {
print("Error $error");
});
}
void _choosePicture(BuildContext context) {
final config = PhotoData()
..galleryAlbumName = "Flutter Album"
..galleryToolBarTitle = "Choose Photo"
..galleryAlbumsTitle = "All Flutter Albums"
..cameraTitle = "Take Picture"
..allowEditing = true
..galleryMaximumPhotos = 3;
_platform.media.choosePicture(config).then((payload) {
_setCurrentImage(payload.images!.first);
print("Success");
}).onError((error, stackTrace) {
print("Error $error");
});
}
void _notify(BuildContext context) {
final config = NotificationData()
..title = "Flutter Notification"
..message = "This is a message from the flutter desk. Watch yourself"
..canVibrate = true
..hasSound = true;
_platform.notification.notify(config).then((payload) {
print("Success");
}).onError((error, stackTrace) {
print("Error $error");
});
}
void _getPlatform() {
_platform.device.getPlatformVersion().then((value) {
setState(() {
_platformName = "Platform : ${value ?? "Unknown"}";
});
}).onError((error, stackTrace) {
setState(() {
_platformName = "Unknown";
});
});
}
void _setCurrentImage(Uint8List bytes) {
setState(() {
memoryImage = MemoryImage(bytes);
});
}