237 lines
9.1 KiB
Dart
237 lines
9.1 KiB
Dart
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,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|