From 344fc3e1f441b2dc7e7b6cca5abe8e6deb9f107b Mon Sep 17 00:00:00 2001 From: shahriaarrr Date: Thu, 29 Oct 2026 12:00:40 +0330 Subject: [PATCH] visually distinguish disabled metro stations --- lib/pages/map.dart | 107 +++++++++++++++----------- lib/pages/station_details.dart | 42 ++++++++--- lib/widgets/stationItem.dart | 53 ++++++++++--- lib/widgets/station_status.dart | 130 ++++++++++++++++++++++++++++++++ test/station_status_test.dart | 26 +++++++ 5 files changed, 292 insertions(+), 66 deletions(-) create mode 100644 lib/widgets/station_status.dart create mode 100644 test/station_status_test.dart diff --git a/lib/pages/map.dart b/lib/pages/map.dart index 9f3c80f..c5c87e1 100644 --- a/lib/pages/map.dart +++ b/lib/pages/map.dart @@ -6,6 +6,7 @@ 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'; +import 'package:mashhad_metro/widgets/station_status.dart'; import 'dart:async'; class MapPage extends ConsumerStatefulWidget { @@ -309,56 +310,72 @@ class _MapPageState extends ConsumerState { 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: Semantics( + button: true, + label: + '${station.translations['fa'] ?? station.name}، ${station.disabled ? 'ایستگاه غیرفعال' : 'ایستگاه فعال'}', + child: GestureDetector( + onTap: () => _showStationBottomSheet(station), + child: Stack( + children: [ + Container( + decoration: BoxDecoration( + color: station.disabled + ? const Color(0xFF424242) + : primaryColor, + shape: BoxShape.circle, + border: Border.all( + color: station.disabled + ? stationUnavailableColor + : Colors.white, + width: 3, ), - ], - ), - child: Center( - child: Icon( - Icons.subway, - color: Colors.white, - size: hasMultipleLines ? 24 : 20, + boxShadow: station.disabled + ? null + : [ + BoxShadow( + color: primaryColor.withOpacity(0.5), + blurRadius: 8, + spreadRadius: 2, + ), + ], + ), + child: Center( + child: station.disabled + ? const StationUnavailableIcon(size: 24) + : Icon( + Icons.subway, + color: Colors.white, + size: hasMultipleLines ? 24 : 20, + ), ), ), - ), - if (hasMultipleLines) - 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, + if (hasMultipleLines) + 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, + ), ), ), ), ), - ), - ], + ], + ), ), ), ); @@ -408,6 +425,10 @@ class _MapPageState extends ConsumerState { ), textAlign: TextAlign.right, ), + if (station.disabled) ...[ + const SizedBox(height: 12), + const StationUnavailableBadge(), + ], const SizedBox(height: 16), Wrap( diff --git a/lib/pages/station_details.dart b/lib/pages/station_details.dart index ab76f28..b06b2df 100644 --- a/lib/pages/station_details.dart +++ b/lib/pages/station_details.dart @@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:mashhad_metro/pages/map.dart'; import 'package:mashhad_metro/providers/station_provider.dart'; import 'package:mashhad_metro/models/station_model.dart'; +import 'package:mashhad_metro/widgets/station_status.dart'; class StationDetail extends ConsumerWidget { final String stationName; @@ -148,6 +149,10 @@ class StationDetail extends ConsumerWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ + if (station.disabled) ...[ + const StationUnavailableNotice(), + const SizedBox(height: 24), + ], _buildSection( title: 'خطوط مترو', icon: Icons.subway, @@ -268,22 +273,29 @@ class StationDetail extends ConsumerWidget { Widget _buildLineChip(int lineNumber, StationModel station) { final position = station.getPositionInLine(lineNumber); - final color = _parseColor( - station.colors.isNotEmpty ? station.colors.first : '#87CEEB', - ); + final color = station.disabled + ? const Color(0xFF555555) + : _parseColor( + station.colors.isNotEmpty ? station.colors.first : '#87CEEB', + ); return Container( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10), decoration: BoxDecoration( - gradient: LinearGradient(colors: [color, color.withOpacity(0.7)]), + color: station.disabled ? color : null, + gradient: station.disabled + ? null + : LinearGradient(colors: [color, color.withOpacity(0.7)]), borderRadius: BorderRadius.circular(12), - boxShadow: [ - BoxShadow( - color: color.withOpacity(0.3), - blurRadius: 8, - offset: const Offset(0, 2), - ), - ], + boxShadow: station.disabled + ? null + : [ + BoxShadow( + color: color.withOpacity(0.3), + blurRadius: 8, + offset: const Offset(0, 2), + ), + ], ), child: Row( mainAxisSize: MainAxisSize.min, @@ -319,6 +331,14 @@ class StationDetail extends ConsumerWidget { } Widget _buildFacilities(StationModel station) { + if (station.disabled) { + return const Text( + 'تا زمان فعال‌شدن ایستگاه، امکانات آن در دسترس نیست.', + style: TextStyle(color: Colors.white70, fontSize: 14, height: 1.6), + textAlign: TextAlign.right, + ); + } + final facilities = >[ if (station.wc) {'icon': Icons.wc, 'label': 'سرویس بهداشتی'}, if (station.elevator) {'icon': Icons.elevator, 'label': 'آسانسور'}, diff --git a/lib/widgets/stationItem.dart b/lib/widgets/stationItem.dart index 2dcadbd..860c3ec 100644 --- a/lib/widgets/stationItem.dart +++ b/lib/widgets/stationItem.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import '../models/station_model.dart'; import 'package:mashhad_metro/pages/station_details.dart'; +import 'station_status.dart'; class StationItem extends StatelessWidget { final StationModel station; @@ -59,17 +60,32 @@ class StationItem extends StatelessWidget { height: 20, decoration: BoxDecoration( shape: BoxShape.circle, - color: currentLineColor, - border: Border.all(color: Colors.white, width: 3), - boxShadow: [ - BoxShadow( - color: currentLineColor.withOpacity(0.5), - blurRadius: 8, - spreadRadius: 2, - ), - ], + color: station.disabled + ? const Color(0xFF343434) + : currentLineColor, + border: Border.all( + color: station.disabled + ? stationUnavailableColor + : Colors.white, + width: station.disabled ? 2 : 3, + ), + boxShadow: station.disabled + ? [] + : [ + BoxShadow( + color: currentLineColor.withOpacity(0.5), + blurRadius: 8, + spreadRadius: 2, + ), + ], ), - child: hasTransfer + child: station.disabled + ? const Icon( + Icons.block, + color: stationUnavailableColor, + size: 12, + ) + : hasTransfer ? Center( child: Container( width: 8, @@ -125,9 +141,18 @@ class StationItem extends StatelessWidget { borderRadius: BorderRadius.circular(16), child: Container( decoration: BoxDecoration( - color: const Color(0xFF2D2D2D), + color: station.disabled + ? const Color(0xFF292725) + : const Color(0xFF2D2D2D), borderRadius: BorderRadius.circular(16), - border: hasTransfer + border: station.disabled + ? Border.all( + color: stationUnavailableColor.withValues( + alpha: 0.45, + ), + width: 1.5, + ) + : hasTransfer ? Border.all( color: currentLineColor.withOpacity(0.3), width: 2, @@ -199,6 +224,10 @@ class StationItem extends StatelessWidget { height: 1.2, ), ), + if (station.disabled) ...[ + const SizedBox(height: 10), + const StationUnavailableBadge(), + ], ], ), ), diff --git a/lib/widgets/station_status.dart b/lib/widgets/station_status.dart new file mode 100644 index 0000000..d664edb --- /dev/null +++ b/lib/widgets/station_status.dart @@ -0,0 +1,130 @@ +import 'package:flutter/material.dart'; + +const stationUnavailableColor = Color(0xFFFFC46B); + +class StationUnavailableIcon extends StatelessWidget { + final double size; + + const StationUnavailableIcon({super.key, required this.size}); + + @override + Widget build(BuildContext context) { + return ExcludeSemantics( + child: SizedBox( + width: size, + height: size, + child: Stack( + children: [ + Center( + child: Icon(Icons.subway, color: Colors.white, size: size * 0.62), + ), + Positioned( + top: 0, + right: 0, + child: Icon( + Icons.block, + color: stationUnavailableColor, + size: size * 0.48, + ), + ), + ], + ), + ), + ); + } +} + +class StationUnavailableBadge extends StatelessWidget { + const StationUnavailableBadge({super.key}); + + @override + Widget build(BuildContext context) { + return Semantics( + label: 'ایستگاه غیرفعال است', + child: ExcludeSemantics( + child: Container( + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5), + decoration: BoxDecoration( + color: stationUnavailableColor.withValues(alpha: 0.14), + borderRadius: BorderRadius.circular(20), + border: Border.all( + color: stationUnavailableColor.withValues(alpha: 0.55), + ), + ), + child: const Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(Icons.block, color: stationUnavailableColor, size: 15), + SizedBox(width: 5), + Text( + 'غیرفعال', + style: TextStyle( + color: stationUnavailableColor, + fontSize: 12, + fontWeight: FontWeight.bold, + ), + ), + ], + ), + ), + ), + ); + } +} + +class StationUnavailableNotice extends StatelessWidget { + const StationUnavailableNotice({super.key}); + + @override + Widget build(BuildContext context) { + return Semantics( + container: true, + label: 'وضعیت ایستگاه: غیرفعال. این ایستگاه در حال حاضر در دسترس نیست.', + child: ExcludeSemantics( + child: Container( + width: double.infinity, + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: stationUnavailableColor.withValues(alpha: 0.12), + borderRadius: BorderRadius.circular(16), + border: Border.all( + color: stationUnavailableColor.withValues(alpha: 0.45), + ), + ), + child: const Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Text( + 'ایستگاه غیرفعال است', + textAlign: TextAlign.right, + style: TextStyle( + color: stationUnavailableColor, + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + SizedBox(height: 4), + Text( + 'این ایستگاه در حال حاضر در دسترس نیست.', + textAlign: TextAlign.right, + style: TextStyle( + color: Colors.white70, + fontSize: 13, + height: 1.5, + ), + ), + ], + ), + ), + SizedBox(width: 12), + StationUnavailableIcon(size: 36), + ], + ), + ), + ), + ); + } +} diff --git a/test/station_status_test.dart b/test/station_status_test.dart new file mode 100644 index 0000000..c8092cc --- /dev/null +++ b/test/station_status_test.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mashhad_metro/widgets/station_status.dart'; + +void main() { + testWidgets('unavailable badge identifies a disabled station', ( + tester, + ) async { + await tester.pumpWidget( + const MaterialApp(home: Scaffold(body: StationUnavailableBadge())), + ); + + expect(find.text('غیرفعال'), findsOneWidget); + expect(find.byIcon(Icons.block), findsOneWidget); + }); + + testWidgets('unavailable notice explains the station status', (tester) async { + await tester.pumpWidget( + const MaterialApp(home: Scaffold(body: StationUnavailableNotice())), + ); + + expect(find.text('ایستگاه غیرفعال است'), findsOneWidget); + expect(find.text('این ایستگاه در حال حاضر در دسترس نیست.'), findsOneWidget); + expect(find.byIcon(Icons.subway), findsOneWidget); + }); +}