Skip to content

Commit

Permalink
feat: WikiDataFetcher with Queries and Fixes in Loading errors in Tou…
Browse files Browse the repository at this point in the history
…r Builder
  • Loading branch information
AritraBiswas9788 committed Jul 16, 2024
1 parent f08be2a commit 6c7c467
Show file tree
Hide file tree
Showing 32 changed files with 1,413 additions and 147 deletions.
Binary file added assets/lottie/loading_failed.lottie
Binary file not shown.
Binary file added assets/lottie/loading_places.lottie
Binary file not shown.
Binary file added assets/lottie/loadingspinner.lottie
Binary file not shown.
Binary file added assets/place_icons/archaeology.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/place_icons/castle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/place_icons/chapel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/place_icons/gate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/place_icons/obelisk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/place_icons/shrine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/place_icons/sights.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/place_icons/strategy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/place_icons/temple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/place_icons/tombstone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion lib/components/galaxy_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class GalaxyButton extends StatelessWidget {
] : [
Icon(icon,size: 45,color: Colors.white,),
Text(actionText,style: const TextStyle(color: Colors.white,fontWeight: FontWeight.w400,fontSize: 25),),

],
),
),
Expand Down
111 changes: 98 additions & 13 deletions lib/components/location_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:lottie/lottie.dart';
import 'package:super_liquid_galaxy_controller/components/galaxytextfield.dart';
import 'package:super_liquid_galaxy_controller/data_class/coordinate.dart';
import 'package:super_liquid_galaxy_controller/data_class/country_data.dart';
Expand Down Expand Up @@ -34,6 +35,8 @@ class _LocationSelectorState extends State<LocationSelector> {
late String selectedCountry;
late String selectedState;

var isLoading = false;


@override
void initState() {
Expand Down Expand Up @@ -61,7 +64,7 @@ class _LocationSelectorState extends State<LocationSelector> {
builder: (context) {
return StatefulBuilder(
builder: (BuildContext context,
StateSetter setModalState) {
StateSetter setModalState){
return SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(
Expand Down Expand Up @@ -106,6 +109,9 @@ class _LocationSelectorState extends State<LocationSelector> {
var country = dataList[index];
return InkWell(
onTap: () {
setState(() {
isLoading = true;
});
Get.back(result: country);
},
child: Padding(
Expand Down Expand Up @@ -210,6 +216,9 @@ class _LocationSelectorState extends State<LocationSelector> {
StateData sta = dataList[index];
return InkWell(
onTap: () {
setState(() {
isLoading = true;
});
Get.back(result: sta);
},
child: Padding(
Expand Down Expand Up @@ -248,9 +257,15 @@ class _LocationSelectorState extends State<LocationSelector> {
isScrollControlled: true);
if (stateData == null) {
selectedState = "";
setState(() {
isLoading = true;
});
setLabelFromName();
return;
}
setState(() {
isLoading = true;
});
selectedState = stateData.name!;
setLabelFromName();
/*List<CountryData> dataList = await getResponse();
Expand All @@ -268,14 +283,31 @@ class _LocationSelectorState extends State<LocationSelector> {
InkWell(
borderRadius: BorderRadius.circular(20.0),
onTap: () async {

Coordinates coordinate = await Get.to(()=> LocationPicker());
setLabelFromPoint(coordinate);
},
child: ImageIcon(
const AssetImage(Assets.iconsPlaceMarker),
color: Colors.white,
size: widget.iconSize ?? 65.0,
child: Stack(
children:[ Visibility(
visible: !isLoading,
child: ImageIcon(
const AssetImage(Assets.iconsPlaceMarker),
color: Colors.white,
size: widget.iconSize ?? 65.0,
),
),

Visibility(
visible: isLoading,
child: Lottie.asset(
Assets.lottieLoadingspinner,
decoder: customDecoder,
repeat: true,
width: widget.iconSize ?? 65.0,
height: widget.iconSize ?? 65.0
),
),

]
),
),
Container(
Expand Down Expand Up @@ -324,6 +356,11 @@ class _LocationSelectorState extends State<LocationSelector> {
}

void setLabelFromPoint(Coordinates point) async {
setState(() {
isLoading = true;
});
widget.tourController.isLoading.value = true;
widget.tourController.isError.value = false;
var out = await placemarkFromCoordinates(point.latitude, point.longitude);
print(out);

Expand All @@ -347,9 +384,14 @@ class _LocationSelectorState extends State<LocationSelector> {
selectedState = likelyPoint.administrativeArea!;
setState(() {
label = "$selectedCountry \n$selectedState";
isLoading = false;
print("point3");

});
}
else {
widget.tourController.isError.value = true;
widget.tourController.isLoading.value = false;
if (!Get.isSnackbarOpen) {
Get.showSnackbar(GetSnackBar(
backgroundColor: Colors.red.shade300,
Expand All @@ -360,30 +402,73 @@ class _LocationSelectorState extends State<LocationSelector> {
));
}
}
setState(() {
isLoading = false;
print("point2");

});
widget.submitData(point,label);
}


void setLabelFromName() async {
setState(() {
label = "$selectedCountry \n$selectedState";
widget.tourController.label.value = "$selectedCountry \n$selectedState";
isLoading=false;
print("point1");
});
var out = await locationFromAddress("$selectedState,$selectedCountry");
print(out);
if (out.isNotEmpty) {
widget.submitData(
Coordinates(latitude: out[0].latitude, longitude: out[0].longitude), label);
try {
widget.tourController.isLoading.value = true;
widget.tourController.isError.value = false;
var out = await locationFromAddress("$selectedState,$selectedCountry").timeout(Duration(seconds: 10), onTimeout: (){
throw Exception("Location fetch timeout...");
});
print(out);
if (out.isNotEmpty) {
print(out);
widget.submitData(
Coordinates(latitude: out[0].latitude, longitude: out[0].longitude), label);
}
else {
print("object");
widget.tourController.isError.value = true;
widget.tourController.isLoading.value = false;
if (!Get.isSnackbarOpen) {
Get.showSnackbar(GetSnackBar(
backgroundColor: Colors.red.shade300,
title: "Location Error",
message: "Could not Geocode area",
isDismissible: true,
duration: 3.seconds,
));
}
}
}
else {
catch(e)
{
print("here");
widget.tourController.isError.value = true;
widget.tourController.isLoading.value = false;
if (!Get.isSnackbarOpen) {
Get.showSnackbar(GetSnackBar(
backgroundColor: Colors.red.shade300,
title: "Location Error",
message: "Could not geocode area",
message: "Could not Geocode area. Error: $e",
isDismissible: true,
duration: 3.seconds,
));
}
}


}

Future<LottieComposition?> customDecoder(List<int> bytes) {
return LottieComposition.decodeZip(bytes, filePicker: (files) {
return files.firstWhere(
(f) => f.name.startsWith('animations/') && f.name.endsWith('.json'),
);
});
}
}
5 changes: 5 additions & 0 deletions lib/data_class/coordinate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class Coordinates {
longitude %= 360.0;
}

mp.LatLng toLatLngMap(Coordinates point)
{
return mp.LatLng(point.latitude, point.longitude);
}

// Override toString for better debugging output
@override
String toString() {
Expand Down
18 changes: 13 additions & 5 deletions lib/data_class/map_position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import 'package:super_liquid_galaxy_controller/data_class/coordinate.dart';
import 'package:super_liquid_galaxy_controller/data_class/look_at.dart';

class MapPosition {
double latitude;
double longitude;
double bearing;
double tilt;
double zoom;
late double latitude;
late double longitude;
late double bearing;
late double tilt;
late double zoom;

MapPosition({
required this.latitude,
Expand All @@ -19,6 +19,14 @@ class MapPosition {
required this.zoom,
});

MapPosition.fromCameraPosition(CameraPosition cameraPosition) {
latitude = cameraPosition.target.latitude;
longitude = cameraPosition.target.longitude;
bearing = cameraPosition.bearing;
tilt = cameraPosition.tilt;
zoom = 591657550.500000 / pow(2, cameraPosition.zoom);
}

// Override toString for better debugging output
@override
String toString() {
Expand Down
25 changes: 25 additions & 0 deletions lib/data_class/place_info.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'coordinate.dart';

class PlaceInfo {
Coordinates coordinate;
String label;
String address;
String category;
String name;

String? wikiMediaTag;
String? wikipediaLang;
String? wikipediaTitle;

PlaceInfo({
required this.coordinate,
required this.label,
required this.address,
required this.category,
required this.name
});
@override
String toString() {
return 'coordinate: ${coordinate} , name: $label, name: $name, desc : $address ';
}
}
15 changes: 15 additions & 0 deletions lib/data_class/place_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,27 @@ class Historic {

class WikiAndMedia {
String? image;
String? wikidata;
String? wikipedia;
String? wikiTitle;
String? wikiLang;

WikiAndMedia({this.image});

WikiAndMedia.fromJson(Map<String, dynamic> json) {
if(json["image"] is String)
this.image = json["image"];
if(json['wikidata'] is String)
this.wikidata = json["wikidata"];
if(json['wikipedia'] is String)
this.wikipedia = json["wikipedia"];

if(wikipedia != null)
{
wikiTitle = wikipedia!.substring(wikipedia!.lastIndexOf(':'));
wikiLang = wikipedia!.substring(0, wikipedia!.indexOf(':'));
}

}

Map<String, dynamic> toJson() {
Expand Down
Loading

0 comments on commit 6c7c467

Please sign in to comment.