outsourced add cam main widgets and cleaned karte widget up
time
This commit is contained in:
111
lib/screens/addCam/widgets/karte.dart
Normal file
111
lib/screens/addCam/widgets/karte.dart
Normal file
@@ -0,0 +1,111 @@
|
||||
import 'package:fforte/screens/helper/snack_bar_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:geocoding/geocoding.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
class Karte extends StatefulWidget {
|
||||
final TextEditingController beiOrtC;
|
||||
final TextEditingController ortInfoC;
|
||||
final TextEditingController decLngC;
|
||||
final TextEditingController decLatC;
|
||||
final Position currentPosition;
|
||||
|
||||
const Karte(
|
||||
{super.key,
|
||||
required this.currentPosition,
|
||||
required this.beiOrtC,
|
||||
required this.ortInfoC,
|
||||
required this.decLngC,
|
||||
required this.decLatC});
|
||||
|
||||
@override
|
||||
KarteState createState() => KarteState();
|
||||
}
|
||||
|
||||
class KarteState extends State<Karte> {
|
||||
Marker? currentMarker;
|
||||
bool saveVisible = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
currentMarker = Marker(
|
||||
point: LatLng(
|
||||
widget.currentPosition.latitude, widget.currentPosition.longitude),
|
||||
child: const Icon(
|
||||
Icons.location_on,
|
||||
color: Colors.red,
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(AppLocalizations.of(context)!.map),
|
||||
actions: [
|
||||
Visibility(
|
||||
visible: saveVisible,
|
||||
child: Row(
|
||||
children: [
|
||||
Text(AppLocalizations.of(context)!.saveMap),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
if (currentMarker != null) {
|
||||
setState(() {
|
||||
widget.decLatC.text =
|
||||
currentMarker!.point.latitude.toString();
|
||||
widget.decLngC.text =
|
||||
currentMarker!.point.longitude.toString();
|
||||
});
|
||||
}
|
||||
if (context.mounted) Navigator.pop(context);
|
||||
},
|
||||
child: const Icon(Icons.save),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: FlutterMap(
|
||||
mapController: MapController(),
|
||||
options: MapOptions(
|
||||
interactionOptions: const InteractionOptions(
|
||||
flags: InteractiveFlag.pinchZoom |
|
||||
InteractiveFlag.drag |
|
||||
InteractiveFlag.pinchMove),
|
||||
initialCenter: LatLng(widget.currentPosition.latitude,
|
||||
widget.currentPosition.longitude),
|
||||
initialZoom: 16.0,
|
||||
onTap: _handleTap,
|
||||
),
|
||||
children: [
|
||||
TileLayer(
|
||||
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
userAgentPackageName: 'com.example.app',
|
||||
),
|
||||
MarkerLayer(markers: currentMarker != null ? [currentMarker!] : []),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
_handleTap(TapPosition position, LatLng latlng) {
|
||||
setState(() {
|
||||
currentMarker = Marker(
|
||||
width: 80.0,
|
||||
height: 80.0,
|
||||
point: latlng,
|
||||
child: const Icon(
|
||||
Icons.location_on,
|
||||
color: Colors.red,
|
||||
),
|
||||
);
|
||||
saveVisible = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user