效果图:
引入第三方库:device_info
Device.dart
import 'package:flutter/material.dart';import 'package:device_info/device_info.dart';class DevicePage extends StatefulWidget {DevicePage({Key key}) : super(key: key);_DevicePageState createState() => _DevicePageState();}class _DevicePageState extends State<DevicePage> {@overridevoid initState() {// TODO: implement initStatesuper.initState();this._getDevice();}_getDevice() async{DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;print('设备号 ${androidInfo.androidId}'); // e.g. "Moto G (4)"}@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: Text("Flutter Native Device演示"),),body: Text("看控制台 信息已经打印到控制台了"),);}}
第一步:使用高德定位准备工作获取 key
1、申请成为开发者
2、创建应用配置获取Key
点击查看教程
第二步:引入第三方库
amap_location
第三步:修改 你的项目目录e /app/build.gradle 在 在 g android/defaultConfig 节点修 改 改 manifestPlaceholders, 新增高德地图 y key 配置
android {.... 你的代码defaultConfig {.....manifestPlaceholders = [AMAP_KEY : "aa9f0cf8574400f2af0078392c556e25", // 高德地图 key]}...你的代码dependencies {/// 注意这里需要在主项目增加一条依赖,否则可能发生编译不通过的情况implementation 'com.amap.api:location:latest.integration'...你的代码}