Initial commit: SIBU 2.0 MISSION
This commit is contained in:
440
old/lib/presentation/bus_stop_details/bus_stop_details.dart
Normal file
440
old/lib/presentation/bus_stop_details/bus_stop_details.dart
Normal 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),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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(),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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(),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
256
old/lib/presentation/coupons_screen/coupons_screen.dart
Normal file
256
old/lib/presentation/coupons_screen/coupons_screen.dart
Normal 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
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
760
old/lib/presentation/map_screen/map_screen.dart
Normal file
760
old/lib/presentation/map_screen/map_screen.dart
Normal 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
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
113
old/lib/presentation/map_screen/widgets/map_controls_widget.dart
Normal file
113
old/lib/presentation/map_screen/widgets/map_controls_widget.dart
Normal 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,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
632
old/lib/presentation/schedules_screen/schedules_screen.dart
Normal file
632
old/lib/presentation/schedules_screen/schedules_screen.dart
Normal 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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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!),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
236
old/lib/presentation/schedules_screen/widgets/schedule_card.dart
Normal file
236
old/lib/presentation/schedules_screen/widgets/schedule_card.dart
Normal 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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
357
old/lib/presentation/splash_screen/splash_screen.dart
Normal file
357
old/lib/presentation/splash_screen/splash_screen.dart
Normal 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(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
265
old/lib/presentation/taxi_screen/taxi_screen.dart
Normal file
265
old/lib/presentation/taxi_screen/taxi_screen.dart
Normal 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
|
||||
}
|
||||
}
|
||||
159
old/lib/presentation/taxi_screen/widgets/taxi_card_widget.dart
Normal file
159
old/lib/presentation/taxi_screen/widgets/taxi_card_widget.dart
Normal 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),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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!),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user