Untitled
unknown
plain_text
2 years ago
4.6 kB
5
Indexable
import 'package:erlebnis_campus/models/PointOfInterest.dart'; import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:latlong2/latlong.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:erlebnis_campus/services/poiDatabaseServices.dart'; import 'dart:async'; class MapWithPOIs extends StatefulWidget { const MapWithPOIs({Key? key}) : super(key: key); @override _MapWithPOIsState createState() => _MapWithPOIsState(); } class _MapWithPOIsState extends State<MapWithPOIs> { late Future<List<PointOfInterest>> poisFuture; @override void initState() { super.initState(); // print("initState executed"); poisFuture = PoiDatabaseServices.getPois(); } @override @override Widget build(BuildContext context) { return Stack( children: <Widget>[ FlutterMap( options: MapOptions( initialCenter: LatLng(52.51261841242752, 13.321896902940018), initialZoom: 17, onTap: (TapPosition t, LatLng coords) { print("Coordinates: ${coords.latitude}, ${coords.longitude}"); }, ), children: <Widget>[ TileLayer( urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', userAgentPackageName: 'com.example.app', ), RichAttributionWidget( attributions: [ TextSourceAttribution( 'OpenStreetMap contributors', onTap: () => launchUrl( Uri.parse('https://openstreetmap.org/copyright')), ), ], ), FutureBuilder<List<PointOfInterest>>( future: poisFuture, builder: (context, snapshot) { if (snapshot.hasData) { // If the Future is complete and successful, add the POIs to the map List<PointOfInterest> pois = snapshot.data ?? []; return _showMarkerDialog(context, pois); } else { // While waiting or in case of error, don't display any POIs return Container(); } }, ), ], ), // Optional: Disyplay a loading indicator or error message over the map FutureBuilder<List<PointOfInterest>>( future: poisFuture, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { // Display a loading indicator in the center return Center(child: CircularProgressIndicator()); } else if (snapshot.hasError) { // Display an error message return Center(child: Text('Error: ${snapshot.error}')); } else { // No additional UI elements for the completed state return Container(); } }, ), ], ); } _showMarkerDialog(BuildContext context, List<PointOfInterest> pois) { return MarkerLayer( markers: pois.map( (poi) => Marker( width: 30.0, height: 30.0, point: LatLng(poi.latitude, poi.longitude), child: IconButton( icon: const Icon( Icons.location_pin, size: 40.0, color: Colors.red,), onPressed: () { _showMarkerDialog2(context, poi); print("button worked"); }, ), ), ).toList(), ); } _showMarkerDialog2(context, poi) { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: Text(poi.name), content: TextField( decoration: InputDecoration(hintText: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.'), ), actions: [ TextButton( child: Text('Cancel'), onPressed: () { Navigator.of(context).pop(); }, ), ], ); }, ); } }
Editor is loading...
Leave a Comment