summaryrefslogtreecommitdiffstats
path: root/lib/search.dart
diff options
context:
space:
mode:
Diffstat (limited to 'lib/search.dart')
-rw-r--r--lib/search.dart69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/search.dart b/lib/search.dart
new file mode 100644
index 0000000..9e02450
--- /dev/null
+++ b/lib/search.dart
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: Apache-2.0
+
+import 'dart:convert';
+
+import 'package:flutter/material.dart';
+import 'package:flutter_navigation/config.dart';
+import 'package:flutter_riverpod/flutter_riverpod.dart';
+
+import 'package:http/http.dart' as http;
+import 'package:latlong2/latlong.dart';
+import 'package:flutter_navigation/kuksa/class-provider.dart';
+import 'package:flutter_navigation/provider.dart';
+
+import 'mapbox.dart';
+
+class SearchPage extends ConsumerWidget {
+ bool iscurrent;
+
+ SearchPage({Key? key, required this.iscurrent}) : super(key: key);
+ final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
+
+
+ @override
+ Widget build(BuildContext context,ref) {
+ final config = ref.read(ConfigStateprovider);
+
+ return Scaffold(
+ key: _scaffoldKey,
+ floatingActionButton: FloatingActionButton(
+ child: Icon(Icons.done),
+ onPressed: () {
+ Navigator.pop(context);
+ },
+ ),
+ body: SafeArea(
+ bottom: false,
+ child: MapBoxPlaceSearchWidget(
+ height: 600,
+ popOnSelect: false,
+ apiKey: config.mapboxAccessToken,
+ searchHint: 'Search around your place',
+ onSelected: (place) async{
+ var url = 'https://api.mapbox.com/geocoding/v5/mapbox.places/${place.placeName}.json?proximity=ip&types=place%2Cpostcode%2Caddress&access_token=${config.mapboxAccessToken}';
+ http.Response response = await http.get(Uri.parse(url));
+ Map data = json.decode(response.body);
+ double longi = data['features'][0]['center'][0];
+ double lati = data['features'][0]['center'][1];
+ if(iscurrent){
+ LatLng value = LatLng(lati,longi);
+ ref.read(vehicleSignalProvider.notifier).update(currentLatitude: lati,currentLongitude: longi);
+ ref.read(CurrentAdressProvider.notifier).update(place.placeName);
+
+ }
+ else{
+ ref.read(vehicleSignalProvider.notifier).update(destinationLatitude: lati,destinationLongitude: longi);
+
+ ref.read(DestinationAdressProvider.notifier).update(place.placeName);
+
+ }
+
+
+
+ },
+ context: context,
+ ),
+ ),
+ );
+ }
+} \ No newline at end of file