Closed adilmhd4539 closed 1 year ago
Unique device identifiers (like serial number) is something that both Google and Apple don't allow developers to get in recent versions of their OSes.
For example, here is Google's guide on this topic: https://developer.android.com/training/articles/user-data-ids
Thus, Plus plugins have no way to get such identifiers.
What is your question?
import 'dart:developer'; import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart';
void main() { runApp(const MyApp()); }
class MyApp extends StatelessWidget { const MyApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(), ); } }
final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
class MyHomePage extends StatelessWidget { const MyHomePage({super.key});
@override Widget build(BuildContext context) { return Scaffold( body: Center( child: ElevatedButton( onPressed: () async { if (Platform.isAndroid) { AndroidDeviceInfo androidDeviceInfo = await deviceInfoPlugin.androidInfo; print(androidDeviceInfo.serialNumber); } else { IosDeviceInfo iosDeviceInfo = await deviceInfoPlugin.iosInfo; String? deviceId = iosDeviceInfo.identifierForVendor; //log(iosDeviceInfo.data.toString()); // print(iosDeviceInfo.identifierForVendor); } }, child: const Text('Authticate')), ), ); } }
class UniqueIdentifier { /// Define a Method channel with 'unique_identifier' name static const MethodChannel _channel = MethodChannel('flutter/platform');
// Static function for getting the identifier // Returns Future<String?> static Future<String?> get serial async { final String? identifier = await _channel.invokeMethod('getSerialNumber'); return identifier; } }
here my code What is the unique key that you provides in android to understand each device , Also serial number always shows unknown
Checklist before submitting a question
flutter pub upgrade
flutter clean