checkpoint

This commit is contained in:
2025-11-26 17:41:37 -05:00
parent ef5c0c1a95
commit 2ecd1c5b4e
15 changed files with 794 additions and 152 deletions
+32 -22
View File
@@ -1,6 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../l10n/app_localizations.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:image_picker/image_picker.dart';
import 'package:http/http.dart' as http;
@@ -85,6 +86,7 @@ class _DeliveriesPageState extends ConsumerState<DeliveriesPage> {
final deliveriesData = ref.watch(deliveriesProvider(widget.routeFragmentId));
final tokenAsync = ref.watch(authTokenProvider);
final token = tokenAsync.hasValue ? tokenAsync.value : null;
final l10n = AppLocalizations.of(context)!;
// When embedded in sidebar, show only the delivery list with back button
// This is a responsive sidebar that collapses like routes
@@ -183,7 +185,7 @@ class _DeliveriesPageState extends ConsumerState<DeliveriesPage> {
child: CircularProgressIndicator(),
),
error: (error, stackTrace) => Center(
child: Text('Error: $error'),
child: Text(l10n.error(error.toString())),
),
);
}
@@ -277,7 +279,7 @@ class _DeliveriesPageState extends ConsumerState<DeliveriesPage> {
child: CircularProgressIndicator(),
),
error: (error, stackTrace) => Center(
child: Text('Error: $error'),
child: Text(l10n.error(error.toString())),
),
),
),
@@ -291,7 +293,8 @@ class _DeliveriesPageState extends ConsumerState<DeliveriesPage> {
String? token,
) async {
if (token == null) {
ToastHelper.showError(context, 'Authentication required');
final l10n = AppLocalizations.of(context)!;
ToastHelper.showError(context, l10n.authenticationRequired);
return;
}
@@ -312,12 +315,14 @@ class _DeliveriesPageState extends ConsumerState<DeliveriesPage> {
);
result.when(
success: (_) {
final l10n = AppLocalizations.of(context)!;
// ignore: unused_result
ref.refresh(deliveriesProvider(widget.routeFragmentId));
ToastHelper.showSuccess(context, 'Delivery marked as completed');
ToastHelper.showSuccess(context, l10n.deliverySuccessful);
},
onError: (error) {
ToastHelper.showError(context, 'Error: ${error.message}');
final l10n = AppLocalizations.of(context)!;
ToastHelper.showError(context, l10n.error(error.message));
},
);
break;
@@ -329,12 +334,14 @@ class _DeliveriesPageState extends ConsumerState<DeliveriesPage> {
);
result.when(
success: (_) {
final l10n = AppLocalizations.of(context)!;
// ignore: unused_result
ref.refresh(deliveriesProvider(widget.routeFragmentId));
ToastHelper.showSuccess(context, 'Delivery marked as uncompleted');
},
onError: (error) {
ToastHelper.showError(context, 'Error: ${error.message}');
final l10n = AppLocalizations.of(context)!;
ToastHelper.showError(context, l10n.error(error.message));
},
);
break;
@@ -368,7 +375,8 @@ class _DeliveriesPageState extends ConsumerState<DeliveriesPage> {
String? token,
) async {
if (token == null) {
ToastHelper.showError(context, 'Authentication required');
final l10n = AppLocalizations.of(context)!;
ToastHelper.showError(context, l10n.authenticationRequired);
return;
}
@@ -416,11 +424,11 @@ class _DeliveriesPageState extends ConsumerState<DeliveriesPage> {
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text('Cancel'),
child: Text(AppLocalizations.of(context)!.cancel),
),
ElevatedButton(
onPressed: () => Navigator.of(dialogContext).pop(true),
child: const Text('Upload'),
child: Text(AppLocalizations.of(context)!.upload),
),
],
);
@@ -511,9 +519,10 @@ class UnifiedDeliveryListView extends StatelessWidget {
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
if (deliveries.isEmpty) {
return const Center(
child: Text('No deliveries'),
return Center(
child: Text(l10n.noDeliveries),
);
}
@@ -599,12 +608,12 @@ class DeliveryCard extends StatelessWidget {
),
if (delivery.delivered)
Chip(
label: const Text('Delivered'),
label: Text(AppLocalizations.of(context)!.delivered),
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
)
else if (order?.isNewCustomer ?? false)
Chip(
label: const Text('New Customer'),
label: Text(AppLocalizations.of(context)!.newCustomer),
backgroundColor: const Color(0xFFFFFBEB),
),
],
@@ -624,11 +633,11 @@ class DeliveryCard extends StatelessWidget {
children: [
if (order.totalItems != null)
Text(
'${order.totalItems} items',
AppLocalizations.of(context)!.items(order.totalItems!),
style: Theme.of(context).textTheme.bodySmall,
),
Text(
'${order.totalAmount} MAD',
AppLocalizations.of(context)!.moneyCurrency(order.totalAmount),
style: Theme.of(context).textTheme.titleSmall?.copyWith(
color: Theme.of(context).colorScheme.primary,
),
@@ -644,7 +653,7 @@ class DeliveryCard extends StatelessWidget {
OutlinedButton.icon(
onPressed: () => onAction(delivery, 'call'),
icon: const Icon(Icons.phone),
label: const Text('Call'),
label: Text(AppLocalizations.of(context)!.call),
),
if (delivery.deliveryAddress != null)
OutlinedButton.icon(
@@ -653,12 +662,12 @@ class DeliveryCard extends StatelessWidget {
onAction(delivery, 'map');
},
icon: const Icon(Icons.map),
label: const Text('Navigate'),
label: Text(AppLocalizations.of(context)!.navigate),
),
OutlinedButton.icon(
onPressed: () => _showDeliveryActions(context),
icon: const Icon(Icons.more_vert),
label: const Text('More'),
label: Text(AppLocalizations.of(context)!.more),
),
],
),
@@ -670,6 +679,7 @@ class DeliveryCard extends StatelessWidget {
}
void _showDeliveryActions(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
showModalBottomSheet(
context: context,
builder: (context) => SafeArea(
@@ -679,7 +689,7 @@ class DeliveryCard extends StatelessWidget {
if (!delivery.delivered)
ListTile(
leading: const Icon(Icons.check_circle),
title: const Text('Mark as Completed'),
title: Text(l10n.markAsCompleted),
onTap: () {
Navigator.pop(context);
onAction(delivery, 'complete');
@@ -688,7 +698,7 @@ class DeliveryCard extends StatelessWidget {
else
ListTile(
leading: const Icon(Icons.undo),
title: const Text('Mark as Uncompleted'),
title: Text(l10n.markAsUncompleted),
onTap: () {
Navigator.pop(context);
onAction(delivery, 'uncomplete');
@@ -696,7 +706,7 @@ class DeliveryCard extends StatelessWidget {
),
ListTile(
leading: const Icon(Icons.camera_alt),
title: const Text('Upload Photo'),
title: Text(l10n.uploadPhoto),
onTap: () {
Navigator.pop(context);
// TODO: Implement photo upload
@@ -704,7 +714,7 @@ class DeliveryCard extends StatelessWidget {
),
ListTile(
leading: const Icon(Icons.description),
title: const Text('View Details'),
title: Text(l10n.viewDetails),
onTap: () {
Navigator.pop(context);
// TODO: Navigate to delivery details
+13 -12
View File
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../l10n/app_localizations.dart';
import '../providers/providers.dart';
import '../utils/toast_helper.dart';
@@ -78,7 +79,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
),
const SizedBox(height: 24),
Text(
'Plan B Logistics',
AppLocalizations.of(context)!.appTitle,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.displayMedium?.copyWith(
color: Theme.of(context).colorScheme.primary,
@@ -87,7 +88,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
),
const SizedBox(height: 8),
Text(
'Delivery Management System',
AppLocalizations.of(context)!.appDescription,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
@@ -96,17 +97,17 @@ class _LoginPageState extends ConsumerState<LoginPage> {
const SizedBox(height: 48),
TextFormField(
controller: _usernameController,
decoration: const InputDecoration(
labelText: 'Username',
hintText: 'Enter your username',
prefixIcon: Icon(Icons.person),
border: OutlineInputBorder(),
decoration: InputDecoration(
labelText: AppLocalizations.of(context)!.username,
hintText: AppLocalizations.of(context)!.usernameHint,
prefixIcon: const Icon(Icons.person),
border: const OutlineInputBorder(),
),
textInputAction: TextInputAction.next,
enabled: !_isLoading,
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Please enter your username';
return AppLocalizations.of(context)!.usernameRequired;
}
return null;
},
@@ -115,8 +116,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
TextFormField(
controller: _passwordController,
decoration: InputDecoration(
labelText: 'Password',
hintText: 'Enter your password',
labelText: AppLocalizations.of(context)!.password,
hintText: AppLocalizations.of(context)!.passwordHint,
prefixIcon: const Icon(Icons.lock),
border: const OutlineInputBorder(),
suffixIcon: IconButton(
@@ -136,7 +137,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
onFieldSubmitted: (_) => _handleLogin(),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter your password';
return AppLocalizations.of(context)!.passwordRequired;
}
return null;
},
@@ -158,7 +159,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
),
),
)
: const Text('Login'),
: Text(AppLocalizations.of(context)!.loginButton),
),
],
),
+20 -12
View File
@@ -1,6 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../l10n/app_localizations.dart';
import 'package:image_picker/image_picker.dart';
import 'package:http/http.dart' as http;
import '../models/delivery.dart';
@@ -86,7 +87,8 @@ class _RoutesPageState extends ConsumerState<RoutesPage> {
final token = await authService.ensureValidToken();
if (token == null) {
if (mounted) {
ToastHelper.showError(context, 'Authentication required');
final l10n = AppLocalizations.of(context)!;
ToastHelper.showError(context, l10n.authenticationRequired);
}
return;
}
@@ -173,7 +175,8 @@ class _RoutesPageState extends ConsumerState<RoutesPage> {
}
if (mounted) {
ToastHelper.showSuccess(context, 'Delivery marked as completed');
final l10n = AppLocalizations.of(context)!;
ToastHelper.showSuccess(context, l10n.deliverySuccessful);
}
}
},
@@ -185,7 +188,8 @@ class _RoutesPageState extends ConsumerState<RoutesPage> {
debugPrint('Complete delivery failed - Type: ${error.type}, Message: ${error.message}');
debugPrint('Error details: ${error.details}');
if (mounted) {
String errorMessage = 'Error: ${error.message}';
final l10n = AppLocalizations.of(context)!;
String errorMessage = l10n.error(error.message);
if (error.statusCode == 500) {
errorMessage = 'Server error - Please contact support';
}
@@ -251,6 +255,7 @@ class _RoutesPageState extends ConsumerState<RoutesPage> {
}
if (mounted) {
final l10n = AppLocalizations.of(context)!;
ToastHelper.showSuccess(context, 'Delivery marked as uncompleted');
}
}
@@ -261,7 +266,8 @@ class _RoutesPageState extends ConsumerState<RoutesPage> {
}
if (mounted) {
ToastHelper.showError(context, 'Error: ${error.message}');
final l10n = AppLocalizations.of(context)!;
ToastHelper.showError(context, l10n.error(error.message));
}
},
);
@@ -286,7 +292,8 @@ class _RoutesPageState extends ConsumerState<RoutesPage> {
final token = await authService.ensureValidToken();
if (token == null) {
if (mounted) {
ToastHelper.showError(context, 'Authentication required');
final l10n = AppLocalizations.of(context)!;
ToastHelper.showError(context, l10n.authenticationRequired);
}
return;
}
@@ -507,10 +514,11 @@ class _RoutesPageState extends ConsumerState<RoutesPage> {
final routesData = ref.watch(deliveryRoutesProvider);
final allDeliveriesData = ref.watch(allDeliveriesProvider);
final userProfile = ref.watch(userProfileProvider);
final l10n = AppLocalizations.of(context)!;
return Scaffold(
appBar: AppBar(
title: const Text('Delivery Routes'),
title: Text(l10n.deliveryRoutes),
elevation: 0,
actions: [
IconButton(
@@ -580,8 +588,8 @@ class _RoutesPageState extends ConsumerState<RoutesPage> {
body: routesData.when(
data: (routes) {
if (routes.isEmpty) {
return const Center(
child: Text('No routes available'),
return Center(
child: Text(l10n.noRoutes),
);
}
return allDeliveriesData.when(
@@ -642,11 +650,11 @@ class _RoutesPageState extends ConsumerState<RoutesPage> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Error loading deliveries: $error'),
Text(l10n.error(error.toString())),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => ref.refresh(allDeliveriesProvider),
child: const Text('Retry'),
child: Text(l10n.retry),
),
],
),
@@ -660,11 +668,11 @@ class _RoutesPageState extends ConsumerState<RoutesPage> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Error: $error'),
Text(l10n.error(error.toString())),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => ref.refresh(deliveryRoutesProvider),
child: const Text('Retry'),
child: Text(l10n.retry),
),
],
),
+34 -27
View File
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../l10n/app_localizations.dart';
import '../providers/providers.dart';
class SettingsPage extends ConsumerWidget {
@@ -8,12 +9,18 @@ class SettingsPage extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final userProfile = ref.watch(userProfileProvider);
final language = ref.watch(languageProvider);
final languageAsync = ref.watch(languageProvider);
final themeMode = ref.watch(themeModeProvider);
final l10n = AppLocalizations.of(context)!;
final language = languageAsync.maybeWhen(
data: (value) => value,
orElse: () => 'system',
);
return Scaffold(
appBar: AppBar(
title: const Text('Settings'),
title: Text(l10n.settings),
),
body: ListView(
children: [
@@ -23,14 +30,14 @@ class SettingsPage extends ConsumerWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Profile',
l10n.profile,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 16),
userProfile.when(
data: (profile) {
if (profile == null) {
return const Text('No profile information');
return Text(l10n.noProfileInfo);
}
return Card(
child: Padding(
@@ -78,7 +85,7 @@ class SettingsPage extends ConsumerWidget {
}
},
color: Theme.of(context).colorScheme.error,
tooltip: 'Logout',
tooltip: l10n.logout,
),
],
),
@@ -88,7 +95,7 @@ class SettingsPage extends ConsumerWidget {
);
},
loading: () => const CircularProgressIndicator(),
error: (error, stackTrace) => Text('Error: $error'),
error: (error, stackTrace) => Text(l10n.error(error.toString())),
),
],
),
@@ -100,18 +107,18 @@ class SettingsPage extends ConsumerWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Preferences',
l10n.preferences,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 16),
ListTile(
title: const Text('Language'),
title: Text(l10n.language),
subtitle: Text(
language == 'system'
? 'System'
? l10n.systemLanguage
: language == 'fr'
? 'Français'
: 'English'
? l10n.french
: l10n.english
),
trailing: DropdownButton<String>(
value: language,
@@ -120,18 +127,18 @@ class SettingsPage extends ConsumerWidget {
ref.read(languageProvider.notifier).setLanguage(newValue);
}
},
items: const [
items: [
DropdownMenuItem(
value: 'system',
child: Text('System'),
child: Text(l10n.systemLanguage),
),
DropdownMenuItem(
value: 'en',
child: Text('English'),
child: Text(l10n.english),
),
DropdownMenuItem(
value: 'fr',
child: Text('Français'),
child: Text(l10n.french),
),
],
),
@@ -141,7 +148,7 @@ class SettingsPage extends ConsumerWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Theme',
l10n.theme,
style: Theme.of(context).textTheme.titleSmall,
),
const SizedBox(height: 8),
@@ -150,21 +157,21 @@ class SettingsPage extends ConsumerWidget {
onSelectionChanged: (Set<ThemeMode> newSelection) {
ref.read(themeModeProvider.notifier).setThemeMode(newSelection.first);
},
segments: const [
segments: [
ButtonSegment<ThemeMode>(
value: ThemeMode.light,
label: Text('Light'),
icon: Icon(Icons.light_mode),
label: Text(l10n.themeLight),
icon: const Icon(Icons.light_mode),
),
ButtonSegment<ThemeMode>(
value: ThemeMode.dark,
label: Text('Dark'),
icon: Icon(Icons.dark_mode),
label: Text(l10n.themeDark),
icon: const Icon(Icons.dark_mode),
),
ButtonSegment<ThemeMode>(
value: ThemeMode.system,
label: Text('Auto'),
icon: Icon(Icons.brightness_auto),
label: Text(l10n.themeSystem),
icon: const Icon(Icons.brightness_auto),
),
],
),
@@ -180,17 +187,17 @@ class SettingsPage extends ConsumerWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'About',
l10n.about,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 16),
ListTile(
title: const Text('App Version'),
title: Text(l10n.appVersion),
subtitle: const Text('1.0.0'),
),
ListTile(
title: const Text('Built with Flutter'),
subtitle: const Text('Plan B Logistics Management System'),
title: Text(l10n.builtWithFlutter),
subtitle: Text(l10n.appDescription),
),
],
),