feat: adding map screen and launch to google maps

This commit is contained in:
pahmiudahgede 2025-05-24 11:02:04 +07:00
parent c214fdaa8a
commit ce514d0a27
10 changed files with 257 additions and 1 deletions

View File

@ -43,5 +43,10 @@
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="google.navigation" />
<category android:name="android.intent.category.DEFAULT" />
</intent>
</queries>
</manifest>

View File

@ -1,9 +1,11 @@
import 'package:rijig_mobile/core/utils/exportimportview.dart';
import 'package:rijig_mobile/features/home/presentation/screen/collector/pickup_history_screen.dart';
import 'package:rijig_mobile/features/pickup/presentation/screen/pickup_map_screen.dart';
final router = GoRouter(
routes: [
GoRoute(path: '/', builder: (context, state) => SplashScreen()),
// GoRoute(path: '/', builder: (context, state) => SplashScreen()),
GoRoute(path: '/', builder: (context, state) => CollectorRouteMapScreen()),
GoRoute(
path: '/onboarding',
builder: (context, state) => OnboardingPageScreen(),

View File

@ -0,0 +1,91 @@
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:rijig_mobile/core/utils/guide.dart';
import 'package:url_launcher/url_launcher.dart';
class CollectorRouteMapScreen extends StatefulWidget {
const CollectorRouteMapScreen({super.key});
@override
State<CollectorRouteMapScreen> createState() =>
_CollectorRouteMapScreenState();
}
class _CollectorRouteMapScreenState extends State<CollectorRouteMapScreen> {
final LatLng userLocation = LatLng(-7.250445, 112.768845);
final LatLng collectorLocation = LatLng(-7.260445, 112.758845);
Future<void> openMapWithGoogle(double latitude, double longitude) async {
final url =
'https://www.google.com/maps/dir/?api=1&destination=$latitude,$longitude';
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
await launchUrl(uri, mode: LaunchMode.externalApplication);
} else {
debugPrint("tidak dapat membuka google maps");
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Peta Lokasi"),
backgroundColor: Colors.green,
foregroundColor: Colors.white,
),
body: Stack(
children: [
FlutterMap(
options: MapOptions(initialCenter: userLocation, initialZoom: 13),
children: [
TileLayer(
urlTemplate: "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
),
MarkerLayer(
markers: [
Marker(
point: userLocation,
child: Icon(Icons.location_on, color: redColor, size: 36),
),
Marker(
point: collectorLocation,
child: Icon(Icons.store, color: primaryColor, size: 36),
),
],
),
PolylineLayer(
polylines: [
Polyline(
points: [userLocation, collectorLocation],
strokeWidth: 4,
color: Colors.orange,
),
],
),
],
),
Positioned(
bottom: 20,
left: 20,
right: 20,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
padding: PaddingCustom().paddingVertical(14),
),
onPressed:
() => openMapWithGoogle(
collectorLocation.latitude,
collectorLocation.longitude,
),
child: const Text("Buka di Google Maps"),
),
),
],
),
);
}
}

View File

@ -8,6 +8,7 @@
#include <file_selector_linux/file_selector_plugin.h>
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
@ -16,4 +17,7 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_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);
}

View File

@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
flutter_secure_storage_linux
url_launcher_linux
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST

View File

@ -11,6 +11,7 @@ import file_selector_macos
import flutter_secure_storage_macos
import path_provider_foundation
import shared_preferences_foundation
import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
@ -19,4 +20,5 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}

View File

@ -137,6 +137,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.1"
dart_earcut:
dependency: transitive
description:
name: dart_earcut
sha256: e485001bfc05dcbc437d7bfb666316182e3522d4c3f9668048e004d0eb2ce43b
url: "https://pub.dev"
source: hosted
version: "1.2.0"
dbus:
dependency: transitive
description:
@ -278,6 +286,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.0.0"
flutter_map:
dependency: "direct main"
description:
name: flutter_map
sha256: f7d0379477274f323c3f3bc12d369a2b42eb86d1e7bd2970ae1ea3cff782449a
url: "https://pub.dev"
source: hosted
version: "8.1.1"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
@ -536,6 +552,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
latlong2:
dependency: "direct main"
description:
name: latlong2
sha256: "98227922caf49e6056f91b6c56945ea1c7b166f28ffcd5fb8e72fc0b453cc8fe"
url: "https://pub.dev"
source: hosted
version: "0.9.1"
leak_tracker:
dependency: transitive
description:
@ -568,6 +592,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.1.1"
lists:
dependency: transitive
description:
name: lists
sha256: "4ca5c19ae4350de036a7e996cdd1ee39c93ac0a2b840f4915459b7d0a7d4ab27"
url: "https://pub.dev"
source: hosted
version: "1.0.1"
localstorage:
dependency: "direct main"
description:
@ -576,6 +608,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.0.0"
logger:
dependency: transitive
description:
name: logger
sha256: be4b23575aac7ebf01f225a241eb7f6b5641eeaf43c6a8613510fc2f8cf187d1
url: "https://pub.dev"
source: hosted
version: "2.5.0"
logging:
dependency: transitive
description:
@ -608,6 +648,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.16.0"
mgrs_dart:
dependency: transitive
description:
name: mgrs_dart
sha256: fb89ae62f05fa0bb90f70c31fc870bcbcfd516c843fb554452ab3396f78586f7
url: "https://pub.dev"
source: hosted
version: "2.0.0"
mime:
dependency: transitive
description:
@ -736,6 +784,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.8"
polylabel:
dependency: transitive
description:
name: polylabel
sha256: "41b9099afb2aa6c1730bdd8a0fab1400d287694ec7615dd8516935fa3144214b"
url: "https://pub.dev"
source: hosted
version: "1.0.1"
posix:
dependency: transitive
description:
@ -744,6 +800,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.0.2"
proj4dart:
dependency: transitive
description:
name: proj4dart
sha256: c8a659ac9b6864aa47c171e78d41bbe6f5e1d7bd790a5814249e6b68bc44324e
url: "https://pub.dev"
source: hosted
version: "2.1.0"
provider:
dependency: "direct main"
description:
@ -901,6 +965,78 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.4.0"
unicode:
dependency: transitive
description:
name: unicode
sha256: "0f69e46593d65245774d4f17125c6084d2c20b4e473a983f6e21b7d7762218f1"
url: "https://pub.dev"
source: hosted
version: "0.3.1"
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: "8582d7f6fe14d2652b4c45c9b6c14c0b678c2af2d083a11b604caeba51930d79"
url: "https://pub.dev"
source: hosted
version: "6.3.16"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
sha256: "7f2022359d4c099eea7df3fdf739f7d3d3b9faf3166fb1dd390775176e0b76cb"
url: "https://pub.dev"
source: hosted
version: "6.3.3"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: "4e9ba368772369e3e08f231d2301b4ef72b9ff87c31192ef471b380ef29a4935"
url: "https://pub.dev"
source: hosted
version: "3.2.1"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
sha256: "17ba2000b847f334f16626a574c702b196723af2a289e7a93ffcb79acff855c2"
url: "https://pub.dev"
source: hosted
version: "3.2.2"
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: "4bd2b7b4dc4d4d0b94e5babfffbca8eac1a126c7f3d6ecbc1a11013faa3abba2"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: "3284b6d2ac454cf34f114e1d3319866fdd1e19cdc329999057e44ffe936cfa77"
url: "https://pub.dev"
source: hosted
version: "3.1.4"
uuid:
dependency: "direct main"
description:
@ -973,6 +1109,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.0"
wkt_parser:
dependency: transitive
description:
name: wkt_parser
sha256: "8a555fc60de3116c00aad67891bcab20f81a958e4219cc106e3c037aa3937f13"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
xdg_directories:
dependency: transitive
description:

View File

@ -21,6 +21,7 @@ dependencies:
flutter_carousel_widget: ^3.1.0
flutter_dotenv: ^5.2.1
flutter_launcher_icons: ^0.14.3
flutter_map: ^8.1.1
flutter_screenutil: ^5.9.3
flutter_secure_storage: ^9.2.4
flutter_svg: ^2.1.0
@ -36,6 +37,7 @@ dependencies:
image_picker: ^1.1.2
intl: ^0.20.2
jwt_decoder: ^2.0.1
latlong2: ^0.9.1
localstorage: ^6.0.0
path_provider: ^2.1.5
pin_code_fields: ^8.0.1
@ -44,6 +46,7 @@ dependencies:
shimmer: ^3.0.0
smooth_page_indicator: ^1.2.1
toastification: ^3.0.2
url_launcher: ^6.3.1
uuid: ^4.5.1
dev_dependencies:

View File

@ -9,6 +9,7 @@
#include <connectivity_plus/connectivity_plus_windows_plugin.h>
#include <file_selector_windows/file_selector_windows.h>
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
@ -17,4 +18,6 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FileSelectorWindows"));
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}

View File

@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus
file_selector_windows
flutter_secure_storage_windows
url_launcher_windows
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST