2023-09-30 21:22:12 -04:00
|
|
|
import 'package:flutter/foundation.dart';
|
2023-09-28 10:06:22 -04:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:mobile_scanner/mobile_scanner.dart';
|
|
|
|
|
|
|
|
class ScannerErrorWidget extends StatelessWidget {
|
2023-09-29 22:45:50 -04:00
|
|
|
const ScannerErrorWidget({required this.error, super.key});
|
2023-09-28 10:06:22 -04:00
|
|
|
|
|
|
|
final MobileScannerException error;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
String errorMessage;
|
|
|
|
|
|
|
|
switch (error.errorCode) {
|
|
|
|
case MobileScannerErrorCode.controllerUninitialized:
|
|
|
|
errorMessage = 'Controller not ready.';
|
|
|
|
break;
|
|
|
|
case MobileScannerErrorCode.permissionDenied:
|
|
|
|
errorMessage = 'Permission denied';
|
|
|
|
break;
|
|
|
|
case MobileScannerErrorCode.unsupported:
|
|
|
|
errorMessage = 'Scanning is unsupported on this device';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errorMessage = 'Generic Error';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ColoredBox(
|
|
|
|
color: Colors.black,
|
|
|
|
child: Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.only(bottom: 16),
|
|
|
|
child: Icon(Icons.error, color: Colors.white),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
errorMessage,
|
|
|
|
style: const TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
error.errorDetails?.message ?? '',
|
|
|
|
style: const TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2023-09-30 21:22:12 -04:00
|
|
|
|
2023-09-29 22:45:50 -04:00
|
|
|
@override
|
|
|
|
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
|
|
|
super.debugFillProperties(properties);
|
|
|
|
properties.add(DiagnosticsProperty<MobileScannerException>('error', error));
|
|
|
|
}
|
2023-09-28 10:06:22 -04:00
|
|
|
}
|