问题描述
对此我需要一些帮助,我正在尝试使我的火力基地中的所有标记都显示在地图上,但是只有一个想要显示!我最终也想在其上添加一个计时方面,但是我还没有弄清楚这一点:)
所以我主要对从Firebase检索感兴趣。但是我还想添加一个功能,说该功能在使用10分钟后会删除数据库中的条目。
我的代码
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
class MapsPage extends StatefulWidget {
@override
_MapsPageState createState() => _MapsPageState();
}
class _MapsPageState extends State<MapsPage> {
GoogleMapController controller;
var currentLocation;
Map<MarkerId,Marker> markers = <MarkerId,Marker>{};
void initMarker(specify,specifyId) async {
var markerIdVal = specifyId;
final MarkerId markerId = MarkerId(markerIdVal);
final Marker marker = Marker(
markerId: markerId,position: LatLng(specify['loc'].latitude,specify['loc'].longitude),infoWindow: InfoWindow(title: 'Shop',snippet: specify['name']),);
setState(() {
markers[specifyId] = marker;
});
}
getMarkerData() async {
FirebaseFirestore.instance.collection('markers').get().then((myMockDoc) {
if (myMockDoc.docs.isNotEmpty) {
for (int i = 0; i < myMockDoc.docs.length; i++) {
initMarker(myMockDoc.docs[i].data,myMockDoc.docs[i].id);
}
}
});
}
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
Set<Marker> getMarker() {
return <Marker>[
Marker(
markerId: MarkerId('markers'),position: LatLng(43.6500194,-79.3916367),icon: BitmapDescriptor.defaultMarkerWithHue(
BitmapDescriptor.hueMagenta),infoWindow: InfoWindow(title: 'Home'))
].toSet();
}
return Scaffold(
appBar: AppBar(
backgroundColor: Color.fromARGB(255,42,27,113),title: Text('Ride!'),),body: GoogleMap(
markers: getMarker(),mapType: MapType.normal,initialCameraPosition: CameraPosition(
target: LatLng(43.6500418,-79.3916043),zoom: 13.5),onMapCreated: (GoogleMapController controller) {
controller = controller;
}));
}
}
我的终端机
Flutter run key commands.
r Hot reload. ???
R Hot restart.
h Repeat this help message.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
An Observatory debugger and profiler on iPhone 11 Pro Max is available at: http://127.0.0.1:58253/XVsWUmPbmt8=/
Google Maps SDK for iOS version: 3.9.0.0
New version of Google Maps SDK for iOS available: 4.0.0.0
[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: RangeError (index): Invalid value: Not in inclusive range 0..3: 5
#0 List.[] (dart:core-patch/growable_array.dart:177:60)
#1 _MapsPageState.getMarkerData.<anonymous closure> (package:myttcmap/screen/home_screen/home_screen.dart:36:36)
#2 _rootRunUnary (dart:async/zone.dart:1198:47)
#3 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#4 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#5 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#6 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#7 Future._completeWithValue (dart:async/future_impl.dart:529:5)
#8 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
#9 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
#10 Query.get (package:cloud_firestore/src/query.dart)
<asynchronous suspension>
#11 _MapsPageState.getMarkerData (package:myttcm<…>
[VERBOSE-2:profiler_metrics_ios.mm(184)] Error retrieving thread information: (ipc/send) invalid destination port
Performing hot restart...
Restarted application in 821ms.
[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: Closure call with mismatched arguments: function '[]'
Receiver: Closure: () => Map<String,dynamic> from Function 'data':.
Tried calling: []("loc")
Found: []() => Map<String,dynamic>
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 _MapsPageState.initMarker (package:myttcmap/screen/home_screen/home_screen.dart:24:31)
#2 _MapsPageState.getMarkerData.<anonymous closure> (package:myttcmap/screen/home_screen/home_screen.dart:36:11)
#3 _rootRunUnary (dart:async/zone.dart:1198:47)
#4 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#5 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#6 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#7 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#8 Future._completeWithValue (dart:async/future_impl.dart:529:5)
#9 _AsyncAwaitCompleter.complete (dart:async-p<…>
[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: Closure call with mismatched arguments: function '[]'
Receiver: Closure: () => Map<String,dynamic>
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 _MapsPageState.initMarker (package:myttcmap/screen/home_screen/home_screen.dart:24:31)
#2 _MapsPageState.getMarkerData.<anonymous closure> (package:myttcmap/screen/home_screen/home_screen.dart:36:11)
#3 _rootRunUnary (dart:async/zone.dart:1198:47)
#4 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#5 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#6 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#7 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#8 Future._completeWithValue (dart:async/future_impl.dart:529:5)
#9 _AsyncAwaitCompleter.complete (dart:async-p<…>
[VERBOSE-2:profiler_metrics_ios.mm(184)] Error retrieving thread information: (ipc/send) invalid destination port
Performing hot restart...
Restarted application in 788ms.
[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: Closure call with mismatched arguments: function '[]'
Receiver: Closure: () => Map<String,dynamic>
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 _MapsPageState.initMarker (package:myttcmap/screen/home_screen/home_screen.dart:24:31)
#2 _MapsPageState.getMarkerData.<anonymous closure> (package:myttcmap/screen/home_screen/home_screen.dart:36:11)
#3 _rootRunUnary (dart:async/zone.dart:1198:47)
#4 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#5 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#6 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#7 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#8 Future._completeWithValue (dart:async/future_impl.dart:529:5)
#9 _AsyncAwaitCompleter.complete (dart:async-p<…>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)