location picker and ui fixes
All checks were successful
Build and release APK / Build APK (pull_request) Successful in 5m25s
All checks were successful
Build and release APK / Build APK (pull_request) Successful in 5m25s
This commit is contained in:
64
frontend/lib/modules/new_trip_location_search.dart
Normal file
64
frontend/lib/modules/new_trip_location_search.dart
Normal file
@@ -0,0 +1,64 @@
|
||||
|
||||
// A search bar that allow the user to enter a city name
|
||||
import 'package:anyway/structs/landmark.dart';
|
||||
import 'package:geocoding/geocoding.dart';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:anyway/structs/trip.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class NewTripLocationSearch extends StatefulWidget {
|
||||
Trip trip;
|
||||
NewTripLocationSearch(
|
||||
this.trip,
|
||||
);
|
||||
|
||||
|
||||
@override
|
||||
State<NewTripLocationSearch> createState() => _NewTripLocationSearchState();
|
||||
}
|
||||
|
||||
class _NewTripLocationSearchState extends State<NewTripLocationSearch> {
|
||||
final TextEditingController _controller = TextEditingController();
|
||||
|
||||
setTripLocation (String query) async {
|
||||
List<Location> locations = [];
|
||||
log('Searching for: $query');
|
||||
|
||||
try{
|
||||
locations = await locationFromAddress(query);
|
||||
} catch (e) {
|
||||
log('No results found for: $query : $e');
|
||||
}
|
||||
|
||||
if (locations.isNotEmpty) {
|
||||
Location location = locations.first;
|
||||
widget.trip.landmarks.clear();
|
||||
widget.trip.addLandmark(
|
||||
Landmark(
|
||||
uuid: 'pending',
|
||||
name: query,
|
||||
location: [location.latitude, location.longitude],
|
||||
type: start
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SearchBar(
|
||||
hintText: 'Enter a city name or long press on the map.',
|
||||
onSubmitted: setTripLocation,
|
||||
controller: _controller,
|
||||
leading: Icon(Icons.search),
|
||||
trailing: [ElevatedButton(
|
||||
onPressed: () {
|
||||
setTripLocation(_controller.text);
|
||||
},
|
||||
child: Text('Search'),
|
||||
),]
|
||||
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user