include_jar/lib/native_uuid_generator.dart

29 lines
886 B
Dart
Raw Normal View History

2025-08-05 00:24:57 +08:00
import 'package:flutter/services.dart';
class NativeUuidGenerator {
static const MethodChannel _channel =
MethodChannel('com.example/native_utils');
static Future<String> generateRandomUUID() async {
try {
return await _channel.invokeMethod('generateRandomUUID');
} on PlatformException catch (e) {
throw Exception("Failed to generate UUID: ${e.message}");
}
}
static Future<String> generateTimeBasedUUID() async {
try {
return await _channel.invokeMethod('generateTimeBasedUUID');
} on PlatformException catch (e) {
throw Exception("Failed to generate UUID: ${e.message}");
}
}
}
/**
* 1. https://mvnrepository.com/artifact/com.fasterxml.uuid/java-uuid-generator/4.0.1
* 2. add jars to app/libs, modify build.gradle.kts
* 3. modify app/src/main/kotlin/com/example/include_jar/MainActivity.kt
* 4. refer in flutter
*/