first app design
This commit is contained in:
@@ -0,0 +1,418 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../../core/models/marketplace.dart';
|
||||
import '../providers/client_providers.dart';
|
||||
|
||||
class BookingScreen extends ConsumerStatefulWidget {
|
||||
final String vehicleId;
|
||||
final MarketplaceVehicle? vehicle;
|
||||
|
||||
const BookingScreen({
|
||||
super.key,
|
||||
required this.vehicleId,
|
||||
this.vehicle,
|
||||
});
|
||||
|
||||
@override
|
||||
ConsumerState<BookingScreen> createState() => _BookingScreenState();
|
||||
}
|
||||
|
||||
class _BookingScreenState extends ConsumerState<BookingScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _firstNameCtrl = TextEditingController();
|
||||
final _lastNameCtrl = TextEditingController();
|
||||
final _emailCtrl = TextEditingController();
|
||||
final _phoneCtrl = TextEditingController();
|
||||
final _notesCtrl = TextEditingController();
|
||||
|
||||
bool _loading = false;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_firstNameCtrl.dispose();
|
||||
_lastNameCtrl.dispose();
|
||||
_emailCtrl.dispose();
|
||||
_phoneCtrl.dispose();
|
||||
_notesCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
|
||||
final params = ref.read(searchParamsProvider);
|
||||
if (!params.hasDateRange) {
|
||||
setState(() => _error = 'Please select dates before booking.');
|
||||
return;
|
||||
}
|
||||
|
||||
final vehicle = widget.vehicle;
|
||||
if (vehicle == null) {
|
||||
setState(() => _error = 'Vehicle information missing.');
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_loading = true;
|
||||
_error = null;
|
||||
});
|
||||
|
||||
try {
|
||||
final reservationId =
|
||||
await ref.read(marketplaceServiceProvider).createReservation(
|
||||
vehicleId: vehicle.id,
|
||||
companySlug: vehicle.companySlug,
|
||||
firstName: _firstNameCtrl.text.trim(),
|
||||
lastName: _lastNameCtrl.text.trim(),
|
||||
email: _emailCtrl.text.trim(),
|
||||
phone: _phoneCtrl.text.trim().isEmpty
|
||||
? null
|
||||
: _phoneCtrl.text.trim(),
|
||||
startDate: params.startDate!,
|
||||
endDate: params.endDate!,
|
||||
notes: _notesCtrl.text.trim().isEmpty
|
||||
? null
|
||||
: _notesCtrl.text.trim(),
|
||||
);
|
||||
|
||||
if (mounted) _showSuccess(reservationId, vehicle, params);
|
||||
} catch (e) {
|
||||
setState(() =>
|
||||
_error = 'Booking failed. Please check your details and try again.');
|
||||
} finally {
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
void _showSuccess(
|
||||
String reservationId, MarketplaceVehicle v, SearchParams params) {
|
||||
final fmt = DateFormat('MMM d, yyyy');
|
||||
final days = params.endDate!.difference(params.startDate!).inDays;
|
||||
final total = v.dailyRateCents * days / 100;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => AlertDialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: const BoxDecoration(
|
||||
color: Color(0xFFDEF7EC),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.check,
|
||||
color: Color(0xFF057A55), size: 32),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text('Booking Confirmed!',
|
||||
style: TextStyle(
|
||||
fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
v.displayName,
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF6B7280), fontSize: 14),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF9FAFB),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_ConfirmRow(
|
||||
label: 'Dates',
|
||||
value:
|
||||
'${fmt.format(params.startDate!)} → ${fmt.format(params.endDate!)}'),
|
||||
const SizedBox(height: 6),
|
||||
_ConfirmRow(
|
||||
label: 'Duration', value: '$days days'),
|
||||
const SizedBox(height: 6),
|
||||
_ConfirmRow(
|
||||
label: 'Total',
|
||||
value: '\$${total.toStringAsFixed(2)}'),
|
||||
const SizedBox(height: 6),
|
||||
_ConfirmRow(
|
||||
label: 'Reference',
|
||||
value: reservationId.substring(0, 8).toUpperCase(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'A confirmation has been sent\nto your email.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 12, color: Color(0xFF9CA3AF)),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
context.go('/client');
|
||||
},
|
||||
child: const Text('Back to Search'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final vehicle = widget.vehicle;
|
||||
final params = ref.watch(searchParamsProvider);
|
||||
final hasDates = params.hasDateRange;
|
||||
final days = hasDates
|
||||
? params.endDate!.difference(params.startDate!).inDays
|
||||
: 0;
|
||||
final fmt = DateFormat('MMM d, yyyy');
|
||||
final total = vehicle != null && hasDates
|
||||
? vehicle.dailyRateCents * days / 100
|
||||
: null;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Complete Booking')),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
// Vehicle summary
|
||||
if (vehicle != null)
|
||||
Card(
|
||||
margin: const EdgeInsets.only(bottom: 16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.directions_car,
|
||||
color: Color(0xFF1A56DB), size: 28),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(vehicle.displayName,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 15)),
|
||||
Text(vehicle.company.brand.displayName,
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF6B7280),
|
||||
fontSize: 12)),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (total != null)
|
||||
Text(
|
||||
'\$${total.toStringAsFixed(0)}',
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1A56DB),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Date summary
|
||||
if (hasDates)
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: 16),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFEBF5FF),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: const Color(0xFFBFDBFE)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.calendar_today,
|
||||
color: Color(0xFF1A56DB), size: 16),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
'${fmt.format(params.startDate!)} → ${fmt.format(params.endDate!)} · $days day${days == 1 ? '' : 's'}',
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF1A56DB),
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
else
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: 16),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFDF6B2),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(Icons.warning_amber,
|
||||
color: Color(0xFFB45309), size: 16),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
'No dates selected — go back and pick dates',
|
||||
style: TextStyle(
|
||||
color: Color(0xFF92400E), fontSize: 13),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
if (_error != null) ...[
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
margin: const EdgeInsets.only(bottom: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFDE8E8),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(_error!,
|
||||
style: const TextStyle(color: Color(0xFF9B1C1C))),
|
||||
),
|
||||
],
|
||||
|
||||
// Personal info
|
||||
const _SectionLabel('Your Information'),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: _firstNameCtrl,
|
||||
textCapitalization: TextCapitalization.words,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration:
|
||||
const InputDecoration(labelText: 'First Name'),
|
||||
validator: (v) =>
|
||||
v == null || v.trim().isEmpty ? 'Required' : null,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: _lastNameCtrl,
|
||||
textCapitalization: TextCapitalization.words,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration:
|
||||
const InputDecoration(labelText: 'Last Name'),
|
||||
validator: (v) =>
|
||||
v == null || v.trim().isEmpty ? 'Required' : null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
TextFormField(
|
||||
controller: _emailCtrl,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Email',
|
||||
prefixIcon: Icon(Icons.email_outlined),
|
||||
),
|
||||
validator: (v) => (v == null || !v.contains('@'))
|
||||
? 'Enter a valid email'
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
TextFormField(
|
||||
controller: _phoneCtrl,
|
||||
keyboardType: TextInputType.phone,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Phone (optional)',
|
||||
prefixIcon: Icon(Icons.phone_outlined),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
TextFormField(
|
||||
controller: _notesCtrl,
|
||||
maxLines: 2,
|
||||
textInputAction: TextInputAction.done,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Notes (optional)',
|
||||
prefixIcon: Icon(Icons.notes_outlined),
|
||||
alignLabelWithHint: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 28),
|
||||
ElevatedButton(
|
||||
onPressed: (_loading || !hasDates) ? null : _submit,
|
||||
style: ElevatedButton.styleFrom(
|
||||
minimumSize: const Size.fromHeight(52)),
|
||||
child: _loading
|
||||
? const SizedBox(
|
||||
height: 22,
|
||||
width: 22,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor:
|
||||
AlwaysStoppedAnimation<Color>(Colors.white)),
|
||||
)
|
||||
: const Text('Confirm Booking',
|
||||
style: TextStyle(fontSize: 16)),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SectionLabel extends StatelessWidget {
|
||||
final String text;
|
||||
const _SectionLabel(this.text);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Text(text,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 15,
|
||||
color: Color(0xFF374151))),
|
||||
);
|
||||
}
|
||||
|
||||
class _ConfirmRow extends StatelessWidget {
|
||||
final String label;
|
||||
final String value;
|
||||
const _ConfirmRow({required this.label, required this.value});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(label,
|
||||
style: const TextStyle(
|
||||
fontSize: 13, color: Color(0xFF6B7280))),
|
||||
Text(value,
|
||||
style: const TextStyle(
|
||||
fontSize: 13, fontWeight: FontWeight.w600)),
|
||||
],
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,45 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
|
||||
class ClientShell extends ConsumerWidget {
|
||||
final Widget child;
|
||||
|
||||
const ClientShell({super.key, required this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final location = GoRouterState.of(context).matchedLocation;
|
||||
final l10n = AppLocalizations.of(context);
|
||||
|
||||
int currentIndex = 0;
|
||||
if (location == '/client/bookings') currentIndex = 1;
|
||||
|
||||
return Scaffold(
|
||||
body: child,
|
||||
bottomNavigationBar: NavigationBar(
|
||||
selectedIndex: currentIndex,
|
||||
onDestinationSelected: (i) {
|
||||
if (i == 0) {
|
||||
context.go('/client');
|
||||
} else {
|
||||
context.go('/client/bookings');
|
||||
}
|
||||
},
|
||||
destinations: [
|
||||
NavigationDestination(
|
||||
icon: const Icon(Icons.search_outlined),
|
||||
selectedIcon: const Icon(Icons.search),
|
||||
label: l10n.browse,
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: const Icon(Icons.bookmark_outline),
|
||||
selectedIcon: const Icon(Icons.bookmark),
|
||||
label: l10n.myBookings,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../../core/models/marketplace.dart';
|
||||
import '../../../core/constants/app_constants.dart';
|
||||
import '../providers/client_providers.dart';
|
||||
|
||||
class ClientVehicleDetailScreen extends ConsumerWidget {
|
||||
final String id;
|
||||
final MarketplaceVehicle? vehicle;
|
||||
|
||||
const ClientVehicleDetailScreen({
|
||||
super.key,
|
||||
required this.id,
|
||||
this.vehicle,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final params = ref.watch(searchParamsProvider);
|
||||
// Use vehicle passed via extra; no separate fetch needed
|
||||
final v = vehicle;
|
||||
if (v == null) {
|
||||
return const Scaffold(body: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
return _DetailView(vehicle: v, searchParams: params);
|
||||
}
|
||||
}
|
||||
|
||||
class _DetailView extends StatelessWidget {
|
||||
final MarketplaceVehicle vehicle;
|
||||
final SearchParams searchParams;
|
||||
|
||||
const _DetailView({required this.vehicle, required this.searchParams});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final hasDates = searchParams.hasDateRange;
|
||||
final days = hasDates
|
||||
? searchParams.endDate!.difference(searchParams.startDate!).inDays
|
||||
: null;
|
||||
final fmt = DateFormat('MMM d, yyyy');
|
||||
final baseUrl = AppConstants.baseUrl.replaceAll('/api/v1', '');
|
||||
|
||||
return Scaffold(
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
SliverAppBar(
|
||||
expandedHeight: 280,
|
||||
pinned: true,
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
background: vehicle.primaryPhoto != null
|
||||
? CachedNetworkImage(
|
||||
imageUrl: vehicle.primaryPhoto!.startsWith('http')
|
||||
? vehicle.primaryPhoto!
|
||||
: '$baseUrl${vehicle.primaryPhoto!}',
|
||||
fit: BoxFit.cover,
|
||||
errorWidget: (_, _, _) => _placeholder(),
|
||||
)
|
||||
: _placeholder(),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Company
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.business_outlined,
|
||||
size: 14, color: Color(0xFF9CA3AF)),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
vehicle.company.brand.displayName,
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF6B7280), fontSize: 13),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
// Name
|
||||
Text(
|
||||
vehicle.displayName,
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF111928),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Specs grid
|
||||
_SpecsGrid(vehicle: vehicle),
|
||||
const SizedBox(height: 20),
|
||||
// Features
|
||||
if (vehicle.features.isNotEmpty) ...[
|
||||
const Text('Features',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 15,
|
||||
color: Color(0xFF374151))),
|
||||
const SizedBox(height: 10),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: vehicle.features
|
||||
.map((f) => Chip(
|
||||
label: Text(f,
|
||||
style: const TextStyle(fontSize: 12)),
|
||||
backgroundColor:
|
||||
const Color(0xFFF3F4F6),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
// Pricing card
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF0F7FF),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFBFDBFE)),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text('Daily rate',
|
||||
style: TextStyle(
|
||||
color: Color(0xFF6B7280),
|
||||
fontSize: 13)),
|
||||
const Spacer(),
|
||||
Text(
|
||||
'\$${vehicle.dailyRate.toStringAsFixed(2)}/day',
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1A56DB),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (hasDates && days != null) ...[
|
||||
const SizedBox(height: 10),
|
||||
const Divider(height: 1),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'${fmt.format(searchParams.startDate!)} → ${fmt.format(searchParams.endDate!)}',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Color(0xFF6B7280)),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
'$days day${days == 1 ? '' : 's'}',
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF6B7280),
|
||||
fontSize: 13),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
const Text('Estimated total',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600)),
|
||||
const Spacer(),
|
||||
Text(
|
||||
'\$${(vehicle.dailyRateCents * days / 100).toStringAsFixed(2)}',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
color: Color(0xFF111928),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 100),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
minimumSize: const Size.fromHeight(52)),
|
||||
onPressed: vehicle.availability
|
||||
? () => context.push('/client/book/${vehicle.id}',
|
||||
extra: vehicle)
|
||||
: null,
|
||||
child: Text(vehicle.availability
|
||||
? 'Reserve This Car'
|
||||
: 'Not Available'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _placeholder() => Container(
|
||||
color: const Color(0xFFF3F4F6),
|
||||
child: const Center(
|
||||
child: Icon(Icons.directions_car,
|
||||
size: 72, color: Color(0xFFD1D5DB)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _SpecsGrid extends StatelessWidget {
|
||||
final MarketplaceVehicle vehicle;
|
||||
|
||||
const _SpecsGrid({required this.vehicle});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final items = [
|
||||
(Icons.category_outlined, 'Category',
|
||||
vehicle.category[0] +
|
||||
vehicle.category.substring(1).toLowerCase()),
|
||||
(Icons.people_outline, 'Seats', '${vehicle.seats}'),
|
||||
(Icons.settings_outlined, 'Transmission',
|
||||
vehicle.transmission[0] +
|
||||
vehicle.transmission.substring(1).toLowerCase()),
|
||||
(Icons.local_gas_station_outlined, 'Fuel',
|
||||
vehicle.fuelType[0] +
|
||||
vehicle.fuelType.substring(1).toLowerCase()),
|
||||
if (vehicle.color != null)
|
||||
(Icons.palette_outlined, 'Color', vehicle.color!),
|
||||
if (vehicle.mileage != null)
|
||||
(Icons.speed_outlined, 'Mileage',
|
||||
'${vehicle.mileage} km'),
|
||||
];
|
||||
|
||||
return GridView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
mainAxisExtent: 64,
|
||||
crossAxisSpacing: 10,
|
||||
mainAxisSpacing: 10,
|
||||
),
|
||||
itemCount: items.length,
|
||||
itemBuilder: (_, i) => Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF9FAFB),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: const Color(0xFFE5E7EB)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(items[i].$1, size: 16, color: const Color(0xFF6B7280)),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(items[i].$2,
|
||||
style: const TextStyle(
|
||||
fontSize: 10, color: Color(0xFF9CA3AF))),
|
||||
Text(items[i].$3,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF111928)),
|
||||
overflow: TextOverflow.ellipsis),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../core/providers/auth_provider.dart';
|
||||
|
||||
class MyBookingsScreen extends ConsumerWidget {
|
||||
const MyBookingsScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final auth = ref.watch(authProvider);
|
||||
|
||||
if (auth.status != AuthStatus.authenticated) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('My Bookings')),
|
||||
body: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.bookmark_outline,
|
||||
size: 64, color: Color(0xFFD1D5DB)),
|
||||
const SizedBox(height: 20),
|
||||
const Text(
|
||||
'Sign in to view your bookings',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF111928),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'Create an account or log in to manage your reservations.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Color(0xFF6B7280)),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton(
|
||||
onPressed: () => context.push('/role'),
|
||||
child: const Text('Sign In'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('My Bookings')),
|
||||
body: const Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.event_available, size: 64, color: Color(0xFFD1D5DB)),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'No bookings yet',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Color(0xFF6B7280),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../core/models/marketplace.dart';
|
||||
import '../../../../core/constants/app_constants.dart';
|
||||
|
||||
const _orange = Color(0xFFFF6B00);
|
||||
|
||||
class MarketplaceVehicleCard extends StatelessWidget {
|
||||
final MarketplaceVehicle vehicle;
|
||||
final DateTime? selectedStart;
|
||||
final DateTime? selectedEnd;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const MarketplaceVehicleCard({
|
||||
super.key,
|
||||
required this.vehicle,
|
||||
this.selectedStart,
|
||||
this.selectedEnd,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
final hasDates = selectedStart != null && selectedEnd != null;
|
||||
final days =
|
||||
hasDates ? selectedEnd!.difference(selectedStart!).inDays : null;
|
||||
final totalCents = days != null ? vehicle.dailyRateCents * days : null;
|
||||
|
||||
return Material(
|
||||
color: cs.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
splashColor: _orange.withValues(alpha: 0.08),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Stack(
|
||||
children: [
|
||||
_VehicleImage(vehicle: vehicle, cs: cs),
|
||||
if (!vehicle.availability)
|
||||
Positioned(
|
||||
top: 10,
|
||||
left: 10,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.65),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: const Text(
|
||||
'Unavailable',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 10,
|
||||
right: 10,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.55),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
vehicle.category[0] +
|
||||
vehicle.category.substring(1).toLowerCase(),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.business_outlined,
|
||||
size: 12, color: cs.onSurfaceVariant),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
vehicle.company.brand.displayName,
|
||||
style: TextStyle(
|
||||
fontSize: 12, color: cs.onSurfaceVariant),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
vehicle.displayName,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 16,
|
||||
color: cs.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
_Spec(
|
||||
icon: Icons.people_outline,
|
||||
label: '${vehicle.seats} seats',
|
||||
cs: cs),
|
||||
const SizedBox(width: 14),
|
||||
_Spec(
|
||||
icon: Icons.settings_outlined,
|
||||
label: vehicle.transmission[0] +
|
||||
vehicle.transmission
|
||||
.substring(1)
|
||||
.toLowerCase(),
|
||||
cs: cs),
|
||||
const SizedBox(width: 14),
|
||||
_Spec(
|
||||
icon: Icons.local_gas_station_outlined,
|
||||
label: vehicle.fuelType[0] +
|
||||
vehicle.fuelType.substring(1).toLowerCase(),
|
||||
cs: cs),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Divider(height: 1, color: cs.outlineVariant),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'\$${vehicle.dailyRate.toStringAsFixed(0)}',
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _orange,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'/day',
|
||||
style: TextStyle(
|
||||
fontSize: 13, color: cs.onSurfaceVariant),
|
||||
),
|
||||
if (totalCents != null) ...[
|
||||
const Spacer(),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'$days day${days == 1 ? '' : 's'}',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: cs.onSurfaceVariant),
|
||||
),
|
||||
Text(
|
||||
'\$${(totalCents / 100).toStringAsFixed(0)} total',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 14,
|
||||
color: cs.onSurface,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _VehicleImage extends StatelessWidget {
|
||||
final MarketplaceVehicle vehicle;
|
||||
final ColorScheme cs;
|
||||
|
||||
const _VehicleImage({required this.vehicle, required this.cs});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final photo = vehicle.primaryPhoto;
|
||||
if (photo == null) return _placeholder();
|
||||
|
||||
final url = _resolveUrl(photo);
|
||||
|
||||
return CachedNetworkImage(
|
||||
imageUrl: url,
|
||||
height: 180,
|
||||
width: double.infinity,
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (_, _) => _placeholder(),
|
||||
errorWidget: (_, _, _) => _placeholder(),
|
||||
);
|
||||
}
|
||||
|
||||
String _resolveUrl(String photo) {
|
||||
if (!photo.startsWith('http')) {
|
||||
return '${AppConstants.baseUrl.replaceAll('/api/v1', '')}$photo';
|
||||
}
|
||||
if (Platform.isAndroid) {
|
||||
return photo.replaceFirst('localhost', '10.0.2.2');
|
||||
}
|
||||
return photo;
|
||||
}
|
||||
|
||||
Widget _placeholder() => Container(
|
||||
height: 180,
|
||||
color: const Color(0xFF1C1C28),
|
||||
child: Center(
|
||||
child: Icon(Icons.directions_car,
|
||||
size: 56, color: cs.outlineVariant),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _Spec extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final ColorScheme cs;
|
||||
|
||||
const _Spec({required this.icon, required this.label, required this.cs});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(icon, size: 13, color: cs.onSurfaceVariant),
|
||||
const SizedBox(width: 3),
|
||||
Text(label,
|
||||
style:
|
||||
TextStyle(fontSize: 12, color: cs.onSurfaceVariant)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../core/models/marketplace.dart';
|
||||
|
||||
class OfferBanner extends StatelessWidget {
|
||||
final MarketplaceOffer offer;
|
||||
|
||||
const OfferBanner({super.key, required this.offer});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final daysLeft =
|
||||
offer.validUntil.difference(DateTime.now()).inDays;
|
||||
|
||||
return Container(
|
||||
width: 260,
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [Color(0xFF1A56DB), Color(0xFF3B82F6)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
offer.title,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.2),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
offer.discountLabel,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
offer.company.brand.displayName,
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.8),
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
daysLeft > 0 ? '$daysLeft days left' : 'Ends today',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.8),
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user