Skip to content
Snippets Groups Projects
Commit 62bf52c1 authored by alper-savas's avatar alper-savas
Browse files

Change design, add house number page and additional bottom sheet info depending on weather.

parent 2c182566
No related branches found
No related tags found
1 merge request!6final project merge into main
class Config {
final String GOOGLE_API = '';
final String WEATHER_API = '';
}
This diff is collapsed.
......@@ -6,10 +6,14 @@ import 'package:google_maps_flutter/google_maps_flutter.dart';
class Directions {
final LatLngBounds bounds;
final List<PointLatLng> polylinePoints;
final String totalDistance;
final String totalDuration;
const Directions({
required this.bounds,
required this.polylinePoints,
required this.totalDistance,
required this.totalDuration,
});
factory Directions.fromMap(Map<String, dynamic> map) {
......@@ -24,10 +28,21 @@ class Directions {
southwest: LatLng(southwest['lat'], southwest['lng']),
);
// Distance and Duration
String distance = '';
String duration = '';
if ((data['legs'] as List).isNotEmpty) {
final leg = data['legs'][0];
distance = leg['distance']['text'];
duration = leg['duration']['text'];
}
return Directions(
bounds: bounds,
polylinePoints:
PolylinePoints().decodePolyline(data['overview_polyline']['points']),
totalDistance: distance,
totalDuration: duration,
);
}
}
......@@ -3,13 +3,13 @@
import 'package:dio/dio.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import './directions.dart';
import '../config/config.dart';
class DirectionsRepo {
Config config = Config();
static const String _baseUrl =
'https://maps.googleapis.com/maps/api/directions/json?';
final Dio _dio;
DirectionsRepo({Dio? dio}) : _dio = dio ?? Dio();
Future<Directions> getDirections({
......@@ -21,7 +21,7 @@ class DirectionsRepo {
queryParameters: {
'origin': '${origin.latitude},${origin.longitude}',
'destination': '${destination.latitude},${destination.longitude}',
'key': '',
'key': config.GOOGLE_API,
},
);
......
// ignore_for_file: prefer_const_literals_to_create_immutables, prefer_const_constructors, sort_child_properties_last, must_be_immutable, use_key_in_widget_constructors, avoid_unnecessary_containers, deprecated_member_use
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'package:http/http.dart' as http;
import '../config/config.dart';
class GetStreetNumber extends StatefulWidget {
String currentAddress;
GetStreetNumber(this.currentAddress);
@override
State<GetStreetNumber> createState() => _GetStreetNumberState();
}
class _GetStreetNumberState extends State<GetStreetNumber> {
Config config = Config();
TextEditingController textFieldController = TextEditingController();
List<String> suggestions = [];
Future<List<String>> fetchLocation(String query) async {
query = widget.currentAddress + query;
final response = await http.get(
Uri.parse(
'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=$query&radius=500&key=${config.GOOGLE_API}',
),
);
var jsonData = jsonDecode(response.body);
suggestions = [];
for (int i = 0; i < jsonData['predictions'][i].length; i++) {
suggestions.add(jsonData['predictions'][i]['description'].toString());
}
return suggestions;
}
void _sendDataBack(BuildContext context) {
Navigator.pop(context, textFieldController.text);
}
void _skip(BuildContext context) {
Navigator.pop(context, widget.currentAddress);
}
void _back(BuildContext context) {
Navigator.pop(context, textFieldController.text);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Color.fromRGBO(9, 89, 95, 1),
title: Text(
'House Number',
style: TextStyle(
color: Theme.of(context).accentColor,
fontSize: 22,
),
),
leading: IconButton(
iconSize: 26,
icon: Icon(
Icons.arrow_back_ios_rounded,
color: Theme.of(context).accentColor,
),
onPressed: () => _back(context),
),
),
body: Container(
color: Theme.of(context).primaryColor,
child: Column(
children: [
Container(
margin: EdgeInsets.only(top: 15, right: 20, left: 10),
child: Row(
children: [
Expanded(
child: Container(
padding: EdgeInsets.only(left: 10, right: 0),
decoration: BoxDecoration(
border: Border.all(
width: 1.5,
color: Color.fromRGBO(9, 89, 95, 1),
),
borderRadius: BorderRadius.all(
Radius.circular(30),
),
),
height: 45,
child: TypeAheadField(
animationStart: 1,
animationDuration: Duration.zero,
textFieldConfiguration: TextFieldConfiguration(
onSubmitted: (_) {
_sendDataBack(context);
},
controller: textFieldController,
autofocus: false,
decoration: InputDecoration(
border: InputBorder.none,
labelStyle: TextStyle(
color: Theme.of(context).accentColor,
),
labelText: 'House number..',
floatingLabelBehavior: FloatingLabelBehavior.never,
),
style: TextStyle(
fontSize: 21,
color: Theme.of(context).accentColor,
),
),
suggestionsBoxDecoration: SuggestionsBoxDecoration(
color: Theme.of(context).primaryColor,
),
suggestionsCallback: (pattern) {
fetchLocation(pattern);
return suggestions;
},
itemBuilder: (context, textField) {
return Container(
decoration: BoxDecoration(
color: Color.fromRGBO(53, 56, 63, 1),
borderRadius: BorderRadius.all(
Radius.circular(25),
),
),
margin: EdgeInsets.only(top: 5, bottom: 5),
padding:
EdgeInsets.only(top: 5, bottom: 5, left: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
child: Icon(Icons.location_city_rounded,
color: Theme.of(context).accentColor),
),
Expanded(
child: Container(
margin: EdgeInsets.only(
top: 10,
bottom: 10,
left: 10,
),
width: double.infinity,
child: Text(
textField.toString(),
style: TextStyle(
fontSize: 20,
color: Theme.of(context).accentColor,
),
),
),
),
],
),
);
},
onSuggestionSelected: (suggestion) {
textFieldController.text = suggestion.toString();
_sendDataBack(context);
},
),
),
),
],
),
),
],
),
),
floatingActionButton: ElevatedButton(
onPressed: () => _skip(context),
child: Container(
child: Text(
'Skip',
style: TextStyle(fontSize: 20),
),
padding: EdgeInsets.all(10),
),
style: ButtonStyle(
backgroundColor: MaterialStatePropertyAll(
Color.fromRGBO(13, 108, 114, 1),
),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
);
}
}
// ignore_for_file: prefer_const_constructors, use_key_in_widget_constructors, avoid_print, prefer_is_not_empty
// ignore_for_file: prefer_const_constructors, use_key_in_widget_constructors, avoid_print, prefer_is_not_empty, use_build_context_synchronously
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'package:http/http.dart' as http;
import 'getStreetNumber.dart';
import '../config/config.dart';
class ReturnDestination extends StatefulWidget {
String destinationText;
......@@ -14,13 +15,14 @@ class ReturnDestination extends StatefulWidget {
}
class _ReturnDestinationState extends State<ReturnDestination> {
Config config = Config();
TextEditingController textFieldController = TextEditingController();
List<String> suggestions = [];
Future<List<String>> fetchLocation(String query) async {
final response = await http.get(
Uri.parse(
'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=$query&radius=500&key=',
'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=$query&radius=500&key=${config.GOOGLE_API}',
),
);
var jsonData = jsonDecode(response.body);
......@@ -31,7 +33,16 @@ class _ReturnDestinationState extends State<ReturnDestination> {
return suggestions;
}
void _sendDataBack(BuildContext context) {
void _sendDataBack(BuildContext context) async {
final result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => GetStreetNumber(textFieldController.text),
),
);
if (result != null) {
textFieldController.text = result;
}
String textToSendBack = textFieldController.text;
if (textToSendBack.isEmpty) return;
Navigator.pop(context, textToSendBack);
......@@ -41,7 +52,7 @@ class _ReturnDestinationState extends State<ReturnDestination> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).primaryColor,
backgroundColor: Color.fromRGBO(9, 89, 95, 1),
title: Text(
'Destination Point',
style: TextStyle(
......@@ -61,19 +72,20 @@ class _ReturnDestinationState extends State<ReturnDestination> {
),
),
body: Container(
color: Theme.of(context).primaryColor,
child: Column(
children: [
Container(
margin: EdgeInsets.only(top: 15, right: 20, left: 20),
margin: EdgeInsets.only(top: 15, right: 10, left: 10),
child: Row(
children: [
Expanded(
child: Container(
padding: EdgeInsets.only(left: 20),
padding: EdgeInsets.only(left: 10, right: 5),
decoration: BoxDecoration(
border: Border.all(
width: 1.5,
color: Theme.of(context).primaryColor,
color: Color.fromRGBO(9, 89, 95, 1),
),
borderRadius: BorderRadius.all(
Radius.circular(30),
......@@ -81,7 +93,7 @@ class _ReturnDestinationState extends State<ReturnDestination> {
),
height: 45,
child: TypeAheadField(
animationStart: 0,
animationStart: 1,
animationDuration: Duration.zero,
textFieldConfiguration: TextFieldConfiguration(
onSubmitted: (_) {
......@@ -92,41 +104,55 @@ class _ReturnDestinationState extends State<ReturnDestination> {
decoration: InputDecoration(
border: InputBorder.none,
labelStyle: TextStyle(
color: Theme.of(context).primaryColor,
fontSize: 21,
color: Theme.of(context).accentColor,
),
labelText: widget.destinationText,
floatingLabelBehavior: FloatingLabelBehavior.never,
),
style: TextStyle(
fontSize: 20,
color: Theme.of(context).primaryColor,
fontSize: 21,
color: Theme.of(context).accentColor,
),
),
suggestionsBoxDecoration:
SuggestionsBoxDecoration(elevation: 0),
suggestionsBoxDecoration: SuggestionsBoxDecoration(
color: Theme.of(context).primaryColor,
),
suggestionsCallback: (pattern) {
fetchLocation(pattern);
return suggestions;
},
itemBuilder: (context, textField) {
return Container(
padding: EdgeInsets.only(top: 1),
decoration: BoxDecoration(
color: Color.fromRGBO(53, 56, 63, 1),
borderRadius: BorderRadius.all(
Radius.circular(25),
),
),
margin: EdgeInsets.only(top: 5, bottom: 5),
padding:
EdgeInsets.only(top: 5, bottom: 5, left: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
child: Icon(Icons.location_city_rounded,
color: Theme.of(context).primaryColor),
color: Theme.of(context).accentColor),
),
Expanded(
child: Container(
margin: EdgeInsets.all(10),
margin: EdgeInsets.only(
top: 10,
bottom: 10,
left: 10,
),
width: double.infinity,
child: Text(
textField.toString(),
style: TextStyle(
fontSize: 20,
color: Theme.of(context).primaryColor,
color: Theme.of(context).accentColor,
),
),
),
......
// ignore_for_file: prefer_const_constructors, use_key_in_widget_constructors, avoid_print, prefer_is_not_empty
// ignore_for_file: prefer_const_constructors, use_key_in_widget_constructors, avoid_print, prefer_is_not_empty, use_build_context_synchronously
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'package:http/http.dart' as http;
import 'getStreetNumber.dart';
import '../config/config.dart';
class ReturnOrigin extends StatefulWidget {
String originText;
......@@ -13,13 +15,14 @@ class ReturnOrigin extends StatefulWidget {
}
class _ReturnOriginState extends State<ReturnOrigin> {
Config config = Config();
TextEditingController textFieldController = TextEditingController();
List<String> suggestions = [];
Future<List<String>> fetchLocation(String query) async {
final response = await http.get(
Uri.parse(
'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=$query&radius=500&key=',
'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=$query&radius=500&key=${config.GOOGLE_API}',
),
);
var jsonData = jsonDecode(response.body);
......@@ -30,7 +33,16 @@ class _ReturnOriginState extends State<ReturnOrigin> {
return suggestions;
}
void _sendDataBack(BuildContext context) {
void _sendDataBack(BuildContext context) async {
final result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => GetStreetNumber(textFieldController.text),
),
);
if (result != null) {
textFieldController.text = result;
}
String textToSendBack = textFieldController.text;
if (textToSendBack.isEmpty) return;
Navigator.pop(context, textToSendBack);
......@@ -40,7 +52,7 @@ class _ReturnOriginState extends State<ReturnOrigin> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).primaryColor,
backgroundColor: Color.fromRGBO(9, 89, 95, 1),
title: Text(
'Starting Point',
style: TextStyle(
......@@ -60,19 +72,20 @@ class _ReturnOriginState extends State<ReturnOrigin> {
),
),
body: Container(
color: Theme.of(context).primaryColor,
child: Column(
children: [
Container(
margin: EdgeInsets.only(top: 15, right: 20, left: 20),
margin: EdgeInsets.only(top: 15, right: 10, left: 10),
child: Row(
children: [
Expanded(
child: Container(
padding: EdgeInsets.only(left: 20),
padding: EdgeInsets.only(left: 10, right: 5),
decoration: BoxDecoration(
border: Border.all(
width: 1.5,
color: Theme.of(context).primaryColor,
color: Color.fromRGBO(9, 89, 95, 1),
),
borderRadius: BorderRadius.all(
Radius.circular(30),
......@@ -80,7 +93,7 @@ class _ReturnOriginState extends State<ReturnOrigin> {
),
height: 45,
child: TypeAheadField(
animationStart: 0,
animationStart: 1,
animationDuration: Duration.zero,
textFieldConfiguration: TextFieldConfiguration(
onSubmitted: (_) {
......@@ -91,41 +104,54 @@ class _ReturnOriginState extends State<ReturnOrigin> {
decoration: InputDecoration(
border: InputBorder.none,
labelStyle: TextStyle(
color: Theme.of(context).primaryColor,
color: Theme.of(context).accentColor,
),
labelText: widget.originText,
floatingLabelBehavior: FloatingLabelBehavior.never,
),
style: TextStyle(
fontSize: 20,
color: Theme.of(context).primaryColor,
color: Theme.of(context).accentColor,
),
),
suggestionsBoxDecoration:
SuggestionsBoxDecoration(elevation: 0),
suggestionsBoxDecoration: SuggestionsBoxDecoration(
color: Theme.of(context).primaryColor,
),
suggestionsCallback: (pattern) {
fetchLocation(pattern);
return suggestions;
},
itemBuilder: (context, textField) {
return Container(
padding: EdgeInsets.only(top: 1),
decoration: BoxDecoration(
color: Color.fromRGBO(53, 56, 63, 1),
borderRadius: BorderRadius.all(
Radius.circular(25),
),
),
margin: EdgeInsets.only(top: 5, bottom: 5),
padding:
EdgeInsets.only(top: 5, bottom: 5, left: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
child: Icon(Icons.location_city_rounded,
color: Theme.of(context).primaryColor),
color: Theme.of(context).accentColor),
),
Expanded(
child: Container(
margin: EdgeInsets.all(10),
margin: EdgeInsets.only(
top: 10,
bottom: 10,
left: 10,
),
width: double.infinity,
child: Text(
textField.toString(),
style: TextStyle(
fontSize: 20,
color: Theme.of(context).primaryColor,
color: Theme.of(context).accentColor,
),
),
),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment