一、Flutter 中獲取設備信息
https://pub.dev/packages/device_info
設備信息代碼
import 'package:flutter/material.dart';
import 'package:device_info/device_info.dart';
class DevicPage extends StatefulWidget{
DevicPage({Key key});
_DevicPage createState() => _DevicPage();
}
class _DevicPage extends State {
var _text;
@override
initState() {
super.initState();
_getDevice();
}
_getDevice() async{
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
print('設備信息 ${androidInfo}');
_text = androidInfo;
}
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(title: Text('device'),),
body: ListView(
children: <Widget>[
Text('${_text.version}'),
Text('${_text.board}'),
Text('${_text.bootloader}'),
Text('${_text.brand}'),
Text('${_text.device}'),
Text('${_text.display}'),
Text('${_text.fingerprint}'),
Text('${_text.hardware}'),
Text('${_text.host}'),
Text('${_text.id}'),
Text('${_text.manufacturer}'),
Text('${_text.model}'),
Text('${_text.product}'),
Text('${_text.tags}'),
Text('${_text.type}'),
Text('${_text.isPhysicalDevice}'),
Text('${_text.androidId}'),
],
)
);
}
}
二、Flutter 中獲取設備信息
https://pub.dev/packages/device_info
三、Flutter 中使用高德定位准備工作獲取 key
1、申請成為開發者
2、創建應用配置獲取 Key (參考教程演示)
https://lbs.amap.com/api/android-sdk/guide/create-project/get-key
四、Flutter 實現用高德定位
https://pub.dev/packages/amap_location
注意點
manifestPlaceholders = [AMAP_KEY : "ad2d13e8fab8a607b4707a598e32fc70"] // 自己的高德key
注意 添加 dependencies 到 andriod 里面 和 manifestPlaceholders = [AMAP_KEY : "ad2d13e8fab8a607b4707a598e32fc70"] 配置同級,不是外層的 dependencies
dependencies {
/// 注意這里需要在主項目增加一條依賴,否則可能發生編譯不通過的情況
implementation 'com.amap.api:location:latest.integration'
}
定位案例代碼
import 'package:flutter/material.dart';
import 'package:amap_location/amap_location.dart';
class GpsPage extends StatefulWidget{
GpsPage({Key key});
_GpsPage createState() => _GpsPage();
}
class _GpsPage extends State {
var gps;
@override
initState() {
super.initState();
_getGps();
}
_getGps() async{
var reult = await AMapLocationClient.startup(new AMapLocationOption( desiredAccuracy:CLLocationAccuracy.kCLLocationAccuracyHundredMeters ));
var res = await AMapLocationClient.getLocation(true);
// print(res.accuracy);
setState(() {
gps = res;
});
}
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(title: Text('device'),),
body: ListView(
children: <Widget>[
Text('${gps.longitude}'),
Text('${gps.latitude}'),
Text('${gps.accuracy}'),
],
)
);
}
}