Navaron Bracke

add mobile scanner error widget to example

  1 +import 'package:flutter/material.dart';
  2 +import 'package:mobile_scanner/mobile_scanner.dart';
  3 +
  4 +class ScannerErrorWidget extends StatelessWidget {
  5 + const ScannerErrorWidget({Key? key, required this.error}) : super(key: key);
  6 +
  7 + final MobileScannerException error;
  8 +
  9 + @override
  10 + Widget build(BuildContext context) {
  11 + String errorMessage;
  12 +
  13 + switch (error.errorCode) {
  14 + case MobileScannerErrorCode.controllerUninitialized:
  15 + errorMessage = 'Controller not ready.';
  16 + break;
  17 + case MobileScannerErrorCode.permissionDenied:
  18 + errorMessage = 'Permission denied';
  19 + break;
  20 + default:
  21 + errorMessage = 'Generic Error';
  22 + break;
  23 + }
  24 +
  25 + return ColoredBox(
  26 + color: Colors.black,
  27 + child: Center(
  28 + child: Column(
  29 + mainAxisSize: MainAxisSize.min,
  30 + children: [
  31 + const Padding(
  32 + padding: EdgeInsets.only(bottom: 16),
  33 + child: Icon(Icons.error, color: Colors.white),
  34 + ),
  35 + Text(
  36 + errorMessage,
  37 + style: const TextStyle(color: Colors.white),
  38 + ),
  39 + ],
  40 + ),
  41 + ),
  42 + );
  43 + }
  44 +}