From 2e1b25264a385ef07f8f40c897b8ed830ddde1c8 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 11 Nov 2024 14:48:23 +0100 Subject: [PATCH 1/6] add mapbox --- covas_mobile/images/marker.png | Bin 0 -> 11120 bytes covas_mobile/lib/pages/ItemMenu.dart | 19 +- covas_mobile/lib/pages/MapboxPages.dart | 142 +++++++++++ .../flutter/generated_plugin_registrant.cc | 4 + .../linux/flutter/generated_plugins.cmake | 1 + .../Flutter/GeneratedPluginRegistrant.swift | 2 + covas_mobile/pubspec.lock | 236 ++++++++++++++---- covas_mobile/pubspec.yaml | 3 + .../flutter/generated_plugin_registrant.cc | 3 + .../windows/flutter/generated_plugins.cmake | 1 + 10 files changed, 355 insertions(+), 56 deletions(-) create mode 100644 covas_mobile/images/marker.png create mode 100644 covas_mobile/lib/pages/MapboxPages.dart diff --git a/covas_mobile/images/marker.png b/covas_mobile/images/marker.png new file mode 100644 index 0000000000000000000000000000000000000000..fa91bb4dbb2aace52e7d9ffea2305ebe1d0e63bf GIT binary patch literal 11120 zcmd6N`9GB3`~N*N#=c}AT>JA}*LCh>8>@3Hi~@`h1hJT!oVA4@B>0Mi z=xM>9pOGJagFlEc+jD22x?!PZ@IZUj{M=cH3jdV8uE+u-48bOjVGzW`3I8IXf+9XJ zNEdEuX+$?eLyJane776E13{vY>DkkEk^lafzL}Z5=)SnQuJk5&)DW^SDr1Ybmijoi1nkxv_ZiUdX&yV;|2e zHgP5zWC%UYKOTwi3Bk-^O1m%PblKSNvy4Y{P9GfDSbG?p)u-iksg5 zzx9z3yKXFMUsvw^9b1iaB;2N`%f;5VFV(v+459_fDY+g7BEi2OQ+Ifj_&THJCqzdd zS}8AAi#kH$+=n#!3J+Ts5$~{jgd)l!(v236%;%?m>85mIdanj|ac}|M#KVo}c`vWaXOhrp{n z+@B!o=ON$Ws^^nCifD0J26Vw1JV_cPuHgO0DoRIEje>M~GwYi@5t+Vw#WASS$oCWK zgn-Snai@Yk_NzSU<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%K!PM849qc zwEsIF1{?dQSUa-a^!l`vK3B=OTt_>+DC5W_;z3?wxJ7X5W=wCsgzYmx zP@V=R7>_RN##Yq;Om_yr0StG{8N5W}gCy`AGPhsc|j4sYz(7`rP zns$0h6kt6MN|d(H=+}XlAAnTZLT$K*9Q#ENDNO(y#U;w1Y+qUe5}<*&M2}u+>by(7 zCVO0;9vMXHeGbv$$1F<_Z7Ris7I*i5D|!&!thnA#*+XX7U<{4CK8o|ZK^gjnumWxi z$!{?ev`MYXFw6a8XB^5Z9IQ}50!=V&(Pgd!LjUm`tX1i$V%h%7DA<;b9|SN+##)Kk zpuhWtx0^_P*B~j7bHM+6tD*27#lPbptU?0Oy39h#F0dm%NW^lYAELETMd`CnFyXPX z3l_GNKfh*atcdHd*fNh^F*!qbdu@-w4|C|!Ou?P!z3VdYQ z!4Nl~bk_aTT2Qjr8JHE2{m7HD>SH2VK!KTQ#}D8c_k?is?KN~~KP4!mZ(Rc3@Jt$e z-F(U0xmhclRwo8H&T?9zRk5jeCFTg9cbl_jutlG2MskdN6T>o)u45qB>I15b?FHmE zN=UZ=^rR2mq>J0K^o8K^LC>o z4H2-+HSypfsM5*?UL@g_Y|4L=JMY0sjShCkrmWJxe&|b=*hKkbNKp2Gkwex&r&p$XIQGFH(gM1(ISc!E zRWJsNV?LZw8uj=K9s%4~;nI(-@apfu_XpQ#mQv#`!J1NNj3mkr@k?*cnE>^;dwH{_57Koz?&>tWpOSR8@dB*I}(yaiBbJ9EInW$&Rt+ zU76q23ZBgWOHD<%^MqI0>J1h+$FM`ZYTdsK-7)A?HhuA^i@vO&fiseCGAfx$-K0eP k-+HI>?>na9T~s#&fik=5C{Gj6y4AL0z?V*mgE literal 0 HcmV?d00001 diff --git a/covas_mobile/lib/pages/ItemMenu.dart b/covas_mobile/lib/pages/ItemMenu.dart index d14cea6..9540e96 100644 --- a/covas_mobile/lib/pages/ItemMenu.dart +++ b/covas_mobile/lib/pages/ItemMenu.dart @@ -17,6 +17,7 @@ import '../classes/events.dart'; import 'ListItemMenu.dart'; import 'ListItemByTags.dart'; +import 'MapboxPages.dart'; import 'ListItemByOrganizers.dart'; void main() { @@ -105,8 +106,7 @@ class _ItemMenuState extends State with ShowErrorDialog { stderr.writeln('Username : ${responseGet.body}'); var events = jsonDecode(utf8.decode(responseGet.bodyBytes)); formerName = events["name"]; - formerMap = - "${events["place"]} - ${events["zip_code"]} ${events["city"]} - ${events["country"]}"; + formerMap = "${events["place"]}"; formerDesc = events["description"]; formerTags = List.from(events['tags'] as List); formerOrga = List.from(events['organizers'] as List); @@ -240,10 +240,17 @@ class _ItemMenuState extends State with ShowErrorDialog { ]), Row(children: [ Flexible( - child: Text("${place}", - style: TextStyle(fontSize: 15.0), - maxLines: 3, - overflow: TextOverflow.ellipsis)) + child: InkWell( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (_) => Mapboxpages(title: '$place'))); + }, + child: Text("${place}", + style: TextStyle(fontSize: 15.0), + maxLines: 3, + overflow: TextOverflow.ellipsis))) ]), Row(children: [ Icon(Icons.group), diff --git a/covas_mobile/lib/pages/MapboxPages.dart b/covas_mobile/lib/pages/MapboxPages.dart new file mode 100644 index 0000000..b5741a3 --- /dev/null +++ b/covas_mobile/lib/pages/MapboxPages.dart @@ -0,0 +1,142 @@ +import 'dart:convert'; +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:http/http.dart' as http; +import 'package:mapbox_gl/mapbox_gl.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; // Import dotenv + +import '../classes/alert.dart'; // Assuming this contains your error dialog code. +import '../classes/events.dart'; // Your Event class, assuming you are using it. +import '../variable/globals.dart' as globals; + +void main() async { + await dotenv.load(fileName: ".env"); // Load .env file + runApp(const MyApp()); +} + +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Demo', + theme: ThemeData( + primarySwatch: Colors.blue, + ), + home: const Mapboxpages(title: 'Event Location'), + ); + } +} + +class Mapboxpages extends StatefulWidget { + const Mapboxpages({Key? key, required this.title}) : super(key: key); + + final String title; + + @override + State createState() => _MapboxpagesState(); +} + +class _MapboxpagesState extends State with ShowErrorDialog { + late String mapboxAccessToken; + late MapboxMapController mapController; + double longitude = 0.0; + double latitude = 0.0; + bool isLoading = true; + + @override + void initState() { + super.initState(); + _initToken(); + } + + // Load the Mapbox access token from the .env file + void _initToken() async { + mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? ''; + if (mapboxAccessToken.isEmpty) { + showErrorDialog(context, "Mapbox Access Token is not available."); + return; + } + + // Fetch event location using the title (address or name) + await _fetchEventLocation(); + + // Set the state after fetching coordinates + } + + // Fetch location coordinates using the event title + Future _fetchEventLocation() async { + if (widget.title.isNotEmpty && mapboxAccessToken.isNotEmpty) { + final geocodeUrl = Uri.parse( + 'https://api.mapbox.com/geocoding/v5/mapbox.places/${Uri.encodeComponent(widget.title)}.json?access_token=$mapboxAccessToken', + ); + + final geocodeResponse = await http.get(geocodeUrl); + + if (geocodeResponse.statusCode == 200) { + final geocodeData = json.decode(geocodeResponse.body); + if (geocodeData['features'].isNotEmpty) { + final coordinates = + geocodeData['features'][0]['geometry']['coordinates']; + longitude = coordinates[0]; // Longitude + latitude = coordinates[1]; // Latitude + setState(() { + isLoading = false; + }); + } + } else { + showErrorDialog(context, "Failed to fetch location data."); + } + } + } + + // Called when the map is created + void _onMapCreated(MapboxMapController controller) { + mapController = controller; + + // Log the map controller and coordinates + print("Mapbox controller initialized: $mapController"); + print("lat - long : $latitude - $longitude"); + + // Check if the mapController is really initialized + if (mapController != null) { + try { + // Check if symbol options are correctly set + final symbolOptions = SymbolOptions( + geometry: LatLng(latitude, longitude), + iconImage: "marker-15", // Make sure this icon exists in your assets + ); + + // Debugging symbol options + print("Adding symbol with options: $symbolOptions"); + + mapController.addSymbol(symbolOptions); + } catch (e) { + // Handle any exception that occurs when adding the symbol + print("Error when adding symbol: $e"); + } + } else { + print( + "Error: MapboxMapController is null at the time of symbol addition"); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: Text(widget.title)), + body: isLoading + ? Center(child: CircularProgressIndicator()) + : MapboxMap( + accessToken: mapboxAccessToken, // Your Mapbox API key + onMapCreated: _onMapCreated, + initialCameraPosition: CameraPosition( + target: LatLng(latitude, longitude), + zoom: 14.0, + ), + ), + ); + } +} diff --git a/covas_mobile/linux/flutter/generated_plugin_registrant.cc b/covas_mobile/linux/flutter/generated_plugin_registrant.cc index 64a0ece..7299b5c 100644 --- a/covas_mobile/linux/flutter/generated_plugin_registrant.cc +++ b/covas_mobile/linux/flutter/generated_plugin_registrant.cc @@ -7,9 +7,13 @@ #include "generated_plugin_registrant.h" #include +#include void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) file_selector_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin"); file_selector_plugin_register_with_registrar(file_selector_linux_registrar); + g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); + url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); } diff --git a/covas_mobile/linux/flutter/generated_plugins.cmake b/covas_mobile/linux/flutter/generated_plugins.cmake index 2db3c22..786ff5c 100644 --- a/covas_mobile/linux/flutter/generated_plugins.cmake +++ b/covas_mobile/linux/flutter/generated_plugins.cmake @@ -4,6 +4,7 @@ list(APPEND FLUTTER_PLUGIN_LIST file_selector_linux + url_launcher_linux ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/covas_mobile/macos/Flutter/GeneratedPluginRegistrant.swift b/covas_mobile/macos/Flutter/GeneratedPluginRegistrant.swift index 53d8e6c..32ef7bb 100644 --- a/covas_mobile/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/covas_mobile/macos/Flutter/GeneratedPluginRegistrant.swift @@ -9,10 +9,12 @@ import file_selector_macos import geolocator_apple import path_provider_foundation import shared_preferences_foundation +import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) + UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) } diff --git a/covas_mobile/pubspec.lock b/covas_mobile/pubspec.lock index 9bad8b5..2f313c7 100644 --- a/covas_mobile/pubspec.lock +++ b/covas_mobile/pubspec.lock @@ -1,6 +1,14 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + sha256: cb6a278ef2dbb298455e1a713bda08524a175630ec643a242c399c932a0a1f7d + url: "https://pub.dev" + source: hosted + version: "3.6.1" async: dependency: transitive description: @@ -29,18 +37,18 @@ packages: dependency: transitive description: name: camera_android_camerax - sha256: "8bd9cab67551642eb33ceb33ece7acc0890014fc90ddfae637c7e2b683657e65" + sha256: e3627fdc2132d89212b8a8676679f5b07008c7e3d8ae00cea775c3397f9e742b url: "https://pub.dev" source: hosted - version: "0.6.7+2" + version: "0.6.10" camera_avfoundation: dependency: transitive description: name: camera_avfoundation - sha256: "7c28969a975a7eb2349bc2cb2dfe3ad218a33dba9968ecfb181ce08c87486655" + sha256: "2e4c568f70e406ccb87376bc06b53d2f5bebaab71e2fbcc1a950e31449381bcf" url: "https://pub.dev" source: hosted - version: "0.9.17+3" + version: "0.9.17+5" camera_platform_interface: dependency: transitive description: @@ -117,18 +125,18 @@ packages: dependency: transitive description: name: dio - sha256: e17f6b3097b8c51b72c74c9f071a605c47bcc8893839bd66732457a5ebe73714 + sha256: "5598aa796bbf4699afd5c67c0f5f6e2ed542afc956884b9cd58c306966efc260" url: "https://pub.dev" source: hosted - version: "5.5.0+1" + version: "5.7.0" dio_web_adapter: dependency: transitive description: name: dio_web_adapter - sha256: "36c5b2d79eb17cdae41e974b7a8284fec631651d2a6f39a8a2ff22327e90aeac" + sha256: "33259a9276d6cea88774a0000cfae0d861003497755969c92faa223108620dc8" url: "https://pub.dev" source: hosted - version: "1.0.1" + version: "2.0.0" fake_async: dependency: transitive description: @@ -141,34 +149,34 @@ packages: dependency: transitive description: name: ffi - sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21" + sha256: "16ed7b077ef01ad6170a3d0c57caa4a112a38d7a2ed5602e0aca9ca6f3d98da6" url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.3" file: dependency: transitive description: name: file - sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4 url: "https://pub.dev" source: hosted - version: "7.0.0" + version: "7.0.1" file_selector_linux: dependency: transitive description: name: file_selector_linux - sha256: "045d372bf19b02aeb69cacf8b4009555fb5f6f0b7ad8016e5f46dd1387ddd492" + sha256: "712ce7fab537ba532c8febdb1a8f167b32441e74acd68c3ccb2e36dcb52c4ab2" url: "https://pub.dev" source: hosted - version: "0.9.2+1" + version: "0.9.3" file_selector_macos: dependency: transitive description: name: file_selector_macos - sha256: f42eacb83b318e183b1ae24eead1373ab1334084404c8c16e0354f9a3e55d385 + sha256: "271ab9986df0c135d45c3cdb6bd0faa5db6f4976d3e4b437cf7d0f258d941bfc" url: "https://pub.dev" source: hosted - version: "0.9.4" + version: "0.9.4+2" file_selector_platform_interface: dependency: transitive description: @@ -181,10 +189,10 @@ packages: dependency: transitive description: name: file_selector_windows - sha256: "2ad726953f6e8affbc4df8dc78b77c3b4a060967a291e528ef72ae846c60fb69" + sha256: "8f5d2f6590d51ecd9179ba39c64f722edc15226cc93dcc8698466ad36a4a85a4" url: "https://pub.dev" source: hosted - version: "0.9.3+2" + version: "0.9.3+3" fixnum: dependency: transitive description: @@ -202,10 +210,10 @@ packages: dependency: "direct main" description: name: flutter_dotenv - sha256: "9357883bdd153ab78cbf9ffa07656e336b8bbb2b5a3ca596b0b27e119f7c7d77" + sha256: b7c7be5cd9f6ef7a78429cabd2774d3c4af50e79cb2b7593e3d5d763ef95c61b url: "https://pub.dev" source: hosted - version: "5.1.0" + version: "5.2.1" flutter_gemini: dependency: "direct main" description: @@ -226,10 +234,10 @@ packages: dependency: transitive description: name: flutter_plugin_android_lifecycle - sha256: "9d98bd47ef9d34e803d438f17fd32b116d31009f534a6fa5ce3a1167f189a6de" + sha256: "9b78450b89f059e96c9ebb355fa6b3df1d6b330436e0b885fb49594c41721398" url: "https://pub.dev" source: hosted - version: "2.0.21" + version: "2.0.23" flutter_test: dependency: "direct dev" description: flutter @@ -312,6 +320,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" + image: + dependency: transitive + description: + name: image + sha256: "8e9d133755c3e84c73288363e6343157c383a0c6c56fc51afcc5d4d7180306d6" + url: "https://pub.dev" + source: hosted + version: "3.3.0" image_picker: dependency: "direct main" description: @@ -324,26 +340,26 @@ packages: dependency: transitive description: name: image_picker_android - sha256: c0e72ecd170b00a5590bb71238d57dc8ad22ee14c60c6b0d1a4e05cafbc5db4b + sha256: "8faba09ba361d4b246dc0a17cb4289b3324c2b9f6db7b3d457ee69106a86bd32" url: "https://pub.dev" source: hosted - version: "0.8.12+11" + version: "0.8.12+17" image_picker_for_web: dependency: transitive description: name: image_picker_for_web - sha256: "65d94623e15372c5c51bebbcb820848d7bcb323836e12dfdba60b5d3a8b39e50" + sha256: "717eb042ab08c40767684327be06a5d8dbb341fe791d514e4b92c7bbe1b7bb83" url: "https://pub.dev" source: hosted - version: "3.0.5" + version: "3.0.6" image_picker_ios: dependency: transitive description: name: image_picker_ios - sha256: "6703696ad49f5c3c8356d576d7ace84d1faf459afb07accbb0fae780753ff447" + sha256: "4f0568120c6fcc0aaa04511cb9f9f4d29fc3d0139884b1d06be88dcec7641d6b" url: "https://pub.dev" source: hosted - version: "0.8.12" + version: "0.8.12+1" image_picker_linux: dependency: transitive description: @@ -384,6 +400,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.19.0" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" json_annotation: dependency: transitive description: @@ -424,6 +448,38 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.0" + mapbox_gl: + dependency: "direct main" + description: + name: mapbox_gl + sha256: d78907338ff232e3cf6c1d6dba45e6a8814069496fd352e49bb1967d498f09af + url: "https://pub.dev" + source: hosted + version: "0.16.0" + mapbox_gl_dart: + dependency: transitive + description: + name: mapbox_gl_dart + sha256: de6d03718e5eb05c9eb1ddaae7f0383b28acb5afa16405e1deed7ff04dd34f3d + url: "https://pub.dev" + source: hosted + version: "0.2.1" + mapbox_gl_platform_interface: + dependency: transitive + description: + name: mapbox_gl_platform_interface + sha256: b7c1490b022e650afd20412bdf8ae45a1897118b7ce6049ef6c42df09193d4b2 + url: "https://pub.dev" + source: hosted + version: "0.16.0" + mapbox_gl_web: + dependency: transitive + description: + name: mapbox_gl_web + sha256: e77113bf95a4f321ff44938232517e0f2725aae991f0b283af1afaa7e7a58aca + url: "https://pub.dev" + source: hosted + version: "0.16.0" matcher: dependency: transitive description: @@ -452,10 +508,10 @@ packages: dependency: transitive description: name: mime - sha256: "2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2" + sha256: "801fd0b26f14a4a58ccb09d5892c3fbdeff209594300a542492cf13fba9d247a" url: "https://pub.dev" source: hosted - version: "1.0.5" + version: "1.0.6" path: dependency: "direct main" description: @@ -468,18 +524,18 @@ packages: dependency: "direct main" description: name: path_provider - sha256: fec0d61223fba3154d87759e3cc27fe2c8dc498f6386c6d6fc80d1afdd1bf378 + sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd" url: "https://pub.dev" source: hosted - version: "2.1.4" + version: "2.1.5" path_provider_android: dependency: transitive description: name: path_provider_android - sha256: "490539678396d4c3c0b06efdaab75ae60675c3e0c66f72bc04c2e2c1e0e2abeb" + sha256: c464428172cb986b758c6d1724c603097febb8fb855aa265aeecc9280c294d4a url: "https://pub.dev" source: hosted - version: "2.2.9" + version: "2.2.12" path_provider_foundation: dependency: transitive description: @@ -560,14 +616,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.1" + petitparser: + dependency: transitive + description: + name: petitparser + sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27 + url: "https://pub.dev" + source: hosted + version: "6.0.2" platform: dependency: transitive description: name: platform - sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65" + sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984" url: "https://pub.dev" source: hosted - version: "3.1.5" + version: "3.1.6" plugin_platform_interface: dependency: transitive description: @@ -580,26 +644,26 @@ packages: dependency: "direct main" description: name: shared_preferences - sha256: c272f9cabca5a81adc9b0894381e9c1def363e980f960fa903c604c471b22f68 + sha256: "95f9997ca1fb9799d494d0cb2a780fd7be075818d59f00c43832ed112b158a82" url: "https://pub.dev" source: hosted - version: "2.3.1" + version: "2.3.3" shared_preferences_android: dependency: transitive description: name: shared_preferences_android - sha256: a7e8467e9181cef109f601e3f65765685786c1a738a83d7fbbde377589c0d974 + sha256: "3b9febd815c9ca29c9e3520d50ec32f49157711e143b7a4ca039eb87e8ade5ab" url: "https://pub.dev" source: hosted - version: "2.3.1" + version: "2.3.3" shared_preferences_foundation: dependency: transitive description: name: shared_preferences_foundation - sha256: "776786cff96324851b656777648f36ac772d88bc4c669acff97b7fce5de3c849" + sha256: "07e050c7cd39bad516f8d64c455f04508d09df104be326d8c02551590a0d513d" url: "https://pub.dev" source: hosted - version: "2.5.1" + version: "2.5.3" shared_preferences_linux: dependency: transitive description: @@ -713,10 +777,74 @@ packages: dependency: transitive description: name: typed_data - sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 url: "https://pub.dev" source: hosted - version: "1.3.2" + version: "1.4.0" + url_launcher: + dependency: "direct main" + description: + name: url_launcher + sha256: "9d06212b1362abc2f0f0d78e6f09f726608c74e3b9462e8368bb03314aa8d603" + url: "https://pub.dev" + source: hosted + version: "6.3.1" + url_launcher_android: + dependency: transitive + description: + name: url_launcher_android + sha256: "6fc2f56536ee873eeb867ad176ae15f304ccccc357848b351f6f0d8d4a40d193" + url: "https://pub.dev" + source: hosted + version: "6.3.14" + url_launcher_ios: + dependency: transitive + description: + name: url_launcher_ios + sha256: e43b677296fadce447e987a2f519dcf5f6d1e527dc35d01ffab4fff5b8a7063e + url: "https://pub.dev" + source: hosted + version: "6.3.1" + url_launcher_linux: + dependency: transitive + description: + name: url_launcher_linux + sha256: e2b9622b4007f97f504cd64c0128309dfb978ae66adbe944125ed9e1750f06af + url: "https://pub.dev" + source: hosted + version: "3.2.0" + url_launcher_macos: + dependency: transitive + description: + name: url_launcher_macos + sha256: "769549c999acdb42b8bcfa7c43d72bf79a382ca7441ab18a808e101149daf672" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + url_launcher_platform_interface: + dependency: transitive + description: + name: url_launcher_platform_interface + sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029" + url: "https://pub.dev" + source: hosted + version: "2.3.2" + url_launcher_web: + dependency: transitive + description: + name: url_launcher_web + sha256: "772638d3b34c779ede05ba3d38af34657a05ac55b06279ea6edd409e323dca8e" + url: "https://pub.dev" + source: hosted + version: "2.3.3" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + sha256: "44cf3aabcedde30f2dba119a9dea3b0f2672fbe6fa96e85536251d678216b3c4" + url: "https://pub.dev" + source: hosted + version: "3.1.3" uuid: dependency: transitive description: @@ -745,18 +873,26 @@ packages: dependency: transitive description: name: web - sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062 + sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb url: "https://pub.dev" source: hosted - version: "1.0.0" + version: "1.1.0" xdg_directories: dependency: transitive description: name: xdg_directories - sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d + sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15" url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "1.1.0" + xml: + dependency: transitive + description: + name: xml + sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 + url: "https://pub.dev" + source: hosted + version: "6.5.0" sdks: - dart: ">=3.4.0 <4.0.0" - flutter: ">=3.22.0" + dart: ">=3.5.0 <4.0.0" + flutter: ">=3.24.0" diff --git a/covas_mobile/pubspec.yaml b/covas_mobile/pubspec.yaml index 6bf13bd..d418a0d 100644 --- a/covas_mobile/pubspec.yaml +++ b/covas_mobile/pubspec.yaml @@ -48,6 +48,8 @@ dependencies: textfield_tags: ^3.0.1 geolocator: ^13.0.1 permission_handler: ^11.3.1 + url_launcher: ^6.3.1 + mapbox_gl: ^0.16.0 dev_dependencies: flutter_test: @@ -76,6 +78,7 @@ flutter: - images/flutter.png - .env - images/search.png + - images/marker.png # - images/a_dot_ham.jpeg # An image asset can refer to one or more resolution-specific "variants", see diff --git a/covas_mobile/windows/flutter/generated_plugin_registrant.cc b/covas_mobile/windows/flutter/generated_plugin_registrant.cc index 921279f..b2cbd25 100644 --- a/covas_mobile/windows/flutter/generated_plugin_registrant.cc +++ b/covas_mobile/windows/flutter/generated_plugin_registrant.cc @@ -9,6 +9,7 @@ #include #include #include +#include void RegisterPlugins(flutter::PluginRegistry* registry) { FileSelectorWindowsRegisterWithRegistrar( @@ -17,4 +18,6 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { registry->GetRegistrarForPlugin("GeolocatorWindows")); PermissionHandlerWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); + UrlLauncherWindowsRegisterWithRegistrar( + registry->GetRegistrarForPlugin("UrlLauncherWindows")); } diff --git a/covas_mobile/windows/flutter/generated_plugins.cmake b/covas_mobile/windows/flutter/generated_plugins.cmake index 71dd257..92c9a0d 100644 --- a/covas_mobile/windows/flutter/generated_plugins.cmake +++ b/covas_mobile/windows/flutter/generated_plugins.cmake @@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST file_selector_windows geolocator_windows permission_handler_windows + url_launcher_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST From be8b0d3b66e4b55b1fd2a1e016a24b84e2afb5e2 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 13 Nov 2024 23:47:40 +0100 Subject: [PATCH 2/6] add marker --- covas_mobile/lib/pages/MapboxPages.dart | 46 ++++++++++++++++++------- covas_mobile/pubspec.lock | 8 ++--- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/covas_mobile/lib/pages/MapboxPages.dart b/covas_mobile/lib/pages/MapboxPages.dart index b5741a3..bfa8049 100644 --- a/covas_mobile/lib/pages/MapboxPages.dart +++ b/covas_mobile/lib/pages/MapboxPages.dart @@ -1,6 +1,7 @@ import 'dart:convert'; +import 'dart:typed_data'; import 'dart:io'; - +import 'package:flutter/services.dart'; // For loading assets import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import 'package:mapbox_gl/mapbox_gl.dart'; @@ -41,7 +42,7 @@ class Mapboxpages extends StatefulWidget { class _MapboxpagesState extends State with ShowErrorDialog { late String mapboxAccessToken; - late MapboxMapController mapController; + MapboxMapController? mapController; // Mark mapController as nullable double longitude = 0.0; double latitude = 0.0; bool isLoading = true; @@ -62,8 +63,6 @@ class _MapboxpagesState extends State with ShowErrorDialog { // Fetch event location using the title (address or name) await _fetchEventLocation(); - - // Set the state after fetching coordinates } // Fetch location coordinates using the event title @@ -80,11 +79,14 @@ class _MapboxpagesState extends State with ShowErrorDialog { if (geocodeData['features'].isNotEmpty) { final coordinates = geocodeData['features'][0]['geometry']['coordinates']; + print("geodate : ${geocodeData['features'][0]}"); longitude = coordinates[0]; // Longitude latitude = coordinates[1]; // Latitude setState(() { isLoading = false; }); + } else { + showErrorDialog(context, "Location not found."); } } else { showErrorDialog(context, "Failed to fetch location data."); @@ -92,8 +94,14 @@ class _MapboxpagesState extends State with ShowErrorDialog { } } + // Load image from assets as Uint8List + Future _loadMarkerImage() async { + final ByteData data = await rootBundle.load('images/marker.png'); + return data.buffer.asUint8List(); + } + // Called when the map is created - void _onMapCreated(MapboxMapController controller) { + void _onMapCreated(MapboxMapController controller) async { mapController = controller; // Log the map controller and coordinates @@ -103,16 +111,28 @@ class _MapboxpagesState extends State with ShowErrorDialog { // Check if the mapController is really initialized if (mapController != null) { try { - // Check if symbol options are correctly set - final symbolOptions = SymbolOptions( - geometry: LatLng(latitude, longitude), - iconImage: "marker-15", // Make sure this icon exists in your assets - ); + // Ensure the coordinates are valid + if (latitude != 0.0 && longitude != 0.0) { + // Load marker image as Uint8List + final markerImage = await _loadMarkerImage(); - // Debugging symbol options - print("Adding symbol with options: $symbolOptions"); + // Register the image with Mapbox + await mapController!.addImage("custom-marker", markerImage); - mapController.addSymbol(symbolOptions); + final symbolOptions = SymbolOptions( + geometry: LatLng(latitude, longitude), + iconImage: "custom-marker", // Use the registered custom marker + iconSize: 0.5, // Optional: Adjust size + ); + + // Debugging symbol options + print("Adding symbol with options: $symbolOptions"); + + // Add symbol to map + mapController!.addSymbol(symbolOptions); + } else { + print("Error: Invalid coordinates, cannot add symbol."); + } } catch (e) { // Handle any exception that occurs when adding the symbol print("Error when adding symbol: $e"); diff --git a/covas_mobile/pubspec.lock b/covas_mobile/pubspec.lock index 2f313c7..8440d75 100644 --- a/covas_mobile/pubspec.lock +++ b/covas_mobile/pubspec.lock @@ -165,10 +165,10 @@ packages: dependency: transitive description: name: file_selector_linux - sha256: "712ce7fab537ba532c8febdb1a8f167b32441e74acd68c3ccb2e36dcb52c4ab2" + sha256: b2b91daf8a68ecfa4a01b778a6f52edef9b14ecd506e771488ea0f2e0784198b url: "https://pub.dev" source: hosted - version: "0.9.3" + version: "0.9.3+1" file_selector_macos: dependency: transitive description: @@ -809,10 +809,10 @@ packages: dependency: transitive description: name: url_launcher_linux - sha256: e2b9622b4007f97f504cd64c0128309dfb978ae66adbe944125ed9e1750f06af + sha256: "4e9ba368772369e3e08f231d2301b4ef72b9ff87c31192ef471b380ef29a4935" url: "https://pub.dev" source: hosted - version: "3.2.0" + version: "3.2.1" url_launcher_macos: dependency: transitive description: From 7182e0e3244a45b2de3246cc3454a0c1c84e3125 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Fri, 15 Nov 2024 22:48:05 +0100 Subject: [PATCH 3/6] fix add marker style --- covas_mobile/lib/pages/MapboxPages.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/covas_mobile/lib/pages/MapboxPages.dart b/covas_mobile/lib/pages/MapboxPages.dart index bfa8049..edb56dc 100644 --- a/covas_mobile/lib/pages/MapboxPages.dart +++ b/covas_mobile/lib/pages/MapboxPages.dart @@ -42,7 +42,7 @@ class Mapboxpages extends StatefulWidget { class _MapboxpagesState extends State with ShowErrorDialog { late String mapboxAccessToken; - MapboxMapController? mapController; // Mark mapController as nullable + late MapboxMapController mapController; // Mark mapController as nullable double longitude = 0.0; double latitude = 0.0; bool isLoading = true; @@ -100,10 +100,12 @@ class _MapboxpagesState extends State with ShowErrorDialog { return data.buffer.asUint8List(); } - // Called when the map is created - void _onMapCreated(MapboxMapController controller) async { + void _onMapCreated(MapboxMapController controller) { mapController = controller; + } + // Called when the map is created + void _onStyleLoaded() async { // Log the map controller and coordinates print("Mapbox controller initialized: $mapController"); print("lat - long : $latitude - $longitude"); @@ -152,6 +154,7 @@ class _MapboxpagesState extends State with ShowErrorDialog { : MapboxMap( accessToken: mapboxAccessToken, // Your Mapbox API key onMapCreated: _onMapCreated, + onStyleLoadedCallback: _onStyleLoaded, initialCameraPosition: CameraPosition( target: LatLng(latitude, longitude), zoom: 14.0, From 74e55f3d6bfa8c962d9bd4324a3d49fdd4e1bbb3 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Fri, 15 Nov 2024 23:22:17 +0100 Subject: [PATCH 4/6] get lati long from backend --- covas_mobile/lib/classes/events.dart | 10 ++- covas_mobile/lib/pages/ItemMenu.dart | 5 +- covas_mobile/lib/pages/MapboxPages.dart | 94 +++++++++++++++++-------- 3 files changed, 72 insertions(+), 37 deletions(-) diff --git a/covas_mobile/lib/classes/events.dart b/covas_mobile/lib/classes/events.dart index d908a58..5879a30 100644 --- a/covas_mobile/lib/classes/events.dart +++ b/covas_mobile/lib/classes/events.dart @@ -5,9 +5,8 @@ class Events { String? startDate; String? endDate; String? description; - String? zipCode; - String? city; - String? country; + double? latitude; + double? longitude; Events({this.place, this.id, this.name, this.startDate}); @@ -18,8 +17,7 @@ class Events { startDate = json["start_date"]; endDate = json['end_date']; description = json['description']; - zipCode = json["zip_code"]; - city = json['city']; - country = json['country']; + latitude = json['latitude']; + longitude = json['longitude']; } } diff --git a/covas_mobile/lib/pages/ItemMenu.dart b/covas_mobile/lib/pages/ItemMenu.dart index 9540e96..82e64cf 100644 --- a/covas_mobile/lib/pages/ItemMenu.dart +++ b/covas_mobile/lib/pages/ItemMenu.dart @@ -16,7 +16,6 @@ import '../variable/globals.dart' as globals; import '../classes/events.dart'; import 'ListItemMenu.dart'; -import 'ListItemByTags.dart'; import 'MapboxPages.dart'; import 'ListItemByOrganizers.dart'; @@ -245,7 +244,9 @@ class _ItemMenuState extends State with ShowErrorDialog { Navigator.push( context, MaterialPageRoute( - builder: (_) => Mapboxpages(title: '$place'))); + builder: (_) => Mapboxpages( + title: '${widget.title}', + place: '${place}'))); }, child: Text("${place}", style: TextStyle(fontSize: 15.0), diff --git a/covas_mobile/lib/pages/MapboxPages.dart b/covas_mobile/lib/pages/MapboxPages.dart index edb56dc..fc09080 100644 --- a/covas_mobile/lib/pages/MapboxPages.dart +++ b/covas_mobile/lib/pages/MapboxPages.dart @@ -11,6 +11,8 @@ import '../classes/alert.dart'; // Assuming this contains your error dialog code import '../classes/events.dart'; // Your Event class, assuming you are using it. import '../variable/globals.dart' as globals; +import 'package:shared_preferences/shared_preferences.dart'; + void main() async { await dotenv.load(fileName: ".env"); // Load .env file runApp(const MyApp()); @@ -26,15 +28,17 @@ class MyApp extends StatelessWidget { theme: ThemeData( primarySwatch: Colors.blue, ), - home: const Mapboxpages(title: 'Event Location'), + home: const Mapboxpages(title: 'Event Location', place: "Flutter"), ); } } class Mapboxpages extends StatefulWidget { - const Mapboxpages({Key? key, required this.title}) : super(key: key); + const Mapboxpages({Key? key, required this.title, required this.place}) + : super(key: key); final String title; + final String place; @override State createState() => _MapboxpagesState(); @@ -51,46 +55,78 @@ class _MapboxpagesState extends State with ShowErrorDialog { void initState() { super.initState(); _initToken(); + _getEventInfo(); } // Load the Mapbox access token from the .env file - void _initToken() async { + void _initToken() { mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? ''; if (mapboxAccessToken.isEmpty) { showErrorDialog(context, "Mapbox Access Token is not available."); return; } - - // Fetch event location using the title (address or name) - await _fetchEventLocation(); } - // Fetch location coordinates using the event title - Future _fetchEventLocation() async { - if (widget.title.isNotEmpty && mapboxAccessToken.isNotEmpty) { - final geocodeUrl = Uri.parse( - 'https://api.mapbox.com/geocoding/v5/mapbox.places/${Uri.encodeComponent(widget.title)}.json?access_token=$mapboxAccessToken', - ); + Future _getEventInfo() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + var accessToken = prefs.getString("access_token") ?? ""; - final geocodeResponse = await http.get(geocodeUrl); + if (accessToken.isNotEmpty) { + var urlGet = Uri.parse("${globals.api}/events/${widget.title}"); - if (geocodeResponse.statusCode == 200) { - final geocodeData = json.decode(geocodeResponse.body); - if (geocodeData['features'].isNotEmpty) { - final coordinates = - geocodeData['features'][0]['geometry']['coordinates']; - print("geodate : ${geocodeData['features'][0]}"); - longitude = coordinates[0]; // Longitude - latitude = coordinates[1]; // Latitude - setState(() { - isLoading = false; - }); - } else { - showErrorDialog(context, "Location not found."); - } + var responseGet = await http.get(urlGet, + headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'}); + stderr.writeln('Response Get status: ${responseGet.statusCode}'); + if (responseGet.statusCode == 200) { + var events = jsonDecode(utf8.decode(responseGet.bodyBytes)); + latitude = events["latitude"]; + longitude = events["longitude"]; + setState(() { + isLoading = false; + }); } else { - showErrorDialog(context, "Failed to fetch location data."); + var text = ""; + switch (responseGet.statusCode) { + case 400: + { + text = "RequĂȘte mal construite"; + } + break; + case 406: + { + text = "Mot de passe incorrect"; + } + break; + case 404: + { + text = "Utilisateur inconnu"; + } + break; + case 403: + { + text = "Vous n'avez pas l'autorisation de faire cette action"; + } + break; + case 410: + { + text = "Token invalide"; + } + break; + case 500: + { + text = "Probleme interne du serveur"; + } + break; + default: + { + text = "Probleme d'authentification inconnu"; + } + break; + } + showErrorDialog(context, text); } + } else { + showErrorDialog(context, "Cache invalide"); } } @@ -148,7 +184,7 @@ class _MapboxpagesState extends State with ShowErrorDialog { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar(title: Text(widget.title)), + appBar: AppBar(title: Text(widget.place)), body: isLoading ? Center(child: CircularProgressIndicator()) : MapboxMap( From 79f457eec196d6439d47808bc64ca0d0551e27d4 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 16 Nov 2024 20:06:58 +0100 Subject: [PATCH 5/6] more precise search --- covas_mobile/lib/pages/UpdateEventImage.dart | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/covas_mobile/lib/pages/UpdateEventImage.dart b/covas_mobile/lib/pages/UpdateEventImage.dart index cd32624..44cbd09 100644 --- a/covas_mobile/lib/pages/UpdateEventImage.dart +++ b/covas_mobile/lib/pages/UpdateEventImage.dart @@ -159,14 +159,19 @@ class _UpdateeventImageState extends State try { await dotenv.load(); final mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? ''; + print("place non encoded : ${place}"); final url = - 'https://api.mapbox.com/geocoding/v5/mapbox.places/${place}.json?access_token=${mapboxAccessToken}&proximity=ip'; - final response = await http.get(Uri.parse(url)); + 'https://api.mapbox.com/geocoding/v5/mapbox.places/${place}.json?access_token=${mapboxAccessToken}&types=poi,address,place'; + var encoded = Uri.encodeFull(url); + print("encoded : ${encoded}"); + final response = await http.get(Uri.parse(encoded)); if (response.statusCode == 200) { final data = json.decode(response.body); + print("data : ${data}"); if (data['features'].isNotEmpty) { + place = data['features'][0]['place_name']; final coordinates = data['features'][0]['geometry']['coordinates']; final longitude = coordinates[0]; // Longitude final latitude = coordinates[1]; // Latitude @@ -316,15 +321,19 @@ class _UpdateeventImageState extends State final mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? ''; final url = - 'https://api.mapbox.com/geocoding/v5/mapbox.places/${input}.json?access_token=${mapboxAccessToken}&proximity=ip'; - final response = await http.get(Uri.parse(url)); + 'https://api.mapbox.com/geocoding/v5/mapbox.places/${input}.json?access_token=${mapboxAccessToken}&types=poi,address,place'; + var encoded = Uri.encodeFull(url); + final response = await http.get(Uri.parse(encoded)); + print("response code suggesttion : ${response.statusCode}"); if (response.statusCode == 200) { final data = json.decode(response.body); + print("data suggestion : ${data}"); setState(() { suggestions = (data['features'] as List) .map((feature) => { 'place_name': feature['place_name'], + 'text': feature['text'], 'geometry': feature[ 'geometry'], // Include geometry for latitude/longitude }) @@ -378,13 +387,14 @@ class _UpdateeventImageState extends State return ListTile( title: Text(suggestions[index]['place_name']), onTap: () async { + print("suggestion tapped : ${suggestions[index]}"); final latitude = suggestions[index]['geometry']['coordinates'][1]; final longitude = suggestions[index]['geometry']['coordinates'][0]; setState(() { - geographicalZone = suggestions[index]['place_name']; + geographicalZone = suggestions[index]['text']; inputGeo.text = geographicalZone; suggestions.clear(); }); From 9146fd02e4da353ee24bbef590ec7095d3c2f9ff Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 16 Nov 2024 21:35:16 +0100 Subject: [PATCH 6/6] add title - subtile in list --- covas_mobile/lib/pages/UpdateEventImage.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/covas_mobile/lib/pages/UpdateEventImage.dart b/covas_mobile/lib/pages/UpdateEventImage.dart index 44cbd09..25ac063 100644 --- a/covas_mobile/lib/pages/UpdateEventImage.dart +++ b/covas_mobile/lib/pages/UpdateEventImage.dart @@ -385,7 +385,8 @@ class _UpdateeventImageState extends State itemCount: suggestions.length, itemBuilder: (context, index) { return ListTile( - title: Text(suggestions[index]['place_name']), + title: Text(suggestions[index]['text']), + subtitle: Text(suggestions[index]['place_name']), onTap: () async { print("suggestion tapped : ${suggestions[index]}"); final latitude =