颤振:如何在可滚动地图下添加Listview
我有个问题。我想在我创建的地图下创建一个列表。地图正在运行,但是如果我想在地图下放置一个列表,我会得到一些失败的结果。这是一个OpenStreetMap而不是谷歌地图,因为我的项目需要它。我只需要建议我如何把一个'名单'或一个图标下的地图文本颤振:如何在可滚动地图下添加Listview,list,flutter,openstreetmap,List,Flutter,Openstreetmap,我有个问题。我想在我创建的地图下创建一个列表。地图正在运行,但是如果我想在地图下放置一个列表,我会得到一些失败的结果。这是一个OpenStreetMap而不是谷歌地图,因为我的项目需要它。我只需要建议我如何把一个'名单'或一个图标下的地图文本 import 'package:flutter/material.dart'; import 'package:geolocation/geolocation.dart'; import 'package:flutter_map/flutter_map.d
import 'package:flutter/material.dart';
import 'package:geolocation/geolocation.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
/*create Controller for map
*MapController provides map properties and allows map movement
*/
MapController controller = new MapController();
//ask for permission to use the device's gps
getPermission() async {
final GeolocationResult result =
await Geolocation.requestLocationPermission(
permission: const LocationPermission(
//permission settings for android and ios
android: LocationPermissionAndroid.fine,
ios: LocationPermissionIOS.always));
return result;
}
/*if permission is granted, request current location (high accuracy)
*return coordinates of current location (Position)
*/
getLocation() {
return getPermission().then((result) async {
if (result.isSuccessful) {
final coords =
await Geolocation.currentLocation(accuracy: LocationAccuracy.best);
return coords;
}
});
}
//view map, move to current lat/long and zoom
buildMap() {
getLocation().then((response) {
response.listen((value) {
if (value.isSuccessful) {
controller.move(
new LatLng(value.location.latitude, value.location.longitude),
17.0);
}
});
});
}
//Application view
@override
Widget build(BuildContext context) {
return new Scaffold(
drawer: Drawer(
child:Container(
color: Color.fromRGBO(0, 111, 118, 0.9),
child: ListView(
// Important: Remove any padding from the ListView.
children: <Widget>[
Text('Menü',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white, fontSize: 25),),
ListTile(
title: Text('LogIn', style: TextStyle(color: Colors.white, fontSize: 20.0),),
leading: Icon(Icons.arrow_forward, color: Colors.white,),
onTap: () {
// Update the state of the app.
// ...
},
),
ListTile(
title: Text('Ort hinzufügen', style: TextStyle(color: Colors.white, fontSize: 20.0),),
leading: Icon(Icons.arrow_forward, color: Colors.white,),
onTap: () {
// Update the state of the app.
// ...
},
),
ListTile(
title: Text('Hilfe', style: TextStyle(color: Colors.white, fontSize: 20.0),),
leading: Icon(Icons.arrow_forward, color: Colors.white,),
onTap: () {
// Update the state of the app.
// ...
},
),
ListTile(
title: Text('Einstellungen', style: TextStyle(color: Colors.white, fontSize: 20.0),),
leading: Icon(Icons.arrow_forward, color: Colors.white,),
onTap: () {
// Update the state of the app.
// ...
},
),
],
),
),
),
appBar: new AppBar(
title: new Text('GeoGuide'),
backgroundColor: Color.fromRGBO(0, 111, 118, 0.8),
),
//create new FlutterMap
body: new Container(
width: 420,
height: 300,
child: new FlutterMap(
mapController: controller,
//center: current location
options: new MapOptions(center: buildMap(), minZoom: 15.0),
layers: [
//implement osm-template
new TileLayerOptions(
urlTemplate:
"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
subdomains: ['a', 'b', 'c']),
]),
),
);
}
}
导入“包装:颤振/材料.省道”;
导入“package:geolocation/geolocation.dart”;
导入“包:颤振图/颤振图.dart”;
导入“包:latlong/latlong.dart”;
void main()=>runApp(新的MyApp());
类MyApp扩展了无状态小部件{
//此小部件是应用程序的根。
@凌驾
小部件构建(构建上下文){
返回新材料PP(
主页:新建MyHomePage(),
);
}
}
类MyHomePage扩展StatefulWidget{
@凌驾
_MyHomePageState createState()=>new_MyHomePageState();
}
类_MyHomePageState扩展状态{
/*为地图创建控制器
*MapController提供地图属性并允许地图移动
*/
MapController=新的MapController();
//请求许可使用设备的gps
getPermission()异步{
最终地理定位结果=
等待Geolocation.requestLocationPermission(
权限:const LocationPermission(
//android和ios的权限设置
android:LocationPermissionAndroid.fine,
ios:LocationPermissionIOS.always);
返回结果;
}
/*如果授予权限,请请求当前位置(高精度)
*返回当前位置(位置)的坐标
*/
getLocation(){
返回getPermission()。然后((结果)异步{
如果(结果:isSuccessful){
最终坐标=
等待地理定位。当前定位(精度:定位精度。最佳);
返回坐标;
}
});
}
//查看地图,移动到当前横向/纵向并缩放
buildMap(){
getLocation()。然后((响应){
response.listen((值){
如果(值isSuccessful){
控制器,移动(
新LatLng(值.位置.纬度,值.位置.经度),
17.0);
}
});
});
}
//应用程序视图
@凌驾
小部件构建(构建上下文){
归还新脚手架(
抽屉(
子:容器(
颜色:color.fromRGBO(0,111118,0.9),
子:ListView(
//重要提示:从ListView中删除任何填充。
儿童:[
文本('menu',
textAlign:textAlign.center,
样式:TextStyle(颜色:Colors.white,字体大小:25),),
列表砖(
标题:文本('LogIn',样式:TextStyle(颜色:Colors.white,fontSize:20.0)),
前导:图标(Icons.arrow_forward,颜色:Colors.white,),
onTap:(){
//更新应用程序的状态。
// ...
},
),
列表砖(
标题:文本(“Ort hinzufügen”,样式:TextStyle(颜色:Colors.white,fontSize:20.0)),
前导:图标(Icons.arrow_forward,颜色:Colors.white,),
onTap:(){
//更新应用程序的状态。
// ...
},
),
列表砖(
标题:文本('Hilfe',样式:TextStyle(颜色:Colors.white,fontSize:20.0)),
前导:图标(Icons.arrow_forward,颜色:Colors.white,),
onTap:(){
//更新应用程序的状态。
// ...
},
),
列表砖(
标题:文本('Einstellungen',样式:TextStyle(颜色:Colors.white,fontSize:20.0),),
前导:图标(Icons.arrow_forward,颜色:Colors.white,),
onTap:(){
//更新应用程序的状态。
// ...
},
),
],
),
),
),
appBar:新的appBar(
标题:新文本(“地理指南”),
背景颜色:颜色。来自RGBO(0,111,118,0.8),
),
//创建新地图
主体:新容器(
宽度:420,
身高:300,
孩子:新地图(
映射控制器:控制器,
//中心:当前位置
选项:新地图选项(中心:buildMap(),最小缩放:15.0),
图层:[
//实现osm模板
新TileLayerOptions(
URL模板:
“https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png”,
子域:['a','b','c']),
]),
),
);
}
}