All checks were successful
Build and release APK / Build APK (pull_request) Successful in 5m25s
64 lines
1.5 KiB
Dart
64 lines
1.5 KiB
Dart
|
|
// 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'),
|
|
),]
|
|
|
|
);
|
|
}
|
|
} |