add map page

This commit is contained in:
shahriaarrr committed 2025-12-13 10:48:17 +03:30
1 parent 97777d0898
commit fdb080372f
8 files changed
+739 -7

No files matched your search

+5
View File
@@ -1,4 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:label="mashhad_metro"
android:name="${applicationName}"
+4 -6
View File
@@ -4,6 +4,7 @@ import 'package:mashhad_metro/pages/LineDetail.dart';
import 'package:mashhad_metro/providers/station_provider.dart';
import 'package:mashhad_metro/models/station_model.dart';
import 'package:mashhad_metro/widgets/line_card.dart';
import 'package:mashhad_metro/pages/map.dart';
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
@@ -288,12 +289,9 @@ class MyHomePage extends ConsumerWidget {
subtitle: 'MAP',
onTap: () {
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('این صفحه بزودی اضافه میشود'),
behavior: SnackBarBehavior.floating,
),
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const MapPage()),
);
},
),
+422
View File
@@ -0,0 +1,422 @@
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:geolocator/geolocator.dart';
import 'package:latlong2/latlong.dart';
import 'package:mashhad_metro/models/station_model.dart';
import 'package:mashhad_metro/pages/station_details.dart';
import 'package:mashhad_metro/providers/station_provider.dart';
class MapPage extends ConsumerStatefulWidget {
const MapPage({super.key});
@override
ConsumerState<ConsumerStatefulWidget> createState() => _MapPageState();
}
class _MapPageState extends ConsumerState<MapPage> {
final MapController _mapController = MapController();
Position? _currentPosition;
bool _isLoadingLocation = false;
@override
void initState() {
super.initState();
}
Future<void> _getCurrentLocation() async {
setState(() {
_isLoadingLocation = true;
});
try {
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('لطفاً GPS را فعال کنید'),
behavior: SnackBarBehavior.floating,
),
);
}
return;
}
LocationPermission permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('دسترسی به موقعیت مکانی رد شد'),
behavior: SnackBarBehavior.floating,
),
);
}
return;
}
}
if (permission == LocationPermission.deniedForever) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
'لطفاً دسترسی موقعیت مکانی را از تنظیمات فعال کنید',
),
behavior: SnackBarBehavior.floating,
),
);
}
return;
}
Position position = await Geolocator.getCurrentPosition();
setState(() {
_currentPosition = position;
});
_mapController.move(LatLng(position.latitude, position.longitude), 15.0);
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('خطا در دریافت موقعیت: $e'),
behavior: SnackBarBehavior.floating,
),
);
}
} finally {
setState(() {
_isLoadingLocation = false;
});
}
}
@override
Widget build(BuildContext context) {
final stationsAsync = ref.watch(allStationsProvider);
return Scaffold(
backgroundColor: const Color(0xFF1A1A1A),
appBar: AppBar(
backgroundColor: const Color(0xFF2D2D2D),
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.arrow_back_ios_new, color: Colors.white),
onPressed: () => Navigator.pop(context),
),
title: const Column(
children: [
Text(
'نقشه ایستگاه‌ها',
style: TextStyle(
color: Colors.white,
fontSize: 19,
fontWeight: FontWeight.bold,
),
),
Text(
'STATIONS MAP',
style: TextStyle(
color: Colors.white70,
fontSize: 12,
letterSpacing: 1.2,
),
),
],
),
centerTitle: true,
),
body: stationsAsync.when(
data: (stations) {
return Stack(
children: [
FlutterMap(
mapController: _mapController,
options: MapOptions(
initialCenter: const LatLng(36.2974, 59.6059),
initialZoom: 15.0,
minZoom: 10.0,
maxZoom: 18.0,
),
children: [
TileLayer(
urlTemplate:
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'ir.shahriaarrr.mashhad_metro',
),
MarkerLayer(markers: _buildStationMarkers(stations)),
if (_currentPosition != null)
MarkerLayer(
markers: [
Marker(
point: LatLng(
_currentPosition!.latitude,
_currentPosition!.longitude,
),
width: 40,
height: 40,
child: Container(
decoration: BoxDecoration(
color: Colors.blue.shade500,
shape: BoxShape.circle,
border: Border.all(color: Colors.white, width: 3),
boxShadow: [
BoxShadow(
color: Colors.blue.withOpacity(0.5),
blurRadius: 10,
spreadRadius: 3,
),
],
),
child: const Icon(
Icons.my_location,
color: Colors.white,
size: 20,
),
),
),
],
),
],
),
Positioned(
bottom: 20,
right: 20,
child: FloatingActionButton(
onPressed: _isLoadingLocation ? null : _getCurrentLocation,
backgroundColor: Colors.white,
child: _isLoadingLocation
? const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
strokeWidth: 2,
color: Colors.deepPurple,
),
)
: Icon(
Icons.my_location,
color: Colors.deepPurple.shade700,
),
),
),
],
);
},
loading: () =>
const Center(child: CircularProgressIndicator(color: Colors.white)),
error: (error, _) => Center(
child: Text(
'خطا در بارگذاری اطلاعات',
style: TextStyle(color: Colors.white),
),
),
),
);
}
List<Marker> _buildStationMarkers(List<StationModel> stations) {
return stations
.map((station) {
final lat = double.tryParse(station.latitude);
final lng = double.tryParse(station.longitude);
if (lat == null || lng == null) return null;
final hasMultipleLines = station.lines.length > 1;
final primaryColor = _parseColor(
station.colors.isNotEmpty ? station.colors.first : '#87CEEB',
);
return Marker(
point: LatLng(lat, lng),
width: hasMultipleLines ? 50 : 40,
height: hasMultipleLines ? 50 : 40,
child: GestureDetector(
onTap: () {
_showStationBottomSheet(station);
},
child: Stack(
children: [
Container(
decoration: BoxDecoration(
color: primaryColor,
shape: BoxShape.circle,
border: Border.all(color: Colors.white, width: 3),
boxShadow: [
BoxShadow(
color: primaryColor.withOpacity(0.5),
blurRadius: 8,
spreadRadius: 2,
),
],
),
child: Center(
child: Icon(
Icons.subway,
color: Colors.white,
size: hasMultipleLines ? 24 : 20,
),
),
),
if (hasMultipleLines && station.lines.length > 1)
Positioned(
right: 0,
top: 0,
child: Container(
width: 16,
height: 16,
decoration: BoxDecoration(
color: _getSecondLineColor(station),
shape: BoxShape.circle,
border: Border.all(color: Colors.white, width: 2),
),
child: Center(
child: Text(
'${station.lines.length}',
style: const TextStyle(
color: Colors.white,
fontSize: 8,
fontWeight: FontWeight.bold,
),
),
),
),
),
],
),
),
);
})
.whereType<Marker>()
.toList();
}
void _showStationBottomSheet(StationModel station) {
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (context) => Container(
decoration: const BoxDecoration(
color: Color(0xFF2D2D2D),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
),
padding: const EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
station.translations['fa'] ?? station.name,
style: const TextStyle(
color: Colors.white,
fontSize: 22,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.right,
),
const SizedBox(height: 4),
Text(
station.name.toUpperCase(),
style: TextStyle(
color: Colors.white.withOpacity(0.7),
fontSize: 16,
fontWeight: FontWeight.bold,
letterSpacing: 0.8,
),
textAlign: TextAlign.right,
),
const SizedBox(height: 16),
Wrap(
spacing: 8,
runSpacing: 8,
alignment: WrapAlignment.end,
children: station.lines.map((lineNum) {
final color = _parseColor(
station.colors.isNotEmpty ? station.colors.first : '#87CEEB',
);
return Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 6,
),
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(12),
),
child: Text(
'خط $lineNum',
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
);
}).toList(),
),
const SizedBox(height: 16),
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: () {
Navigator.pop(context);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
StationDetail(stationName: station.name),
),
);
},
icon: const Icon(Icons.info_outline),
label: const Text(
'مشاهده جزئیات ایستگاه',
style: TextStyle(fontSize: 19, fontWeight: FontWeight.bold),
),
style: ElevatedButton.styleFrom(
backgroundColor: _parseColor(
station.colors.isNotEmpty
? station.colors.first
: '#87CEEB',
),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
),
],
),
),
);
}
Color _parseColor(String colorString) {
try {
return Color(int.parse(colorString.replaceFirst('#', '0xFF')));
} catch (e) {
return Colors.blue;
}
}
Color _getSecondLineColor(StationModel station) {
if (station.lines.length < 2) return Colors.grey;
return Colors.orange;
}
}
@@ -5,6 +5,12 @@
import FlutterMacOS
import Foundation
import geolocator_apple
import package_info_plus
import path_provider_foundation
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
}
+294 -1
View File
@@ -225,6 +225,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.0+7.7.0"
dart_earcut:
dependency: transitive
description:
name: dart_earcut
sha256: e485001bfc05dcbc437d7bfb666316182e3522d4c3f9668048e004d0eb2ce43b
url: "https://pub.dev"
source: hosted
version: "1.2.0"
dart_polylabel2:
dependency: transitive
description:
name: dart_polylabel2
sha256: "7eeab15ce72894e4bdba6a8765712231fc81be0bd95247de4ad9966abc57adc6"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
dart_style:
dependency: transitive
description:
@@ -233,6 +249,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.1.1"
dbus:
dependency: transitive
description:
name: dbus
sha256: "79e0c23480ff85dc68de79e2cd6334add97e48f7f4865d17686dd6ea81a47e8c"
url: "https://pub.dev"
source: hosted
version: "0.7.11"
fake_async:
dependency: transitive
description:
@@ -241,6 +265,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.3"
ffi:
dependency: transitive
description:
name: ffi
sha256: "289279317b4b16eb2bb7e271abccd4bf84ec9bdcbe999e278a94b804f5630418"
url: "https://pub.dev"
source: hosted
version: "2.1.4"
file:
dependency: transitive
description:
@@ -270,6 +302,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.0.0"
flutter_map:
dependency: "direct main"
description:
name: flutter_map
sha256: "391e7dc95cc3f5190748210a69d4cfeb5d8f84dcdfa9c3235d0a9d7742ccb3f8"
url: "https://pub.dev"
source: hosted
version: "8.2.2"
flutter_riverpod:
dependency: "direct main"
description:
@@ -283,6 +323,11 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
freezed_annotation:
dependency: transitive
description:
@@ -299,6 +344,70 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.0"
geoclue:
dependency: transitive
description:
name: geoclue
sha256: c2a998c77474fc57aa00c6baa2928e58f4b267649057a1c76738656e9dbd2a7f
url: "https://pub.dev"
source: hosted
version: "0.1.1"
geolocator:
dependency: "direct main"
description:
name: geolocator
sha256: "79939537046c9025be47ec645f35c8090ecadb6fe98eba146a0d25e8c1357516"
url: "https://pub.dev"
source: hosted
version: "14.0.2"
geolocator_android:
dependency: transitive
description:
name: geolocator_android
sha256: "179c3cb66dfa674fc9ccbf2be872a02658724d1c067634e2c427cf6df7df901a"
url: "https://pub.dev"
source: hosted
version: "5.0.2"
geolocator_apple:
dependency: transitive
description:
name: geolocator_apple
sha256: dbdd8789d5aaf14cf69f74d4925ad1336b4433a6efdf2fce91e8955dc921bf22
url: "https://pub.dev"
source: hosted
version: "2.3.13"
geolocator_linux:
dependency: transitive
description:
name: geolocator_linux
sha256: c4e966f0a7a87e70049eac7a2617f9e16fd4c585a26e4330bdfc3a71e6a721f3
url: "https://pub.dev"
source: hosted
version: "0.2.3"
geolocator_platform_interface:
dependency: transitive
description:
name: geolocator_platform_interface
sha256: "30cb64f0b9adcc0fb36f628b4ebf4f731a2961a0ebd849f4b56200205056fe67"
url: "https://pub.dev"
source: hosted
version: "4.2.6"
geolocator_web:
dependency: transitive
description:
name: geolocator_web
sha256: b1ae9bdfd90f861fde8fd4f209c37b953d65e92823cb73c7dee1fa021b06f172
url: "https://pub.dev"
source: hosted
version: "4.1.3"
geolocator_windows:
dependency: transitive
description:
name: geolocator_windows
sha256: "175435404d20278ffd220de83c2ca293b73db95eafbdc8131fe8609be1421eb6"
url: "https://pub.dev"
source: hosted
version: "0.2.5"
glob:
dependency: transitive
description:
@@ -315,6 +424,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.3.2"
gsettings:
dependency: transitive
description:
name: gsettings
sha256: "1b0ce661f5436d2db1e51f3c4295a49849f03d304003a7ba177d01e3a858249c"
url: "https://pub.dev"
source: hosted
version: "0.2.8"
hotreloader:
dependency: transitive
description:
@@ -347,6 +464,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.1.2"
intl:
dependency: transitive
description:
name: intl
sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5"
url: "https://pub.dev"
source: hosted
version: "0.20.2"
io:
dependency: transitive
description:
@@ -371,6 +496,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.9.0"
latlong2:
dependency: "direct main"
description:
name: latlong2
sha256: "98227922caf49e6056f91b6c56945ea1c7b166f28ffcd5fb8e72fc0b453cc8fe"
url: "https://pub.dev"
source: hosted
version: "0.9.1"
leak_tracker:
dependency: transitive
description:
@@ -403,6 +536,22 @@ 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"
logger:
dependency: transitive
description:
name: logger
sha256: a7967e31b703831a893bbc3c3dd11db08126fe5f369b5c648a36f821979f5be3
url: "https://pub.dev"
source: hosted
version: "2.6.2"
logging:
dependency: transitive
description:
@@ -435,6 +584,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:
@@ -451,6 +608,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.2.0"
package_info_plus:
dependency: transitive
description:
name: package_info_plus
sha256: "16eee997588c60225bda0488b6dcfac69280a6b7a3cf02c741895dd370a02968"
url: "https://pub.dev"
source: hosted
version: "8.3.1"
package_info_plus_platform_interface:
dependency: transitive
description:
name: package_info_plus_platform_interface
sha256: "202a487f08836a592a6bd4f901ac69b3a8f146af552bbd14407b6b41e1c3f086"
url: "https://pub.dev"
source: hosted
version: "3.2.1"
path:
dependency: transitive
description:
@@ -459,6 +632,78 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.1"
path_provider:
dependency: transitive
description:
name: path_provider
sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd"
url: "https://pub.dev"
source: hosted
version: "2.1.5"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
sha256: f2c65e21139ce2c3dad46922be8272bb5963516045659e71bb16e151c93b580e
url: "https://pub.dev"
source: hosted
version: "2.2.22"
path_provider_foundation:
dependency: transitive
description:
name: path_provider_foundation
sha256: "6d13aece7b3f5c5a9731eaf553ff9dcbc2eff41087fd2df587fd0fed9a3eb0c4"
url: "https://pub.dev"
source: hosted
version: "2.5.1"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279
url: "https://pub.dev"
source: hosted
version: "2.2.1"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7
url: "https://pub.dev"
source: hosted
version: "2.3.0"
petitparser:
dependency: transitive
description:
name: petitparser
sha256: "1a97266a94f7350d30ae522c0af07890c70b8e62c71e8e3920d1db4d23c057d1"
url: "https://pub.dev"
source: hosted
version: "7.0.1"
platform:
dependency: transitive
description:
name: platform
sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984"
url: "https://pub.dev"
source: hosted
version: "3.1.6"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
url: "https://pub.dev"
source: hosted
version: "2.1.8"
pool:
dependency: transitive
description:
@@ -467,6 +712,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.5.2"
proj4dart:
dependency: transitive
description:
name: proj4dart
sha256: c8a659ac9b6864aa47c171e78d41bbe6f5e1d7bd790a5814249e6b68bc44324e
url: "https://pub.dev"
source: hosted
version: "2.1.0"
pub_semver:
dependency: transitive
description:
@@ -640,6 +893,14 @@ 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"
uuid:
dependency: transitive
description:
@@ -696,6 +957,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.3"
win32:
dependency: transitive
description:
name: win32
sha256: d7cb55e04cd34096cd3a79b3330245f54cb96a370a1c27adb3c84b917de8b08e
url: "https://pub.dev"
source: hosted
version: "5.15.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:
name: xdg_directories
sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
xml:
dependency: transitive
description:
name: xml
sha256: "971043b3a0d3da28727e40ed3e0b5d18b742fa5a68665cca88e74b7876d5e025"
url: "https://pub.dev"
source: hosted
version: "6.6.1"
yaml:
dependency: transitive
description:
@@ -706,4 +999,4 @@ packages:
version: "3.1.3"
sdks:
dart: ">=3.9.2 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
flutter: ">=3.35.0"
+4
View File
@@ -33,10 +33,14 @@ dependencies:
flutter_riverpod: ^2.4.9
riverpod_annotation: ^2.3.3
flutter_map: ^8.2.2
geolocator: ^14.0.2
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.8
latlong2: ^0.9.1
dev_dependencies:
flutter_test:
@@ -6,6 +6,9 @@
#include "generated_plugin_registrant.h"
#include <geolocator_windows/geolocator_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
GeolocatorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("GeolocatorWindows"));
}
+1
View File
@@ -3,6 +3,7 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
geolocator_windows
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST