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

Add config, delete unnecessary code

parent 1cc8488c
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 = '';
final String OSM_API = '';
final String GOOGLE_API = 'AIzaSyAzedQacDEZmyxAOUEEeocvehT8MEdMWys';
final String WEATHER_API = '07cd339d66d846c7b33192823232003';
final String OSM_API =
'5b3ce3597851110001cf6248c6ba0beaf1a7480ba9f460646ae0c47b';
}
// ignore_for_file: prefer_const_constructors, sort_child_properties_last, import_of_legacy_library_into_null_safe, prefer_is_not_empty, unnecessary_null_comparison, deprecated_member_use, depend_on_referenced_packages, avoid_function_literals_in_foreach_calls, prefer_final_fields, prefer_typing_uninitialized_variables
// ignore_for_file: prefer_const_constructors, sort_child_properties_last, import_of_legacy_library_into_null_safe, prefer_is_not_empty, unnecessary_null_comparison, deprecated_member_use, depend_on_referenced_packages, avoid_function_literals_in_foreach_calls, prefer_final_fields, prefer_typing_uninitialized_variables, use_build_context_synchronously
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:intl/intl.dart';
......@@ -13,9 +13,6 @@ import 'dart:convert';
import 'package:weather_icons/weather_icons.dart';
import 'config/config.dart';
import 'package:latlong/latlong.dart' as latlng;
// import 'widgets/directionsRepo.dart';
// import 'package:google_maps_flutter/google_maps_flutter.dart';
// import 'widgets/directions.dart';
void main() => runApp(MyApp());
......@@ -56,9 +53,6 @@ class _MyHomePageState extends State<MyHomePage> {
Config config = Config();
// Initial map coords and map controller to control camera movements.
late final MapController _mapController = MapController();
// static const _initialCameraPosition =
// CameraPosition(target: LatLng(52.5163, 13.3777), zoom: 12);
// late GoogleMapController _mapController;
// Input field texts for origin/dest points.
String originText = 'Starting Point...';
......@@ -71,8 +65,6 @@ class _MyHomePageState extends State<MyHomePage> {
Set<Marker> _markers = {};
var _data;
List<latlng.LatLng> _polyline = <latlng.LatLng>[];
// late Directions _info;
// Set<Polyline> _polyline = {};
String _totalDuration = '';
String _totalDistance = '';
String _totalDaysFormatted = '';
......@@ -233,6 +225,7 @@ class _MyHomePageState extends State<MyHomePage> {
// Get coords between origin/dest points corresponding to shortest path.
Future<void> _getDirections() async {
_resetPolyline();
try {
var originlat = _originCoordinates.latitude;
var originlon = _originCoordinates.longitude;
......@@ -256,7 +249,9 @@ class _MyHomePageState extends State<MyHomePage> {
if (_data.containsKey('error_code') && _data['error_code'] != 0) {
switch (_data['error_code']) {
case 1:
_showMessage('The address is outside the solution space. Please enter an address within Berlin-Brandenburg.', context);
_showMessage(
'The address is outside the solution space. Please enter an address within Berlin-Brandenburg.',
context);
return;
case 2:
_showMessage('The address could not be found.', context);
......@@ -356,44 +351,6 @@ class _MyHomePageState extends State<MyHomePage> {
_dateRange.end.difference(DateTime.now()).inDays);
}
// Get coords between origin/dest points corresponding to shortest path and update _info.
// This part is going to be updated to take directions from backend instead of Direction API.
// Future<Directions> _getDirections() async {
// final directions = await DirectionsRepo().getDirections(
// origin: _originCoordinates, destination: _destCoordinates);
// setState(() {
// _info = directions;
// });
// return _info;
// }
// Draw Polyline between given list of coordinates and update _polyline
// void _drawPolyline() {
// _getDirections().then((value) {
// _polyline.add(Polyline(
// polylineId: PolylineId("polylineId"),
// color: Theme.of(context).primaryColor,
// width: 4,
// points: value.polylinePoints
// .map((e) => LatLng(e.latitude, e.longitude))
// .toList(),
// ));
// _totalDuration = value.totalDuration;
// _totalDistance = value.totalDistance;
// setState(() {
// _polyline;
// _totalDuration;
// _totalDistance;
// });
// // Animate camera to the shortest path.
// // _mapController.animateCamera(
// // CameraUpdate.newLatLngBounds(_info.bounds, 110.0),
// // );
// });
// }
// Helper function to reset polyline before calculating new polyline for another route.
void _resetPolyline() {
_polyline = [];
......@@ -403,7 +360,7 @@ class _MyHomePageState extends State<MyHomePage> {
}
// Helper function to reset marker.
void _resetOriginMarker() {
void _resetMarker() {
_markers = {};
setState(() {
_markers;
......@@ -429,7 +386,7 @@ class _MyHomePageState extends State<MyHomePage> {
latlng.LatLng(position.latitude, position.longitude);
});
_mapController.move(_originCoordinates, 13);
_resetOriginMarker();
_resetMarker();
_addOriginMarker();
_resetPolyline();
},
......@@ -445,7 +402,7 @@ class _MyHomePageState extends State<MyHomePage> {
// Add origin marker on touch.
void _appearOriginMarkerOnTouch(latlng.LatLng pos) async {
_resetPolyline();
_resetOriginMarker();
_resetMarker();
_markers.add(
Marker(
width: 100,
......@@ -1033,24 +990,29 @@ class _MyHomePageState extends State<MyHomePage> {
itemBuilder: (BuildContext context, int index) {
return Stack(
children: [
_isLoading ? Center(child: const CircularProgressIndicator()) : Column(
_isLoading
? Center(child: const CircularProgressIndicator())
: Column(
children: [
Container(
margin: EdgeInsets.only(bottom: 15, top: 5),
decoration: BoxDecoration(
color: Color.fromRGBO(53, 56, 63, 1),
borderRadius:
BorderRadius.all(Radius.circular(25))),
borderRadius: BorderRadius.all(
Radius.circular(25))),
padding: EdgeInsets.only(
bottom: 15, top: 15, left: 20),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.only(right: 5, top: 2),
padding:
EdgeInsets.only(right: 5, top: 2),
child: Icon(
Icons.calendar_month,
color: Theme.of(context).accentColor,
color:
Theme.of(context).accentColor,
size: 20,
),
),
......@@ -1060,14 +1022,16 @@ class _MyHomePageState extends State<MyHomePage> {
letterSpacing: 0.6,
fontSize: 21,
fontWeight: FontWeight.w500,
color: Theme.of(context).accentColor),
color: Theme.of(context)
.accentColor),
),
Text(
displayDate(),
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w400,
color: Theme.of(context).accentColor),
color: Theme.of(context)
.accentColor),
),
],
),
......@@ -1077,8 +1041,8 @@ class _MyHomePageState extends State<MyHomePage> {
padding: EdgeInsets.only(bottom: 15),
decoration: BoxDecoration(
color: Color.fromRGBO(53, 56, 63, 1),
borderRadius:
BorderRadius.all(Radius.circular(25))),
borderRadius: BorderRadius.all(
Radius.circular(25))),
child: Column(
children: [
Container(
......@@ -1089,11 +1053,12 @@ class _MyHomePageState extends State<MyHomePage> {
CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.only(right: 8),
padding:
EdgeInsets.only(right: 8),
child: Icon(
WeatherIcons.cloudy,
color:
Theme.of(context).accentColor,
color: Theme.of(context)
.accentColor,
size: 18,
),
),
......@@ -1110,7 +1075,8 @@ class _MyHomePageState extends State<MyHomePage> {
),
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
crossAxisAlignment:
CrossAxisAlignment.end,
children: [
SizedBox(
width: 20,
......@@ -1125,7 +1091,8 @@ class _MyHomePageState extends State<MyHomePage> {
Container(
padding: EdgeInsets.only(top: 7, bottom: 7),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: _collapse,
......@@ -1141,7 +1108,8 @@ class _MyHomePageState extends State<MyHomePage> {
),
),
style: ButtonStyle(
backgroundColor: MaterialStatePropertyAll(
backgroundColor:
MaterialStatePropertyAll(
Color.fromRGBO(13, 108, 114, 1),
),
shape: MaterialStateProperty.all<
......@@ -1156,15 +1124,17 @@ class _MyHomePageState extends State<MyHomePage> {
],
),
),
if (_availableDatesForTrip != null && _isCollapsed)
if (_availableDatesForTrip != null &&
_isCollapsed)
Container(
decoration: BoxDecoration(
color: Color.fromRGBO(53, 56, 63, 1),
borderRadius:
BorderRadius.all(Radius.circular(25))),
borderRadius: BorderRadius.all(
Radius.circular(25))),
padding: EdgeInsets.only(
top: 15, left: 20, bottom: 15),
margin: EdgeInsets.only(top: 10, bottom: 10),
margin:
EdgeInsets.only(top: 10, bottom: 10),
child: Column(
children: [
Row(
......@@ -1172,12 +1142,13 @@ class _MyHomePageState extends State<MyHomePage> {
CrossAxisAlignment.start,
children: [
Container(
padding:
EdgeInsets.only(right: 5, top: 2),
padding: EdgeInsets.only(
right: 5, top: 2),
child: Icon(
Icons.access_time_filled_outlined,
color:
Theme.of(context).accentColor,
Icons
.access_time_filled_outlined,
color: Theme.of(context)
.accentColor,
size: 20,
),
),
......@@ -1208,12 +1179,12 @@ class _MyHomePageState extends State<MyHomePage> {
CrossAxisAlignment.start,
children: [
Container(
padding:
EdgeInsets.only(right: 5, top: 2),
padding: EdgeInsets.only(
right: 5, top: 2),
child: Icon(
Icons.directions_car_rounded,
color:
Theme.of(context).accentColor,
color: Theme.of(context)
.accentColor,
size: 20,
),
),
......@@ -1244,12 +1215,12 @@ class _MyHomePageState extends State<MyHomePage> {
CrossAxisAlignment.start,
children: [
Container(
padding:
EdgeInsets.only(right: 5, top: 2),
padding: EdgeInsets.only(
right: 5, top: 2),
child: Icon(
Icons.date_range,
color:
Theme.of(context).accentColor,
color: Theme.of(context)
.accentColor,
size: 20,
),
),
......@@ -1275,14 +1246,16 @@ class _MyHomePageState extends State<MyHomePage> {
],
),
),
if (_availableDatesForTrip != null && _isCollapsed)
if (_availableDatesForTrip != null &&
_isCollapsed)
Container(
margin: EdgeInsets.only(top: 10),
padding: EdgeInsets.only(left: 5, top: 10),
padding:
EdgeInsets.only(left: 5, top: 10),
decoration: BoxDecoration(
color: Color.fromRGBO(53, 56, 63, 1),
borderRadius:
BorderRadius.all(Radius.circular(25))),
borderRadius: BorderRadius.all(
Radius.circular(25))),
child: Column(
children: [
Row(children: [
......@@ -1294,7 +1267,8 @@ class _MyHomePageState extends State<MyHomePage> {
left: 15),
child: Icon(
Icons.event_available,
color: Theme.of(context).accentColor,
color: Theme.of(context)
.accentColor,
size: 24,
),
),
......@@ -1337,7 +1311,8 @@ class _MyHomePageState extends State<MyHomePage> {
style: TextStyle(
letterSpacing: 0.6,
fontSize: 20,
fontWeight: FontWeight.w400,
fontWeight:
FontWeight.w400,
color: Theme.of(context)
.accentColor),
),
......
// // ignore_for_file: import_of_legacy_library_into_null_safe
// import 'package:flutter_polyline_points/flutter_polyline_points.dart';
// 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) {
// // Get route information
// final data = Map<String, dynamic>.from(map['routes'][0]);
// // Bounds
// final northeast = data['bounds']['northeast'];
// final southwest = data['bounds']['southwest'];
// final bounds = LatLngBounds(
// northeast: LatLng(northeast['lat'], northeast['lng']),
// 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,
// );
// }
// }
// ignore_for_file: file_names
// // import 'package:google_maps_flutter/google_maps_flutter.dart';
// import '../config/config.dart';
// import 'package:latlong/latlong.dart' as latlng;
// import 'package:http/http.dart' as http;
// class DirectionsRepo {
// Config config = Config();
// latlng.LatLng origin;
// latlng.LatLng destination;
// DirectionsRepo(this.origin, this.destination);
// Future<http.Response> getDirections() async {
// var originlat = origin.latitude;
// var originlon = origin.longitude;
// var destlat = destination.latitude;
// var destlon = destination.longitude;
// final response = await http.get(
// Uri.parse(
// 'https://api.openrouteservice.org/v2/directions/driving-car?api_key=${config.OSM_API}&start=$originlon,$originlat&end=$destlon,$destlat',
// ),
// );
// // Check if response is successful
// return response;
// }
// }
......@@ -28,7 +28,7 @@ class _GetStreetNumberState extends State<GetStreetNumber> {
);
var jsonData = jsonDecode(response.body);
suggestions = [];
for (int i = 0; i < jsonData['predictions'][i].length; i++) {
for (int i = 0; i < jsonData['predictions'].length; i++) {
suggestions.add(jsonData['predictions'][i]['description'].toString());
}
return suggestions;
......
......@@ -27,7 +27,7 @@ class _ReturnDestinationState extends State<ReturnDestination> {
);
var jsonData = jsonDecode(response.body);
suggestions = [];
for (int i = 0; i < jsonData['predictions'][i].length; i++) {
for (int i = 0; i < jsonData['predictions'].length; i++) {
suggestions.add(jsonData['predictions'][i]['description'].toString());
}
return suggestions;
......
......@@ -27,7 +27,7 @@ class _ReturnOriginState extends State<ReturnOrigin> {
);
var jsonData = jsonDecode(response.body);
suggestions = [];
for (int i = 0; i < jsonData['predictions'][i].length; i++) {
for (int i = 0; i < jsonData['predictions'].length; i++) {
suggestions.add(jsonData['predictions'][i]['description'].toString());
}
return suggestions;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment