64 lines
2.1 KiB
Dart
64 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:wetter/components/locations/add_location_by_search_form.dart';
|
|
import 'package:wetter/components/locations/add_location_form.dart';
|
|
import 'package:wetter/components/locations/manage_single_location.dart';
|
|
import 'package:wetter/services/user_preferences.dart';
|
|
|
|
class Locations extends StatefulWidget {
|
|
const Locations({super.key});
|
|
|
|
@override
|
|
State<Locations> createState() => _LocationsState();
|
|
}
|
|
|
|
class _LocationsState extends State<Locations> {
|
|
List<String> locations = [];
|
|
@override
|
|
void initState() {
|
|
locations = UserPreferences.getSavedLocations();
|
|
super.initState();
|
|
}
|
|
|
|
void saveNewLocation(String name, double lat, double lon) {
|
|
setState(() {
|
|
locations = UserPreferences.saveNewLocation(name, lat, lon);
|
|
});
|
|
}
|
|
|
|
void deleteLocation(String name) {
|
|
setState(() {
|
|
locations = UserPreferences.deleteLocation(name);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Locations'),
|
|
),
|
|
body: SingleChildScrollView(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(20),
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
for (String name in locations)
|
|
ManageSingleLocation(
|
|
name: name, delete: deleteLocation),
|
|
...[
|
|
const SizedBox(height: 20),
|
|
const Text("Add location by search"),
|
|
AddLocationBySearchForm(
|
|
saveNewLocation: saveNewLocation),
|
|
const SizedBox(height: 20),
|
|
const Text("Add location by coordinates"),
|
|
AddLocationsForm(
|
|
saveNewLocation: saveNewLocation,
|
|
savedLocations: locations),
|
|
],
|
|
])))));
|
|
}
|
|
}
|