Initial commit: SIBU 2.0 MISSION

This commit is contained in:
2026-02-21 09:53:31 -05:00
commit 0c7aa53c8b
400 changed files with 67708 additions and 0 deletions

View File

@ -0,0 +1,6 @@
export 'package:connectivity_plus/connectivity_plus.dart';
export 'package:google_fonts/google_fonts.dart';
export '../routes/app_routes.dart';
export '../widgets/custom_icon_widget.dart';
export '../widgets/custom_image_widget.dart';
export '../theme/app_theme.dart';

75
old/lib/main.dart Normal file
View File

@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
import './services/app_state_service.dart';
import './services/supabase_service.dart';
import './services/api_client.dart';
import 'core/app_export.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
try {
// Initialize Supabase (required for app functionality)
try {
await SupabaseService.initialize();
debugPrint('✅ Supabase initialized successfully');
} catch (e) {
debugPrint('❌ Supabase initialization failed: $e');
debugPrint(' Make sure to run with: ./scripts/run-flutter-supabase.sh');
// Continue - app will show error UI
}
// Initialize API Client (optional, for PostgreSQL backend)
try {
final apiBaseUrl = ApiClient.getBaseUrl();
ApiClient.instance.initialize(baseUrl: apiBaseUrl);
debugPrint('✅ API Client initialized: $apiBaseUrl');
} catch (e) {
debugPrint('⚠️ API Client initialization skipped: $e');
}
// Initialize global app state
await AppStateService().initialize();
debugPrint('✅ App state initialized successfully');
} catch (e) {
debugPrint('❌ Initialization failed: $e');
// Continue running the app even if initialization fails
}
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return Sizer(
builder: (context, orientation, deviceType) {
return AnimatedBuilder(
animation: AppStateService(),
builder: (context, child) {
return MaterialApp(
title: 'SIBU - Sistema de Transporte',
theme: AppTheme.lightTheme,
darkTheme: AppTheme.darkTheme,
themeMode: ThemeMode.system,
debugShowCheckedModeBanner: false,
builder: (context, child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaler: TextScaler.linear(1.0),
),
child: child!,
);
},
routes: AppRoutes.routes,
initialRoute: AppRoutes.splash,
);
},
);
},
);
}
}

View File

@ -0,0 +1,203 @@
class BusStopModel {
final String id;
final String name;
final double lat;
final double lng;
final String? city;
final String? address;
final String? parentId;
final String? side;
final String stopType;
final bool hasShelter;
final bool hasSeating;
final bool isAccessible;
final DateTime? createdAt;
final DateTime? updatedAt;
// Route-specific fields (from route_stops junction table)
final int? stopOrder;
final int? travelTimeMinutes;
final bool? isPickupPoint;
final bool? isDropoffPoint;
BusStopModel({
required this.id,
required this.name,
required this.lat,
required this.lng,
this.city,
this.address,
this.parentId,
this.side,
this.stopType = 'regular',
this.hasShelter = false,
this.hasSeating = false,
this.isAccessible = false,
this.createdAt,
this.updatedAt,
this.stopOrder,
this.travelTimeMinutes,
this.isPickupPoint,
this.isDropoffPoint,
});
factory BusStopModel.fromJson(Map<String, dynamic> json) {
return BusStopModel(
id: json['id']?.toString() ?? '',
name: json['name']?.toString() ?? '',
lat: double.tryParse(json['lat']?.toString() ?? '0') ?? 0.0,
lng: double.tryParse(json['lng']?.toString() ?? '0') ?? 0.0,
city: json['city']?.toString(),
address: json['address']?.toString(),
parentId: json['parent_id']?.toString(),
side: json['side']?.toString(),
stopType: json['stop_type']?.toString() ?? 'regular',
hasShelter: json['has_shelter'] == true,
hasSeating: json['has_seating'] == true,
isAccessible: json['is_accessible'] == true,
createdAt:
json['created_at'] != null
? DateTime.tryParse(json['created_at'].toString())
: null,
updatedAt:
json['updated_at'] != null
? DateTime.tryParse(json['updated_at'].toString())
: null,
stopOrder:
json['stop_order'] != null
? int.tryParse(json['stop_order'].toString())
: null,
travelTimeMinutes:
json['travel_time_minutes'] != null
? int.tryParse(json['travel_time_minutes'].toString())
: null,
isPickupPoint: json['is_pickup_point'] == true,
isDropoffPoint: json['is_dropoff_point'] == true,
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'lat': lat,
'lng': lng,
'city': city,
'address': address,
'parent_id': parentId,
'side': side,
'stop_type': stopType,
'has_shelter': hasShelter,
'has_seating': hasSeating,
'is_accessible': isAccessible,
'created_at': createdAt?.toIso8601String(),
'updated_at': updatedAt?.toIso8601String(),
'stop_order': stopOrder,
'travel_time_minutes': travelTimeMinutes,
'is_pickup_point': isPickupPoint,
'is_dropoff_point': isDropoffPoint,
};
}
// Helper getters
String get displayName => name;
String get fullAddress {
if (address != null && address!.isNotEmpty) {
return city != null ? '$address, $city' : address!;
}
return city ?? 'Ubicación desconocida';
}
String get stopTypeDisplay {
switch (stopType) {
case 'terminal':
return 'Terminal';
case 'express_only':
return 'Solo Express';
case 'regular':
default:
return 'Parada Regular';
}
}
List<String> get amenities {
List<String> amenityList = [];
if (hasShelter) amenityList.add('Refugio');
if (hasSeating) amenityList.add('Asientos');
if (isAccessible) amenityList.add('Accesible');
return amenityList;
}
String get amenitiesText {
final amenityList = amenities;
if (amenityList.isEmpty) return 'Sin servicios especiales';
return amenityList.join(', ');
}
bool get isTerminal => stopType == 'terminal';
bool get isExpressOnly => stopType == 'express_only';
String get travelTimeText {
if (travelTimeMinutes != null && travelTimeMinutes! > 0) {
return '${travelTimeMinutes} min';
}
return 'N/A';
}
BusStopModel copyWith({
String? id,
String? name,
double? lat,
double? lng,
String? city,
String? address,
String? parentId,
String? side,
String? stopType,
bool? hasShelter,
bool? hasSeating,
bool? isAccessible,
DateTime? createdAt,
DateTime? updatedAt,
int? stopOrder,
int? travelTimeMinutes,
bool? isPickupPoint,
bool? isDropoffPoint,
}) {
return BusStopModel(
id: id ?? this.id,
name: name ?? this.name,
lat: lat ?? this.lat,
lng: lng ?? this.lng,
city: city ?? this.city,
address: address ?? this.address,
parentId: parentId ?? this.parentId,
side: side ?? this.side,
stopType: stopType ?? this.stopType,
hasShelter: hasShelter ?? this.hasShelter,
hasSeating: hasSeating ?? this.hasSeating,
isAccessible: isAccessible ?? this.isAccessible,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
stopOrder: stopOrder ?? this.stopOrder,
travelTimeMinutes: travelTimeMinutes ?? this.travelTimeMinutes,
isPickupPoint: isPickupPoint ?? this.isPickupPoint,
isDropoffPoint: isDropoffPoint ?? this.isDropoffPoint,
);
}
@override
String toString() {
return 'BusStopModel(id: $id, name: $name, city: $city, stopType: $stopType)';
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is BusStopModel && other.id == id;
}
@override
int get hashCode => id.hashCode;
}

View File

@ -0,0 +1,113 @@
class CouponModel {
final String id;
final String businessName;
final String title;
final String description;
final DateTime? validUntil;
final String? imageUrl;
final String category;
final bool isActive;
final DateTime createdAt;
CouponModel({
required this.id,
required this.businessName,
required this.title,
required this.description,
this.validUntil,
this.imageUrl,
required this.category,
required this.isActive,
required this.createdAt,
});
factory CouponModel.fromMap(Map<String, dynamic> map) {
return CouponModel(
id: map['id'] as String,
businessName: map['business_name'] as String,
title: map['title'] as String,
description: map['description'] as String? ?? '',
validUntil: map['valid_until'] != null
? DateTime.parse(map['valid_until'])
: null,
imageUrl: map['image_url'] as String?,
category: map['category'] as String,
isActive: map['is_active'] as bool? ?? true,
createdAt: DateTime.parse(map['created_at']),
);
}
Map<String, dynamic> toMap() {
return {
'id': id,
'business_name': businessName,
'title': title,
'description': description,
'valid_until': validUntil?.toIso8601String(),
'image_url': imageUrl,
'category': category,
'is_active': isActive,
'created_at': createdAt.toIso8601String(),
};
}
bool get isExpired {
if (validUntil == null) return false;
return DateTime.now().isAfter(validUntil!);
}
bool get isExpiringSoon {
if (validUntil == null) return false;
final now = DateTime.now();
final difference = validUntil!.difference(now).inDays;
return difference <= 3 && difference >= 0;
}
String get categoryDisplayName {
switch (category.toLowerCase()) {
case 'restaurantes':
return 'Restaurantes';
case 'tiendas':
return 'Tiendas';
case 'servicios':
return 'Servicios';
case 'entretenimiento':
return 'Entretenimiento';
case 'salud':
return 'Salud';
case 'belleza':
return 'Belleza';
default:
return 'Otros';
}
}
String get validUntilFormatted {
if (validUntil == null) return 'Sin fecha de vencimiento';
return '${validUntil!.day.toString().padLeft(2, '0')}/${validUntil!.month.toString().padLeft(2, '0')}/${validUntil!.year}';
}
CouponModel copyWith({
String? id,
String? businessName,
String? title,
String? description,
DateTime? validUntil,
String? imageUrl,
String? category,
bool? isActive,
DateTime? createdAt,
}) {
return CouponModel(
id: id ?? this.id,
businessName: businessName ?? this.businessName,
title: title ?? this.title,
description: description ?? this.description,
validUntil: validUntil ?? this.validUntil,
imageUrl: imageUrl ?? this.imageUrl,
category: category ?? this.category,
isActive: isActive ?? this.isActive,
createdAt: createdAt ?? this.createdAt,
);
}
}

View File

@ -0,0 +1,154 @@
class RouteModel {
final String id;
final String name;
final String? description;
final String color;
final String direction;
final String? originCity;
final String? destinationCity;
final double? distanceKm;
final int? estimatedDurationMinutes;
final String status;
final DateTime? createdAt;
final DateTime? updatedAt;
RouteModel({
required this.id,
required this.name,
this.description,
required this.color,
required this.direction,
this.originCity,
this.destinationCity,
this.distanceKm,
this.estimatedDurationMinutes,
this.status = 'active',
this.createdAt,
this.updatedAt,
});
factory RouteModel.fromJson(Map<String, dynamic> json) {
return RouteModel(
id: json['id']?.toString() ?? '',
name: json['name']?.toString() ?? '',
description: json['description']?.toString(),
color: json['color']?.toString() ?? '#FEE715',
direction: json['direction']?.toString() ?? 'outbound',
originCity: json['origin_city']?.toString(),
destinationCity: json['destination_city']?.toString(),
distanceKm: json['distance_km'] != null
? double.tryParse(json['distance_km'].toString())
: null,
estimatedDurationMinutes: json['estimated_duration_minutes'] != null
? int.tryParse(json['estimated_duration_minutes'].toString())
: null,
status: json['status']?.toString() ?? 'active',
createdAt: json['created_at'] != null
? DateTime.tryParse(json['created_at'].toString())
: null,
updatedAt: json['updated_at'] != null
? DateTime.tryParse(json['updated_at'].toString())
: null,
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'description': description,
'color': color,
'direction': direction,
'origin_city': originCity,
'destination_city': destinationCity,
'distance_km': distanceKm,
'estimated_duration_minutes': estimatedDurationMinutes,
'status': status,
'created_at': createdAt?.toIso8601String(),
'updated_at': updatedAt?.toIso8601String(),
};
}
// Helper getters
String get displayName {
if (name.isNotEmpty) return name;
final od = [originCity, destinationCity]
.where((e) => e != null && e.trim().isNotEmpty)
.map((e) => e!.trim())
.join(' ');
return od.isNotEmpty ? od : 'Route';
}
String get routeDescription {
if (description != null && description!.isNotEmpty) {
return description!;
}
return 'Ruta $displayName';
}
String get durationText {
if (estimatedDurationMinutes != null) {
if (estimatedDurationMinutes! >= 60) {
final hours = estimatedDurationMinutes! ~/ 60;
final minutes = estimatedDurationMinutes! % 60;
return minutes > 0 ? '${hours}h ${minutes}min' : '${hours}h';
}
return '${estimatedDurationMinutes}min';
}
return 'N/A';
}
String get distanceText {
if (distanceKm != null) {
return '${distanceKm!.toStringAsFixed(1)} km';
}
return 'N/A';
}
bool get isActive => status == 'active';
RouteModel copyWith({
String? id,
String? name,
String? description,
String? color,
String? direction,
String? originCity,
String? destinationCity,
double? distanceKm,
int? estimatedDurationMinutes,
String? status,
DateTime? createdAt,
DateTime? updatedAt,
}) {
return RouteModel(
id: id ?? this.id,
name: name ?? this.name,
description: description ?? this.description,
color: color ?? this.color,
direction: direction ?? this.direction,
originCity: originCity ?? this.originCity,
destinationCity: destinationCity ?? this.destinationCity,
distanceKm: distanceKm ?? this.distanceKm,
estimatedDurationMinutes:
estimatedDurationMinutes ?? this.estimatedDurationMinutes,
status: status ?? this.status,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
);
}
@override
String toString() {
return 'RouteModel(id: $id, name: $name, direction: $direction, status: $status)';
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is RouteModel && other.id == id;
}
@override
int get hashCode => id.hashCode;
}

View File

@ -0,0 +1,72 @@
class RouteStopModel {
final String id;
final String routeId;
final String stopId;
final int stopOrder;
final int? travelTimeMinutes;
final bool isPickupPoint;
final bool isDropoffPoint;
final DateTime createdAt;
// Populated from joined data
final String? stopName;
final double? latitude;
final double? longitude;
final String? city;
RouteStopModel({
required this.id,
required this.routeId,
required this.stopId,
required this.stopOrder,
this.travelTimeMinutes,
required this.isPickupPoint,
required this.isDropoffPoint,
required this.createdAt,
this.stopName,
this.latitude,
this.longitude,
this.city,
});
factory RouteStopModel.fromJson(Map<String, dynamic> json) {
return RouteStopModel(
id: json['id'] as String,
routeId: json['route_id'] as String,
stopId: json['stop_id'] as String,
stopOrder: json['stop_order'] as int,
travelTimeMinutes: json['travel_time_minutes'] as int?,
isPickupPoint: json['is_pickup_point'] as bool,
isDropoffPoint: json['is_dropoff_point'] as bool,
createdAt: DateTime.parse(json['created_at'] as String),
stopName: json['stop_name'] as String?,
latitude: json['latitude']?.toDouble(),
longitude: json['longitude']?.toDouble(),
city: json['city'] as String?,
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'route_id': routeId,
'stop_id': stopId,
'stop_order': stopOrder,
'travel_time_minutes': travelTimeMinutes,
'is_pickup_point': isPickupPoint,
'is_dropoff_point': isDropoffPoint,
'created_at': createdAt.toIso8601String(),
if (stopName != null) 'stop_name': stopName,
if (latitude != null) 'latitude': latitude,
if (longitude != null) 'longitude': longitude,
if (city != null) 'city': city,
};
}
String get operationType {
if (isPickupPoint && isDropoffPoint) return 'Subida/Bajada';
if (isPickupPoint) return 'Solo Subida';
if (isDropoffPoint) return 'Solo Bajada';
return 'Sin servicio';
}
}

View File

@ -0,0 +1,140 @@
import 'package:flutter/foundation.dart';
/// Model representing a taxi service with contact and location information
@immutable
class TaxiModel {
final String id;
final String name;
final String phone;
final String corregimiento;
final String shift;
final bool isActive;
final DateTime createdAt;
final DateTime updatedAt;
const TaxiModel({
required this.id,
required this.name,
required this.phone,
required this.corregimiento,
required this.shift,
required this.isActive,
required this.createdAt,
required this.updatedAt,
});
/// Create TaxiModel from Supabase JSON response
factory TaxiModel.fromJson(Map<String, dynamic> json) {
return TaxiModel(
id: json['id'] as String,
name: json['name'] as String,
phone: json['phone'] as String,
corregimiento: json['corregimiento'] as String,
shift: json['shift'] as String,
isActive: json['is_active'] as bool? ?? true,
createdAt: DateTime.parse(json['created_at'] as String),
updatedAt: DateTime.parse(json['updated_at'] as String),
);
}
/// Convert TaxiModel to JSON for Supabase operations
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'phone': phone,
'corregimiento': corregimiento,
'shift': shift,
'is_active': isActive,
'created_at': createdAt.toIso8601String(),
'updated_at': updatedAt.toIso8601String(),
};
}
/// Create a copy with modified properties
TaxiModel copyWith({
String? id,
String? name,
String? phone,
String? corregimiento,
String? shift,
bool? isActive,
DateTime? createdAt,
DateTime? updatedAt,
}) {
return TaxiModel(
id: id ?? this.id,
name: name ?? this.name,
phone: phone ?? this.phone,
corregimiento: corregimiento ?? this.corregimiento,
shift: shift ?? this.shift,
isActive: isActive ?? this.isActive,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
);
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is TaxiModel && other.id == id;
}
@override
int get hashCode => id.hashCode;
@override
String toString() {
return 'TaxiModel(id: $id, name: $name, phone: $phone, corregimiento: $corregimiento, shift: $shift, isActive: $isActive)';
}
}
/// Model representing a user's favorite taxi
@immutable
class FavoriteTaxiModel {
final String id;
final String userId;
final String taxiId;
final DateTime createdAt;
const FavoriteTaxiModel({
required this.id,
required this.userId,
required this.taxiId,
required this.createdAt,
});
/// Create FavoriteTaxiModel from Supabase JSON response
factory FavoriteTaxiModel.fromJson(Map<String, dynamic> json) {
return FavoriteTaxiModel(
id: json['id'] as String,
userId: json['user_id'] as String,
taxiId: json['taxi_id'] as String,
createdAt: DateTime.parse(json['created_at'] as String),
);
}
/// Convert FavoriteTaxiModel to JSON for Supabase operations
Map<String, dynamic> toJson() {
return {
'id': id,
'user_id': userId,
'taxi_id': taxiId,
'created_at': createdAt.toIso8601String(),
};
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is FavoriteTaxiModel && other.id == id;
}
@override
int get hashCode => id.hashCode;
@override
String toString() {
return 'FavoriteTaxiModel(id: $id, userId: $userId, taxiId: $taxiId)';
}
}

View File

@ -0,0 +1,440 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sizer/sizer.dart';
import '../../core/app_export.dart';
import './widgets/bus_route_card_widget.dart';
import './widgets/nearby_landmarks_widget.dart';
import './widgets/report_issue_widget.dart';
import './widgets/stop_amenities_widget.dart';
import './widgets/user_comments_widget.dart';
class BusStopDetails extends StatefulWidget {
const BusStopDetails({super.key});
@override
State<BusStopDetails> createState() => _BusStopDetailsState();
}
class _BusStopDetailsState extends State<BusStopDetails> {
bool _isLoading = true;
DateTime _lastUpdated = DateTime.now();
// Mock data for bus stop details
final Map<String, dynamic> _busStopData = {
"stopId": "BS001",
"stopName": "Parada Central Boquete",
"address": "Av. Central, frente al Parque José Domingo de Obaldía",
"coordinates": {"lat": 8.7833, "lng": -82.4333},
"lastUpdated": "2025-10-19 18:45:00",
};
final List<Map<String, dynamic>> _routesData = [
{
"routeName": "Boquete - David",
"nextBusMinutes": 12,
"upcomingTimes": ["19:15", "19:45", "20:15", "20:45"],
"isDelayed": false,
},
{
"routeName": "David - Boquete",
"nextBusMinutes": 25,
"upcomingTimes": ["19:30", "20:00", "20:30", "21:00"],
"isDelayed": true,
},
{
"routeName": "Boquete - Caldera",
"nextBusMinutes": 45,
"upcomingTimes": ["19:50", "20:50", "21:50"],
"isDelayed": false,
},
];
final Map<String, dynamic> _amenitiesData = {
"hasShelter": true,
"hasBench": true,
"isAccessible": false,
"hasLighting": true,
"hasTrashCan": true,
};
final List<Map<String, dynamic>> _landmarksData = [
{
"name": "Parque José Domingo de Obaldía",
"distance": "50m",
"type": "park",
},
{
"name": "Banco Nacional de Panamá",
"distance": "120m",
"type": "bank",
},
{
"name": "Supermercado El Mandado",
"distance": "200m",
"type": "store",
},
{
"name": "Hospital Regional de Boquete",
"distance": "350m",
"type": "hospital",
},
];
final List<Map<String, dynamic>> _commentsData = [
{
"userName": "María González",
"userAvatar":
"https://images.unsplash.com/photo-1687757660301-7aac1198ed63",
"semanticLabel":
"Profile photo of a woman with long brown hair wearing a blue blouse, smiling at the camera",
"comment":
"Muy buena parada, siempre está limpia y los buses llegan a tiempo. El refugio protege bien de la lluvia.",
"timestamp": "Hace 2 horas",
"rating": 5,
},
{
"userName": "Carlos Rodríguez",
"userAvatar":
"https://images.unsplash.com/photo-1735651705945-64bc6d18d555",
"semanticLabel":
"Profile photo of a middle-aged man with short gray hair and glasses wearing a white shirt",
"comment":
"La parada está bien ubicada pero necesita mejor iluminación en las noches. Los horarios son confiables.",
"timestamp": "Hace 1 día",
"rating": 4,
},
{
"userName": "Ana Morales",
"userAvatar":
"https://images.unsplash.com/photo-1722291493584-9e75986c6c5c",
"semanticLabel":
"Profile photo of a young woman with curly black hair wearing a red top, smiling outdoors",
"comment":
"Excelente ubicación cerca del parque. Los buses de la ruta Boquete-David son muy puntuales.",
"timestamp": "Hace 3 días",
"rating": 5,
},
];
@override
void initState() {
super.initState();
_loadBusStopData();
}
Future<void> _loadBusStopData() async {
// Simulate loading data
await Future.delayed(const Duration(seconds: 1));
if (mounted) {
setState(() {
_isLoading = false;
_lastUpdated = DateTime.now();
});
}
}
Future<void> _refreshData() async {
setState(() {
_isLoading = true;
});
await _loadBusStopData();
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Información actualizada'),
backgroundColor: AppTheme.successGreen,
duration: Duration(seconds: 2),
),
);
}
}
void _shareStopInfo() {
HapticFeedback.lightImpact();
final stopName = _busStopData['stopName'] as String;
final address = _busStopData['address'] as String;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Compartiendo información de: $stopName'),
backgroundColor: AppTheme.primaryBlack,
duration: const Duration(seconds: 2),
),
);
}
void _handleNotificationToggle() {
HapticFeedback.lightImpact();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Notificación configurada'),
backgroundColor: AppTheme.accentYellow,
duration: Duration(seconds: 2),
),
);
}
void _handleAddComment() {
HapticFeedback.lightImpact();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Función de comentarios próximamente'),
backgroundColor: AppTheme.primaryBlack,
duration: Duration(seconds: 2),
),
);
}
void _handleReportSubmitted() {
HapticFeedback.lightImpact();
}
String _formatLastUpdated() {
final now = DateTime.now();
final difference = now.difference(_lastUpdated);
if (difference.inMinutes < 1) {
return 'Actualizado hace unos segundos';
} else if (difference.inMinutes < 60) {
return 'Actualizado hace ${difference.inMinutes} min';
} else {
return 'Actualizado hace ${difference.inHours}h';
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final stopName = _busStopData['stopName'] as String? ?? '';
final address = _busStopData['address'] as String? ?? '';
return Scaffold(
backgroundColor: AppTheme.backgroundGray,
appBar: AppBar(
backgroundColor: theme.colorScheme.surface,
elevation: 0,
leading: GestureDetector(
onTap: () {
HapticFeedback.lightImpact();
Navigator.pop(context);
},
child: Container(
margin: EdgeInsets.all(2.w),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: theme.shadowColor.withValues(alpha: 0.1),
blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
child: Center(
child: CustomIconWidget(
iconName: 'close',
color: theme.colorScheme.onSurface,
size: 24,
),
),
),
),
actions: [
GestureDetector(
onTap: _shareStopInfo,
child: Container(
margin: EdgeInsets.all(2.w),
padding: EdgeInsets.all(2.w),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: theme.shadowColor.withValues(alpha: 0.1),
blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
child: CustomIconWidget(
iconName: 'share',
color: theme.colorScheme.onSurface,
size: 24,
),
),
),
],
systemOverlayStyle: SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: theme.brightness == Brightness.light
? Brightness.dark
: Brightness.light,
),
),
body: _isLoading
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const CircularProgressIndicator(
color: AppTheme.accentYellow,
),
SizedBox(height: 2.h),
Text(
'Cargando información de la parada...',
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withValues(alpha: 0.6),
),
),
],
),
)
: RefreshIndicator(
onRefresh: _refreshData,
color: AppTheme.accentYellow,
backgroundColor: theme.colorScheme.surface,
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 2.h),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Stop header information
Container(
width: double.infinity,
padding: EdgeInsets.all(4.w),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: theme.shadowColor.withValues(alpha: 0.1),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
stopName,
style: theme.textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.w700,
color: theme.colorScheme.onSurface,
),
),
SizedBox(height: 1.h),
Row(
children: [
CustomIconWidget(
iconName: 'location_on',
color: AppTheme.primaryBlack,
size: 16,
),
SizedBox(width: 1.w),
Expanded(
child: Text(
address,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface
.withValues(alpha: 0.7),
),
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
),
],
),
SizedBox(height: 2.h),
Container(
padding: EdgeInsets.symmetric(
horizontal: 3.w, vertical: 1.h),
decoration: BoxDecoration(
color: AppTheme.successGreen
.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(6),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
CustomIconWidget(
iconName: 'access_time',
color: AppTheme.successGreen,
size: 14,
),
SizedBox(width: 1.w),
Text(
_formatLastUpdated(),
style: theme.textTheme.labelSmall?.copyWith(
color: AppTheme.successGreen,
fontWeight: FontWeight.w500,
),
),
],
),
),
],
),
),
SizedBox(height: 3.h),
// Real-time arrival predictions
Text(
'Llegadas en tiempo real',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w600,
color: theme.colorScheme.onSurface,
),
),
SizedBox(height: 2.h),
// Route cards
..._routesData
.map((routeData) => BusRouteCardWidget(
routeData: routeData,
onNotificationToggle: _handleNotificationToggle,
))
.toList(),
SizedBox(height: 4.h),
// Stop amenities
StopAmenitiesWidget(amenitiesData: _amenitiesData),
SizedBox(height: 3.h),
// Nearby landmarks
NearbyLandmarksWidget(landmarks: _landmarksData),
SizedBox(height: 3.h),
// User comments section
UserCommentsWidget(
comments: _commentsData,
onAddComment: _handleAddComment,
),
SizedBox(height: 3.h),
// Report issue section
ReportIssueWidget(
onReportSubmitted: _handleReportSubmitted,
),
SizedBox(height: 4.h),
],
),
),
),
),
);
}
}

View File

@ -0,0 +1,207 @@
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
import '../../../../core/app_export.dart';
class BusRouteCardWidget extends StatefulWidget {
final Map<String, dynamic> routeData;
final VoidCallback? onNotificationToggle;
const BusRouteCardWidget({
super.key,
required this.routeData,
this.onNotificationToggle,
});
@override
State<BusRouteCardWidget> createState() => _BusRouteCardWidgetState();
}
class _BusRouteCardWidgetState extends State<BusRouteCardWidget> {
bool _isNotificationEnabled = false;
void _toggleNotification() {
setState(() {
_isNotificationEnabled = !_isNotificationEnabled;
});
if (widget.onNotificationToggle != null) {
widget.onNotificationToggle!();
}
}
String _formatTime(int minutes) {
if (minutes < 60) {
return '${minutes}min';
} else {
final hours = minutes ~/ 60;
final remainingMinutes = minutes % 60;
return remainingMinutes > 0
? '${hours}h ${remainingMinutes}min'
: '${hours}h';
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final routeName = widget.routeData['routeName'] as String? ?? '';
final nextBusMinutes = widget.routeData['nextBusMinutes'] as int? ?? 0;
final upcomingTimes =
(widget.routeData['upcomingTimes'] as List?)?.cast<String>() ?? [];
final isDelayed = widget.routeData['isDelayed'] as bool? ?? false;
return Container(
margin: EdgeInsets.symmetric(horizontal: 4.w, vertical: 1.h),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: theme.shadowColor.withValues(alpha: 0.1),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Padding(
padding: EdgeInsets.all(4.w),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Route header with notification toggle
Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
routeName,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
color: theme.colorScheme.onSurface,
),
overflow: TextOverflow.ellipsis,
),
if (isDelayed) ...[
SizedBox(height: 0.5.h),
Container(
padding: EdgeInsets.symmetric(
horizontal: 2.w, vertical: 0.5.h),
decoration: BoxDecoration(
color:
AppTheme.warningOrange.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(4),
),
child: Text(
'Retraso reportado',
style: theme.textTheme.labelSmall?.copyWith(
color: AppTheme.warningOrange,
fontWeight: FontWeight.w500,
),
),
),
],
],
),
),
GestureDetector(
onTap: _toggleNotification,
child: Container(
padding: EdgeInsets.all(2.w),
decoration: BoxDecoration(
color: _isNotificationEnabled
? AppTheme.accentYellow.withValues(alpha: 0.1)
: Colors.transparent,
borderRadius: BorderRadius.circular(8),
),
child: CustomIconWidget(
iconName: _isNotificationEnabled
? 'notifications'
: 'notifications_none',
color: _isNotificationEnabled
? AppTheme.accentYellow
: theme.colorScheme.onSurface.withValues(alpha: 0.6),
size: 24,
),
),
),
],
),
SizedBox(height: 3.h),
// Next bus countdown
Container(
width: double.infinity,
padding: EdgeInsets.all(4.w),
decoration: BoxDecoration(
color: AppTheme.accentYellow.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: AppTheme.accentYellow.withValues(alpha: 0.3),
width: 1,
),
),
child: Column(
children: [
Text(
'Próximo bus en:',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurface.withValues(alpha: 0.7),
),
),
SizedBox(height: 1.h),
Text(
_formatTime(nextBusMinutes),
style: theme.textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.w700,
color: AppTheme.primaryBlack,
),
),
],
),
),
// Upcoming times
if (upcomingTimes.isNotEmpty) ...[
SizedBox(height: 3.h),
Text(
'Próximas salidas:',
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w500,
color: theme.colorScheme.onSurface,
),
),
SizedBox(height: 1.h),
Wrap(
spacing: 2.w,
runSpacing: 1.h,
children: upcomingTimes
.take(4)
.map((time) => Container(
padding: EdgeInsets.symmetric(
horizontal: 3.w, vertical: 1.h),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(6),
border: Border.all(
color: theme.colorScheme.outline
.withValues(alpha: 0.3),
width: 1,
),
),
child: Text(
time,
style: theme.textTheme.bodySmall?.copyWith(
fontWeight: FontWeight.w500,
color: theme.colorScheme.onSurface,
),
),
))
.toList(),
),
],
],
),
),
);
}
}

View File

@ -0,0 +1,172 @@
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
import '../../../../core/app_export.dart';
class NearbyLandmarksWidget extends StatelessWidget {
final List<Map<String, dynamic>> landmarks;
const NearbyLandmarksWidget({
super.key,
required this.landmarks,
});
Widget _buildLandmarkItem(
BuildContext context, Map<String, dynamic> landmark) {
final theme = Theme.of(context);
final name = landmark['name'] as String? ?? '';
final distance = landmark['distance'] as String? ?? '';
final type = landmark['type'] as String? ?? '';
String iconName = 'place';
switch (type.toLowerCase()) {
case 'restaurant':
iconName = 'restaurant';
break;
case 'hospital':
iconName = 'local_hospital';
break;
case 'school':
iconName = 'school';
break;
case 'bank':
iconName = 'account_balance';
break;
case 'store':
iconName = 'store';
break;
case 'gas_station':
iconName = 'local_gas_station';
break;
default:
iconName = 'place';
}
return Container(
margin: EdgeInsets.only(bottom: 2.h),
padding: EdgeInsets.all(3.w),
decoration: BoxDecoration(
color: theme.colorScheme.surface.withValues(alpha: 0.5),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: theme.colorScheme.outline.withValues(alpha: 0.2),
width: 1,
),
),
child: Row(
children: [
Container(
width: 10.w,
height: 5.h,
decoration: BoxDecoration(
color: AppTheme.primaryBlack.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(6),
),
child: Center(
child: CustomIconWidget(
iconName: iconName,
color: AppTheme.primaryBlack,
size: 20,
),
),
),
SizedBox(width: 3.w),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w500,
color: theme.colorScheme.onSurface,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(height: 0.5.h),
Text(
distance,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurface.withValues(alpha: 0.6),
),
),
],
),
),
],
),
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
if (landmarks.isEmpty) {
return Container(
width: double.infinity,
padding: EdgeInsets.all(4.w),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: theme.shadowColor.withValues(alpha: 0.1),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Column(
children: [
CustomIconWidget(
iconName: 'location_off',
color: theme.colorScheme.onSurface.withValues(alpha: 0.4),
size: 32,
),
SizedBox(height: 2.h),
Text(
'No hay puntos de referencia cercanos',
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withValues(alpha: 0.6),
),
textAlign: TextAlign.center,
),
],
),
);
}
return Container(
width: double.infinity,
padding: EdgeInsets.all(4.w),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: theme.shadowColor.withValues(alpha: 0.1),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Puntos de referencia cercanos',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
color: theme.colorScheme.onSurface,
),
),
SizedBox(height: 3.h),
...landmarks
.map((landmark) => _buildLandmarkItem(context, landmark))
.toList(),
],
),
);
}
}

View File

@ -0,0 +1,396 @@
import 'package:camera/camera.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sizer/sizer.dart';
import '../../../../core/app_export.dart';
class ReportIssueWidget extends StatefulWidget {
final VoidCallback? onReportSubmitted;
const ReportIssueWidget({
super.key,
this.onReportSubmitted,
});
@override
State<ReportIssueWidget> createState() => _ReportIssueWidgetState();
}
class _ReportIssueWidgetState extends State<ReportIssueWidget> {
final TextEditingController _issueController = TextEditingController();
String _selectedIssueType = 'Limpieza';
XFile? _capturedImage;
CameraController? _cameraController;
List<CameraDescription> _cameras = [];
bool _isCameraInitialized = false;
bool _isSubmitting = false;
final List<String> _issueTypes = [
'Limpieza',
'Daños en la estructura',
'Falta de iluminación',
'Problemas de accesibilidad',
'Vandalismo',
'Otro',
];
@override
void initState() {
super.initState();
_initializeCamera();
}
@override
void dispose() {
_issueController.dispose();
_cameraController?.dispose();
super.dispose();
}
Future<bool> _requestCameraPermission() async {
if (kIsWeb) return true;
return (await Permission.camera.request()).isGranted;
}
Future<void> _initializeCamera() async {
try {
if (!await _requestCameraPermission()) return;
_cameras = await availableCameras();
if (_cameras.isEmpty) return;
final camera = kIsWeb
? _cameras.firstWhere(
(c) => c.lensDirection == CameraLensDirection.front,
orElse: () => _cameras.first)
: _cameras.firstWhere(
(c) => c.lensDirection == CameraLensDirection.back,
orElse: () => _cameras.first);
_cameraController = CameraController(
camera, kIsWeb ? ResolutionPreset.medium : ResolutionPreset.high);
await _cameraController!.initialize();
if (!kIsWeb) {
try {
await _cameraController!.setFocusMode(FocusMode.auto);
await _cameraController!.setFlashMode(FlashMode.auto);
} catch (e) {}
}
if (mounted) {
setState(() {
_isCameraInitialized = true;
});
}
} catch (e) {
// Silent fail - camera not available
}
}
Future<void> _capturePhoto() async {
if (_cameraController == null || !_cameraController!.value.isInitialized)
return;
try {
final XFile photo = await _cameraController!.takePicture();
setState(() {
_capturedImage = photo;
});
} catch (e) {
// Silent fail
}
}
Future<void> _pickImageFromGallery() async {
try {
final ImagePicker picker = ImagePicker();
final XFile? image = await picker.pickImage(source: ImageSource.gallery);
if (image != null) {
setState(() {
_capturedImage = image;
});
}
} catch (e) {
// Silent fail
}
}
Future<void> _submitReport() async {
if (_issueController.text.trim().isEmpty) return;
setState(() {
_isSubmitting = true;
});
// Simulate report submission
await Future.delayed(const Duration(seconds: 2));
if (mounted) {
setState(() {
_isSubmitting = false;
_issueController.clear();
_capturedImage = null;
_selectedIssueType = 'Limpieza';
});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Reporte enviado exitosamente'),
backgroundColor: AppTheme.successGreen,
),
);
if (widget.onReportSubmitted != null) {
widget.onReportSubmitted!();
}
}
}
void _showReportDialog() {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (context) => Container(
height: 85.h,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
),
child: Padding(
padding: EdgeInsets.all(4.w),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Handle bar
Center(
child: Container(
width: 12.w,
height: 0.5.h,
decoration: BoxDecoration(
color: Theme.of(context)
.colorScheme
.onSurface
.withValues(alpha: 0.3),
borderRadius: BorderRadius.circular(2),
),
),
),
SizedBox(height: 3.h),
// Header
Row(
children: [
Expanded(
child: Text(
'Reportar problema',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w600,
),
),
),
GestureDetector(
onTap: () => Navigator.pop(context),
child: CustomIconWidget(
iconName: 'close',
color: Theme.of(context).colorScheme.onSurface,
size: 24,
),
),
],
),
SizedBox(height: 4.h),
// Issue type dropdown
Text(
'Tipo de problema',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w500,
),
),
SizedBox(height: 1.h),
Container(
width: double.infinity,
padding: EdgeInsets.symmetric(horizontal: 4.w),
decoration: BoxDecoration(
border:
Border.all(color: Theme.of(context).colorScheme.outline),
borderRadius: BorderRadius.circular(8),
),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
value: _selectedIssueType,
isExpanded: true,
items: _issueTypes
.map((type) => DropdownMenuItem(
value: type,
child: Text(type),
))
.toList(),
onChanged: (value) {
if (value != null) {
setState(() {
_selectedIssueType = value;
});
}
},
),
),
),
SizedBox(height: 3.h),
// Description field
Text(
'Descripción del problema',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w500,
),
),
SizedBox(height: 1.h),
TextField(
controller: _issueController,
maxLines: 4,
decoration: const InputDecoration(
hintText:
'Describe el problema que encontraste en esta parada...',
),
),
SizedBox(height: 3.h),
// Photo section
Text(
'Agregar foto (opcional)',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w500,
),
),
SizedBox(height: 1.h),
if (_capturedImage != null) ...[
Container(
width: double.infinity,
height: 20.h,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: Theme.of(context).colorScheme.outline),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: kIsWeb
? Image.network(_capturedImage!.path, fit: BoxFit.cover)
: Image.network(_capturedImage!.path,
fit: BoxFit.cover),
),
),
SizedBox(height: 2.h),
],
Row(
children: [
if (_isCameraInitialized) ...[
Expanded(
child: ElevatedButton.icon(
onPressed: _capturePhoto,
icon: CustomIconWidget(
iconName: 'camera_alt',
color: AppTheme.primaryBlack,
size: 20,
),
label: const Text('Tomar foto'),
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.accentYellow,
foregroundColor: AppTheme.primaryBlack,
),
),
),
SizedBox(width: 2.w),
],
Expanded(
child: OutlinedButton.icon(
onPressed: _pickImageFromGallery,
icon: CustomIconWidget(
iconName: 'photo_library',
color: Theme.of(context).colorScheme.primary,
size: 20,
),
label: const Text('Galería'),
),
),
],
),
const Spacer(),
// Submit button
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _isSubmitting ? null : _submitReport,
child: _isSubmitting
? const CircularProgressIndicator()
: const Text('Enviar reporte'),
),
),
SizedBox(height: 2.h),
],
),
),
),
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Container(
width: double.infinity,
padding: EdgeInsets.all(4.w),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: theme.shadowColor.withValues(alpha: 0.1),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Reportar problema',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
color: theme.colorScheme.onSurface,
),
),
SizedBox(height: 2.h),
Text(
'¿Encontraste algún problema en esta parada? Ayúdanos a mejorar reportándolo.',
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withValues(alpha: 0.7),
),
),
SizedBox(height: 3.h),
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: _showReportDialog,
icon: CustomIconWidget(
iconName: 'report_problem',
color: AppTheme.primaryBlack,
size: 20,
),
label: const Text('Reportar problema'),
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.warningOrange,
foregroundColor: AppTheme.primaryBlack,
padding: EdgeInsets.symmetric(vertical: 3.h),
),
),
),
],
),
);
}
}

View File

@ -0,0 +1,144 @@
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
import '../../../../core/app_export.dart';
class StopAmenitiesWidget extends StatelessWidget {
final Map<String, dynamic> amenitiesData;
const StopAmenitiesWidget({
super.key,
required this.amenitiesData,
});
Widget _buildAmenityItem(
BuildContext context, String iconName, String label, bool isAvailable) {
final theme = Theme.of(context);
return Column(
children: [
Container(
width: 12.w,
height: 6.h,
decoration: BoxDecoration(
color: isAvailable
? AppTheme.successGreen.withValues(alpha: 0.1)
: theme.colorScheme.surface.withValues(alpha: 0.5),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: isAvailable
? AppTheme.successGreen.withValues(alpha: 0.3)
: theme.colorScheme.outline.withValues(alpha: 0.3),
width: 1,
),
),
child: Center(
child: CustomIconWidget(
iconName: iconName,
color: isAvailable
? AppTheme.successGreen
: theme.colorScheme.onSurface.withValues(alpha: 0.4),
size: 24,
),
),
),
SizedBox(height: 1.h),
Text(
label,
style: theme.textTheme.labelSmall?.copyWith(
color: isAvailable
? theme.colorScheme.onSurface
: theme.colorScheme.onSurface.withValues(alpha: 0.5),
fontWeight: FontWeight.w500,
),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
),
],
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final hasShelter = amenitiesData['hasShelter'] as bool? ?? false;
final hasBench = amenitiesData['hasBench'] as bool? ?? false;
final isAccessible = amenitiesData['isAccessible'] as bool? ?? false;
final hasLighting = amenitiesData['hasLighting'] as bool? ?? false;
final hasTrashCan = amenitiesData['hasTrashCan'] as bool? ?? false;
return Container(
width: double.infinity,
padding: EdgeInsets.all(4.w),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: theme.shadowColor.withValues(alpha: 0.1),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Comodidades de la parada',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
color: theme.colorScheme.onSurface,
),
),
SizedBox(height: 3.h),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
child: _buildAmenityItem(
context,
'home',
'Refugio',
hasShelter,
),
),
Expanded(
child: _buildAmenityItem(
context,
'chair',
'Asiento',
hasBench,
),
),
Expanded(
child: _buildAmenityItem(
context,
'accessible',
'Accesible',
isAccessible,
),
),
Expanded(
child: _buildAmenityItem(
context,
'lightbulb',
'Iluminación',
hasLighting,
),
),
Expanded(
child: _buildAmenityItem(
context,
'delete',
'Basura',
hasTrashCan,
),
),
],
),
],
),
);
}
}

View File

@ -0,0 +1,236 @@
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
import '../../../../core/app_export.dart';
class UserCommentsWidget extends StatefulWidget {
final List<Map<String, dynamic>> comments;
final VoidCallback? onAddComment;
const UserCommentsWidget({
super.key,
required this.comments,
this.onAddComment,
});
@override
State<UserCommentsWidget> createState() => _UserCommentsWidgetState();
}
class _UserCommentsWidgetState extends State<UserCommentsWidget> {
bool _isExpanded = false;
Widget _buildCommentItem(BuildContext context, Map<String, dynamic> comment) {
final theme = Theme.of(context);
final userName = comment['userName'] as String? ?? '';
final userAvatar = comment['userAvatar'] as String? ?? '';
final semanticLabel = comment['semanticLabel'] as String? ?? '';
final commentText = comment['comment'] as String? ?? '';
final timestamp = comment['timestamp'] as String? ?? '';
final rating = comment['rating'] as int? ?? 0;
return Container(
margin: EdgeInsets.only(bottom: 3.h),
padding: EdgeInsets.all(4.w),
decoration: BoxDecoration(
color: theme.colorScheme.surface.withValues(alpha: 0.5),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: theme.colorScheme.outline.withValues(alpha: 0.2),
width: 1,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// User info and rating
Row(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: CustomImageWidget(
imageUrl: userAvatar,
width: 40,
height: 40,
fit: BoxFit.cover,
semanticLabel: semanticLabel,
),
),
SizedBox(width: 3.w),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
userName,
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
color: theme.colorScheme.onSurface,
),
overflow: TextOverflow.ellipsis,
),
Text(
timestamp,
style: theme.textTheme.bodySmall?.copyWith(
color:
theme.colorScheme.onSurface.withValues(alpha: 0.6),
),
),
],
),
),
// Rating stars
Row(
children: List.generate(
5,
(index) => CustomIconWidget(
iconName: index < rating ? 'star' : 'star_border',
color: index < rating
? AppTheme.accentYellow
: theme.colorScheme.onSurface
.withValues(alpha: 0.3),
size: 16,
)),
),
],
),
SizedBox(height: 2.h),
// Comment text
Text(
commentText,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface,
),
),
],
),
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Container(
width: double.infinity,
padding: EdgeInsets.all(4.w),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: theme.shadowColor.withValues(alpha: 0.1),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Header with expand/collapse
GestureDetector(
onTap: () {
setState(() {
_isExpanded = !_isExpanded;
});
},
child: Row(
children: [
Expanded(
child: Text(
'Comentarios de usuarios (${widget.comments.length})',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
color: theme.colorScheme.onSurface,
),
),
),
CustomIconWidget(
iconName: _isExpanded ? 'expand_less' : 'expand_more',
color: theme.colorScheme.onSurface.withValues(alpha: 0.6),
size: 24,
),
],
),
),
if (_isExpanded) ...[
SizedBox(height: 3.h),
// Add comment button
GestureDetector(
onTap: widget.onAddComment,
child: Container(
width: double.infinity,
padding: EdgeInsets.all(3.w),
decoration: BoxDecoration(
color: AppTheme.accentYellow.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: AppTheme.accentYellow.withValues(alpha: 0.3),
width: 1,
),
),
child: Row(
children: [
CustomIconWidget(
iconName: 'add_comment',
color: AppTheme.primaryBlack,
size: 20,
),
SizedBox(width: 2.w),
Text(
'Agregar comentario',
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w500,
color: AppTheme.primaryBlack,
),
),
],
),
),
),
SizedBox(height: 3.h),
// Comments list
if (widget.comments.isEmpty)
Container(
width: double.infinity,
padding: EdgeInsets.all(6.w),
child: Column(
children: [
CustomIconWidget(
iconName: 'comment',
color: theme.colorScheme.onSurface.withValues(alpha: 0.4),
size: 32,
),
SizedBox(height: 2.h),
Text(
'Aún no hay comentarios',
style: theme.textTheme.bodyMedium?.copyWith(
color:
theme.colorScheme.onSurface.withValues(alpha: 0.6),
),
textAlign: TextAlign.center,
),
SizedBox(height: 1.h),
Text(
'¡Sé el primero en compartir tu experiencia!',
style: theme.textTheme.bodySmall?.copyWith(
color:
theme.colorScheme.onSurface.withValues(alpha: 0.5),
),
textAlign: TextAlign.center,
),
],
),
)
else
...widget.comments
.map((comment) => _buildCommentItem(context, comment))
.toList(),
],
],
),
);
}
}

View File

@ -0,0 +1,256 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sizer/sizer.dart';
import '../../core/app_export.dart';
import '../../models/coupon_model.dart';
import '../../services/coupon_service.dart';
import '../../theme/app_theme.dart';
import '../../widgets/custom_bottom_bar.dart';
import './widgets/category_filter_chips.dart';
import './widgets/coupon_card_widget.dart';
import './widgets/coupon_detail_modal.dart';
import './widgets/empty_state_widget.dart';
import './widgets/sort_dropdown.dart';
class CouponsScreen extends StatefulWidget {
const CouponsScreen({super.key});
@override
State<CouponsScreen> createState() => _CouponsScreenState();
}
class _CouponsScreenState extends State<CouponsScreen> {
final ScrollController _scrollController = ScrollController();
bool _isLoading = true;
bool _isRefreshing = false;
String _selectedCategory = 'Todos';
String _selectedSort = 'Más recientes';
List<CouponModel> _coupons = [];
@override
void initState() {
super.initState();
_loadCoupons();
}
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
/// Load coupons with silent error handling - no user error messages
Future<void> _loadCoupons() async {
try {
setState(() {
_isLoading = true;
});
final coupons = await CouponService.getCoupons(
selectedCategory: _selectedCategory,
sort: _selectedSort,
);
setState(() {
_coupons = coupons;
_isLoading = false;
});
} catch (e) {
// Silent failure - show empty state but don't show error to user
setState(() {
_coupons = [];
_isLoading = false;
});
}
}
/// Refresh coupons with silent error handling
Future<void> _refreshCoupons() async {
setState(() {
_isRefreshing = true;
});
HapticFeedback.lightImpact();
try {
final coupons = await CouponService.getCoupons(
selectedCategory: _selectedCategory,
sort: _selectedSort,
);
setState(() {
_coupons = coupons;
});
} catch (e) {
// Silent failure - keep existing coupons, don't show error
} finally {
setState(() {
_isRefreshing = false;
});
}
}
/// Handle category change and auto-refresh data
void _onCategoryChanged(String category) {
if (_selectedCategory != category) {
setState(() {
_selectedCategory = category;
});
_loadCoupons(); // Automatically refresh when filters change
}
}
/// Handle sort change and auto-refresh data
void _onSortChanged(String sort) {
if (_selectedSort != sort) {
setState(() {
_selectedSort = sort;
});
_loadCoupons(); // Automatically refresh when sorting changes
}
}
void _showCouponDetail(CouponModel coupon) {
HapticFeedback.lightImpact();
showDialog(
context: context,
builder: (context) => CouponDetailModal(coupon: coupon),
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
backgroundColor: theme.scaffoldBackgroundColor,
appBar: AppBar(
title: Text(
'Cupones',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w600,
),
),
backgroundColor: theme.colorScheme.surface,
elevation: 0,
),
body: Column(
children: [
// Category Filter Chips (Spanish UI)
CategoryFilterChips(
selectedCategory: _selectedCategory,
onCategorySelected: _onCategoryChanged,
),
// Sort Dropdown (Spanish UI)
Container(
padding: EdgeInsets.symmetric(vertical: 1.h),
color: theme.colorScheme.surface,
child: SortDropdown(
selectedSort: _selectedSort,
onSortChanged: _onSortChanged,
),
),
// Content
Expanded(child: _buildContent()),
],
),
bottomNavigationBar: CustomBottomBar(
currentIndex: 2,
onTap: (index) {
switch (index) {
case 0:
Navigator.pushReplacementNamed(context, '/map-screen');
break;
case 1:
Navigator.pushReplacementNamed(context, '/schedules-screen');
break;
case 2:
// Already on coupons screen
break;
}
},
),
);
}
Widget _buildContent() {
final theme = Theme.of(context);
if (_isLoading) {
return Center(
child: CircularProgressIndicator(color: AppTheme.accentYellow),
);
}
// No error states shown to user - only empty states
if (_coupons.isEmpty) {
final isFiltered = _selectedCategory != 'Todos';
return EmptyStateWidget(
title:
isFiltered
? 'No hay cupones disponibles para esta categoría.'
: 'Aún no hay cupones registrados.',
subtitle:
isFiltered
? 'Intenta seleccionando otra categoría'
: 'Vuelve pronto para ver nuevas ofertas',
actionText: isFiltered ? 'Ver todos' : null,
onActionPressed: isFiltered ? () => _onCategoryChanged('Todos') : null,
);
}
return RefreshIndicator(
onRefresh: _refreshCoupons,
color: AppTheme.accentYellow,
backgroundColor: theme.colorScheme.surface,
child: GridView.builder(
controller: _scrollController,
padding: EdgeInsets.all(4.w),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: _getGridCrossAxisCount(),
crossAxisSpacing: 4.w,
mainAxisSpacing: 4.w,
childAspectRatio: 0.75,
),
itemCount: _coupons.length + (_isRefreshing ? 2 : 0),
itemBuilder: (context, index) {
if (index >= _coupons.length) {
return Card(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: theme.colorScheme.surface,
),
child: Center(
child: CircularProgressIndicator(
color: AppTheme.accentYellow,
strokeWidth: 2,
),
),
),
);
}
final coupon = _coupons[index];
return CouponCardWidget(
coupon: coupon,
onTap: () => _showCouponDetail(coupon),
);
},
),
);
}
int _getGridCrossAxisCount() {
if (MediaQuery.of(context).size.width > 768) {
return 3; // Tablet
}
return 2; // Phone
}
}

View File

@ -0,0 +1,73 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sizer/sizer.dart';
import '../../../core/app_export.dart';
import '../../../services/coupon_service.dart';
import '../../../theme/app_theme.dart';
class CategoryFilterChips extends StatelessWidget {
final String selectedCategory;
final ValueChanged<String> onCategorySelected;
const CategoryFilterChips({
super.key,
required this.selectedCategory,
required this.onCategorySelected,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final categories = CouponService.getCategoryOptions();
return Container(
height: 6.h,
padding: EdgeInsets.symmetric(vertical: 1.h),
child: ListView.separated(
scrollDirection: Axis.horizontal,
padding: EdgeInsets.symmetric(horizontal: 4.w),
itemCount: categories.length,
separatorBuilder: (context, index) => SizedBox(width: 2.w),
itemBuilder: (context, index) {
final category = categories[index];
final isSelected = selectedCategory == category;
return GestureDetector(
onTap: () {
HapticFeedback.lightImpact();
onCategorySelected(category);
},
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 4.w,
vertical: 1.h,
),
decoration: BoxDecoration(
color: isSelected
? AppTheme.accentYellow
: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: isSelected
? AppTheme.accentYellow
: theme.colorScheme.outline,
width: 1,
),
),
child: Text(
category,
style: theme.textTheme.labelMedium?.copyWith(
color: isSelected
? AppTheme.primaryBlack
: theme.colorScheme.onSurface,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500,
),
),
),
);
},
),
);
}
}

View File

@ -0,0 +1,157 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sizer/sizer.dart';
import '../../../core/app_export.dart';
import '../../../models/coupon_model.dart';
class CouponCardWidget extends StatelessWidget {
final CouponModel coupon;
final VoidCallback onTap;
const CouponCardWidget({
super.key,
required this.coupon,
required this.onTap,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Card(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: InkWell(
onTap: () {
HapticFeedback.lightImpact();
onTap();
},
borderRadius: BorderRadius.circular(12),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: theme.colorScheme.surface,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Image Section (16:9 aspect ratio)
Expanded(
flex: 4,
child: Container(
width: double.infinity,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(12),
topRight: Radius.circular(12),
),
),
child: ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(12),
topRight: Radius.circular(12),
),
child: AspectRatio(
aspectRatio: 16 / 9,
child: coupon.imageUrl != null
? CustomImageWidget(
imageUrl: coupon.imageUrl!,
width: double.infinity,
height: double.infinity,
fit: BoxFit.cover,
semanticLabel: 'Imagen de ${coupon.businessName}',
)
: Container(
color: theme.colorScheme.surfaceContainerHighest,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CustomIconWidget(
iconName: 'image',
color: theme.colorScheme.onSurfaceVariant,
size: 24,
),
SizedBox(height: 1.h),
Text(
'Sin imagen',
style:
theme.textTheme.bodySmall?.copyWith(
color:
theme.colorScheme.onSurfaceVariant,
),
),
],
),
),
),
),
),
),
),
// Content Section
Expanded(
flex: 3,
child: Padding(
padding: EdgeInsets.all(3.w),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Business Name (bold)
Text(
coupon.businessName,
style: theme.textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.bold,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
SizedBox(height: 0.5.h),
// Title (subtitle style)
Text(
coupon.title,
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w500,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
SizedBox(height: 0.5.h),
// Description (2 lines max, small text)
Expanded(
child: Text(
coupon.description,
style: theme.textTheme.bodySmall,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
SizedBox(height: 1.h),
// Valid until text
Text(
coupon.validUntil != null
? 'Válido hasta: ${coupon.validUntilFormatted}'
: 'Sin fecha de vencimiento',
style: theme.textTheme.bodySmall?.copyWith(
color: coupon.isExpired
? AppTheme.errorRed
: coupon.isExpiringSoon
? Colors.orange
: theme.colorScheme.onSurface,
fontWeight: FontWeight.w500,
),
),
],
),
),
),
],
),
),
),
);
}
}

View File

@ -0,0 +1,251 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sizer/sizer.dart';
import '../../../core/app_export.dart';
import '../../../models/coupon_model.dart';
class CouponDetailModal extends StatelessWidget {
final CouponModel coupon;
final VoidCallback? onUseCoupon;
const CouponDetailModal({
super.key,
required this.coupon,
this.onUseCoupon,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Dialog(
backgroundColor: Colors.transparent,
insetPadding: EdgeInsets.all(4.w),
child: Container(
constraints: BoxConstraints(
maxHeight: 85.h,
),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(16),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Close Button
Align(
alignment: Alignment.topRight,
child: Padding(
padding: EdgeInsets.all(2.w),
child: IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: CustomIconWidget(
iconName: 'close',
color: theme.colorScheme.onSurface,
size: 24,
),
),
),
),
// Content
Flexible(
child: Padding(
padding: EdgeInsets.fromLTRB(6.w, 0, 6.w, 6.w),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Full Image
Container(
width: double.infinity,
height: 25.h,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: theme.colorScheme.surfaceContainerHighest,
),
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: coupon.imageUrl != null
? CustomImageWidget(
imageUrl: coupon.imageUrl!,
width: double.infinity,
height: double.infinity,
fit: BoxFit.cover,
semanticLabel:
'Imagen de ${coupon.businessName}',
)
: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CustomIconWidget(
iconName: 'image',
color: theme.colorScheme.onSurfaceVariant,
size: 32,
),
SizedBox(height: 1.h),
Text(
'Sin imagen',
style:
theme.textTheme.bodyMedium?.copyWith(
color:
theme.colorScheme.onSurfaceVariant,
),
),
],
),
),
),
),
SizedBox(height: 4.w),
// Business Name
Text(
coupon.businessName,
style: theme.textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 2.w),
// Title
Text(
coupon.title,
style: theme.textTheme.titleMedium?.copyWith(
color: AppTheme.accentYellow,
fontWeight: FontWeight.w600,
),
),
SizedBox(height: 3.w),
// Description
Text(
coupon.description,
style: theme.textTheme.bodyMedium,
),
SizedBox(height: 3.w),
// Valid Until
Container(
padding: EdgeInsets.all(3.w),
decoration: BoxDecoration(
color: theme.colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
CustomIconWidget(
iconName: 'access_time',
color: theme.colorScheme.onSurfaceVariant,
size: 20,
),
SizedBox(width: 2.w),
Text(
coupon.validUntil != null
? 'Válido hasta: ${coupon.validUntilFormatted}'
: 'Sin fecha de vencimiento',
style: theme.textTheme.bodyMedium?.copyWith(
color: coupon.isExpired
? AppTheme.errorRed
: coupon.isExpiringSoon
? Colors.orange
: theme.colorScheme.onSurfaceVariant,
fontWeight: FontWeight.w500,
),
),
],
),
),
SizedBox(height: 4.w),
// Action Buttons Row
Row(
children: [
// Call Button (placeholder)
Expanded(
child: OutlinedButton.icon(
onPressed: () {
HapticFeedback.lightImpact();
// TODO: Implement call functionality
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content:
Text('Función de llamada próximamente'),
),
);
},
icon: CustomIconWidget(
iconName: 'call',
color: theme.colorScheme.primary,
size: 20,
),
label: const Text('Llamar'),
style: OutlinedButton.styleFrom(
foregroundColor: theme.colorScheme.primary,
side:
BorderSide(color: theme.colorScheme.outline),
),
),
),
SizedBox(width: 3.w),
// WhatsApp Button (placeholder)
Expanded(
child: OutlinedButton.icon(
onPressed: () {
HapticFeedback.lightImpact();
// TODO: Implement WhatsApp functionality
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content:
Text('Función de WhatsApp próximamente'),
),
);
},
icon: CustomIconWidget(
iconName: 'chat',
color: Colors.green,
size: 20,
),
label: const Text('WhatsApp'),
style: OutlinedButton.styleFrom(
foregroundColor: Colors.green,
side:
BorderSide(color: theme.colorScheme.outline),
),
),
),
SizedBox(width: 3.w),
// Location Button (placeholder)
Expanded(
child: OutlinedButton.icon(
onPressed: () {
HapticFeedback.lightImpact();
// TODO: Implement location functionality
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content:
Text('Función de ubicación próximamente'),
),
);
},
icon: CustomIconWidget(
iconName: 'location_on',
color: AppTheme.errorRed,
size: 20,
),
label: const Text('Ubicación'),
style: OutlinedButton.styleFrom(
foregroundColor: AppTheme.errorRed,
side:
BorderSide(color: theme.colorScheme.outline),
),
),
),
],
),
],
),
),
),
],
),
),
);
}
}

View File

@ -0,0 +1,90 @@
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
import '../../../core/app_export.dart';
class EmptyStateWidget extends StatelessWidget {
final String title;
final String subtitle;
final String? actionText;
final VoidCallback? onActionPressed;
const EmptyStateWidget({
super.key,
required this.title,
required this.subtitle,
this.actionText,
this.onActionPressed,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Center(
child: Padding(
padding: EdgeInsets.all(8.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Empty state icon
Container(
padding: EdgeInsets.all(6.w),
decoration: BoxDecoration(
color: theme.colorScheme.surfaceContainerHighest,
shape: BoxShape.circle,
),
child: CustomIconWidget(
iconName: 'local_offer',
color: theme.colorScheme.onSurfaceVariant,
size: 48,
),
),
SizedBox(height: 4.h),
// Title
Text(
title,
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w600,
),
textAlign: TextAlign.center,
),
SizedBox(height: 2.h),
// Subtitle
Text(
subtitle,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withValues(alpha: 0.7),
),
textAlign: TextAlign.center,
),
if (actionText != null && onActionPressed != null) ...[
SizedBox(height: 4.h),
// Action button
ElevatedButton(
onPressed: onActionPressed,
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.accentYellow,
foregroundColor: AppTheme.primaryBlack,
padding: EdgeInsets.symmetric(
horizontal: 8.w,
vertical: 1.5.h,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text(
actionText!,
style: theme.textTheme.labelLarge?.copyWith(
fontWeight: FontWeight.w600,
),
),
),
],
],
),
),
);
}
}

View File

@ -0,0 +1,273 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sizer/sizer.dart';
import '../../../core/app_export.dart';
import '../../../theme/app_theme.dart';
class FilterBottomSheet extends StatefulWidget {
final Map<String, dynamic> currentFilters;
final Function(Map<String, dynamic>) onFiltersChanged;
const FilterBottomSheet({
super.key,
required this.currentFilters,
required this.onFiltersChanged,
});
@override
State<FilterBottomSheet> createState() => _FilterBottomSheetState();
}
class _FilterBottomSheetState extends State<FilterBottomSheet> {
late Map<String, dynamic> _filters;
final List<String> _categories = [
'Todos',
'Restaurantes',
'Tiendas',
'Servicios',
'Entretenimiento',
'Salud',
'Belleza',
];
final List<String> _sortOptions = [
'Más recientes',
'Por vencer',
'Mayor descuento',
'Distancia',
];
@override
void initState() {
super.initState();
_filters = Map<String, dynamic>.from(widget.currentFilters);
}
void _applyFilters() {
HapticFeedback.lightImpact();
widget.onFiltersChanged(_filters);
Navigator.of(context).pop();
}
void _resetFilters() {
HapticFeedback.lightImpact();
setState(() {
_filters = {
'category': 'Todos',
'sortBy': 'Más recientes',
'showUsed': false,
'showExpired': false,
};
});
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Container(
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Handle bar
Container(
margin: EdgeInsets.only(top: 2.h),
width: 12.w,
height: 0.5.h,
decoration: BoxDecoration(
color: theme.colorScheme.outline,
borderRadius: BorderRadius.circular(2),
),
),
// Header
Padding(
padding: EdgeInsets.all(4.w),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Filtros',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w600,
),
),
TextButton(
onPressed: _resetFilters,
child: Text(
'Limpiar',
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.primary,
fontWeight: FontWeight.w500,
),
),
),
],
),
),
Divider(height: 1, color: theme.colorScheme.outline),
// Content
Flexible(
child: SingleChildScrollView(
padding: EdgeInsets.all(4.w),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Category Filter
Text(
'Categoría',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
),
),
SizedBox(height: 2.h),
Wrap(
spacing: 2.w,
runSpacing: 1.h,
children: _categories.map((category) {
final isSelected = _filters['category'] == category;
return FilterChip(
label: Text(category),
selected: isSelected,
onSelected: (selected) {
HapticFeedback.lightImpact();
setState(() {
_filters['category'] = category;
});
},
backgroundColor: theme.colorScheme.surface,
selectedColor:
AppTheme.accentYellow.withValues(alpha: 0.2),
checkmarkColor: AppTheme.primaryBlack,
labelStyle: theme.textTheme.bodyMedium?.copyWith(
color: isSelected
? AppTheme.primaryBlack
: theme.colorScheme.onSurface,
fontWeight:
isSelected ? FontWeight.w600 : FontWeight.w400,
),
side: BorderSide(
color: isSelected
? AppTheme.accentYellow
: theme.colorScheme.outline,
),
);
}).toList(),
),
SizedBox(height: 3.h),
// Sort Options
Text(
'Ordenar por',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
),
),
SizedBox(height: 2.h),
Column(
children: _sortOptions.map((option) {
final isSelected = _filters['sortBy'] == option;
return RadioListTile<String>(
title: Text(
option,
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight:
isSelected ? FontWeight.w600 : FontWeight.w400,
),
),
value: option,
groupValue: _filters['sortBy'],
onChanged: (value) {
HapticFeedback.lightImpact();
setState(() {
_filters['sortBy'] = value;
});
},
activeColor: AppTheme.primaryBlack,
contentPadding: EdgeInsets.zero,
);
}).toList(),
),
SizedBox(height: 2.h),
// Additional Options
Text(
'Mostrar',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
),
),
SizedBox(height: 1.h),
SwitchListTile(
title: Text(
'Cupones usados',
style: theme.textTheme.bodyMedium,
),
value: _filters['showUsed'] ?? false,
onChanged: (value) {
HapticFeedback.lightImpact();
setState(() {
_filters['showUsed'] = value;
});
},
activeColor: AppTheme.accentYellow,
activeTrackColor: AppTheme.primaryBlack,
contentPadding: EdgeInsets.zero,
),
SwitchListTile(
title: Text(
'Cupones vencidos',
style: theme.textTheme.bodyMedium,
),
value: _filters['showExpired'] ?? false,
onChanged: (value) {
HapticFeedback.lightImpact();
setState(() {
_filters['showExpired'] = value;
});
},
activeColor: AppTheme.accentYellow,
activeTrackColor: AppTheme.primaryBlack,
contentPadding: EdgeInsets.zero,
),
],
),
),
),
// Apply Button
Padding(
padding: EdgeInsets.all(4.w),
child: SizedBox(
width: double.infinity,
height: 6.h,
child: ElevatedButton(
onPressed: _applyFilters,
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.accentYellow,
foregroundColor: AppTheme.primaryBlack,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
'Aplicar Filtros',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
),
),
),
),
),
SizedBox(height: MediaQuery.of(context).padding.bottom),
],
),
);
}
}

View File

@ -0,0 +1,74 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sizer/sizer.dart';
import '../../../core/app_export.dart';
import '../../../services/coupon_service.dart';
import '../../../widgets/custom_icon_widget.dart';
class SortDropdown extends StatelessWidget {
final String selectedSort;
final ValueChanged<String> onSortChanged;
const SortDropdown({
super.key,
required this.selectedSort,
required this.onSortChanged,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final sortOptions = CouponService.getSortOptions();
return Container(
padding: EdgeInsets.symmetric(horizontal: 4.w),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Ordenar por:',
style: theme.textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.w600,
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 3.w),
decoration: BoxDecoration(
border: Border.all(color: theme.colorScheme.outline),
borderRadius: BorderRadius.circular(8),
),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
value: selectedSort,
isDense: true,
icon: CustomIconWidget(
iconName: 'keyboard_arrow_down',
color: theme.colorScheme.onSurface,
size: 20,
),
items: sortOptions.map((String option) {
return DropdownMenuItem<String>(
value: option,
child: Text(
option,
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w500,
),
),
);
}).toList(),
onChanged: (String? newValue) {
if (newValue != null) {
HapticFeedback.lightImpact();
onSortChanged(newValue);
}
},
),
),
),
],
),
);
}
}

View File

@ -0,0 +1,760 @@
import 'dart:async';
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:fluttertoast/fluttertoast.dart';
import '../../models/bus_stop_model.dart';
import '../../models/route_model.dart';
import '../../services/transportation_service.dart';
import '../../services/app_state_service.dart';
import '../../services/supabase_service.dart';
import '../../widgets/custom_bottom_bar.dart';
import '../../widgets/route_selection_bottom_sheet.dart';
import '../../widgets/debug_banner_widget.dart';
import './widgets/bus_arrival_bottom_sheet.dart';
class MapScreen extends StatefulWidget {
const MapScreen({super.key});
@override
State<MapScreen> createState() => _MapScreenState();
}
class _MapScreenState extends State<MapScreen> {
final TransportationService _transportationService = TransportationService();
final AppStateService _appStateService = AppStateService();
GoogleMapController? _mapController;
// State variables
List<BusStopModel> _routeStops = [];
BusStopModel? _selectedStop;
Set<Marker> _markers = {};
bool _isLoading = false;
String? _error;
String? _nextBusMessage;
String? _lastRoutesError;
int _routeCount = 0;
// New connection check state variables
bool _isConnected = false;
String _connectionStatus = 'Not checked';
// Panama coordinates (centered around David/Boquete area)
static const LatLng _initialPosition = LatLng(8.4177, -82.4270);
@override
void initState() {
super.initState();
_appStateService.addListener(_onGlobalStateChanged);
_performSupabaseConnectionCheck();
}
@override
void dispose() {
_appStateService.removeListener(_onGlobalStateChanged);
_mapController?.dispose();
super.dispose();
}
void _onGlobalStateChanged() {
// React to global route selection changes
if (mounted) {
_loadStopsForSelectedRoute();
}
}
/// Perform Supabase connection check as specified in requirements
Future<void> _performSupabaseConnectionCheck() async {
if (!mounted) return;
setState(() {
_isLoading = true;
_error = null;
});
// Step 1 & 2: Validate credentials and initialize Supabase client
final connectionResult = await SupabaseService.performConnectionCheck();
if (connectionResult['success']) {
// Connection successful - show "Connected ✓" and count
if (mounted) {
setState(() {
_isConnected = true;
_connectionStatus = 'Connected ✓';
_routeCount = connectionResult['count'] ?? 0;
_lastRoutesError = null;
_isLoading = false;
});
}
// Load initial data after successful connection
if (mounted) {
await _loadInitialData();
}
} else {
// Connection failed - show error
final errorMessage = connectionResult['error'] ?? 'Unknown error';
if (mounted) {
setState(() {
_isConnected = false;
_connectionStatus = 'Connection Failed';
_lastRoutesError = errorMessage;
_error = errorMessage;
_isLoading = false;
});
}
// Show red toast for credential issues
if (errorMessage.contains('Missing') ||
errorMessage.contains('SUPABASE_URL') ||
errorMessage.contains('SUPABASE_ANON_KEY')) {
Fluttertoast.showToast(
msg: "Missing SUPABASE_URL or SUPABASE_ANON_KEY",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
}
}
}
Future<void> _loadInitialData() async {
setState(() {
_isLoading = true;
_error = null;
_lastRoutesError = null;
});
try {
// Check if we have routes loaded globally
if (_appStateService.allRoutes.isEmpty &&
!_appStateService.isLoadingRoutes) {
await _appStateService.loadRoutes();
}
final routes = _appStateService.allRoutes;
if (mounted) {
setState(() {
_routeCount = routes.length;
_lastRoutesError = null; // Clear any previous errors when successful
_isConnected = true; // Update connection status on successful data load
_connectionStatus = 'Connected ✓';
});
}
// Show toast if no routes found as specified in requirements
if (routes.isEmpty) {
WidgetsBinding.instance.addPostFrameCallback((_) {
Fluttertoast.showToast(
msg: "No routes available",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.orange,
textColor: Colors.white,
fontSize: 16.0,
);
});
if (mounted) {
setState(() {
_isLoading = false;
});
}
return;
}
// Auto-pick the first route if no route is selected (Step 6 from requirements)
if (mounted && _appStateService.selectedRouteId == null && routes.isNotEmpty) {
final firstRoute = routes.first;
await _appStateService.selectRoute(firstRoute.id);
}
// Load stops for currently selected route
if (mounted) {
await _loadStopsForSelectedRoute();
}
} catch (e) {
if (mounted) {
setState(() {
_error = 'Error loading routes: ${e.toString()}';
_lastRoutesError = e.toString();
_isLoading = false;
_isConnected = false;
_connectionStatus = 'Connection Failed';
});
}
// Show Supabase connection error as per requirements
if (e.toString().contains('connection') ||
e.toString().contains('credentials')) {
WidgetsBinding.instance.addPostFrameCallback((_) {
Fluttertoast.showToast(
msg: "Could not connect to Supabase. Please check credentials.",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
});
}
}
}
Future<void> _loadStopsForSelectedRoute() async {
final selectedRouteId = _appStateService.selectedRouteId;
if (selectedRouteId == null) {
setState(() {
_routeStops = [];
_markers = {};
_selectedStop = null;
_nextBusMessage = null;
_isLoading = false;
});
return;
}
setState(() {
_isLoading = true;
_error = null;
_selectedStop = null;
_nextBusMessage = null;
});
try {
// Use the exact query from requirements (Step 7)
final stops = await _transportationService.getRouteStopsOrderedBySeq(
selectedRouteId,
);
if (mounted) {
setState(() {
_routeStops = stops;
_isLoading = false;
});
}
// Clear and re-render markers
if (mounted) {
await _updateMapMarkers();
}
// Move camera to show all stops
if (mounted && stops.isNotEmpty && _mapController != null) {
_fitCameraToStops(stops);
}
} catch (e) {
if (mounted) {
setState(() {
_error = 'Error loading stops: ${e.toString()}';
_isLoading = false;
_routeStops = [];
_markers = {};
});
}
}
}
Future<void> _updateMapMarkers() async {
Set<Marker> markers = {};
for (int i = 0; i < _routeStops.length; i++) {
final stop = _routeStops[i];
final isSelected = _selectedStop?.id == stop.id;
markers.add(
Marker(
markerId: MarkerId(stop.id),
position: LatLng(stop.lat, stop.lng),
onTap: () => _onStopTapped(stop),
icon: await _createStopMarkerIcon(
isSelected: isSelected,
stopNumber: (i + 1).toString(),
),
infoWindow: InfoWindow(title: stop.name, snippet: 'Parada ${i + 1}'),
),
);
}
if (mounted) {
setState(() {
_markers = markers;
});
}
}
Future<BitmapDescriptor> _createStopMarkerIcon({
required bool isSelected,
required String stopNumber,
}) async {
if (isSelected) {
return BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueGreen);
} else {
return BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueYellow);
}
}
Future<void> _onStopTapped(BusStopModel stop) async {
if (!mounted) return;
setState(() {
_selectedStop = stop;
_nextBusMessage = null;
});
if (mounted) {
await _updateMapMarkers();
}
// Calculate next bus time for this stop
if (mounted) {
final selectedRouteId = _appStateService.selectedRouteId;
if (selectedRouteId != null) {
await _calculateNextBusTime(stop, selectedRouteId);
}
}
}
Future<void> _calculateNextBusTime(BusStopModel stop, String routeId) async {
try {
final nextBusInfo = await _transportationService.getNextBusTime(
routeId,
stop.id,
);
if (nextBusInfo != null) {
if (nextBusInfo['minutes_until_arrival'] != null) {
final minutes = nextBusInfo['minutes_until_arrival'] ?? 0;
final scheduleType = nextBusInfo['schedule_type'] ?? 'weekday';
String scheduleDisplay = '';
switch (scheduleType) {
case 'weekday':
scheduleDisplay = 'Lunes-Viernes';
break;
case 'saturday':
scheduleDisplay = 'Sábado';
break;
case 'sunday':
scheduleDisplay = 'Domingo';
break;
}
if (mounted) {
setState(() {
_nextBusMessage = 'Próximo bus en: $minutes min ($scheduleDisplay)';
});
}
} else if (nextBusInfo['first_tomorrow'] != null) {
if (mounted) {
setState(() {
_nextBusMessage =
'No hay más buses hoy. Primer bus mañana: ${nextBusInfo['first_tomorrow']}';
});
}
}
} else {
if (mounted) {
setState(() {
_nextBusMessage = 'No hay más buses programados';
});
}
}
} catch (e) {
if (mounted) {
setState(() {
_nextBusMessage = 'Error calculando próximo bus';
});
}
}
}
void _showBusArrivalInfo(BusStopModel stop, RouteModel route) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (context) => DraggableScrollableSheet(
initialChildSize: 0.6,
maxChildSize: 0.9,
minChildSize: 0.3,
builder: (context, scrollController) =>
BusArrivalBottomSheet(busStop: stop, route: route),
),
);
}
void _showRouteSelector() {
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
isScrollControlled: true,
builder: (context) => RouteSelectionBottomSheet(
title: 'Seleccionar Ruta',
onRouteChanged: () {
// The global state listener will handle the reload
},
),
);
}
void _fitCameraToStops(List<BusStopModel> stops) {
if (stops.isEmpty || _mapController == null) return;
double minLat = stops.first.lat;
double maxLat = stops.first.lat;
double minLng = stops.first.lng;
double maxLng = stops.first.lng;
for (final stop in stops) {
minLat = math.min(minLat, stop.lat);
maxLat = math.max(maxLat, stop.lat);
minLng = math.min(minLng, stop.lng);
maxLng = math.max(maxLng, stop.lng);
}
_mapController!.animateCamera(
CameraUpdate.newLatLngBounds(
LatLngBounds(
southwest: LatLng(minLat - 0.01, minLng - 0.01),
northeast: LatLng(maxLat + 0.01, maxLng + 0.01),
),
100.0,
),
);
}
void _onMapCreated(GoogleMapController controller) {
_mapController = controller;
if (_routeStops.isNotEmpty) {
_fitCameraToStops(_routeStops);
}
}
@override
Widget build(BuildContext context) {
final selectedRoute = _appStateService.getSelectedRoute();
final selectedRouteName = _appStateService.selectedRouteName;
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: const Color(0xFFFEE715),
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.menu, color: Color(0xFF101820)),
onPressed: () {
// TODO: Implement menu functionality
},
),
title: const Text(
'SIBU',
style: TextStyle(
color: Color(0xFF101820),
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
centerTitle: true,
actions: [
IconButton(
icon: const Icon(Icons.feedback, color: Color(0xFF101820)),
onPressed: () {
// TODO: Implement feedback functionality
},
),
],
),
body: RefreshIndicator(
onRefresh: _performSupabaseConnectionCheck,
child: Stack(
children: [
// Google Map
GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: const CameraPosition(
target: _initialPosition,
zoom: 11.0,
),
markers: _markers,
myLocationEnabled: true,
myLocationButtonEnabled: false,
zoomControlsEnabled: false,
mapToolbarEnabled: false,
),
// Debug banner with updated connection status
DebugBannerWidget(
lastError: _lastRoutesError,
routeCount: _routeCount,
isConnected: _isConnected,
connectionStatus: _connectionStatus,
),
// Route selector card (always visible when route is selected)
if (selectedRoute != null && selectedRouteName != null)
Positioned(
top: 80,
left: 16,
right: 16,
child: GestureDetector(
onTap: _showRouteSelector,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(26),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Row(
children: [
Icon(
Icons.route,
color: const Color(0xFF101820),
size: 24,
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Route: $selectedRouteName',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Color(0xFF101820),
),
),
Text(
'${_routeStops.length} stops',
style: TextStyle(
fontSize: 14,
color: Colors.grey[600],
),
),
],
),
),
Icon(
Icons.keyboard_arrow_down,
color: Colors.grey[600],
size: 20,
),
],
),
),
),
),
// Next bus info (when stop is selected)
if (_selectedStop != null && selectedRoute != null)
Positioned(
bottom: 100,
left: 16,
right: 16,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: const Color(0xFFFEE715),
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(26),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
_selectedStop!.name,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Color(0xFF101820),
),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
_nextBusMessage ?? 'Calculando próximo bus...',
style: TextStyle(
fontSize: 14,
color: const Color(0xFF101820).withAlpha(204),
),
textAlign: TextAlign.center,
),
const SizedBox(height: 12),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () => _showBusArrivalInfo(
_selectedStop!,
selectedRoute,
),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF101820),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
padding: const EdgeInsets.symmetric(vertical: 12),
),
child: const Text(
'CONSULTAR SIGUIENTE BUS',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
),
),
// Loading indicator
if (_isLoading)
Container(
color: Colors.black.withAlpha(77),
child: const Center(
child: CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation<Color>(Color(0xFFFEE715)),
),
),
),
// Error message (Step 4: red error card)
if (_error != null)
Positioned(
top: 150,
left: 16,
right: 16,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.red[100],
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.red[300]!),
),
child: Row(
children: [
Icon(Icons.error_outline,
color: Colors.red[600], size: 24),
const SizedBox(width: 12),
Expanded(
child: Text(
_error!,
style:
TextStyle(color: Colors.red[600], fontSize: 14),
),
),
IconButton(
onPressed: () {
setState(() => _error = null);
_performSupabaseConnectionCheck();
},
icon: Icon(
Icons.refresh,
color: Colors.red[600],
size: 20,
),
),
],
),
),
),
// No routes found message (Step 4)
if (_routeCount == 0 && !_isLoading && _error == null)
Positioned(
top: 150,
left: 16,
right: 16,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.orange[100],
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.orange[300]!),
),
child: Row(
children: [
Icon(
Icons.warning_outlined,
color: Colors.orange[600],
size: 24,
),
const SizedBox(width: 12),
const Expanded(
child: Text(
'No routes available',
style: TextStyle(fontSize: 14),
),
),
IconButton(
onPressed: _performSupabaseConnectionCheck,
icon: Icon(
Icons.refresh,
color: Colors.orange[600],
size: 20,
),
),
],
),
),
),
// Route selector floating button (when no route selected)
if (selectedRoute == null &&
!_appStateService.isLoadingRoutes &&
_routeCount > 0)
Positioned(
top: 80,
right: 16,
child: FloatingActionButton(
mini: true,
backgroundColor: const Color(0xFFFEE715),
onPressed: _showRouteSelector,
child: const Icon(Icons.route, color: Color(0xFF101820)),
),
),
// Small refresh icon with updated refresh method
if (selectedRoute != null)
Positioned(
top: 80,
right: 16,
child: FloatingActionButton(
mini: true,
backgroundColor: const Color(0xFFFEE715),
onPressed:
_performSupabaseConnectionCheck, // Updated to use connection check
child: const Icon(Icons.refresh, color: Color(0xFF101820)),
),
),
],
),
),
bottomNavigationBar: CustomBottomBar(
currentIndex: 0,
onTap: (int index) {
// Handle navigation tap
},
),
);
}
}

View File

@ -0,0 +1,461 @@
import 'package:flutter/material.dart';
import '../../../models/bus_stop_model.dart';
import '../../../models/route_model.dart';
import '../../../services/transportation_service.dart';
class BusArrivalBottomSheet extends StatefulWidget {
final BusStopModel busStop;
final RouteModel route;
const BusArrivalBottomSheet({
super.key,
required this.busStop,
required this.route,
});
@override
State<BusArrivalBottomSheet> createState() => _BusArrivalBottomSheetState();
}
class _BusArrivalBottomSheetState extends State<BusArrivalBottomSheet> {
final TransportationService _transportationService = TransportationService();
Map<String, dynamic>? _arrivalInfo;
List<Map<String, dynamic>> _schedules = [];
bool _isLoading = true;
String? _error;
@override
void initState() {
super.initState();
_loadArrivalInfo();
}
Future<void> _loadArrivalInfo() async {
try {
setState(() {
_isLoading = true;
_error = null;
});
// Load next bus arrival info using the new method with schedule_type
final arrivalInfo = await _transportationService.getNextBusTime(
widget.route.id,
widget.busStop.id,
);
// Load all schedules for this route from timetable (current day's schedule)
final schedules = await _transportationService.getRouteTimetables(
widget.route.id,
);
setState(() {
_arrivalInfo = arrivalInfo;
_schedules = schedules;
_isLoading = false;
});
} catch (e) {
setState(() {
_error = 'Error cargando información: ${e.toString()}';
_isLoading = false;
});
}
}
String _formatTime(String timeStr) {
try {
final parts = timeStr.split(':');
final hour = int.parse(parts[0]);
final minute = int.parse(parts[1]);
final period = hour >= 12 ? 'PM' : 'AM';
final displayHour = hour > 12 ? hour - 12 : (hour == 0 ? 12 : hour);
return '${displayHour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')} $period';
} catch (e) {
return timeStr;
}
}
String _formatMinutesUntil(int minutes) {
if (minutes <= 0) return 'Llegando ahora';
if (minutes == 1) return 'En 1 minuto';
if (minutes < 60) return 'En $minutes minutos';
final hours = minutes ~/ 60;
final remainingMinutes = minutes % 60;
if (remainingMinutes == 0) {
return hours == 1 ? 'En 1 hora' : 'En $hours horas';
}
return 'En ${hours}h ${remainingMinutes}min';
}
String _getScheduleTypeDisplay(String scheduleType) {
switch (scheduleType) {
case 'weekday':
return 'Lunes-Viernes';
case 'saturday':
return 'Sábado';
case 'sunday':
return 'Domingo';
default:
return scheduleType;
}
}
@override
Widget build(BuildContext context) {
return Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Handle bar
Container(
margin: const EdgeInsets.only(top: 12),
height: 4,
width: 40,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(2),
),
),
// Header
Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: const Color(0xFFFEE715),
borderRadius: BorderRadius.circular(8),
),
child: const Icon(
Icons.directions_bus,
color: Color(0xFF101820),
size: 24,
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.busStop.displayName,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF101820),
),
),
Text(
widget.route.displayName,
style: TextStyle(
fontSize: 14,
color: Colors.grey[600],
),
),
],
),
),
IconButton(
onPressed: () => Navigator.pop(context),
icon: const Icon(Icons.close),
color: const Color(0xFF101820),
),
],
),
],
),
),
// Content
Flexible(child: _buildContent()),
],
),
);
}
Widget _buildContent() {
if (_isLoading) {
return const Padding(
padding: EdgeInsets.all(40),
child: Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Color(0xFFFEE715)),
),
),
);
}
if (_error != null) {
return Padding(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.error_outline, size: 48, color: Colors.red[400]),
const SizedBox(height: 16),
Text(
_error!,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 16, color: Colors.red[600]),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _loadArrivalInfo,
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFFFEE715),
foregroundColor: const Color(0xFF101820),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text('Reintentar'),
),
],
),
);
}
return SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Next bus info
if (_arrivalInfo != null) ...[
Container(
width: double.infinity,
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: const Color(0xFFFEE715).withAlpha(26),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: const Color(0xFFFEE715), width: 1),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'Próximo Bus',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: const Color(0xFF101820),
),
),
const SizedBox(height: 8),
Text(
_formatMinutesUntil(
_arrivalInfo!['minutes_until_arrival'] ?? 0,
),
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Color(0xFF101820),
),
),
if (_arrivalInfo!['next_departure'] != null) ...[
const SizedBox(height: 4),
Text(
'Salida: ${_formatTime(_arrivalInfo!['next_departure'])}',
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
),
if (_arrivalInfo!['schedule_type'] != null) ...[
const SizedBox(height: 2),
Text(
'Horario: ${_getScheduleTypeDisplay(_arrivalInfo!['schedule_type'])}',
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
),
],
],
],
),
),
const SizedBox(height: 24),
],
// Next bus button
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _loadArrivalInfo,
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF101820),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
padding: const EdgeInsets.symmetric(vertical: 16),
),
child: const Text(
'Next bus',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
),
),
const SizedBox(height: 24),
// Bus stop info
Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.grey[50],
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Información de la Parada',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: const Color(0xFF101820),
),
),
const SizedBox(height: 12),
if (widget.busStop.fullAddress.isNotEmpty) ...[
Row(
children: [
Icon(
Icons.location_on,
size: 16,
color: Colors.grey[600],
),
const SizedBox(width: 8),
Expanded(
child: Text(
widget.busStop.fullAddress,
style: TextStyle(
fontSize: 14,
color: Colors.grey[600],
),
),
),
],
),
const SizedBox(height: 8),
],
Row(
children: [
Icon(Icons.category, size: 16, color: Colors.grey[600]),
const SizedBox(width: 8),
Text(
widget.busStop.stopTypeDisplay,
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
),
],
),
if (widget.busStop.amenities.isNotEmpty) ...[
const SizedBox(height: 8),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(Icons.star, size: 16, color: Colors.grey[600]),
const SizedBox(width: 8),
Expanded(
child: Text(
widget.busStop.amenitiesText,
style: TextStyle(
fontSize: 14,
color: Colors.grey[600],
),
),
),
],
),
],
],
),
),
// Schedule list
if (_schedules.isNotEmpty) ...[
const SizedBox(height: 24),
Text(
'Horarios de Salida',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: const Color(0xFF101820),
),
),
const SizedBox(height: 12),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.grey[300]!),
),
child: ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: _schedules.length > 6 ? 6 : _schedules.length,
separatorBuilder:
(context, index) =>
Divider(height: 1, color: Colors.grey[200]),
itemBuilder: (context, index) {
final schedule = _schedules[index];
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
child: Row(
children: [
Icon(Icons.schedule, size: 16, color: Colors.grey[600]),
const SizedBox(width: 12),
Text(
_formatTime(schedule['departure_time'] ?? ''),
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Color(0xFF101820),
),
),
const Spacer(),
if (schedule['frequency_minutes'] != null)
Text(
'Cada ${schedule['frequency_minutes']} min',
style: TextStyle(
fontSize: 12,
color: Colors.grey[600],
),
),
],
),
);
},
),
),
if (_schedules.length > 6) ...[
const SizedBox(height: 8),
Center(
child: Text(
'Y ${_schedules.length - 6} horarios más...',
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
),
),
],
],
const SizedBox(height: 24),
],
),
);
}
}

View File

@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
import '../../../core/app_export.dart';
class BusStopMarkerWidget extends StatelessWidget {
final Map<String, dynamic> busStop;
final bool isSelected;
final VoidCallback onTap;
const BusStopMarkerWidget({
super.key,
required this.busStop,
required this.isSelected,
required this.onTap,
});
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: AnimatedContainer(
duration: const Duration(milliseconds: 200),
width: isSelected ? 48.w : 40.w,
height: isSelected ? 48.w : 40.w,
decoration: BoxDecoration(
color: isSelected
? AppTheme.accentYellow
: AppTheme.accentYellow.withValues(alpha: 0.9),
shape: BoxShape.circle,
border: Border.all(
color: AppTheme.primaryBlack,
width: isSelected ? 3 : 2,
),
boxShadow: [
BoxShadow(
color: AppTheme.primaryBlack.withValues(alpha: 0.3),
blurRadius: isSelected ? 8 : 4,
offset: const Offset(0, 2),
),
],
),
child: Center(
child: CustomIconWidget(
iconName: 'directions_bus',
color: AppTheme.primaryBlack,
size: isSelected ? 24 : 20,
),
),
),
);
}
}

View File

@ -0,0 +1,120 @@
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
import '../../../core/app_export.dart';
import '../../../theme/app_theme.dart';
class LoadingOverlayWidget extends StatefulWidget {
final bool isVisible;
final String message;
const LoadingOverlayWidget({
super.key,
required this.isVisible,
this.message = 'Cargando...',
});
@override
State<LoadingOverlayWidget> createState() => _LoadingOverlayWidgetState();
}
class _LoadingOverlayWidgetState extends State<LoadingOverlayWidget>
with SingleTickerProviderStateMixin {
late AnimationController _animationController;
late Animation<double> _fadeAnimation;
@override
void initState() {
super.initState();
_animationController = AnimationController(
duration: const Duration(milliseconds: 300),
vsync: this,
);
_fadeAnimation = Tween<double>(
begin: 0.0,
end: 1.0,
).animate(CurvedAnimation(
parent: _animationController,
curve: Curves.easeInOut,
));
}
@override
void didUpdateWidget(LoadingOverlayWidget oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.isVisible != oldWidget.isVisible) {
if (widget.isVisible) {
_animationController.forward();
} else {
_animationController.reverse();
}
}
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (!widget.isVisible && _animationController.isDismissed) {
return const SizedBox.shrink();
}
return AnimatedBuilder(
animation: _fadeAnimation,
builder: (context, child) {
return Opacity(
opacity: _fadeAnimation.value,
child: Container(
width: double.infinity,
height: double.infinity,
color: AppTheme.primaryBlack.withValues(alpha: 0.3),
child: Center(
child: Container(
padding: EdgeInsets.all(6.w),
decoration: BoxDecoration(
color: AppTheme.lightTheme.colorScheme.surface,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: AppTheme.primaryBlack.withValues(alpha: 0.2),
blurRadius: 10,
offset: const Offset(0, 4),
),
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
width: 12.w,
height: 12.w,
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
AppTheme.accentYellow,
),
strokeWidth: 3,
),
),
SizedBox(height: 3.h),
Text(
widget.message,
style: AppTheme.lightTheme.textTheme.bodyMedium?.copyWith(
color: AppTheme.primaryBlack,
fontWeight: FontWeight.w500,
),
textAlign: TextAlign.center,
),
],
),
),
),
),
);
},
);
}
}

View File

@ -0,0 +1,113 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sizer/sizer.dart';
import '../../../core/app_export.dart';
class MapControlsWidget extends StatelessWidget {
final VoidCallback onLocationPressed;
final VoidCallback onZoomIn;
final VoidCallback onZoomOut;
final bool isLocationEnabled;
const MapControlsWidget({
super.key,
required this.onLocationPressed,
required this.onZoomIn,
required this.onZoomOut,
this.isLocationEnabled = true,
});
@override
Widget build(BuildContext context) {
return Positioned(
right: 4.w,
bottom: 25.h,
child: Column(
children: [
// Zoom In Button
_buildControlButton(
icon: 'add',
onPressed: () {
HapticFeedback.lightImpact();
onZoomIn();
},
tooltip: 'Acercar',
),
SizedBox(height: 1.h),
// Zoom Out Button
_buildControlButton(
icon: 'remove',
onPressed: () {
HapticFeedback.lightImpact();
onZoomOut();
},
tooltip: 'Alejar',
),
SizedBox(height: 2.h),
// Location Button
_buildControlButton(
icon: 'my_location',
onPressed: isLocationEnabled
? () {
HapticFeedback.mediumImpact();
onLocationPressed();
}
: null,
tooltip: 'Mi ubicación',
isLocationButton: true,
isEnabled: isLocationEnabled,
),
],
),
);
}
Widget _buildControlButton({
required String icon,
required VoidCallback? onPressed,
required String tooltip,
bool isLocationButton = false,
bool isEnabled = true,
}) {
return Container(
width: 12.w,
height: 12.w,
decoration: BoxDecoration(
color: isEnabled
? AppTheme.lightTheme.colorScheme.surface
: AppTheme.lightTheme.colorScheme.surface.withValues(alpha: 0.7),
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: AppTheme.primaryBlack.withValues(alpha: 0.1),
blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: onPressed,
borderRadius: BorderRadius.circular(8),
child: Center(
child: CustomIconWidget(
iconName: icon,
color: isEnabled
? (isLocationButton
? AppTheme.accentYellow
: AppTheme.primaryBlack)
: AppTheme.textSecondary,
size: 24,
),
),
),
),
);
}
}

View File

@ -0,0 +1,632 @@
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
import '../../core/app_export.dart';
import '../../models/route_model.dart';
import '../../services/app_state_service.dart';
import '../../services/transportation_service.dart';
import '../../widgets/custom_app_bar.dart';
import '../../widgets/custom_bottom_bar.dart';
import '../../widgets/route_selection_bottom_sheet.dart';
import './widgets/empty_state_widget.dart';
import './widgets/notification_badge_widget.dart';
import './widgets/route_selection_card.dart';
import './widgets/schedule_card.dart';
import './widgets/search_bar_widget.dart';
class SchedulesScreen extends StatefulWidget {
const SchedulesScreen({super.key});
@override
State<SchedulesScreen> createState() => _SchedulesScreenState();
}
class _SchedulesScreenState extends State<SchedulesScreen>
with TickerProviderStateMixin {
int _currentBottomIndex = 1; // Schedules tab
String _searchQuery = '';
final ScrollController _scrollController = ScrollController();
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
GlobalKey<RefreshIndicatorState>();
// Animation controllers
late AnimationController _fadeAnimationController;
late Animation<double> _fadeAnimation;
// Service and data
final TransportationService _transportationService = TransportationService();
final AppStateService _appStateService = AppStateService();
List<RouteModel> _routes = [];
List<Map<String, dynamic>> _schedules = [];
bool _isLoadingSchedules = false;
String _currentScheduleType = 'weekday';
// Notification state
final Map<String, bool> _notificationStates = {};
int _activeNotifications = 0;
@override
void initState() {
super.initState();
_initializeAnimations();
_appStateService.addListener(_onGlobalStateChanged);
_loadInitialData();
_determineCurrentScheduleType();
}
@override
void dispose() {
_appStateService.removeListener(_onGlobalStateChanged);
_fadeAnimationController.dispose();
_scrollController.dispose();
super.dispose();
}
void _initializeAnimations() {
_fadeAnimationController = AnimationController(
duration: const Duration(milliseconds: 300),
vsync: this,
);
_fadeAnimation = Tween<double>(
begin: 0.0,
end: 1.0,
).animate(CurvedAnimation(
parent: _fadeAnimationController,
curve: Curves.easeInOut,
));
}
void _onGlobalStateChanged() {
// React to global route selection changes
if (mounted) {
_loadSchedulesForSelectedRoute();
}
}
void _determineCurrentScheduleType() {
// Use Panama timezone as specified in requirements
final panamaNow =
DateTime.now().toUtc().add(Duration(hours: -5)); // Panama is UTC-5
final dayOfWeek = panamaNow.weekday;
// Monday = 1, Sunday = 7
if (dayOfWeek >= 1 && dayOfWeek <= 5) {
_currentScheduleType = 'weekday';
} else if (dayOfWeek == 6) {
_currentScheduleType = 'saturday';
} else {
_currentScheduleType = 'sunday';
}
}
Future<void> _loadInitialData() async {
// Check if we have routes loaded globally
if (_appStateService.allRoutes.isEmpty &&
!_appStateService.isLoadingRoutes) {
await _appStateService.loadRoutes();
}
// Show toast if no routes found
if (_appStateService.allRoutes.isEmpty) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_appStateService.showNoRoutesToast(context);
});
}
// Update local routes reference
setState(() {
_routes = _appStateService.allRoutes;
});
// Load schedules for currently selected route
await _loadSchedulesForSelectedRoute();
}
Future<void> _loadSchedulesForSelectedRoute() async {
final selectedRouteId = _appStateService.selectedRouteId;
if (selectedRouteId == null) {
setState(() {
_schedules = [];
_isLoadingSchedules = false;
});
return;
}
setState(() {
_isLoadingSchedules = true;
});
try {
final schedules =
await _transportationService.getRouteTimetablesByScheduleType(
selectedRouteId,
_currentScheduleType,
);
setState(() {
_schedules = schedules;
_isLoadingSchedules = false;
});
_fadeAnimationController.forward();
} catch (e) {
setState(() {
_isLoadingSchedules = false;
_schedules = [];
});
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Error loading schedules: ${e.toString()}'),
backgroundColor: Colors.red,
duration: const Duration(seconds: 3),
),
);
}
}
}
List<RouteModel> get _filteredRoutes {
if (_searchQuery.isEmpty) return _routes;
return _routes.where((route) {
final name = route.name.toLowerCase();
final query = _searchQuery.toLowerCase();
return name.contains(query);
}).toList();
}
List<Map<String, dynamic>> get _filteredSchedules {
if (_searchQuery.isEmpty) return _schedules;
return _schedules.where((schedule) {
final departureTime =
(schedule['departure_time'] as String).toLowerCase();
final query = _searchQuery.toLowerCase();
return departureTime.contains(query);
}).toList();
}
void _onBottomNavTap(int index) {
setState(() {
_currentBottomIndex = index;
});
}
Future<void> _onRouteSelected(String routeId) async {
await _appStateService.selectRoute(routeId);
setState(() {
_searchQuery = '';
});
}
void _onSearchChanged(String query) {
setState(() {
_searchQuery = query;
});
}
void _onSearchClear() {
setState(() {
_searchQuery = '';
});
}
void _toggleNotification(String scheduleId) {
setState(() {
final currentState = _notificationStates[scheduleId] ?? false;
_notificationStates[scheduleId] = !currentState;
if (!currentState) {
_activeNotifications++;
} else {
_activeNotifications--;
}
});
}
Future<void> _onRefresh() async {
await _appStateService.refreshRoutes();
setState(() {
_routes = _appStateService.allRoutes;
});
await _loadSchedulesForSelectedRoute();
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('Horarios actualizados'),
backgroundColor: AppTheme.lightTheme.colorScheme.tertiary,
duration: const Duration(seconds: 2),
),
);
}
}
void _showRouteSelector() {
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
isScrollControlled: true,
builder: (context) => RouteSelectionBottomSheet(
title: 'Seleccionar Ruta',
onRouteChanged: () {
// The global state listener will handle the reload
},
),
);
}
void _showScheduleContextMenu(String scheduleId, String departureTime) {
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (context) => Container(
decoration: BoxDecoration(
color: AppTheme.lightTheme.colorScheme.surface,
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
),
child: SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 12.w,
height: 0.5.h,
margin: EdgeInsets.symmetric(vertical: 2.h),
decoration: BoxDecoration(
color: AppTheme.lightTheme.colorScheme.outline,
borderRadius: BorderRadius.circular(2),
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 4.w),
child: Text(
'Opciones para $departureTime',
style: AppTheme.lightTheme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
),
),
),
SizedBox(height: 2.h),
_buildContextMenuItem(
icon: 'alarm_add',
title: 'Configurar Recordatorio',
onTap: () {
Navigator.pop(context);
_showReminderDialog(scheduleId, departureTime);
},
),
_buildContextMenuItem(
icon: 'share',
title: 'Compartir Horario',
onTap: () {
Navigator.pop(context);
_shareSchedule(departureTime);
},
),
_buildContextMenuItem(
icon: 'report_problem',
title: 'Reportar Problema',
onTap: () {
Navigator.pop(context);
_reportIssue(scheduleId);
},
),
SizedBox(height: 2.h),
],
),
),
),
);
}
Widget _buildContextMenuItem({
required String icon,
required String title,
required VoidCallback onTap,
}) {
return ListTile(
leading: CustomIconWidget(
iconName: icon,
color: AppTheme.lightTheme.colorScheme.onSurface,
size: 24,
),
title: Text(
title,
style: AppTheme.lightTheme.textTheme.bodyLarge,
),
onTap: onTap,
);
}
void _showReminderDialog(String scheduleId, String departureTime) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Configurar Recordatorio'),
content: Text(
'¿Deseas recibir una notificación antes de la salida de las $departureTime?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancelar'),
),
ElevatedButton(
onPressed: () {
Navigator.pop(context);
_toggleNotification(scheduleId);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Recordatorio configurado'),
duration: Duration(seconds: 2),
),
);
},
child: const Text('Confirmar'),
),
],
),
);
}
void _shareSchedule(String departureTime) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Compartiendo horario de $departureTime'),
duration: const Duration(seconds: 2),
),
);
}
void _reportIssue(String scheduleId) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Reporte enviado. Gracias por tu feedback.'),
duration: Duration(seconds: 2),
),
);
}
String _getScheduleTypeDisplayName() {
switch (_currentScheduleType) {
case 'weekday':
return 'Lunes a Viernes';
case 'saturday':
return 'Sábado';
case 'sunday':
return 'Domingo';
default:
return 'Horario';
}
}
Widget _buildRouteSelectionView() {
return Column(
children: [
Container(
padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 1.h),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CustomIconWidget(
iconName: 'schedule',
color: AppTheme.lightTheme.colorScheme.secondary,
size: 20,
),
SizedBox(width: 2.w),
Text(
'Horarios para ${_getScheduleTypeDisplayName()}',
style: AppTheme.lightTheme.textTheme.bodyMedium?.copyWith(
color: AppTheme.lightTheme.colorScheme.onSurfaceVariant,
fontWeight: FontWeight.w500,
),
),
],
),
),
SearchBarWidget(
hintText: 'Buscar rutas...',
onChanged: _onSearchChanged,
onClear: _onSearchClear,
),
Expanded(
child: _appStateService.isLoadingRoutes
? const Center(child: CircularProgressIndicator())
: _filteredRoutes.isEmpty
? const EmptyStateWidget(
title: 'No se encontraron rutas',
subtitle: 'Intenta con otros términos de búsqueda',
)
: ListView.builder(
controller: _scrollController,
itemCount: _filteredRoutes.length,
itemBuilder: (context, index) {
final route = _filteredRoutes[index];
return RouteSelectionCard(
routeName: route.displayName,
duration: route.direction,
onTap: () => _onRouteSelected(route.id),
);
},
),
),
],
);
}
Widget _buildScheduleView() {
final selectedRoute = _appStateService.getSelectedRoute();
final selectedRouteName = _appStateService.selectedRouteName;
if (selectedRoute == null || selectedRouteName == null) {
return const Center(
child: Text('No route selected'),
);
}
return Column(
children: [
Container(
padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 2.h),
decoration: BoxDecoration(
color: AppTheme.lightTheme.colorScheme.surface,
border: Border(
bottom: BorderSide(
color: AppTheme.lightTheme.colorScheme.outline,
width: 1,
),
),
),
child: Row(
children: [
GestureDetector(
onTap: () {
_appStateService.clearSelectedRoute();
setState(() {
_searchQuery = '';
_schedules.clear();
});
},
child: Container(
padding: EdgeInsets.all(2.w),
decoration: BoxDecoration(
color: AppTheme.lightTheme.colorScheme.secondary
.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
),
child: CustomIconWidget(
iconName: 'arrow_back',
color: AppTheme.lightTheme.colorScheme.primary,
size: 20,
),
),
),
SizedBox(width: 3.w),
Expanded(
child: GestureDetector(
onTap: _showRouteSelector,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
selectedRouteName,
style:
AppTheme.lightTheme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
),
overflow: TextOverflow.ellipsis,
),
Text(
'${_getScheduleTypeDisplayName()}${selectedRoute.direction}',
style:
AppTheme.lightTheme.textTheme.bodySmall?.copyWith(
color:
AppTheme.lightTheme.colorScheme.onSurfaceVariant,
),
),
],
),
),
),
],
),
),
SearchBarWidget(
hintText: 'Buscar horarios...',
onChanged: _onSearchChanged,
onClear: _onSearchClear,
),
Expanded(
child: RefreshIndicator(
key: _refreshIndicatorKey,
onRefresh: _onRefresh,
color: AppTheme.lightTheme.colorScheme.secondary,
child: _isLoadingSchedules
? const Center(child: CircularProgressIndicator())
: _filteredSchedules.isEmpty
? const EmptyStateWidget(
title: 'No hay horarios disponibles',
subtitle: 'Intenta actualizar o selecciona otra ruta',
)
: FadeTransition(
opacity: _fadeAnimation,
child: ListView.builder(
controller: _scrollController,
itemCount: _filteredSchedules.length,
itemBuilder: (context, index) {
final schedule = _filteredSchedules[index];
final scheduleId = schedule['id'].toString();
final departureTime =
schedule['departure_time'] as String;
final timeParts = departureTime.split(':');
final hour = timeParts[0];
final minute = timeParts[1];
final formattedTime = '$hour:$minute';
return ScheduleCard(
departureTime: formattedTime,
duration: selectedRoute.direction,
arrivalTime: '',
isNotificationEnabled:
_notificationStates[scheduleId] ?? false,
onNotificationToggle: () =>
_toggleNotification(scheduleId),
onLongPress: () => _showScheduleContextMenu(
scheduleId,
formattedTime,
),
);
},
),
),
),
),
],
);
}
@override
Widget build(BuildContext context) {
final hasSelectedRoute = _appStateService.hasSelectedRoute;
return Scaffold(
backgroundColor: AppTheme.lightTheme.scaffoldBackgroundColor,
appBar: CustomAppBar(
title: 'Horarios',
actions: [
NotificationBadgeWidget(
count: _activeNotifications,
child: IconButton(
icon: CustomIconWidget(
iconName: 'notifications',
color: AppTheme.lightTheme.colorScheme.onSurface,
size: 24,
),
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Tienes $_activeNotifications notificaciones activas'),
duration: const Duration(seconds: 2),
),
);
},
),
),
],
),
body: SafeArea(
child: !hasSelectedRoute
? _buildRouteSelectionView()
: _buildScheduleView(),
),
bottomNavigationBar: CustomBottomBar(
currentIndex: _currentBottomIndex,
onTap: _onBottomNavTap,
),
);
}
}

View File

@ -0,0 +1,71 @@
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
import '../../../core/app_export.dart';
class EmptyStateWidget extends StatelessWidget {
final String title;
final String subtitle;
final String? actionText;
final VoidCallback? onActionPressed;
const EmptyStateWidget({
super.key,
required this.title,
required this.subtitle,
this.actionText,
this.onActionPressed,
});
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(8.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 30.w,
height: 30.w,
decoration: BoxDecoration(
color: AppTheme.lightTheme.colorScheme.secondary
.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(15.w),
),
child: Center(
child: CustomIconWidget(
iconName: 'schedule',
color: AppTheme.lightTheme.colorScheme.secondary,
size: 15.w,
),
),
),
SizedBox(height: 4.h),
Text(
title,
style: AppTheme.lightTheme.textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.w600,
color: AppTheme.lightTheme.colorScheme.onSurface,
),
textAlign: TextAlign.center,
),
SizedBox(height: 2.h),
Text(
subtitle,
style: AppTheme.lightTheme.textTheme.bodyMedium?.copyWith(
color: AppTheme.lightTheme.colorScheme.onSurfaceVariant,
),
textAlign: TextAlign.center,
),
if (actionText != null && onActionPressed != null) ...[
SizedBox(height: 4.h),
ElevatedButton(
onPressed: onActionPressed,
child: Text(actionText!),
),
],
],
),
);
}
}

View File

@ -0,0 +1,58 @@
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
import '../../../core/app_export.dart';
import '../../../theme/app_theme.dart';
class NotificationBadgeWidget extends StatelessWidget {
final int count;
final Widget child;
const NotificationBadgeWidget({
super.key,
required this.count,
required this.child,
});
@override
Widget build(BuildContext context) {
return Stack(
clipBehavior: Clip.none,
children: [
child,
if (count > 0)
Positioned(
right: -1.w,
top: -0.5.h,
child: Container(
padding: EdgeInsets.symmetric(
horizontal: count > 9 ? 1.5.w : 1.w,
vertical: 0.5.h,
),
decoration: BoxDecoration(
color: AppTheme.lightTheme.colorScheme.error,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: AppTheme.lightTheme.colorScheme.surface,
width: 2,
),
),
constraints: BoxConstraints(
minWidth: 5.w,
minHeight: 2.5.h,
),
child: Text(
count > 99 ? '99+' : count.toString(),
style: AppTheme.lightTheme.textTheme.labelSmall?.copyWith(
color: AppTheme.lightTheme.colorScheme.onError,
fontWeight: FontWeight.w600,
fontSize: 10.sp,
),
textAlign: TextAlign.center,
),
),
),
],
);
}
}

View File

@ -0,0 +1,100 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sizer/sizer.dart';
import '../../../core/app_export.dart';
class RouteSelectionCard extends StatelessWidget {
final String routeName;
final String duration;
final VoidCallback onTap;
final bool isSelected;
const RouteSelectionCard({
super.key,
required this.routeName,
required this.duration,
required this.onTap,
this.isSelected = false,
});
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 4.w, vertical: 1.h),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () {
HapticFeedback.lightImpact();
onTap();
},
borderRadius: BorderRadius.circular(12),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 2.h),
decoration: BoxDecoration(
color: isSelected
? AppTheme.lightTheme.colorScheme.secondary
.withValues(alpha: 0.1)
: AppTheme.lightTheme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: isSelected
? AppTheme.lightTheme.colorScheme.secondary
: AppTheme.lightTheme.colorScheme.outline,
width: isSelected ? 2 : 1,
),
boxShadow: [
BoxShadow(
color: AppTheme.lightTheme.shadowColor.withValues(alpha: 0.1),
blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
routeName,
style:
AppTheme.lightTheme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
color: isSelected
? AppTheme.lightTheme.colorScheme.primary
: AppTheme.lightTheme.colorScheme.onSurface,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(height: 0.5.h),
Text(
'Duración estimada: $duration',
style:
AppTheme.lightTheme.textTheme.bodySmall?.copyWith(
color:
AppTheme.lightTheme.colorScheme.onSurfaceVariant,
),
overflow: TextOverflow.ellipsis,
),
],
),
),
SizedBox(width: 2.w),
CustomIconWidget(
iconName: 'chevron_right',
color: isSelected
? AppTheme.lightTheme.colorScheme.secondary
: AppTheme.lightTheme.colorScheme.onSurfaceVariant,
size: 24,
),
],
),
),
),
),
);
}
}

View File

@ -0,0 +1,236 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sizer/sizer.dart';
import '../../../core/app_export.dart';
class ScheduleCard extends StatefulWidget {
final String departureTime;
final String duration;
final String arrivalTime;
final bool isNotificationEnabled;
final VoidCallback onNotificationToggle;
final VoidCallback? onLongPress;
const ScheduleCard({
super.key,
required this.departureTime,
required this.duration,
required this.arrivalTime,
required this.isNotificationEnabled,
required this.onNotificationToggle,
this.onLongPress,
});
@override
State<ScheduleCard> createState() => _ScheduleCardState();
}
class _ScheduleCardState extends State<ScheduleCard>
with SingleTickerProviderStateMixin {
late AnimationController _animationController;
late Animation<double> _scaleAnimation;
@override
void initState() {
super.initState();
_animationController = AnimationController(
duration: const Duration(milliseconds: 150),
vsync: this,
);
_scaleAnimation = Tween<double>(
begin: 1.0,
end: 0.95,
).animate(CurvedAnimation(
parent: _animationController,
curve: Curves.easeInOut,
));
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
void _handleTapDown(TapDownDetails details) {
_animationController.forward();
}
void _handleTapUp(TapUpDetails details) {
_animationController.reverse();
}
void _handleTapCancel() {
_animationController.reverse();
}
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 4.w, vertical: 1.h),
child: AnimatedBuilder(
animation: _scaleAnimation,
builder: (context, child) {
return Transform.scale(
scale: _scaleAnimation.value,
child: GestureDetector(
onTapDown: _handleTapDown,
onTapUp: _handleTapUp,
onTapCancel: _handleTapCancel,
onLongPress: widget.onLongPress != null
? () {
HapticFeedback.mediumImpact();
widget.onLongPress!();
}
: null,
child: Container(
padding: EdgeInsets.all(4.w),
decoration: BoxDecoration(
color: AppTheme.lightTheme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: AppTheme.lightTheme.colorScheme.outline,
width: 1,
),
boxShadow: [
BoxShadow(
color: AppTheme.lightTheme.shadowColor
.withValues(alpha: 0.08),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Salida',
style: AppTheme
.lightTheme.textTheme.labelSmall
?.copyWith(
color: AppTheme.lightTheme.colorScheme
.onSurfaceVariant,
fontWeight: FontWeight.w500,
),
),
SizedBox(height: 0.5.h),
Text(
widget.departureTime,
style: AppTheme
.lightTheme.textTheme.titleLarge
?.copyWith(
fontWeight: FontWeight.w600,
color: AppTheme
.lightTheme.colorScheme.onSurface,
),
),
],
),
),
Container(
padding: EdgeInsets.symmetric(
horizontal: 2.w, vertical: 0.5.h),
decoration: BoxDecoration(
color: AppTheme
.lightTheme.colorScheme.secondary
.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
),
child: Text(
widget.duration,
style: AppTheme
.lightTheme.textTheme.labelMedium
?.copyWith(
color:
AppTheme.lightTheme.colorScheme.primary,
fontWeight: FontWeight.w600,
),
),
),
SizedBox(width: 3.w),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'Llegada',
style: AppTheme
.lightTheme.textTheme.labelSmall
?.copyWith(
color: AppTheme.lightTheme.colorScheme
.onSurfaceVariant,
fontWeight: FontWeight.w500,
),
),
SizedBox(height: 0.5.h),
Text(
widget.arrivalTime,
style: AppTheme
.lightTheme.textTheme.titleLarge
?.copyWith(
fontWeight: FontWeight.w600,
color: AppTheme
.lightTheme.colorScheme.onSurface,
),
),
],
),
),
],
),
],
),
),
SizedBox(width: 3.w),
GestureDetector(
onTap: () {
HapticFeedback.lightImpact();
widget.onNotificationToggle();
},
child: Container(
padding: EdgeInsets.all(2.w),
decoration: BoxDecoration(
color: widget.isNotificationEnabled
? AppTheme.lightTheme.colorScheme.secondary
: Colors.transparent,
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: widget.isNotificationEnabled
? AppTheme.lightTheme.colorScheme.secondary
: AppTheme.lightTheme.colorScheme.outline,
width: 1,
),
),
child: CustomIconWidget(
iconName: widget.isNotificationEnabled
? 'notifications'
: 'notifications_none',
color: widget.isNotificationEnabled
? AppTheme.lightTheme.colorScheme.onSecondary
: AppTheme
.lightTheme.colorScheme.onSurfaceVariant,
size: 20,
),
),
),
],
),
),
),
);
},
),
);
}
}

View File

@ -0,0 +1,109 @@
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
import '../../../core/app_export.dart';
class SearchBarWidget extends StatefulWidget {
final String hintText;
final ValueChanged<String> onChanged;
final VoidCallback? onClear;
const SearchBarWidget({
super.key,
required this.hintText,
required this.onChanged,
this.onClear,
});
@override
State<SearchBarWidget> createState() => _SearchBarWidgetState();
}
class _SearchBarWidgetState extends State<SearchBarWidget> {
final TextEditingController _controller = TextEditingController();
bool _hasText = false;
@override
void initState() {
super.initState();
_controller.addListener(_onTextChanged);
}
@override
void dispose() {
_controller.removeListener(_onTextChanged);
_controller.dispose();
super.dispose();
}
void _onTextChanged() {
final hasText = _controller.text.isNotEmpty;
if (hasText != _hasText) {
setState(() {
_hasText = hasText;
});
}
widget.onChanged(_controller.text);
}
void _clearSearch() {
_controller.clear();
widget.onClear?.call();
}
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 4.w, vertical: 1.h),
child: TextField(
controller: _controller,
style: AppTheme.lightTheme.textTheme.bodyMedium,
decoration: InputDecoration(
hintText: widget.hintText,
prefixIcon: Padding(
padding: EdgeInsets.all(3.w),
child: CustomIconWidget(
iconName: 'search',
color: AppTheme.lightTheme.colorScheme.onSurfaceVariant,
size: 20,
),
),
suffixIcon: _hasText
? IconButton(
icon: CustomIconWidget(
iconName: 'clear',
color: AppTheme.lightTheme.colorScheme.onSurfaceVariant,
size: 20,
),
onPressed: _clearSearch,
)
: null,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: AppTheme.lightTheme.colorScheme.outline,
width: 1,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: AppTheme.lightTheme.colorScheme.outline,
width: 1,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: AppTheme.lightTheme.colorScheme.primary,
width: 2,
),
),
filled: true,
fillColor: AppTheme.lightTheme.colorScheme.surface,
contentPadding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 2.h),
),
),
);
}
}

View File

@ -0,0 +1,357 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sizer/sizer.dart';
import '../../../core/app_export.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen>
with TickerProviderStateMixin {
late AnimationController _logoAnimationController;
late AnimationController _loadingAnimationController;
late Animation<double> _logoFadeAnimation;
late Animation<double> _logoScaleAnimation;
late Animation<double> _loadingOpacityAnimation;
bool _showLoading = false;
bool _initializationComplete = false;
String _statusMessage = 'Iniciando SIBU...';
@override
void initState() {
super.initState();
_setupAnimations();
_startInitialization();
}
void _setupAnimations() {
// Logo animation controller
_logoAnimationController = AnimationController(
duration: const Duration(milliseconds: 1500),
vsync: this,
);
// Loading animation controller
_loadingAnimationController = AnimationController(
duration: const Duration(milliseconds: 800),
vsync: this,
);
// Logo fade in animation
_logoFadeAnimation = Tween<double>(
begin: 0.0,
end: 1.0,
).animate(CurvedAnimation(
parent: _logoAnimationController,
curve: const Interval(0.0, 0.6, curve: Curves.easeOut),
));
// Logo scale animation
_logoScaleAnimation = Tween<double>(
begin: 0.8,
end: 1.0,
).animate(CurvedAnimation(
parent: _logoAnimationController,
curve: const Interval(0.0, 0.8, curve: Curves.elasticOut),
));
// Loading indicator opacity animation
_loadingOpacityAnimation = Tween<double>(
begin: 0.0,
end: 1.0,
).animate(CurvedAnimation(
parent: _loadingAnimationController,
curve: Curves.easeIn,
));
// Start logo animation
_logoAnimationController.forward();
}
Future<void> _startInitialization() async {
try {
// Show loading indicator after logo animation
await Future.delayed(const Duration(milliseconds: 1000));
setState(() {
_showLoading = true;
});
_loadingAnimationController.forward();
// Simulate initialization tasks
await _performInitializationTasks();
// Mark initialization as complete
setState(() {
_initializationComplete = true;
_statusMessage = 'Listo para usar';
});
// Navigate to main screen after brief delay
await Future.delayed(const Duration(milliseconds: 500));
_navigateToMainScreen();
} catch (e) {
_handleInitializationError(e);
}
}
Future<void> _performInitializationTasks() async {
// Task 1: Check GPS permissions
setState(() {
_statusMessage = 'Verificando permisos GPS...';
});
await Future.delayed(const Duration(milliseconds: 600));
// Task 2: Load cached route data
setState(() {
_statusMessage = 'Cargando datos de rutas...';
});
await Future.delayed(const Duration(milliseconds: 700));
// Task 3: Fetch latest bus schedules
setState(() {
_statusMessage = 'Actualizando horarios...';
});
await Future.delayed(const Duration(milliseconds: 800));
// Task 4: Prepare map tiles
setState(() {
_statusMessage = 'Preparando mapas...';
});
await Future.delayed(const Duration(milliseconds: 500));
}
void _navigateToMainScreen() {
// Navigate to map screen (main tab)
Navigator.pushReplacementNamed(context, '/map-screen');
}
void _handleInitializationError(dynamic error) {
setState(() {
_statusMessage = 'Error de conexión';
});
// Show continue offline option after 5 seconds
Future.delayed(const Duration(seconds: 5), () {
if (mounted && !_initializationComplete) {
_showContinueOfflineDialog();
}
});
}
void _showContinueOfflineDialog() {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
backgroundColor: AppTheme.lightTheme.colorScheme.surface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
title: Text(
'Continuar sin conexión',
style: AppTheme.lightTheme.textTheme.titleLarge?.copyWith(
color: AppTheme.lightTheme.colorScheme.onSurface,
),
),
content: Text(
'No se pudo conectar al servidor. ¿Deseas continuar con datos guardados?',
style: AppTheme.lightTheme.textTheme.bodyMedium?.copyWith(
color: AppTheme.lightTheme.colorScheme.onSurface,
),
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
_startInitialization(); // Retry
},
child: Text(
'Reintentar',
style: TextStyle(
color: AppTheme.lightTheme.colorScheme.primary,
),
),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
_navigateToMainScreen();
},
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.accentYellow,
foregroundColor: AppTheme.primaryBlack,
),
child: const Text('Continuar'),
),
],
);
},
);
}
Widget _buildLogo() {
return AnimatedBuilder(
animation: _logoAnimationController,
builder: (context, child) {
return Transform.scale(
scale: _logoScaleAnimation.value,
child: Opacity(
opacity: _logoFadeAnimation.value,
child: Container(
width: 35.w,
height: 35.w,
decoration: BoxDecoration(
color: AppTheme.accentYellow,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: AppTheme.primaryBlack.withValues(alpha: 0.2),
blurRadius: 20,
offset: const Offset(0, 8),
),
],
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CustomIconWidget(
iconName: 'directions_bus',
color: AppTheme.primaryBlack,
size: 12.w,
),
SizedBox(height: 1.h),
Text(
'SIBU',
style:
AppTheme.lightTheme.textTheme.headlineSmall?.copyWith(
color: AppTheme.primaryBlack,
fontWeight: FontWeight.bold,
letterSpacing: 2,
),
),
],
),
),
),
),
);
},
);
}
Widget _buildLoadingIndicator() {
return _showLoading
? AnimatedBuilder(
animation: _loadingAnimationController,
builder: (context, child) {
return Opacity(
opacity: _loadingOpacityAnimation.value,
child: Column(
children: [
SizedBox(height: 8.h),
SizedBox(
width: 8.w,
height: 8.w,
child: CircularProgressIndicator(
strokeWidth: 3,
valueColor: AlwaysStoppedAnimation<Color>(
AppTheme.accentYellow,
),
backgroundColor:
AppTheme.accentYellow.withValues(alpha: 0.3),
),
),
SizedBox(height: 3.h),
Text(
_statusMessage,
style: AppTheme.lightTheme.textTheme.bodyMedium?.copyWith(
color: AppTheme.surfaceWhite.withValues(alpha: 0.8),
),
textAlign: TextAlign.center,
),
],
),
);
},
)
: const SizedBox.shrink();
}
Widget _buildVersionInfo() {
return Positioned(
bottom: 8.h,
left: 0,
right: 0,
child: Column(
children: [
Text(
'Transporte Público Boquete',
style: AppTheme.lightTheme.textTheme.bodySmall?.copyWith(
color: AppTheme.surfaceWhite.withValues(alpha: 0.6),
),
),
SizedBox(height: 1.h),
Text(
'Versión 1.0.0',
style: AppTheme.lightTheme.textTheme.labelSmall?.copyWith(
color: AppTheme.surfaceWhite.withValues(alpha: 0.4),
),
),
],
),
);
}
@override
void dispose() {
_logoAnimationController.dispose();
_loadingAnimationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.light,
statusBarBrightness: Brightness.dark,
systemNavigationBarColor: AppTheme.primaryBlack,
systemNavigationBarIconBrightness: Brightness.light,
),
child: Scaffold(
backgroundColor: AppTheme.primaryBlack,
body: SafeArea(
child: SizedBox(
width: double.infinity,
height: double.infinity,
child: Stack(
children: [
// Main content
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildLogo(),
_buildLoadingIndicator(),
],
),
),
// Version info
_buildVersionInfo(),
],
),
),
),
),
);
}
}

View File

@ -0,0 +1,265 @@
import 'dart:async';
import 'package:flutter/material.dart';
import '../../models/taxi_model.dart';
import '../../services/taxi_service.dart';
import '../../widgets/custom_app_bar.dart';
import '../../widgets/custom_bottom_bar.dart';
import './widgets/taxi_card_widget.dart';
import './widgets/taxi_empty_state_widget.dart';
import './widgets/taxi_filters_widget.dart';
/// Main taxi screen with filtering, search, and favorites functionality
class TaxiScreen extends StatefulWidget {
const TaxiScreen({super.key});
@override
State<TaxiScreen> createState() => _TaxiScreenState();
}
class _TaxiScreenState extends State<TaxiScreen> {
final TaxiService _taxiService = TaxiService.instance;
Timer? _searchDebouncer;
// State variables
List<String> _corregimientos = [];
List<String> _shifts = [];
List<TaxiModel> _taxis = [];
Set<String> _favoriteTaxiIds = {};
String? _selectedCorregimiento;
String? _selectedShift;
String _searchText = '';
bool _isLoading = true;
String? _error;
@override
void initState() {
super.initState();
_loadInitialData();
}
@override
void dispose() {
_searchDebouncer?.cancel();
super.dispose();
}
/// Load corregimientos, shifts and initial taxi data
Future<void> _loadInitialData() async {
try {
setState(() {
_isLoading = true;
_error = null;
});
// Load corregimientos, shifts and favorites
final results = await Future.wait([
_taxiService.getCorregimientos(),
_taxiService.getFavoriteTaxiIds(),
]);
final corregimientos = results[0];
final favoriteIds = results[1];
setState(() {
_corregimientos = corregimientos;
_shifts = _taxiService.getShifts();
_favoriteTaxiIds = favoriteIds.toSet();
_isLoading = false;
});
// Load taxis for all corregimientos initially
await _searchTaxis();
} catch (e) {
setState(() {
_error = e.toString();
_isLoading = false;
});
}
}
/// Search taxis with current filters
Future<void> _searchTaxis() async {
try {
final taxis = await _taxiService.searchTaxis(
selectedCorregimiento: _selectedCorregimiento,
selectedShift: _selectedShift,
searchText: _searchText.isEmpty ? null : _searchText,
);
setState(() {
_taxis = taxis;
_error = null;
});
} catch (e) {
setState(() {
_error = e.toString();
});
}
}
/// Handle corregimiento selection change
void _onCorregimientoChanged(String? corregimiento) {
setState(() {
_selectedCorregimiento = corregimiento;
});
_searchTaxis();
}
/// Handle shift selection change
void _onShiftChanged(String? shift) {
setState(() {
_selectedShift = shift;
});
_searchTaxis();
}
/// Handle search text change with debouncing
void _onSearchChanged(String text) {
setState(() {
_searchText = text;
});
// Cancel previous timer
_searchDebouncer?.cancel();
// Start new timer for debounced search
_searchDebouncer = Timer(const Duration(milliseconds: 300), () {
_searchTaxis();
});
}
/// Clear all filters
void _onClearFilters() {
setState(() {
_selectedCorregimiento = null;
_selectedShift = null;
_searchText = '';
});
_searchTaxis();
}
/// Toggle favorite status for a taxi
Future<void> _onFavoriteToggle(String taxiId) async {
try {
final isFavorite = await _taxiService.toggleFavorite(taxiId);
setState(() {
if (isFavorite) {
_favoriteTaxiIds.add(taxiId);
} else {
_favoriteTaxiIds.remove(taxiId);
}
});
// Show feedback
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
isFavorite
? 'Taxi agregado a favoritos'
: 'Taxi removido de favoritos',
),
duration: const Duration(seconds: 2),
backgroundColor: isFavorite ? Colors.green : Colors.orange,
),
);
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Error al actualizar favoritos: $e'),
backgroundColor: Colors.red,
),
);
}
}
}
/// Handle pull to refresh
Future<void> _onRefresh() async {
await _loadInitialData();
}
/// Get current empty state widget based on context
Widget _getEmptyStateWidget() {
if (_error != null) {
return TaxiEmptyStateWidget.error(
error: _error!,
onRetry: _loadInitialData,
);
}
if (_selectedCorregimiento == null &&
_selectedShift == null &&
_searchText.isEmpty) {
return TaxiEmptyStateWidget.noFiltersSelected();
}
return TaxiEmptyStateWidget.noResultsFound(onClearFilters: _onClearFilters);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
backgroundColor: theme.colorScheme.surface,
appBar: const CustomAppBar(
title: 'Taxi Directory',
backgroundColor: Color(0xFF101820),
foregroundColor: Color(0xFFFEE715),
),
body: Column(
children: [
// Filters Section
TaxiFiltersWidget(
corregimientos: _corregimientos,
shifts: _shifts,
selectedCorregimiento: _selectedCorregimiento,
selectedShift: _selectedShift,
searchText: _searchText,
onCorregimientoChanged: _onCorregimientoChanged,
onShiftChanged: _onShiftChanged,
onSearchChanged: _onSearchChanged,
onClearFilters: _onClearFilters,
),
// Results Section
Expanded(
child:
_isLoading
? const Center(child: CircularProgressIndicator())
: _taxis.isEmpty
? _getEmptyStateWidget()
: RefreshIndicator(
onRefresh: _onRefresh,
child: ListView.builder(
itemCount: _taxis.length,
itemBuilder: (context, index) {
final taxi = _taxis[index];
return TaxiCardWidget(
taxi: taxi,
isFavorite: _favoriteTaxiIds.contains(taxi.id),
onFavoriteToggle: _onFavoriteToggle,
);
},
),
),
),
],
),
bottomNavigationBar: CustomBottomBar(
currentIndex: 3, // Taxi tab index
onTap: _onBottomNavTap,
),
);
}
/// Handle bottom navigation tap
void _onBottomNavTap(int index) {
// Navigation is handled by CustomBottomBar
}
}

View File

@ -0,0 +1,159 @@
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../../models/taxi_model.dart';
/// Individual taxi card widget displaying taxi information with call and favorite functionality
class TaxiCardWidget extends StatelessWidget {
final TaxiModel taxi;
final bool isFavorite;
final Function(String) onFavoriteToggle;
const TaxiCardWidget({
super.key,
required this.taxi,
required this.isFavorite,
required this.onFavoriteToggle,
});
/// Launch phone call
Future<void> _makePhoneCall(String phoneNumber) async {
final Uri launchUri = Uri(scheme: 'tel', path: phoneNumber);
try {
if (await canLaunchUrl(launchUri)) {
await launchUrl(launchUri);
}
} catch (e) {
// Handle error silently or show user feedback
}
}
/// Capitalize first letter of shift for display
String _formatShift(String shift) {
if (shift.isEmpty) return '';
return shift[0].toUpperCase() + shift.substring(1);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
elevation: 2,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Header Row: Name and Favorite Button
Row(
children: [
Expanded(
child: Text(
taxi.name,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
color: const Color(0xFF101820),
),
),
),
IconButton(
onPressed: () => onFavoriteToggle(taxi.id),
icon: Icon(
isFavorite ? Icons.favorite : Icons.favorite_border,
color:
isFavorite
? const Color(0xFFFEE715)
: theme.iconTheme.color,
),
tooltip:
isFavorite ? 'Remove from favorites' : 'Add to favorites',
),
],
),
const SizedBox(height: 8),
// Phone Row with Call Button
Row(
children: [
Icon(Icons.phone, size: 20, color: theme.iconTheme.color),
const SizedBox(width: 8),
Expanded(
child: Text(
taxi.phone,
style: theme.textTheme.bodyMedium?.copyWith(
color: const Color(0xFF101820),
),
),
),
ElevatedButton.icon(
onPressed: () => _makePhoneCall(taxi.phone),
icon: const Icon(Icons.call, size: 18),
label: const Text('Call'),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFFFEE715),
foregroundColor: const Color(0xFF101820),
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
],
),
const SizedBox(height: 8),
// Location and Shift Info
Row(
children: [
// Corregimiento
Expanded(
child: Row(
children: [
Icon(
Icons.location_on,
size: 16,
color: theme.iconTheme.color?.withAlpha(153),
),
const SizedBox(width: 4),
Text(
taxi.corregimiento,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.textTheme.bodySmall?.color?.withAlpha(
153,
),
),
),
],
),
),
// Shift
Row(
children: [
Icon(
Icons.schedule,
size: 16,
color: theme.iconTheme.color?.withAlpha(153),
),
const SizedBox(width: 4),
Text(
_formatShift(taxi.shift),
style: theme.textTheme.bodySmall?.copyWith(
color: theme.textTheme.bodySmall?.color?.withAlpha(153),
),
),
],
),
],
),
],
),
),
);
}
}

View File

@ -0,0 +1,116 @@
import 'package:flutter/material.dart';
/// Widget for displaying various empty states in the taxi screen
class TaxiEmptyStateWidget extends StatelessWidget {
final String title;
final String message;
final IconData icon;
final String? buttonText;
final VoidCallback? onButtonPressed;
const TaxiEmptyStateWidget({
super.key,
required this.title,
required this.message,
required this.icon,
this.buttonText,
this.onButtonPressed,
});
/// Empty state when no filters are selected
factory TaxiEmptyStateWidget.noFiltersSelected() {
return const TaxiEmptyStateWidget(
title: 'Select Filters',
message: 'Choose a corregimiento and/or shift to see available taxis.',
icon: Icons.filter_list,
);
}
/// Empty state when no results match the current filters
factory TaxiEmptyStateWidget.noResultsFound({
required VoidCallback onClearFilters,
}) {
return TaxiEmptyStateWidget(
title: 'No taxis available for this selection.',
message: 'Try adjusting your filters or search terms.',
icon: Icons.search_off,
buttonText: 'Clear Filters',
onButtonPressed: onClearFilters,
);
}
/// Empty state when there's no data at all
factory TaxiEmptyStateWidget.noData() {
return const TaxiEmptyStateWidget(
title: 'No taxis registered yet.',
message: 'There are no taxi services available at the moment.',
icon: Icons.local_taxi,
);
}
/// Empty state for error conditions
factory TaxiEmptyStateWidget.error({
required String error,
required VoidCallback onRetry,
}) {
return TaxiEmptyStateWidget(
title: 'Error Loading Taxis',
message: error,
icon: Icons.error_outline,
buttonText: 'Retry',
onButtonPressed: onRetry,
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon, size: 80, color: theme.iconTheme.color?.withAlpha(128)),
const SizedBox(height: 24),
Text(
title,
style: theme.textTheme.headlineSmall?.copyWith(
color: const Color(0xFF101820),
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 12),
Text(
message,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.textTheme.bodyMedium?.color?.withAlpha(153),
),
textAlign: TextAlign.center,
),
if (buttonText != null && onButtonPressed != null) ...[
const SizedBox(height: 24),
ElevatedButton(
onPressed: onButtonPressed,
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFFFEE715),
foregroundColor: const Color(0xFF101820),
padding: const EdgeInsets.symmetric(
horizontal: 24,
vertical: 12,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text(buttonText!),
),
],
],
),
),
);
}
}

View File

@ -0,0 +1,189 @@
import 'package:flutter/material.dart';
/// Widget for taxi search filters including corregimiento dropdown, shift dropdown and search input
class TaxiFiltersWidget extends StatefulWidget {
final List<String> corregimientos; // Changed from districts
final List<String> shifts; // Added shifts list
final String? selectedCorregimiento; // Changed from selectedDistrict
final String? selectedShift; // Added shift selection
final String searchText;
final Function(String?)
onCorregimientoChanged; // Changed from onDistrictChanged
final Function(String?) onShiftChanged; // Added shift handler
final Function(String) onSearchChanged;
final VoidCallback onClearFilters;
const TaxiFiltersWidget({
super.key,
required this.corregimientos, // Changed from districts
required this.shifts, // Added shifts
required this.selectedCorregimiento, // Changed from selectedDistrict
required this.selectedShift, // Added shift selection
required this.searchText,
required this.onCorregimientoChanged, // Changed from onDistrictChanged
required this.onShiftChanged, // Added shift handler
required this.onSearchChanged,
required this.onClearFilters,
});
@override
State<TaxiFiltersWidget> createState() => _TaxiFiltersWidgetState();
}
class _TaxiFiltersWidgetState extends State<TaxiFiltersWidget> {
late TextEditingController _searchController;
@override
void initState() {
super.initState();
_searchController = TextEditingController(text: widget.searchText);
}
@override
void dispose() {
_searchController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
boxShadow: [
BoxShadow(
color: theme.shadowColor.withAlpha(26),
blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
child: Column(
children: [
// Filter Dropdowns Row
Row(
children: [
// Corregimiento Dropdown
Expanded(
child: DropdownButtonFormField<String?>(
value:
widget
.selectedCorregimiento, // Changed from selectedDistrict
hint: const Text(
'Seleccionar Corregimiento',
), // Updated hint text
decoration: InputDecoration(
labelText:
'Filter by Corregimiento', // Updated label as requested
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
),
),
items: [
const DropdownMenuItem<String?>(
value: null,
child: Text('Todos los corregimientos'), // Updated text
),
...widget.corregimientos.map(
// Changed from districts
(corregimiento) => DropdownMenuItem<String?>(
value: corregimiento,
child: Text(corregimiento),
),
),
],
onChanged:
widget
.onCorregimientoChanged, // Changed from onDistrictChanged
),
),
const SizedBox(width: 12),
// Shift Dropdown
Expanded(
child: DropdownButtonFormField<String?>(
value: widget.selectedShift,
hint: const Text('Seleccionar Turno'),
decoration: InputDecoration(
labelText: 'Filter by Shift', // Label as requested
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
),
),
items: [
const DropdownMenuItem<String?>(
value: null,
child: Text('Todos los turnos'),
),
...widget.shifts.map(
(shift) => DropdownMenuItem<String?>(
value: shift,
child: Text(shift),
),
),
],
onChanged: widget.onShiftChanged,
),
),
if (widget.selectedCorregimiento !=
null || // Changed from selectedDistrict
widget.selectedShift != null || // Added shift condition
widget.searchText.isNotEmpty) ...[
const SizedBox(width: 8),
IconButton(
onPressed: widget.onClearFilters,
icon: const Icon(Icons.clear),
tooltip: 'Clear Filters', // Updated tooltip text as requested
style: IconButton.styleFrom(
backgroundColor: theme.colorScheme.errorContainer,
foregroundColor: theme.colorScheme.onErrorContainer,
),
),
],
],
),
const SizedBox(height: 12),
// Search Input
TextField(
controller: _searchController,
decoration: InputDecoration(
labelText: 'Buscar taxi o teléfono',
hintText: 'Escribe el nombre o número...',
prefixIcon: const Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
),
suffixIcon:
widget.searchText.isNotEmpty
? IconButton(
onPressed: () {
_searchController.clear();
widget.onSearchChanged('');
},
icon: const Icon(Icons.clear),
tooltip: 'Limpiar búsqueda',
)
: null,
),
onChanged: widget.onSearchChanged,
textInputAction: TextInputAction.search,
),
],
),
);
}
}

View File

@ -0,0 +1,29 @@
import 'package:flutter/material.dart';
import '../presentation/bus_stop_details/bus_stop_details.dart';
import '../presentation/splash_screen/splash_screen.dart';
import '../presentation/coupons_screen/coupons_screen.dart';
import '../presentation/schedules_screen/schedules_screen.dart';
import '../presentation/map_screen/map_screen.dart';
import '../presentation/taxi_screen/taxi_screen.dart';
class AppRoutes {
// TODO: Add your routes here
static const String initial = '/';
static const String busStopDetails = '/bus-stop-details';
static const String splash = '/splash-screen';
static const String coupons = '/coupons-screen';
static const String schedules = '/schedules-screen';
static const String map = '/map-screen';
static const String taxi = '/taxi-screen';
static Map<String, WidgetBuilder> routes = {
initial: (context) => const SplashScreen(),
busStopDetails: (context) => const BusStopDetails(),
splash: (context) => const SplashScreen(),
coupons: (context) => const CouponsScreen(),
schedules: (context) => const SchedulesScreen(),
map: (context) => const MapScreen(),
taxi: (context) => const TaxiScreen(),
// TODO: Add your other routes here
};
}

View File

@ -0,0 +1,170 @@
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
/// API Client for connecting to the FastAPI backend
class ApiClient {
static ApiClient? _instance;
static ApiClient get instance => _instance ??= ApiClient._();
late Dio _dio;
String _baseUrl = 'http://localhost:8000';
ApiClient._() {
_dio = Dio(BaseOptions(
baseUrl: _baseUrl,
connectTimeout: const Duration(seconds: 10),
receiveTimeout: const Duration(seconds: 10),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
));
// Add interceptors for logging in debug mode
if (kDebugMode) {
_dio.interceptors.add(LogInterceptor(
requestBody: true,
responseBody: true,
error: true,
));
}
// Error handling interceptor
_dio.interceptors.add(InterceptorsWrapper(
onError: (error, handler) {
if (error.response != null) {
debugPrint('API Error: ${error.response?.statusCode} - ${error.response?.data}');
} else {
debugPrint('API Error: ${error.message}');
}
handler.next(error);
},
));
}
/// Initialize with custom base URL
void initialize({String? baseUrl}) {
final url = baseUrl ?? getBaseUrl();
_baseUrl = url;
_dio.options.baseUrl = _baseUrl;
}
/// Get base URL from environment or use default
static String getBaseUrl() {
const url = String.fromEnvironment('API_BASE_URL');
return url.isNotEmpty ? url : 'http://localhost:8000';
}
/// Get current base URL
String get baseUrl => _baseUrl;
/// GET request
Future<Response<T>> get<T>(
String path, {
Map<String, dynamic>? queryParameters,
Options? options,
}) async {
try {
return await _dio.get<T>(
path,
queryParameters: queryParameters,
options: options,
);
} catch (e) {
if (e is DioException) {
rethrow;
}
throw DioException(
requestOptions: RequestOptions(path: path),
error: e,
);
}
}
/// POST request
Future<Response<T>> post<T>(
String path, {
dynamic data,
Map<String, dynamic>? queryParameters,
Options? options,
}) async {
try {
return await _dio.post<T>(
path,
data: data,
queryParameters: queryParameters,
options: options,
);
} catch (e) {
if (e is DioException) {
rethrow;
}
throw DioException(
requestOptions: RequestOptions(path: path),
error: e,
);
}
}
/// PUT request
Future<Response<T>> put<T>(
String path, {
dynamic data,
Map<String, dynamic>? queryParameters,
Options? options,
}) async {
try {
return await _dio.put<T>(
path,
data: data,
queryParameters: queryParameters,
options: options,
);
} catch (e) {
if (e is DioException) {
rethrow;
}
throw DioException(
requestOptions: RequestOptions(path: path),
error: e,
);
}
}
/// DELETE request
Future<Response<T>> delete<T>(
String path, {
dynamic data,
Map<String, dynamic>? queryParameters,
Options? options,
}) async {
try {
return await _dio.delete<T>(
path,
data: data,
queryParameters: queryParameters,
options: options,
);
} catch (e) {
if (e is DioException) {
rethrow;
}
throw DioException(
requestOptions: RequestOptions(path: path),
error: e,
);
}
}
/// Check if API is available
Future<bool> checkConnection() async {
try {
final response = await _dio.get('/health');
return response.statusCode == 200;
} catch (e) {
return false;
}
}
}

View File

@ -0,0 +1,207 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import '../models/route_model.dart';
import './transportation_service.dart';
/// Global app state service to manage selected route across the entire app
class AppStateService extends ChangeNotifier {
static final AppStateService _instance = AppStateService._internal();
factory AppStateService() => _instance;
AppStateService._internal();
final TransportationService _transportationService = TransportationService();
// Global state
String? _selectedRouteId;
String? _selectedRouteName;
List<RouteModel> _allRoutes = [];
bool _isLoadingRoutes = false;
String? _error;
// Getters
String? get selectedRouteId => _selectedRouteId;
String? get selectedRouteName => _selectedRouteName;
List<RouteModel> get allRoutes => List.unmodifiable(_allRoutes);
bool get isLoadingRoutes => _isLoadingRoutes;
String? get error => _error;
bool get hasSelectedRoute =>
_selectedRouteId != null && _selectedRouteName != null;
/// Initialize app state - call this on app start
Future<void> initialize() async {
await loadRoutes();
}
/// Load all routes from Supabase
Future<void> loadRoutes() async {
if (_isLoadingRoutes) return;
_isLoadingRoutes = true;
notifyListeners();
try {
final result = await _transportationService.getRoutesWithCount();
final routes = result['data'] as List<RouteModel>;
final count = result['count'] as int;
final error = result['error'] as String?;
if (error != null) {
print('Error loading routes: $error');
// Handle error but continue with empty list
_allRoutes = [];
} else {
_allRoutes = routes;
// Auto-select first route if none selected and routes available
if (routes.isNotEmpty && _selectedRouteId == null) {
await selectRoute(routes.first.id);
}
}
_isLoadingRoutes = false;
notifyListeners();
// Show toast if no routes found as specified in requirements
if (_allRoutes.isEmpty) {
_showNoRoutesToast();
}
} catch (e) {
print('Exception loading routes: $e');
_allRoutes = [];
_isLoadingRoutes = false;
notifyListeners();
// Show error toast for exceptions
Fluttertoast.showToast(
msg: "Error loading routes: ${e.toString()}",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
}
}
void _showNoRoutesToast() {
Fluttertoast.showToast(
msg: "No routes found",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.orange,
textColor: Colors.white,
fontSize: 16.0,
);
}
/// Select a route and update global state
Future<void> selectRoute(String routeId) async {
if (routeId == _selectedRouteId) return;
try {
// Find the route in our cached routes
final route = _allRoutes.firstWhere(
(r) => r.id == routeId,
orElse: () => throw Exception('Route not found: $routeId'),
);
_selectedRouteId = routeId;
_selectedRouteName = route.displayName;
_error = null;
debugPrint('✅ Route selected: $routeId - $_selectedRouteName');
notifyListeners();
} catch (e) {
_error = 'Error selecting route: $e';
debugPrint('❌ Error selecting route: $e');
notifyListeners();
}
}
/// Clear selected route
void clearSelectedRoute() {
_selectedRouteId = null;
_selectedRouteName = null;
notifyListeners();
}
/// Get selected route model
RouteModel? getSelectedRoute() {
if (_selectedRouteId == null) return null;
try {
return _allRoutes.firstWhere((r) => r.id == _selectedRouteId!);
} catch (e) {
return null;
}
}
/// Private method to select first available route with stops
Future<void> _selectFirstAvailableRoute() async {
for (final route in _allRoutes) {
try {
final stops =
await _transportationService.getRouteStopsOrderedBySeq(route.id);
if (stops.isNotEmpty) {
_selectedRouteId = route.id;
_selectedRouteName = route.displayName;
debugPrint(
'✅ Auto-selected route: ${route.id} - ${route.displayName}');
return;
}
} catch (e) {
debugPrint('⚠️ Error checking stops for route ${route.id}: $e');
}
}
// Fallback: select first route even if no stops
if (_allRoutes.isNotEmpty) {
final firstRoute = _allRoutes.first;
_selectedRouteId = firstRoute.id;
_selectedRouteName = firstRoute.displayName;
debugPrint(
'✅ Fallback: selected first route: ${firstRoute.id} - ${firstRoute.displayName}');
}
}
/// Refresh routes and maintain selection if possible
Future<void> refreshRoutes() async {
final previousSelectedId = _selectedRouteId;
await loadRoutes();
// Try to restore previous selection
if (previousSelectedId != null &&
_allRoutes.any((r) => r.id == previousSelectedId)) {
await selectRoute(previousSelectedId);
}
}
/// Get route by ID
RouteModel? getRouteById(String routeId) {
try {
return _allRoutes.firstWhere((r) => r.id == routeId);
} catch (e) {
return null;
}
}
/// Check if route exists
bool hasRoute(String routeId) {
return _allRoutes.any((r) => r.id == routeId);
}
/// Show toast message for no routes found
void showNoRoutesToast(BuildContext context) {
if (_allRoutes.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('No routes found'),
backgroundColor: Colors.orange,
duration: Duration(seconds: 3),
),
);
}
}
}

View File

@ -0,0 +1,130 @@
import '../models/coupon_model.dart';
import './supabase_service.dart';
class CouponService {
/// Fetches coupons with auto-reconnection and exact query logic from requirements
static Future<List<CouponModel>> getCoupons({
String? selectedCategory,
String? sort,
}) async {
return await SupabaseService.withAutoReconnect(() async {
final client = SupabaseService.client;
// Exact query from requirements specification
var query = client
.from('coupons')
.select(
'id, business_name, title, description, valid_until, image_url, category, is_active, created_at',
);
// Apply the exact WHERE conditions from requirements
query = query.eq('is_active', true);
// Handle date filter: (valid_until IS NULL OR valid_until >= CURRENT_DATE)
final currentDate = DateTime.now().toIso8601String().split('T')[0];
query = query.or('valid_until.is.null,valid_until.gte.$currentDate');
// Category filter: ignore when 'Todos' is selected
if (selectedCategory != null && selectedCategory != 'Todos') {
final categoryValue = _mapDisplayCategoryToDbValue(selectedCategory);
query = query.eq('category', categoryValue);
}
// Apply sorting based on requirements
final dynamic response;
if (sort == 'Por vencer') {
// Sort by expiring first (null values last)
response = await query.order('valid_until', ascending: true, nullsFirst: false);
} else {
// Default: "Más recientes" - sort by created_at descending
response = await query.order('created_at', ascending: false);
}
return (response as List)
.map((data) => CouponModel.fromMap(data))
.toList();
});
}
/// Maps display category names to database enum values
static String _mapDisplayCategoryToDbValue(String displayCategory) {
switch (displayCategory.toLowerCase()) {
case 'restaurantes':
return 'restaurantes';
case 'tiendas':
return 'tiendas';
case 'servicios':
return 'servicios';
case 'entretenimiento':
return 'entretenimiento';
case 'salud':
return 'salud';
case 'belleza':
return 'belleza';
default:
return 'restaurantes'; // fallback
}
}
/// Gets available category options for filtering (Spanish UI)
static List<String> getCategoryOptions() {
return [
'Todos',
'Restaurantes',
'Tiendas',
'Servicios',
'Entretenimiento',
'Salud',
'Belleza',
];
}
/// Gets available sort options (Spanish UI)
static List<String> getSortOptions() {
return ['Más recientes', 'Por vencer'];
}
/// Gets a single coupon by ID with auto-reconnection
static Future<CouponModel?> getCouponById(String id) async {
try {
return await SupabaseService.withAutoReconnect(() async {
final client = SupabaseService.client;
final response =
await client
.from('coupons')
.select(
'id, business_name, title, description, valid_until, image_url, category, is_active, created_at',
)
.eq('id', id)
.eq('is_active', true)
.single();
return CouponModel.fromMap(response);
});
} catch (e) {
// Silent failure - return null
return null;
}
}
/// Counts total coupons for a category with auto-reconnection
static Future<int> getCouponCount({String? category}) async {
try {
return await SupabaseService.withAutoReconnect(() async {
final client = SupabaseService.client;
var query = client.from('coupons').select('id').eq('is_active', true);
if (category != null && category.toLowerCase() != 'todos') {
final categoryValue = _mapDisplayCategoryToDbValue(category);
query = query.eq('category', categoryValue);
}
final response = await query.count();
return response.count ?? 0;
});
} catch (e) {
// Silent failure - return 0
return 0;
}
}
}

View File

@ -0,0 +1,255 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:fluttertoast/fluttertoast.dart';
/// Enhanced Supabase service with auto-connection and silent retry logic
class SupabaseService {
static SupabaseService? _instance;
static SupabaseService get instance => _instance ??= SupabaseService._();
static Timer? _retryTimer;
static bool _isInitializing = false;
SupabaseService._();
/// Get the Supabase client instance with auto-initialization
static SupabaseClient get client {
_ensureInitialized();
return Supabase.instance.client;
}
/// Auto-initialize with environment variables and silent retry
static void _ensureInitialized() {
if (!_isInitialized() && !_isInitializing) {
_initializeWithRetry();
}
}
/// Check if Supabase is properly initialized
static bool _isInitialized() {
try {
final url = const String.fromEnvironment('SUPABASE_URL');
final key = const String.fromEnvironment('SUPABASE_ANON_KEY');
if (url.isEmpty || key.isEmpty) {
return false;
}
// Check if current client matches the environment variables
final currentClient = Supabase.instance.client;
return currentClient.headers['Authorization']?.contains(key) ?? false;
} catch (e) {
return false;
}
}
/// Initialize with automatic retry every 2 seconds until success
static void _initializeWithRetry() {
if (_isInitializing) return;
_isInitializing = true;
_retryTimer?.cancel();
_retryTimer = Timer.periodic(const Duration(seconds: 2), (timer) async {
try {
const supabaseUrl = String.fromEnvironment('SUPABASE_URL');
const supabaseAnonKey = String.fromEnvironment('SUPABASE_ANON_KEY');
// Stop and reinitialize once envs are available
if (supabaseUrl.isNotEmpty && supabaseAnonKey.isNotEmpty) {
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseAnonKey,
debug: false,
);
timer.cancel();
_isInitializing = false;
_retryTimer = null;
}
} catch (e) {
// Silent retry - continue timer
}
});
}
/// Initialize Supabase with environment variables
static Future<void> initialize() async {
const supabaseUrl = String.fromEnvironment('SUPABASE_URL');
const supabaseAnonKey = String.fromEnvironment('SUPABASE_ANON_KEY');
if (supabaseUrl.isEmpty || supabaseAnonKey.isEmpty) {
throw Exception('Missing Supabase credentials');
}
await Supabase.initialize(
url: supabaseUrl,
anonKey: supabaseAnonKey,
debug: false,
);
}
/// Auto-reconnection wrapper for database operations
static Future<T> withAutoReconnect<T>(Future<T> Function() operation) async {
try {
return await operation();
} catch (e) {
final errorMessage = e.toString().toLowerCase();
// Check for connection errors
if (errorMessage.contains('failed to connect') ||
errorMessage.contains('networkerror') ||
errorMessage.contains('invalid key') ||
errorMessage.contains('connection') ||
errorMessage.contains('timeout')) {
// Wait 500-1000ms debounce before retry
await Future.delayed(const Duration(milliseconds: 750));
try {
// Reinitialize client
await initialize();
// Retry the operation once
return await operation();
} catch (retryError) {
// Silent failure - operation will return empty results
throw retryError;
}
}
// Re-throw non-connection errors
throw e;
}
}
/// Validate Supabase credentials and show toast if missing
static bool validateCredentials(BuildContext? context) {
const supabaseUrl = String.fromEnvironment('SUPABASE_URL');
const supabaseAnonKey = String.fromEnvironment('SUPABASE_ANON_KEY');
if (supabaseUrl.isEmpty || supabaseAnonKey.isEmpty) {
Fluttertoast.showToast(
msg: "Missing SUPABASE_URL or SUPABASE_ANON_KEY",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
return false;
}
return true;
}
/// Get truncated Supabase URL for debug display (first/last 8 chars)
static String getTruncatedUrl() {
const supabaseUrl = String.fromEnvironment('SUPABASE_URL');
if (supabaseUrl.isEmpty) return 'Not configured';
if (supabaseUrl.length <= 16) return supabaseUrl;
final first8 = supabaseUrl.substring(0, 8);
final last8 = supabaseUrl.substring(supabaseUrl.length - 8);
return '$first8...$last8';
}
/// Get masked Supabase anon key for debug display (first/last 6 chars, masked middle)
static String getMaskedAnonKey() {
const supabaseAnonKey = String.fromEnvironment('SUPABASE_ANON_KEY');
if (supabaseAnonKey.isEmpty) return 'Not configured';
if (supabaseAnonKey.length <= 12)
return '${supabaseAnonKey.substring(0, 3)}***${supabaseAnonKey.substring(supabaseAnonKey.length - 3)}';
final first6 = supabaseAnonKey.substring(0, 6);
final last6 = supabaseAnonKey.substring(supabaseAnonKey.length - 6);
return '$first6***$last6';
}
/// Connection check with lightweight test query
static Future<Map<String, dynamic>> performConnectionCheck() async {
try {
// 1) Read env vars and validate
if (!validateCredentials(null)) {
return {
'success': false,
'error': 'Missing SUPABASE_URL or SUPABASE_ANON_KEY',
'count': null,
};
}
// 2) Initialize Supabase client if needed
try {
await initialize();
} catch (e) {
// Client might already be initialized, continue
}
// 3) Run lightweight test query exactly as specified:
// const { data, error } = await supabase.from('routes').select('id', { head: true, count: 'exact' });
final response = await Supabase.instance.client
.from('routes')
.select('id')
.limit(1); // Using limit instead of head for Flutter supabase client
// Get count separately for exact count
final countResponse =
await Supabase.instance.client.from('routes').select('*');
final count = (countResponse as List).length;
return {'success': true, 'error': null, 'count': count};
} catch (e) {
return {'success': false, 'error': e.toString(), 'count': null};
}
}
/// Check if Supabase is initialized
bool get isInitialized {
try {
return Supabase.instance.client.auth.currentUser != null ||
Supabase.instance.client.auth.currentSession != null ||
true; // Supabase is initialized even without user
} catch (e) {
return false;
}
}
/// Force reconnect to Supabase
static Future<bool> forceReconnect(BuildContext? context) async {
try {
if (!validateCredentials(context)) {
return false;
}
// Re-initialize Supabase
await initialize();
// Test connection with the lightweight query
final result = await performConnectionCheck();
if (!result['success']) {
Fluttertoast.showToast(
msg: "Connection failed: ${result['error']}",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
return false;
}
return true;
} catch (e) {
Fluttertoast.showToast(
msg: "Failed to connect to Supabase: ${e.toString()}",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
return false;
}
}
}

View File

@ -0,0 +1,243 @@
import 'package:shared_preferences/shared_preferences.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import '../models/taxi_model.dart';
import './supabase_service.dart';
/// Service for managing taxi data and favorites functionality
class TaxiService {
static TaxiService? _instance;
static TaxiService get instance => _instance ??= TaxiService._();
TaxiService._();
final SupabaseClient _client = SupabaseService.client;
static const String _favoritesKey = 'favorite_taxi_ids';
/// Get distinct corregimientos from active taxis
Future<List<String>> getCorregimientos() async {
try {
final response = await _client
.from('taxis')
.select('corregimiento')
.eq('is_active', true)
.order('corregimiento');
if (response.isEmpty) return [];
// Extract unique corregimientos
final Set<String> uniqueCorregimientos = {};
for (final item in response) {
final corregimiento = item['corregimiento'] as String?;
if (corregimiento != null && corregimiento.isNotEmpty) {
uniqueCorregimientos.add(corregimiento);
}
}
return uniqueCorregimientos.toList()..sort();
} catch (e) {
throw Exception('Failed to fetch corregimientos: $e');
}
}
/// Get available shifts
List<String> getShifts() {
return ['Day', 'Evening', 'Night'];
}
/// Search taxis with optional corregimiento, shift, and text filters
Future<List<TaxiModel>> searchTaxis({
String? selectedCorregimiento,
String? selectedShift,
String? searchText,
}) async {
try {
var query = _client.from('taxis').select('*').eq('is_active', true);
// Apply corregimiento filter
if (selectedCorregimiento != null && selectedCorregimiento.isNotEmpty) {
query = query.eq('corregimiento', selectedCorregimiento);
}
// Apply shift filter
if (selectedShift != null && selectedShift.isNotEmpty) {
// Convert display name to database value
String dbShift = selectedShift.toLowerCase();
query = query.eq('shift', dbShift);
}
// Apply text search filter
if (searchText != null && searchText.isNotEmpty) {
query = query.or('name.ilike.%$searchText%,phone.ilike.%$searchText%');
}
final response = await query.order('name');
return response
.map<TaxiModel>((json) => TaxiModel.fromJson(json))
.toList();
} catch (e) {
throw Exception('Failed to search taxis: $e');
}
}
/// Get user's favorite taxi IDs (from Supabase or local storage)
Future<List<String>> getFavoriteTaxiIds() async {
try {
// Check if user is authenticated
final user = _client.auth.currentUser;
if (user != null) {
// Get favorites from Supabase
final response = await _client
.from('favorite_taxis')
.select('taxi_id')
.eq('user_id', user.id);
return response
.map<String>((item) => item['taxi_id'] as String)
.toList();
} else {
// Get favorites from local storage
return await _getLocalFavorites();
}
} catch (e) {
// Fallback to local storage if Supabase fails
return await _getLocalFavorites();
}
}
/// Toggle favorite status for a taxi
Future<bool> toggleFavorite(String taxiId) async {
try {
final user = _client.auth.currentUser;
if (user != null) {
// Handle Supabase favorites
return await _toggleSupabaseFavorite(user.id, taxiId);
} else {
// Handle local storage favorites
return await _toggleLocalFavorite(taxiId);
}
} catch (e) {
// Fallback to local storage
return await _toggleLocalFavorite(taxiId);
}
}
/// Check if taxi is favorited
Future<bool> isFavorite(String taxiId) async {
final favorites = await getFavoriteTaxiIds();
return favorites.contains(taxiId);
}
/// Handle Supabase favorite toggle
Future<bool> _toggleSupabaseFavorite(String userId, String taxiId) async {
try {
// Check if favorite exists
final existing =
await _client
.from('favorite_taxis')
.select('id')
.eq('user_id', userId)
.eq('taxi_id', taxiId)
.maybeSingle();
if (existing != null) {
// Remove favorite
await _client
.from('favorite_taxis')
.delete()
.eq('user_id', userId)
.eq('taxi_id', taxiId);
return false;
} else {
// Add favorite
await _client.from('favorite_taxis').insert({
'user_id': userId,
'taxi_id': taxiId,
});
return true;
}
} catch (e) {
throw Exception('Failed to toggle Supabase favorite: $e');
}
}
/// Handle local storage favorite toggle
Future<bool> _toggleLocalFavorite(String taxiId) async {
try {
final prefs = await SharedPreferences.getInstance();
final favorites = prefs.getStringList(_favoritesKey) ?? [];
if (favorites.contains(taxiId)) {
favorites.remove(taxiId);
await prefs.setStringList(_favoritesKey, favorites);
return false;
} else {
favorites.add(taxiId);
await prefs.setStringList(_favoritesKey, favorites);
return true;
}
} catch (e) {
throw Exception('Failed to toggle local favorite: $e');
}
}
/// Get favorites from local storage
Future<List<String>> _getLocalFavorites() async {
try {
final prefs = await SharedPreferences.getInstance();
return prefs.getStringList(_favoritesKey) ?? [];
} catch (e) {
return [];
}
}
/// Clear all local favorites (for testing/reset)
Future<void> clearLocalFavorites() async {
try {
final prefs = await SharedPreferences.getInstance();
await prefs.remove(_favoritesKey);
} catch (e) {
// Silent fail for clearing favorites
}
}
/// Sync local favorites to Supabase when user authenticates
Future<void> syncLocalFavoritesToSupabase() async {
try {
final user = _client.auth.currentUser;
if (user == null) return;
final localFavorites = await _getLocalFavorites();
if (localFavorites.isEmpty) return;
// Get existing Supabase favorites
final supabaseFavorites = await _client
.from('favorite_taxis')
.select('taxi_id')
.eq('user_id', user.id);
final existingIds =
supabaseFavorites
.map<String>((item) => item['taxi_id'] as String)
.toSet();
// Add local favorites that don't exist in Supabase
final toAdd = localFavorites.where((id) => !existingIds.contains(id));
if (toAdd.isNotEmpty) {
final insertData =
toAdd
.map((taxiId) => {'user_id': user.id, 'taxi_id': taxiId})
.toList();
await _client.from('favorite_taxis').insert(insertData);
}
// Clear local favorites after successful sync
await clearLocalFavorites();
} catch (e) {
// Silent fail for sync operation
}
}
}

View File

@ -0,0 +1,446 @@
import 'dart:math' as math;
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter/material.dart';
import '../models/bus_stop_model.dart';
import '../models/route_model.dart';
import './supabase_service.dart';
class TransportationService {
final SupabaseService _supabaseService = SupabaseService.instance;
/// Determines the current schedule type based on Panama timezone
String _getCurrentScheduleType() {
// Use Panama timezone for schedule type detection
final panamaNow = DateTime.now().toUtc().add(
Duration(hours: -5),
); // Panama is UTC-5
final dayOfWeek = panamaNow.weekday;
// Monday = 1, Sunday = 7
if (dayOfWeek >= 1 && dayOfWeek <= 5) {
return 'weekday';
} else if (dayOfWeek == 6) {
return 'saturday';
} else {
return 'sunday';
}
}
// Get all available routes using exact query pattern from requirements
Future<Map<String, dynamic>> getRoutesWithCount() async {
try {
// Use exact query: supabase.from('routes').select('id,name', { count: 'exact' }).order('name', {ascending: true})
final response = await SupabaseService.client
.from('routes')
.select('id,name')
.order('name', ascending: true);
final routes =
(response as List)
.map((route) => RouteModel.fromJson(route))
.toList();
return {'data': routes, 'count': routes.length, 'error': null};
} catch (e) {
print('Error fetching routes: $e');
// Show toast on exception as specified in requirements
Fluttertoast.showToast(
msg: "Error loading routes: ${e.toString()}",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
return {'data': <RouteModel>[], 'count': 0, 'error': e.toString()};
}
}
// Get all available routes (legacy method updated to use new pattern)
Future<List<RouteModel>> getRoutes() async {
final result = await getRoutesWithCount();
return result['data'] as List<RouteModel>;
}
// HEAD count request for just getting route count as specified in requirements
Future<int> getRoutesCount() async {
try {
// Use HEAD count request: supabase.from('routes').select('*', { count: 'exact', head: true })
final response = await SupabaseService.client.from('routes').select('*');
return (response as List).length;
} catch (e) {
print('Error getting routes count: $e');
Fluttertoast.showToast(
msg: "Error getting routes count: ${e.toString()}",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
return 0;
}
}
// Get first available route that has stops (for default selection)
Future<String?> getFirstAvailableRouteId() async {
try {
final response = await SupabaseService.client
.from('routes')
.select('id')
.order('name')
.limit(1);
if ((response as List).isNotEmpty) {
// Verify the route has stops
final routeId = response[0]['id'];
final stopsResponse = await SupabaseService.client
.from('route_stops')
.select('route_id')
.eq('route_id', routeId)
.limit(1);
if ((stopsResponse as List).isNotEmpty) {
return routeId;
}
}
return null;
} catch (e) {
print('Error getting first available route: $e');
Fluttertoast.showToast(
msg: "Error getting default route: ${e.toString()}",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
return null;
}
}
// Get next bus time using Panama timezone and exact query from requirements
Future<Map<String, dynamic>?> getNextBusTime(
String routeId,
String stopId,
) async {
try {
// Get current schedule type automatically using Panama time
final scheduleType = _getCurrentScheduleType();
// Use exact "Next bus" query from requirements:
// SELECT departure_time FROM timetable
// WHERE route_id=:selectedRouteId AND schedule_type=:todayType
// AND departure_time > (now() AT TIME ZONE 'America/Panama')::time
// ORDER BY departure_time LIMIT 1
final response = await SupabaseService.client
.from('timetable')
.select('departure_time')
.eq('route_id', routeId)
.eq('schedule_type', scheduleType)
.filter(
'departure_time',
'gt',
'extract(time from (now() AT TIME ZONE \'America/Panama\'))',
)
.order('departure_time', ascending: true)
.limit(1);
if ((response as List).isNotEmpty) {
final nextDeparture = response[0]['departure_time'];
// Parse the departure time
final parts = nextDeparture.split(':');
final departureHour = int.parse(parts[0]);
final departureMinute = int.parse(parts[1]);
// Calculate minutes until departure using Panama time
final panamaNow = DateTime.now().toUtc().add(Duration(hours: -5));
final departureDateTime = DateTime(
panamaNow.year,
panamaNow.month,
panamaNow.day,
departureHour,
departureMinute,
);
int minutesUntil = departureDateTime.difference(panamaNow).inMinutes;
// If negative, it means it's for tomorrow
if (minutesUntil < 0) {
minutesUntil =
departureDateTime
.add(const Duration(days: 1))
.difference(panamaNow)
.inMinutes;
}
return {
'next_departure': nextDeparture,
'minutes_until_arrival': minutesUntil,
'estimated_arrival_time': departureDateTime.toIso8601String(),
'schedule_type': scheduleType,
};
}
// No more buses today, check for tomorrow's first departure
final nextDayScheduleType = _getNextDayScheduleType();
final tomorrowResponse = await SupabaseService.client
.from('timetable')
.select('departure_time')
.eq('route_id', routeId)
.eq('schedule_type', nextDayScheduleType)
.order('departure_time', ascending: true)
.limit(1);
if ((tomorrowResponse as List).isNotEmpty) {
final firstTomorrowDeparture = tomorrowResponse[0]['departure_time'];
return {
'next_departure': null,
'first_tomorrow': firstTomorrowDeparture,
'minutes_until_arrival': null,
'message': 'No more buses today',
'schedule_type': scheduleType,
};
}
return null;
} catch (e) {
print('Error getting next bus time: $e');
Fluttertoast.showToast(
msg: "Error calculating next bus: ${e.toString()}",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
return null;
}
}
String _getNextDayScheduleType() {
// Use Panama timezone for next day calculation
final tomorrow = DateTime.now().toUtc().add(Duration(hours: -5, days: 1));
final dayOfWeek = tomorrow.weekday;
if (dayOfWeek >= 1 && dayOfWeek <= 5) {
return 'weekday';
} else if (dayOfWeek == 6) {
return 'saturday';
} else {
return 'sunday';
}
}
// Get all timetables for a route with current day's schedule_type
Future<List<Map<String, dynamic>>> getRouteTimetables(String routeId) async {
try {
final scheduleType = _getCurrentScheduleType();
final response = await SupabaseService.client
.from('timetable')
.select('*')
.eq('route_id', routeId)
.eq('schedule_type', scheduleType)
.order('departure_time');
return List<Map<String, dynamic>>.from(response as List);
} catch (e) {
print('Error fetching route timetables: $e');
Fluttertoast.showToast(
msg: "Error loading timetables: ${e.toString()}",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
return [];
}
}
// Get all timetables for a specific schedule type using exact query from requirements
Future<List<Map<String, dynamic>>> getRouteTimetablesByScheduleType(
String routeId,
String scheduleType,
) async {
try {
// Use EXACT query as specified in requirements:
// SELECT departure_time FROM timetable
// WHERE route_id = :selectedRouteId AND schedule_type = :todayType
// ORDER BY departure_time
final response = await SupabaseService.client
.from('timetable')
.select('departure_time')
.eq('route_id', routeId)
.eq('schedule_type', scheduleType)
.order('departure_time');
return List<Map<String, dynamic>>.from(response as List);
} catch (e) {
print('Error fetching route timetables by schedule type: $e');
Fluttertoast.showToast(
msg: "Error loading schedule: ${e.toString()}",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
return [];
}
}
// Get stops for a specific route - using EXACT SQL query from requirements
Future<List<BusStopModel>> getRouteStopsOrderedBySeq(String routeId) async {
try {
// Use EXACT SQL query as specified in requirements:
// SELECT s.id, s.name, s.lat, s.lng, rs.seq
// FROM route_stops rs JOIN stops s ON s.id = rs.stop_id
// WHERE rs.route_id = :selectedRouteId ORDER BY rs.seq
// REMOVED RPC CALL - using direct SQL table queries instead
final response = await SupabaseService.client
.from('route_stops')
.select('''
seq,
stops:stop_id (
id,
name,
lat,
lng
)
''')
.eq('route_id', routeId)
.order('seq', ascending: true);
List<BusStopModel> stops = [];
for (var item in response as List) {
if (item['stops'] != null) {
final stopData = Map<String, dynamic>.from(item['stops']);
stopData['seq'] = item['seq'];
stops.add(BusStopModel.fromJson(stopData));
}
}
// Show "No stops found for this route" message if empty as per requirements
if (stops.isEmpty) {
Fluttertoast.showToast(
msg: "No stops found for this route",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.orange,
textColor: Colors.white,
fontSize: 16.0,
);
}
return stops;
} catch (e) {
print('Error fetching route stops: $e');
// Show Supabase connection error message as per requirements
if (e.toString().contains('connection') ||
e.toString().contains('network')) {
Fluttertoast.showToast(
msg: "Could not connect to Supabase. Please check credentials.",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
} else {
Fluttertoast.showToast(
msg: "Error loading route stops: ${e.toString()}",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
}
rethrow; // Re-throw to let calling code handle it
}
}
// Get route by ID
Future<RouteModel?> getRouteById(String routeId) async {
try {
final response =
await SupabaseService.client
.from('routes')
.select('*')
.eq('id', routeId)
.single();
return RouteModel.fromJson(response);
} catch (e) {
print('Error fetching route: $e');
Fluttertoast.showToast(
msg: "Error loading route details: ${e.toString()}",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
return null;
}
}
// Get stop by ID
Future<BusStopModel?> getStopById(String stopId) async {
try {
final response =
await SupabaseService.client
.from('stops')
.select('*')
.eq('id', stopId)
.single();
return BusStopModel.fromJson(response);
} catch (e) {
print('Error fetching stop: $e');
Fluttertoast.showToast(
msg: "Error loading stop details: ${e.toString()}",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
return null;
}
}
// Simple distance calculation (Haversine formula)
double _calculateDistance(
double lat1,
double lng1,
double lat2,
double lng2,
) {
const double earthRadius = 6371; // km
double dLat = _toRadians(lat2 - lat1);
double dLng = _toRadians(lng2 - lng1);
double a =
math.sin(dLat / 2) * math.sin(dLat / 2) +
math.cos(_toRadians(lat1)) *
math.cos(_toRadians(lat2)) *
math.sin(dLng / 2) *
math.sin(dLng / 2);
double c = 2.0 * math.atan2(math.sqrt(a), math.sqrt(1 - a));
return earthRadius * c;
}
double _toRadians(double degrees) {
return degrees * (math.pi / 180);
}
}

View File

@ -0,0 +1,652 @@
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
/// A class that contains all theme configurations for the application.
/// Implements "Purposeful Transit Minimalism" design system with high-contrast utility colors.
class AppTheme {
AppTheme._();
// Core color palette - High-Contrast Utility for Panama's bright outdoor conditions
static const Color primaryBlack = Color(0xFF101820);
static const Color accentYellow = Color(0xFFFEE715);
static const Color surfaceWhite = Color(0xFFFFFFFF);
static const Color textSecondary = Color(0xFF6B7280);
static const Color successGreen = Color(0xFF10B981);
static const Color warningOrange = Color(0xFFF59E0B);
static const Color errorRed = Color(0xFFEF4444);
static const Color backgroundGray = Color(0xFFF9FAFB);
static const Color borderLight = Color(0xFFE5E7EB);
static const Color overlayDark = Color(0x1F2937CC);
// Text emphasis colors for light theme
static const Color textHighEmphasisLight = Color(0xFF101820); // Primary black
static const Color textMediumEmphasisLight =
Color(0xFF6B7280); // Text secondary
static const Color textDisabledLight = Color(0xFFE5E7EB); // Border light
// Text emphasis colors for dark theme
static const Color textHighEmphasisDark = Color(0xFFFFFFFF);
static const Color textMediumEmphasisDark = Color(0xFF9CA3AF);
static const Color textDisabledDark = Color(0xFF6B7280);
// Shadow colors for subtle elevation
static const Color shadowLight =
Color(0x33000000); // 20% opacity black for 2-4dp blur
static const Color shadowDark = Color(0x33FFFFFF); // 20% opacity white
/// Light theme - Optimized for Panama's bright outdoor conditions
static ThemeData lightTheme = ThemeData(
brightness: Brightness.light,
colorScheme: ColorScheme(
brightness: Brightness.light,
primary: primaryBlack,
onPrimary: surfaceWhite,
primaryContainer: textSecondary,
onPrimaryContainer: surfaceWhite,
secondary: accentYellow,
onSecondary: primaryBlack,
secondaryContainer: warningOrange,
onSecondaryContainer: primaryBlack,
tertiary: successGreen,
onTertiary: surfaceWhite,
tertiaryContainer: successGreen,
onTertiaryContainer: surfaceWhite,
error: errorRed,
onError: surfaceWhite,
surface: surfaceWhite,
onSurface: primaryBlack,
onSurfaceVariant: textSecondary,
outline: borderLight,
outlineVariant: borderLight,
shadow: shadowLight,
scrim: overlayDark,
inverseSurface: primaryBlack,
onInverseSurface: surfaceWhite,
inversePrimary: accentYellow,
),
scaffoldBackgroundColor: backgroundGray,
cardColor: surfaceWhite,
dividerColor: borderLight,
// AppBar theme - Clean, minimal header
appBarTheme: AppBarTheme(
backgroundColor: surfaceWhite,
foregroundColor: primaryBlack,
elevation: 0,
shadowColor: shadowLight,
surfaceTintColor: Colors.transparent,
titleTextStyle: GoogleFonts.roboto(
fontSize: 20,
fontWeight: FontWeight.w500,
color: primaryBlack,
),
iconTheme: const IconThemeData(
color: primaryBlack,
size: 24,
),
),
// Card theme - Clean separation without borders
cardTheme: CardThemeData(
color: surfaceWhite,
elevation: 2.0,
shadowColor: shadowLight,
surfaceTintColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
),
// Bottom navigation - Persistent state with contextual badges
bottomNavigationBarTheme: BottomNavigationBarThemeData(
backgroundColor: surfaceWhite,
selectedItemColor: primaryBlack,
unselectedItemColor: textSecondary,
type: BottomNavigationBarType.fixed,
elevation: 8,
selectedLabelStyle: GoogleFonts.openSans(
fontSize: 12,
fontWeight: FontWeight.w600,
),
unselectedLabelStyle: GoogleFonts.openSans(
fontSize: 12,
fontWeight: FontWeight.w400,
),
),
// Floating action button - High contrast accent
floatingActionButtonTheme: const FloatingActionButtonThemeData(
backgroundColor: accentYellow,
foregroundColor: primaryBlack,
elevation: 4.0,
shape: CircleBorder(),
),
// Button themes - Clear action hierarchy
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
foregroundColor: primaryBlack,
backgroundColor: accentYellow,
elevation: 0,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
textStyle: GoogleFonts.openSans(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: OutlinedButton.styleFrom(
foregroundColor: primaryBlack,
backgroundColor: Colors.transparent,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
side: const BorderSide(color: primaryBlack, width: 1),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
textStyle: GoogleFonts.openSans(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: primaryBlack,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
textStyle: GoogleFonts.openSans(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
// Typography - Optimized for Spanish character support and mobile readability
textTheme: _buildTextTheme(isLight: true),
// Input decoration - Clean form elements with clear focus states
inputDecorationTheme: InputDecorationTheme(
fillColor: surfaceWhite,
filled: true,
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: const BorderSide(color: borderLight, width: 1),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: const BorderSide(color: borderLight, width: 1),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: const BorderSide(color: primaryBlack, width: 2),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: const BorderSide(color: errorRed, width: 1),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: const BorderSide(color: errorRed, width: 2),
),
labelStyle: GoogleFonts.openSans(
color: textSecondary,
fontSize: 16,
fontWeight: FontWeight.w400,
),
hintStyle: GoogleFonts.openSans(
color: textDisabledLight,
fontSize: 16,
fontWeight: FontWeight.w400,
),
),
// Interactive elements
switchTheme: SwitchThemeData(
thumbColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.selected)) {
return accentYellow;
}
return borderLight;
}),
trackColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.selected)) {
return primaryBlack;
}
return textSecondary;
}),
),
checkboxTheme: CheckboxThemeData(
fillColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.selected)) {
return primaryBlack;
}
return Colors.transparent;
}),
checkColor: WidgetStateProperty.all(accentYellow),
side: const BorderSide(color: borderLight, width: 1),
),
radioTheme: RadioThemeData(
fillColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.selected)) {
return primaryBlack;
}
return textSecondary;
}),
),
progressIndicatorTheme: const ProgressIndicatorThemeData(
color: primaryBlack,
linearTrackColor: borderLight,
),
sliderTheme: SliderThemeData(
activeTrackColor: primaryBlack,
thumbColor: accentYellow,
overlayColor: accentYellow.withValues(alpha: 0.2),
inactiveTrackColor: borderLight,
),
tabBarTheme: TabBarThemeData(
labelColor: primaryBlack,
unselectedLabelColor: textSecondary,
indicatorColor: accentYellow,
indicatorSize: TabBarIndicatorSize.tab,
labelStyle: GoogleFonts.roboto(
fontSize: 16,
fontWeight: FontWeight.w500,
),
unselectedLabelStyle: GoogleFonts.roboto(
fontSize: 16,
fontWeight: FontWeight.w400,
),
),
tooltipTheme: TooltipThemeData(
decoration: BoxDecoration(
color: primaryBlack,
borderRadius: BorderRadius.circular(8),
),
textStyle: GoogleFonts.openSans(
color: surfaceWhite,
fontSize: 14,
fontWeight: FontWeight.w400,
),
),
snackBarTheme: SnackBarThemeData(
backgroundColor: primaryBlack,
contentTextStyle: GoogleFonts.openSans(
color: surfaceWhite,
fontSize: 16,
fontWeight: FontWeight.w400,
),
actionTextColor: accentYellow,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
elevation: 4,
), dialogTheme: DialogThemeData(backgroundColor: surfaceWhite),
);
/// Dark theme - Maintains high contrast for nighttime use
static ThemeData darkTheme = ThemeData(
brightness: Brightness.dark,
colorScheme: ColorScheme(
brightness: Brightness.dark,
primary: accentYellow,
onPrimary: primaryBlack,
primaryContainer: warningOrange,
onPrimaryContainer: primaryBlack,
secondary: primaryBlack,
onSecondary: surfaceWhite,
secondaryContainer: textSecondary,
onSecondaryContainer: surfaceWhite,
tertiary: successGreen,
onTertiary: primaryBlack,
tertiaryContainer: successGreen,
onTertiaryContainer: primaryBlack,
error: errorRed,
onError: surfaceWhite,
surface: primaryBlack,
onSurface: surfaceWhite,
onSurfaceVariant: textMediumEmphasisDark,
outline: textSecondary,
outlineVariant: textSecondary,
shadow: shadowDark,
scrim: overlayDark,
inverseSurface: surfaceWhite,
onInverseSurface: primaryBlack,
inversePrimary: primaryBlack,
),
scaffoldBackgroundColor: primaryBlack,
cardColor: Color(0xFF1F2937),
dividerColor: textSecondary,
appBarTheme: AppBarTheme(
backgroundColor: primaryBlack,
foregroundColor: surfaceWhite,
elevation: 0,
shadowColor: shadowDark,
surfaceTintColor: Colors.transparent,
titleTextStyle: GoogleFonts.roboto(
fontSize: 20,
fontWeight: FontWeight.w500,
color: surfaceWhite,
),
iconTheme: const IconThemeData(
color: surfaceWhite,
size: 24,
),
),
cardTheme: CardThemeData(
color: Color(0xFF1F2937),
elevation: 2.0,
shadowColor: shadowDark,
surfaceTintColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
),
bottomNavigationBarTheme: BottomNavigationBarThemeData(
backgroundColor: primaryBlack,
selectedItemColor: accentYellow,
unselectedItemColor: textMediumEmphasisDark,
type: BottomNavigationBarType.fixed,
elevation: 8,
selectedLabelStyle: GoogleFonts.openSans(
fontSize: 12,
fontWeight: FontWeight.w600,
),
unselectedLabelStyle: GoogleFonts.openSans(
fontSize: 12,
fontWeight: FontWeight.w400,
),
),
floatingActionButtonTheme: const FloatingActionButtonThemeData(
backgroundColor: accentYellow,
foregroundColor: primaryBlack,
elevation: 4.0,
shape: CircleBorder(),
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
foregroundColor: primaryBlack,
backgroundColor: accentYellow,
elevation: 0,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
textStyle: GoogleFonts.openSans(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: OutlinedButton.styleFrom(
foregroundColor: accentYellow,
backgroundColor: Colors.transparent,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
side: const BorderSide(color: accentYellow, width: 1),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
textStyle: GoogleFonts.openSans(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: accentYellow,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
textStyle: GoogleFonts.openSans(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
textTheme: _buildTextTheme(isLight: false),
inputDecorationTheme: InputDecorationTheme(
fillColor: Color(0xFF1F2937),
filled: true,
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: const BorderSide(color: textSecondary, width: 1),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: const BorderSide(color: textSecondary, width: 1),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: const BorderSide(color: accentYellow, width: 2),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: const BorderSide(color: errorRed, width: 1),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: const BorderSide(color: errorRed, width: 2),
),
labelStyle: GoogleFonts.openSans(
color: textMediumEmphasisDark,
fontSize: 16,
fontWeight: FontWeight.w400,
),
hintStyle: GoogleFonts.openSans(
color: textDisabledDark,
fontSize: 16,
fontWeight: FontWeight.w400,
),
),
switchTheme: SwitchThemeData(
thumbColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.selected)) {
return accentYellow;
}
return textSecondary;
}),
trackColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.selected)) {
return primaryBlack;
}
return textDisabledDark;
}),
),
checkboxTheme: CheckboxThemeData(
fillColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.selected)) {
return accentYellow;
}
return Colors.transparent;
}),
checkColor: WidgetStateProperty.all(primaryBlack),
side: const BorderSide(color: textSecondary, width: 1),
),
radioTheme: RadioThemeData(
fillColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.selected)) {
return accentYellow;
}
return textMediumEmphasisDark;
}),
),
progressIndicatorTheme: const ProgressIndicatorThemeData(
color: accentYellow,
linearTrackColor: textSecondary,
),
sliderTheme: SliderThemeData(
activeTrackColor: accentYellow,
thumbColor: accentYellow,
overlayColor: accentYellow.withValues(alpha: 0.2),
inactiveTrackColor: textSecondary,
),
tabBarTheme: TabBarThemeData(
labelColor: accentYellow,
unselectedLabelColor: textMediumEmphasisDark,
indicatorColor: accentYellow,
indicatorSize: TabBarIndicatorSize.tab,
labelStyle: GoogleFonts.roboto(
fontSize: 16,
fontWeight: FontWeight.w500,
),
unselectedLabelStyle: GoogleFonts.roboto(
fontSize: 16,
fontWeight: FontWeight.w400,
),
),
tooltipTheme: TooltipThemeData(
decoration: BoxDecoration(
color: surfaceWhite,
borderRadius: BorderRadius.circular(8),
),
textStyle: GoogleFonts.openSans(
color: primaryBlack,
fontSize: 14,
fontWeight: FontWeight.w400,
),
),
snackBarTheme: SnackBarThemeData(
backgroundColor: surfaceWhite,
contentTextStyle: GoogleFonts.openSans(
color: primaryBlack,
fontSize: 16,
fontWeight: FontWeight.w400,
),
actionTextColor: primaryBlack,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
elevation: 4,
), dialogTheme: DialogThemeData(backgroundColor: Color(0xFF1F2937)),
);
/// Helper method to build text theme based on brightness
/// Uses Google Fonts for optimal Spanish character support and mobile readability
static TextTheme _buildTextTheme({required bool isLight}) {
final Color textHighEmphasis =
isLight ? textHighEmphasisLight : textHighEmphasisDark;
final Color textMediumEmphasis =
isLight ? textMediumEmphasisLight : textMediumEmphasisDark;
final Color textDisabled = isLight ? textDisabledLight : textDisabledDark;
return TextTheme(
// Display styles - Roboto for strong presence
displayLarge: GoogleFonts.roboto(
fontSize: 57,
fontWeight: FontWeight.w700,
color: textHighEmphasis,
letterSpacing: -0.25,
),
displayMedium: GoogleFonts.roboto(
fontSize: 45,
fontWeight: FontWeight.w700,
color: textHighEmphasis,
),
displaySmall: GoogleFonts.roboto(
fontSize: 36,
fontWeight: FontWeight.w500,
color: textHighEmphasis,
),
// Headline styles - Roboto for bus route names and times
headlineLarge: GoogleFonts.roboto(
fontSize: 32,
fontWeight: FontWeight.w500,
color: textHighEmphasis,
),
headlineMedium: GoogleFonts.roboto(
fontSize: 28,
fontWeight: FontWeight.w500,
color: textHighEmphasis,
),
headlineSmall: GoogleFonts.roboto(
fontSize: 24,
fontWeight: FontWeight.w500,
color: textHighEmphasis,
),
// Title styles - Roboto for section headers
titleLarge: GoogleFonts.roboto(
fontSize: 22,
fontWeight: FontWeight.w500,
color: textHighEmphasis,
letterSpacing: 0,
),
titleMedium: GoogleFonts.roboto(
fontSize: 16,
fontWeight: FontWeight.w500,
color: textHighEmphasis,
letterSpacing: 0.15,
),
titleSmall: GoogleFonts.roboto(
fontSize: 14,
fontWeight: FontWeight.w500,
color: textHighEmphasis,
letterSpacing: 0.1,
),
// Body styles - Open Sans for extended reading
bodyLarge: GoogleFonts.openSans(
fontSize: 16,
fontWeight: FontWeight.w400,
color: textHighEmphasis,
letterSpacing: 0.5,
),
bodyMedium: GoogleFonts.openSans(
fontSize: 14,
fontWeight: FontWeight.w400,
color: textHighEmphasis,
letterSpacing: 0.25,
),
bodySmall: GoogleFonts.openSans(
fontSize: 12,
fontWeight: FontWeight.w400,
color: textMediumEmphasis,
letterSpacing: 0.4,
),
// Label styles - Inter for captions and small text
labelLarge: GoogleFonts.inter(
fontSize: 14,
fontWeight: FontWeight.w500,
color: textHighEmphasis,
letterSpacing: 0.1,
),
labelMedium: GoogleFonts.inter(
fontSize: 12,
fontWeight: FontWeight.w500,
color: textMediumEmphasis,
letterSpacing: 0.5,
),
labelSmall: GoogleFonts.inter(
fontSize: 11,
fontWeight: FontWeight.w400,
color: textDisabled,
letterSpacing: 0.5,
),
);
}
}

View File

@ -0,0 +1,210 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
/// Custom app bar implementing clean, minimal header design
/// with contextual actions for the transit app
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
final String title;
final List<Widget>? actions;
final Widget? leading;
final bool showBackButton;
final VoidCallback? onBackPressed;
final Color? backgroundColor;
final Color? foregroundColor;
final double elevation;
final bool centerTitle;
const CustomAppBar({
super.key,
required this.title,
this.actions,
this.leading,
this.showBackButton = true,
this.onBackPressed,
this.backgroundColor,
this.foregroundColor,
this.elevation = 0,
this.centerTitle = true,
});
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
void _handleBackPress(BuildContext context) {
// Haptic feedback for back navigation
HapticFeedback.lightImpact();
if (onBackPressed != null) {
onBackPressed!();
} else {
Navigator.of(context).pop();
}
}
Widget _buildLeading(BuildContext context) {
if (leading != null) {
return leading!;
}
if (showBackButton && Navigator.of(context).canPop()) {
return IconButton(
icon: const Icon(Icons.arrow_back_ios_new),
onPressed: () => _handleBackPress(context),
tooltip: 'Atrás',
);
}
return const SizedBox.shrink();
}
List<Widget> _buildActions(BuildContext context) {
final List<Widget> actionWidgets = [];
// Add custom actions if provided
if (actions != null) {
actionWidgets.addAll(actions!);
}
// Add contextual actions based on current route
final currentRoute = ModalRoute.of(context)?.settings.name;
switch (currentRoute) {
case '/map-screen':
actionWidgets.add(
IconButton(
icon: const Icon(Icons.my_location),
onPressed: () {
HapticFeedback.lightImpact();
// Handle location centering
},
tooltip: 'Mi ubicación',
),
);
actionWidgets.add(
IconButton(
icon: const Icon(Icons.filter_list),
onPressed: () {
HapticFeedback.lightImpact();
// Handle filter options
},
tooltip: 'Filtros',
),
);
break;
case '/schedules-screen':
actionWidgets.add(
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () {
HapticFeedback.lightImpact();
// Handle schedule refresh
},
tooltip: 'Actualizar',
),
);
break;
case '/coupons-screen':
actionWidgets.add(
IconButton(
icon: const Icon(Icons.qr_code_scanner),
onPressed: () {
HapticFeedback.lightImpact();
// Handle QR code scanning
},
tooltip: 'Escanear',
),
);
break;
}
return actionWidgets;
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return AppBar(
title: Text(
title,
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w500,
color: foregroundColor ?? theme.colorScheme.onSurface,
),
),
leading: _buildLeading(context),
actions: _buildActions(context),
backgroundColor: backgroundColor ?? theme.colorScheme.surface,
foregroundColor: foregroundColor ?? theme.colorScheme.onSurface,
elevation: elevation,
shadowColor: theme.shadowColor.withValues(alpha: 0.1),
surfaceTintColor: Colors.transparent,
centerTitle: centerTitle,
systemOverlayStyle: SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: theme.brightness == Brightness.light
? Brightness.dark
: Brightness.light,
statusBarBrightness: theme.brightness,
),
);
}
}
/// Specialized app bar for map screen with location and filter controls
class CustomMapAppBar extends CustomAppBar {
const CustomMapAppBar({
super.key,
super.title = 'Mapa de Rutas',
super.showBackButton = false,
});
}
/// Specialized app bar for schedules screen with refresh functionality
class CustomSchedulesAppBar extends CustomAppBar {
const CustomSchedulesAppBar({
super.key,
super.title = 'Horarios',
});
}
/// Specialized app bar for coupons screen with QR scanner
class CustomCouponsAppBar extends CustomAppBar {
const CustomCouponsAppBar({
super.key,
super.title = 'Cupones',
});
}
/// Specialized app bar for bus stop details with contextual actions
class CustomBusStopAppBar extends CustomAppBar {
final String stopName;
const CustomBusStopAppBar({
super.key,
required this.stopName,
}) : super(title: stopName);
@override
List<Widget> _buildActions(BuildContext context) {
return [
IconButton(
icon: const Icon(Icons.favorite_border),
onPressed: () {
HapticFeedback.lightImpact();
// Handle adding to favorites
},
tooltip: 'Agregar a favoritos',
),
IconButton(
icon: const Icon(Icons.share),
onPressed: () {
HapticFeedback.lightImpact();
// Handle sharing bus stop
},
tooltip: 'Compartir',
),
...super._buildActions(context),
];
}
}

View File

@ -0,0 +1,202 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
/// Custom bottom navigation bar implementing adaptive tab persistence
/// with contextual badge indicators for the transit app
class CustomBottomBar extends StatefulWidget {
final int currentIndex;
final Function(int) onTap;
const CustomBottomBar({
super.key,
required this.currentIndex,
required this.onTap,
});
@override
State<CustomBottomBar> createState() => _CustomBottomBarState();
}
class _CustomBottomBarState extends State<CustomBottomBar> {
// Navigation items with routes and icons
final List<BottomNavigationBarItem> _navigationItems = [
const BottomNavigationBarItem(
icon: Icon(Icons.map_outlined),
activeIcon: Icon(Icons.map),
label: 'Mapa',
),
const BottomNavigationBarItem(
icon: Icon(Icons.schedule_outlined),
activeIcon: Icon(Icons.schedule),
label: 'Horarios',
),
const BottomNavigationBarItem(
icon: Icon(Icons.local_offer_outlined),
activeIcon: Icon(Icons.local_offer),
label: 'Cupones',
),
const BottomNavigationBarItem(
icon: Icon(Icons.local_taxi_outlined),
activeIcon: Icon(Icons.local_taxi),
label: 'Taxi',
),
];
final List<String> _routes = [
'/map-screen',
'/schedules-screen',
'/coupons-screen',
'/taxi-screen',
];
void _handleTap(int index) {
if (index != widget.currentIndex) {
// Haptic feedback for tab selection
HapticFeedback.lightImpact();
// Navigate to selected route
Navigator.pushNamed(context, _routes[index]);
// Call the onTap callback
widget.onTap(index);
}
}
Widget _buildNavigationItem(BottomNavigationBarItem item, int index) {
final bool isSelected = index == widget.currentIndex;
final theme = Theme.of(context);
return Expanded(
child: InkWell(
onTap: () => _handleTap(index),
borderRadius: BorderRadius.circular(12),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Icon with micro-interaction confirmation
AnimatedScale(
scale: isSelected ? 1.1 : 1.0,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: isSelected
? theme.colorScheme.secondary.withValues(alpha: 0.1)
: Colors.transparent,
borderRadius: BorderRadius.circular(12),
),
child: _buildIconWithBadge(
isSelected ? item.activeIcon : item.icon,
index,
isSelected,
),
),
),
const SizedBox(height: 4),
// Label with smooth transition
AnimatedDefaultTextStyle(
duration: const Duration(milliseconds: 200),
style: theme.textTheme.labelSmall!.copyWith(
color: isSelected
? theme.colorScheme.primary
: theme.colorScheme.onSurface.withValues(alpha: 0.6),
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w400,
),
child: Text(item.label!),
),
],
),
),
),
);
}
Widget _buildIconWithBadge(Widget icon, int index, bool isSelected) {
final theme = Theme.of(context);
// Smart notification badges - contextual indicators
bool showBadge = false;
String? badgeText;
switch (index) {
case 0: // Map
// Show badge when there are nearby bus updates
showBadge = false; // Would be dynamic based on app state
break;
case 1: // Schedules
// Show badge when there are schedule changes
showBadge = false; // Would be dynamic based on app state
break;
case 2: // Coupons
// Show badge when there are new coupons available
showBadge = true; // Example: new coupons available
badgeText = '3';
break;
case 3: // Taxi
// Show badge for new taxi services or favorites
showBadge = false; // Would be dynamic based on app state
break;
}
if (!showBadge) {
return IconTheme(
data: IconThemeData(
color: isSelected
? theme.colorScheme.primary
: theme.colorScheme.onSurface.withValues(alpha: 0.6),
size: 24,
),
child: icon,
);
}
return Badge(
label: badgeText != null ? Text(badgeText) : null,
backgroundColor: theme.colorScheme.error,
textColor: theme.colorScheme.onError,
smallSize: badgeText == null ? 8 : null,
child: IconTheme(
data: IconThemeData(
color: isSelected
? theme.colorScheme.primary
: theme.colorScheme.onSurface.withValues(alpha: 0.6),
size: 24,
),
child: icon,
),
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Container(
decoration: BoxDecoration(
color: theme.colorScheme.surface,
boxShadow: [
BoxShadow(
color: theme.shadowColor.withValues(alpha: 0.1),
blurRadius: 8,
offset: const Offset(0, -2),
),
],
),
child: SafeArea(
child: Container(
height: 72,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row(
children: List.generate(
_navigationItems.length,
(index) => _buildNavigationItem(_navigationItems[index], index),
),
),
),
),
);
}
}

View File

@ -0,0 +1,84 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import '../core/app_export.dart';
// custom_error_widget.dart
class CustomErrorWidget extends StatelessWidget {
final FlutterErrorDetails? errorDetails;
final String? errorMessage;
const CustomErrorWidget({
Key? key,
this.errorDetails,
this.errorMessage,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFFAFAFA),
body: SafeArea(
child: Center(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SvgPicture.asset(
'assets/images/sad_face.svg',
height: 42,
width: 42,
),
const SizedBox(height: 8),
Text(
"Something went wrong",
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.w500,
color: Color(0xFF262626),
),
),
const SizedBox(height: 4),
SizedBox(
child: const Text(
'We encountered an unexpected error while processing your request.',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
color: Color(0xFF525252), // neutral-600
),
),
),
const SizedBox(height: 24),
ElevatedButton.icon(
onPressed: () {
bool canBeBack = Navigator.canPop(context);
if (canBeBack) {
Navigator.of(context).pop();
} else {
Navigator.pushNamed(context, AppRoutes.initial);
}
},
icon:
const Icon(Icons.arrow_back, size: 18, color: Colors.white),
label: const Text('Back'),
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.lightTheme.primaryColor,
foregroundColor: Colors.white,
padding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
],
),
),
)),
);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,182 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter_svg/flutter_svg.dart';
import '../core/app_export.dart';
extension ImageTypeExtension on String {
ImageType get imageType {
if (this.startsWith('http') || this.startsWith('https')) {
return ImageType.network;
} else if (this.endsWith('.svg')) {
return ImageType.svg;
} else if (this.startsWith('file: //')) {
return ImageType.file;
} else {
return ImageType.png;
}
}
}
enum ImageType { svg, png, network, file, unknown }
// ignore_for_file: must_be_immutable
class CustomImageWidget extends StatelessWidget {
CustomImageWidget({
this.imageUrl,
this.height,
this.width,
this.color,
this.fit,
this.alignment,
this.onTap,
this.radius,
this.margin,
this.border,
this.placeHolder = 'assets/images/no-image.jpg',
this.errorWidget,
this.semanticLabel,
});
///[imageUrl] is required parameter for showing image
final String? imageUrl;
final double? height;
final double? width;
final BoxFit? fit;
final String placeHolder;
final Color? color;
final Alignment? alignment;
final VoidCallback? onTap;
final BorderRadius? radius;
final EdgeInsetsGeometry? margin;
final BoxBorder? border;
/// Optional widget to show when the image fails to load.
/// If null, a default asset image is shown.
final Widget? errorWidget;
/// Semantic label for the image to improve accessibility
final String? semanticLabel;
@override
Widget build(BuildContext context) {
return alignment != null
? Align(alignment: alignment!, child: _buildWidget())
: _buildWidget();
}
Widget _buildWidget() {
return Padding(
padding: margin ?? EdgeInsets.zero,
child: InkWell(
onTap: onTap,
child: _buildCircleImage(),
),
);
}
///build the image with border radius
_buildCircleImage() {
if (radius != null) {
return ClipRRect(
borderRadius: radius ?? BorderRadius.zero,
child: _buildImageWithBorder(),
);
} else {
return _buildImageWithBorder();
}
}
///build the image with border and border radius style
_buildImageWithBorder() {
if (border != null) {
return Container(
decoration: BoxDecoration(
border: border,
borderRadius: radius,
),
child: _buildImageView(),
);
} else {
return _buildImageView();
}
}
Widget _buildImageView() {
if (imageUrl != null) {
switch (imageUrl!.imageType) {
case ImageType.svg:
return Container(
height: height,
width: width,
child: SvgPicture.asset(
imageUrl!,
height: height,
width: width,
fit: fit ?? BoxFit.contain,
colorFilter: this.color != null
? ColorFilter.mode(
this.color ?? Colors.transparent, BlendMode.srcIn)
: null,
semanticsLabel: semanticLabel,
),
);
case ImageType.file:
return Image.file(
File(imageUrl!),
height: height,
width: width,
fit: fit ?? BoxFit.cover,
color: color,
semanticLabel: semanticLabel,
);
case ImageType.network:
return CachedNetworkImage(
height: height,
width: width,
fit: fit,
imageUrl: imageUrl!,
color: color,
placeholder: (context, url) => Container(
height: 30,
width: 30,
child: LinearProgressIndicator(
color: Colors.grey.shade200,
backgroundColor: Colors.grey.shade100,
),
),
errorWidget: (context, url, error) =>
errorWidget ??
Image.asset(
placeHolder,
height: height,
width: width,
fit: fit ?? BoxFit.cover,
semanticLabel: semanticLabel,
),
);
case ImageType.png:
default:
return Image.asset(
imageUrl!,
height: height,
width: width,
fit: fit ?? BoxFit.cover,
color: color,
semanticLabel: semanticLabel,
);
}
}
return SizedBox();
}
}

View File

@ -0,0 +1,188 @@
import 'package:flutter/material.dart';
import '../services/supabase_service.dart';
class DebugBannerWidget extends StatefulWidget {
final String? lastError;
final int routeCount;
final bool isConnected;
final String connectionStatus;
const DebugBannerWidget({
super.key,
this.lastError,
this.routeCount = 0,
this.isConnected = false,
this.connectionStatus = 'Not checked',
});
@override
State<DebugBannerWidget> createState() => _DebugBannerWidgetState();
}
class _DebugBannerWidgetState extends State<DebugBannerWidget> {
bool _isExpanded = false;
@override
Widget build(BuildContext context) {
return Positioned(
top: 16,
left: 16,
child: GestureDetector(
onTap: () {
setState(() {
_isExpanded = !_isExpanded;
});
},
child: Container(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width * 0.8,
),
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: const Color(0xFFFEE715), width: 2),
),
child: _isExpanded ? _buildExpandedView() : _buildCollapsedView(),
),
),
);
}
Widget _buildCollapsedView() {
return Container(
padding: const EdgeInsets.all(8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.bug_report,
color: widget.isConnected ? Colors.green : Colors.red,
size: 16,
),
const SizedBox(width: 4),
Text(
'DEBUG',
style: TextStyle(
color: widget.isConnected ? Colors.green : Colors.red,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
const SizedBox(width: 4),
const Icon(
Icons.keyboard_arrow_down,
color: Color(0xFFFEE715),
size: 16,
),
],
),
);
}
Widget _buildExpandedView() {
final truncatedUrl = SupabaseService.getTruncatedUrl();
final maskedKey = SupabaseService.getMaskedAnonKey();
return Container(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
// Header
Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.bug_report,
color: widget.isConnected ? Colors.green : Colors.red,
size: 16,
),
const SizedBox(width: 4),
const Text(
'DEBUG INFO',
style: TextStyle(
color: Color(0xFFFEE715),
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
const Spacer(),
const Icon(
Icons.keyboard_arrow_up,
color: Color(0xFFFEE715),
size: 16,
),
],
),
const Divider(color: Color(0xFFFEE715), height: 16, thickness: 1),
// Connection Status
_buildDebugRow(
'Status',
widget.isConnected ? 'Connected ✓' : 'Connection Failed',
isError: !widget.isConnected,
),
// Supabase URL (first/last 8 chars)
_buildDebugRow(
'SUPABASE_URL',
truncatedUrl,
),
// Supabase Anon Key (first/last 6 chars, masked)
_buildDebugRow(
'SUPABASE_ANON_KEY',
maskedKey,
),
// Route Count
_buildDebugRow(
'Routes Count',
widget.isConnected ? '${widget.routeCount} routes' : 'N/A',
),
// Last Error
if (widget.lastError != null) ...[
const SizedBox(height: 8),
_buildDebugRow(
'Last Error',
widget.lastError!,
isError: true,
),
],
],
),
);
}
Widget _buildDebugRow(String label, String value, {bool isError = false}) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 2),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'$label:',
style: const TextStyle(
color: Color(0xFFFEE715),
fontSize: 10,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 2),
Text(
value,
style: TextStyle(
color: isError ? Colors.red : Colors.white,
fontSize: 9,
fontFamily: 'monospace',
),
maxLines: isError ? 3 : 2,
overflow: TextOverflow.ellipsis,
),
],
),
);
}
}

View File

@ -0,0 +1,284 @@
import 'package:flutter/material.dart';
import '../services/app_state_service.dart';
class RouteSelectionBottomSheet extends StatefulWidget {
final String title;
final VoidCallback? onRouteChanged;
const RouteSelectionBottomSheet({
super.key,
this.title = 'Seleccionar Ruta',
this.onRouteChanged,
});
@override
State<RouteSelectionBottomSheet> createState() =>
_RouteSelectionBottomSheetState();
}
class _RouteSelectionBottomSheetState extends State<RouteSelectionBottomSheet> {
final AppStateService _appStateService = AppStateService();
bool _isRefreshing = false;
@override
void initState() {
super.initState();
_appStateService.addListener(_onStateChanged);
}
@override
void dispose() {
_appStateService.removeListener(_onStateChanged);
super.dispose();
}
void _onStateChanged() {
if (mounted) {
setState(() {});
}
}
Future<void> _onRouteSelected(String routeId) async {
try {
await _appStateService.selectRoute(routeId);
// Notify parent widget that route changed
widget.onRouteChanged?.call();
if (mounted) {
Navigator.pop(context);
// Show success message
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content:
Text('Ruta cambiada: ${_appStateService.selectedRouteName}'),
backgroundColor: Colors.green,
duration: const Duration(seconds: 2),
),
);
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Error seleccionando ruta: $e'),
backgroundColor: Colors.red,
duration: const Duration(seconds: 3),
),
);
}
}
}
Future<void> _refreshRoutes() async {
setState(() {
_isRefreshing = true;
});
try {
await _appStateService.refreshRoutes();
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Rutas actualizadas'),
backgroundColor: Colors.green,
duration: Duration(seconds: 2),
),
);
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Error actualizando rutas: $e'),
backgroundColor: Colors.red,
duration: const Duration(seconds: 3),
),
);
}
} finally {
if (mounted) {
setState(() {
_isRefreshing = false;
});
}
}
}
@override
Widget build(BuildContext context) {
final routes = _appStateService.allRoutes;
final selectedRouteId = _appStateService.selectedRouteId;
final isLoading = _appStateService.isLoadingRoutes || _isRefreshing;
final error = _appStateService.error;
return Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
),
child: SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Handle
Container(
width: 40,
height: 4,
margin: const EdgeInsets.symmetric(vertical: 12),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(2),
),
),
// Header
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
children: [
Expanded(
child: Text(
widget.title,
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Color(0xFF101820),
),
),
),
IconButton(
onPressed: _refreshRoutes,
icon: Icon(
Icons.refresh,
color: isLoading ? Colors.grey : const Color(0xFF101820),
),
),
],
),
),
const SizedBox(height: 16),
// Content
Flexible(
child: isLoading
? const Center(
child: Padding(
padding: EdgeInsets.all(40),
child: CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation<Color>(Color(0xFFFEE715)),
),
),
)
: error != null
? Padding(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.error_outline,
color: Colors.red[600],
size: 48,
),
const SizedBox(height: 16),
Text(
error,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.red[600],
fontSize: 16,
),
),
const SizedBox(height: 16),
ElevatedButton.icon(
onPressed: _refreshRoutes,
icon: const Icon(Icons.refresh),
label: const Text('Reintentar'),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFFFEE715),
foregroundColor: const Color(0xFF101820),
),
),
],
),
)
: routes.isEmpty
? const Padding(
padding: EdgeInsets.all(40),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.route_outlined,
color: Colors.grey,
size: 48,
),
SizedBox(height: 16),
Text(
'No hay rutas disponibles',
style: TextStyle(
fontSize: 16,
color: Colors.grey,
),
),
],
),
)
: ListView.builder(
shrinkWrap: true,
itemCount: routes.length,
itemBuilder: (context, index) {
final route = routes[index];
final isSelected = selectedRouteId == route.id;
return ListTile(
leading: Container(
width: 12,
height: 12,
decoration: BoxDecoration(
color: Color(int.parse(route.color
.replaceFirst('#', '0xFF'))),
shape: BoxShape.circle,
),
),
title: Text(
route.displayName,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
subtitle: route.direction.isNotEmpty
? Text(
route.direction,
style: TextStyle(
fontSize: 14,
color: Colors.grey[600],
),
)
: null,
trailing: isSelected
? const Icon(
Icons.check_circle,
color: Color(0xFFFEE715),
)
: null,
onTap: () => _onRouteSelected(route.id),
);
},
),
),
const SizedBox(height: 16),
],
),
),
);
}
}