init method

Future<bool> init()

初始化:按当前平台(Android / iOS / Windows / macOS)读取并缓存设备信息。 任何平台异常都吞掉并返回 false,便于调用方在无插件环境降级。

Implementation

Future<bool> init() async {
  try {
    final plugin = DeviceInfoPlugin();
    if (Platform.isAndroid) {
      await _getAndroidInfo(plugin);
    } else if (Platform.isIOS) {
      await _getIosInfo(plugin);
    } else if (Platform.isWindows) {
      await _getWindowsInfo(plugin);
    } else if (Platform.isMacOS) {
      await _getMacOsInfo(plugin);
    }
  } catch (e) {
    return false;
  }
  return true;
}