This document describes the public APIs, widgets, and the platform channel used by this Flutter application.
Entry point that bootstraps the Flutter application.
Example:
void main() {
runApp(const MyApp());
}Root widget that configures application-wide MaterialApp settings.
- title:
'Android GUID' - theme: Seeded
ColorSchemewith Material 3 - home:
MyHomePage
Usage:
const app = MyApp();
runApp(app);Top-level screen that displays the device GUID fetched via a platform channel.
Constructor:
MyHomePage({ Key? key, required String title })
Public members:
final String title— AppBar title.
Usage:
MaterialApp(
home: const MyHomePage(title: 'Get Android GUID'),
);Asynchronously invokes the platform channel method getDeviceGUID and updates the view state with the returned Android ID. Returns the GUID string or null on failure.
Notes:
- The method catches
PlatformExceptionand returnsnull. - On success, it updates the
_deviceGUIDstate.
Example (call from UI):
ElevatedButton(
onPressed: _getDeviceGUID,
child: const Text('Get Device GUID'),
);The page shows:
- Current GUID text bound to
_deviceGUID - A button to trigger
_getDeviceGUID()
Channel name:
com.example.get_android_guid/guid
Method(s):
getDeviceGUID→String(Android ID)
Android implementation: android/app/src/main/kotlin/com/example/get_android_guid/MainActivity.kt
private val CHANNEL = "com.example.get_android_guid/guid"
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
if (call.method == "getDeviceGUID") {
val guid = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
result.success(guid)
} else {
result.notImplemented()
}
}
}Dart client usage:
static const platform = MethodChannel('com.example.get_android_guid/guid');
final String? androidId = await platform.invokeMethod<String>('getDeviceGUID');- On Android: Returns the device-specific
Settings.Secure.ANDROID_IDas aString. - On other platforms: The method is not implemented natively; the Dart side will throw
MissingPluginExceptionif invoked. The current code only calls it on button press and catchesPlatformException.
PlatformExceptionon Dart side is caught and results in anullreturn.notImplementedis returned from Android when an unknown method is called on the channel.
To add more methods, use the same channel and switch on call.method in Android (and analogous on iOS if implemented), then expose typed wrappers in Dart.