map_launcher
Map Launcher 是一个Flutter插件,用于查找安装在设备上的可用地图并使用标记启动它们。
安装
flutter pub add map_launcher
导包
import 'package:map_launcher/map_launcher.dart';
封装
class MapsSheet {
static show({
BuildContext context,
Function(AvailableMap map) onMapTap,
}) async {
final availableMaps = await MapLauncher.installedMaps;
for (var map in availableMaps) {
map.mapName = getLocalName(amap: map);
}
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (BuildContext context) {
return SafeArea(
child: Container(
margin: EdgeInsets.only(top: 20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(20)),
),
child: Column(
children: <Widget>[
Expanded(
child: SingleChildScrollView(
child: Container(
margin: EdgeInsets.only(top: 20, bottom: 20),
child: Wrap(
children: <Widget>[
for (var map in availableMaps)
ListTile(
onTap: () => onMapTap(map),
title: Text(map.mapName),
leading: SvgPicture.asset(
map.icon,
height: 50.0,
width: 50.0,
),
),
],
),
),
),
),
],
),
),
);
},
);
}
}
String getLocalName({AvailableMap amap}) {
switch (amap.mapType) {
case MapType.amap:
return '高德地图';
case MapType.baidu:
return '百度地图';
case MapType.tencent:
return '腾讯地图';
case MapType.google:
return '谷歌地图';
case MapType.apple:
return '苹果地图';
default:
return amap.mapName;
}
}
使用
MapsSheet.show(
context: context,
onMapTap: (map) {
map.showMarker(
coords: Coords(lat, lng),
title: info.location,
);
},
);