feat(scanner): polish detection feedback and main collection behavior
- Replace noisy no-id snackbars with in-screen red status feedback - Keep success state green and reduce interruption during scan flow - Make scan-tab collection switching session-only (does not overwrite main) - Keep main collection preselected from collections tab preference - Apply recent UX text/layout polish for scan and detail actions
This commit is contained in:
parent
4fbea2c1e4
commit
1be830b16f
7 changed files with 82 additions and 50 deletions
|
|
@ -19,6 +19,9 @@ Future<void> main() async {
|
||||||
await Supabase.initialize(
|
await Supabase.initialize(
|
||||||
url: _supabaseUrl,
|
url: _supabaseUrl,
|
||||||
anonKey: _supabaseAnonKey,
|
anonKey: _supabaseAnonKey,
|
||||||
|
authOptions: const FlutterAuthClientOptions(
|
||||||
|
authFlowType: AuthFlowType.implicit,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
runApp(const Car64App());
|
runApp(const Car64App());
|
||||||
|
|
@ -33,10 +36,18 @@ final scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
|
||||||
|
|
||||||
/// Show a snackbar safely through the global key.
|
/// Show a snackbar safely through the global key.
|
||||||
void showGlobalSnackBar(String message, {bool isError = false}) {
|
void showGlobalSnackBar(String message, {bool isError = false}) {
|
||||||
scaffoldMessengerKey.currentState?.showSnackBar(
|
final messenger = scaffoldMessengerKey.currentState;
|
||||||
|
if (messenger == null) return;
|
||||||
|
|
||||||
|
messenger
|
||||||
|
..hideCurrentSnackBar()
|
||||||
|
..showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(message),
|
content: Text(message),
|
||||||
backgroundColor: isError ? Colors.red : null,
|
backgroundColor: isError ? Colors.red : null,
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
margin: const EdgeInsets.fromLTRB(16, 0, 16, 96),
|
||||||
|
duration: const Duration(seconds: 3),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -78,6 +89,7 @@ class AuthGate extends StatefulWidget {
|
||||||
|
|
||||||
class _AuthGateState extends State<AuthGate> {
|
class _AuthGateState extends State<AuthGate> {
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
|
bool _isInPasswordRecoveryFlow = false;
|
||||||
Session? _session;
|
Session? _session;
|
||||||
String? _lastEnsuredUserId;
|
String? _lastEnsuredUserId;
|
||||||
|
|
||||||
|
|
@ -103,6 +115,7 @@ class _AuthGateState extends State<AuthGate> {
|
||||||
_ensureDefaultCollectionIfNeeded();
|
_ensureDefaultCollectionIfNeeded();
|
||||||
|
|
||||||
if (authState.event == AuthChangeEvent.passwordRecovery) {
|
if (authState.event == AuthChangeEvent.passwordRecovery) {
|
||||||
|
setState(() => _isInPasswordRecoveryFlow = true);
|
||||||
_showResetPasswordDialog();
|
_showResetPasswordDialog();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -132,6 +145,10 @@ class _AuthGateState extends State<AuthGate> {
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
builder: (_) => const _ResetPasswordDialog(),
|
builder: (_) => const _ResetPasswordDialog(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() => _isInPasswordRecoveryFlow = false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -141,6 +158,7 @@ class _AuthGateState extends State<AuthGate> {
|
||||||
body: Center(child: CircularProgressIndicator()),
|
body: Center(child: CircularProgressIndicator()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (_isInPasswordRecoveryFlow) return const LoginScreen();
|
||||||
return _session != null ? const HomeShell() : const LoginScreen();
|
return _session != null ? const HomeShell() : const LoginScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||||
bool _cameraReady = false;
|
bool _cameraReady = false;
|
||||||
String? _lastDetected;
|
String? _lastDetected;
|
||||||
bool _scanAccepted = false;
|
bool _scanAccepted = false;
|
||||||
|
bool _scanNotFound = false;
|
||||||
String _statusText = 'Ready to scan';
|
String _statusText = 'Ready to scan';
|
||||||
String? _activeCollectionId;
|
String? _activeCollectionId;
|
||||||
bool _autoScanEnabled = false;
|
bool _autoScanEnabled = false;
|
||||||
|
|
@ -96,6 +97,7 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||||
void _toggleAutoScan() {
|
void _toggleAutoScan() {
|
||||||
setState(() {
|
setState(() {
|
||||||
_autoScanEnabled = !_autoScanEnabled;
|
_autoScanEnabled = !_autoScanEnabled;
|
||||||
|
_scanNotFound = false;
|
||||||
_statusText = _autoScanEnabled ? 'Auto scan enabled' : 'Auto scan paused';
|
_statusText = _autoScanEnabled ? 'Auto scan enabled' : 'Auto scan paused';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -106,6 +108,7 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_isBusy = true;
|
_isBusy = true;
|
||||||
|
_scanNotFound = false;
|
||||||
_statusText = 'Scanning…';
|
_statusText = 'Scanning…';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -133,18 +136,11 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||||
await _submitDetected(found);
|
await _submitDetected(found);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Show all detected text so user knows what was seen.
|
setState(() {
|
||||||
final allText = recognized.blocks.map((b) => b.text).join('\n');
|
_scanAccepted = false;
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
_scanNotFound = true;
|
||||||
SnackBar(
|
_statusText = 'No HW ID found';
|
||||||
content: Text(
|
});
|
||||||
allText.isEmpty
|
|
||||||
? 'No text detected — try again closer.'
|
|
||||||
: 'No HW ID found. Detected:\n$allText',
|
|
||||||
),
|
|
||||||
duration: const Duration(seconds: 4),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
|
|
@ -178,11 +174,17 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||||
setState(() {
|
setState(() {
|
||||||
_lastDetected = null;
|
_lastDetected = null;
|
||||||
_scanAccepted = true;
|
_scanAccepted = true;
|
||||||
|
_scanNotFound = false;
|
||||||
_statusText = 'Saved. Ready for next scan';
|
_statusText = 'Saved. Ready for next scan';
|
||||||
});
|
});
|
||||||
Future<void>.delayed(const Duration(milliseconds: 650), () {
|
Future<void>.delayed(const Duration(milliseconds: 650), () {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() => _scanAccepted = false);
|
setState(() {
|
||||||
|
_scanAccepted = false;
|
||||||
|
if (_statusText == 'Saved. Ready for next scan') {
|
||||||
|
_statusText = 'Ready to scan';
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
|
@ -253,6 +255,8 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
||||||
color: _scanAccepted
|
color: _scanAccepted
|
||||||
? AppColors.success.withValues(alpha: 0.12)
|
? AppColors.success.withValues(alpha: 0.12)
|
||||||
|
: _scanNotFound
|
||||||
|
? AppColors.error.withValues(alpha: 0.14)
|
||||||
: Colors.black.withValues(alpha: 0.55),
|
: Colors.black.withValues(alpha: 0.55),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
|
@ -261,7 +265,11 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||||
_statusText,
|
_statusText,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: _scanAccepted ? AppColors.success : Colors.white,
|
color: _scanAccepted
|
||||||
|
? AppColors.success
|
||||||
|
: _scanNotFound
|
||||||
|
? AppColors.error
|
||||||
|
: Colors.white,
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
|
|
@ -308,6 +316,8 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: (_scanAccepted
|
color: (_scanAccepted
|
||||||
? AppColors.success
|
? AppColors.success
|
||||||
|
: _scanNotFound
|
||||||
|
? AppColors.error
|
||||||
: AppColors.orange)
|
: AppColors.orange)
|
||||||
.withValues(alpha: 0.9),
|
.withValues(alpha: 0.9),
|
||||||
width: 2.5,
|
width: 2.5,
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ class CollectionsScreenState extends State<CollectionsScreen> {
|
||||||
await prefs.setString(_activeCollectionPrefKey, collectionId);
|
await prefs.setString(_activeCollectionPrefKey, collectionId);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() => _activeCollectionId = collectionId);
|
setState(() => _activeCollectionId = collectionId);
|
||||||
showGlobalSnackBar('Active scan collection set.');
|
showGlobalSnackBar('Main collection set for scanning.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -419,7 +419,7 @@ class _CollectionCard extends StatelessWidget {
|
||||||
borderRadius: BorderRadius.circular(6),
|
borderRadius: BorderRadius.circular(6),
|
||||||
),
|
),
|
||||||
child: const Text(
|
child: const Text(
|
||||||
'Active',
|
'Main',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 11,
|
fontSize: 11,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
|
|
@ -436,7 +436,9 @@ class _CollectionCard extends StatelessWidget {
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: isActive ? 'Already active for scan' : 'Set active for scan',
|
tooltip: isActive
|
||||||
|
? 'Already main collection'
|
||||||
|
: 'Make main collection',
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
isActive ? Icons.my_location : Icons.location_searching,
|
isActive ? Icons.my_location : Icons.location_searching,
|
||||||
color: isActive ? AppColors.success : AppColors.textHint,
|
color: isActive ? AppColors.success : AppColors.textHint,
|
||||||
|
|
|
||||||
|
|
@ -655,16 +655,21 @@ class GarageScreenState extends State<GarageScreen> {
|
||||||
child: ElevatedButton.icon(
|
child: ElevatedButton.icon(
|
||||||
onPressed: () => _editCar(car, context),
|
onPressed: () => _editCar(car, context),
|
||||||
icon: const Icon(Icons.edit, size: 18),
|
icon: const Icon(Icons.edit, size: 18),
|
||||||
label: const Text('Edit Details'),
|
label: const Text('Edit'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
],
|
||||||
Expanded(
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
child: OutlinedButton.icon(
|
child: OutlinedButton.icon(
|
||||||
onPressed: () => _deleteCar(car, context),
|
onPressed: () => _deleteCar(car, context),
|
||||||
icon: const Icon(Icons.delete_outline, color: AppColors.error),
|
icon: const Icon(Icons.delete_outline, color: AppColors.error),
|
||||||
label: const Text('Remove',
|
label: const Text(
|
||||||
style: TextStyle(color: AppColors.error)),
|
'Remove',
|
||||||
|
style: TextStyle(color: AppColors.error),
|
||||||
|
),
|
||||||
style: OutlinedButton.styleFrom(
|
style: OutlinedButton.styleFrom(
|
||||||
side: const BorderSide(color: AppColors.error),
|
side: const BorderSide(color: AppColors.error),
|
||||||
),
|
),
|
||||||
|
|
@ -672,8 +677,6 @@ class GarageScreenState extends State<GarageScreen> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@ class _HomeShellState extends State<HomeShell> {
|
||||||
int _currentIndex = 0;
|
int _currentIndex = 0;
|
||||||
final _collectionsKey = GlobalKey<CollectionsScreenState>();
|
final _collectionsKey = GlobalKey<CollectionsScreenState>();
|
||||||
final _scanKey = GlobalKey<ScanTabState>();
|
final _scanKey = GlobalKey<ScanTabState>();
|
||||||
final Map<int, DateTime> _lastRefreshed = {};
|
|
||||||
static const _refreshDebounce = Duration(seconds: 30);
|
|
||||||
|
|
||||||
late final List<Widget> _pages = <Widget>[
|
late final List<Widget> _pages = <Widget>[
|
||||||
CollectionsScreen(key: _collectionsKey),
|
CollectionsScreen(key: _collectionsKey),
|
||||||
|
|
@ -26,10 +24,7 @@ class _HomeShellState extends State<HomeShell> {
|
||||||
|
|
||||||
void _onTabSelected(int i) {
|
void _onTabSelected(int i) {
|
||||||
setState(() => _currentIndex = i);
|
setState(() => _currentIndex = i);
|
||||||
final now = DateTime.now();
|
|
||||||
final last = _lastRefreshed[i];
|
|
||||||
if (last != null && now.difference(last) < _refreshDebounce) return;
|
|
||||||
_lastRefreshed[i] = now;
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
_collectionsKey.currentState?.refresh();
|
_collectionsKey.currentState?.refresh();
|
||||||
} else if (i == 1) {
|
} else if (i == 1) {
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ class _LoginScreenState extends State<LoginScreen>
|
||||||
try {
|
try {
|
||||||
await supabase.auth.resetPasswordForEmail(
|
await supabase.auth.resetPasswordForEmail(
|
||||||
email,
|
email,
|
||||||
redirectTo: 'hwcollector://login',
|
redirectTo: 'hwcollector://login/recovery',
|
||||||
);
|
);
|
||||||
showGlobalSnackBar('Password reset email sent! Check your inbox.');
|
showGlobalSnackBar('Password reset email sent! Check your inbox.');
|
||||||
} on AuthException catch (e) {
|
} on AuthException catch (e) {
|
||||||
|
|
@ -134,12 +134,19 @@ class _LoginScreenState extends State<LoginScreen>
|
||||||
width: 2,
|
width: 2,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: const Icon(
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(14),
|
||||||
|
child: Image.asset(
|
||||||
|
'assets/img/icon_bg_removed.png',
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
errorBuilder: (context, error, stackTrace) => const Icon(
|
||||||
Icons.directions_car_filled,
|
Icons.directions_car_filled,
|
||||||
size: 44,
|
size: 44,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
const Text(
|
const Text(
|
||||||
'CAR64',
|
'CAR64',
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ class ScanTabState extends State<ScanTab> {
|
||||||
))
|
))
|
||||||
.toList(),
|
.toList(),
|
||||||
onChanged: (id) {
|
onChanged: (id) {
|
||||||
_setActiveCollection(id);
|
_setSelectedCollection(id);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -227,15 +227,12 @@ class ScanTabState extends State<ScanTab> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _setActiveCollection(String? id) async {
|
void _setSelectedCollection(String? id) {
|
||||||
if (id == null) return;
|
if (id == null) return;
|
||||||
final matching = _collections.where((c) => c.id == id);
|
final matching = _collections.where((c) => c.id == id);
|
||||||
if (matching.isEmpty) return;
|
if (matching.isEmpty) return;
|
||||||
|
|
||||||
setState(() => _selectedCollection = matching.first);
|
setState(() => _selectedCollection = matching.first);
|
||||||
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
await prefs.setString(_activeCollectionPrefKey, id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _openScanner() async {
|
Future<void> _openScanner() async {
|
||||||
|
|
@ -244,7 +241,7 @@ class ScanTabState extends State<ScanTab> {
|
||||||
builder: (_) => ScannerScreen(
|
builder: (_) => ScannerScreen(
|
||||||
collections: _collections,
|
collections: _collections,
|
||||||
activeCollectionId: _selectedCollection?.id,
|
activeCollectionId: _selectedCollection?.id,
|
||||||
onCollectionChanged: _setActiveCollection,
|
onCollectionChanged: _setSelectedCollection,
|
||||||
onDetected: (hwId) => _processHwId(hwId),
|
onDetected: (hwId) => _processHwId(hwId),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue