MobileScannerErrorCode enum

This enum defines the different error codes for the mobile scanner.

Inheritance
Available extensions

Values

controllerAlreadyInitialized → const MobileScannerErrorCode

The controller was already started.

The controller should be stopped using MobileScannerController.stop, before restarting it.

controllerDisposed → const MobileScannerErrorCode

The controller was used after being disposed.

controllerUninitialized → const MobileScannerErrorCode

The controller was used while it was not yet initialized using MobileScannerController.start.

genericError → const MobileScannerErrorCode

A generic error occurred.

This error code is used for all errors that do not have a specific error code.

permissionDenied → const MobileScannerErrorCode

The permission to use the camera was denied.

unsupported → const MobileScannerErrorCode

Scanning is unsupported on the current device.

controllerInitializing → const MobileScannerErrorCode

The controller is currently initializing.

This error occurs when MobileScannerController.start is called while a previous initialization is still in progress.

To avoid this error:

controllerNotAttached → const MobileScannerErrorCode

The controller is not attached to any widget.

This error occurs when MobileScannerController.start is called but there is no active MobileScanner widget for the MobileScannerController in the widget tree.

To avoid this error, ensure that a MobileScanner widget is attached to the widget tree when MobileScannerController.start is called.

BAD:

class ScannerExample extends StatefulWidget {
  const ScannerExample({super.key});

  @override
  State<ScannerExample> createState() => _ScannerExampleState();
}

class _ScannerExampleState extends State<ScannerExample> {
  final MobileScannerController controller = MobileScannerController();

  bool _showScanner = false;

  @override
  void initState() {
    super.initState();
    // The MobileScanner is only in the widget tree after the button is pressed.
    controller.start();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        ElevatedButton(
          onPressed: () {
            setState(() {
              _showScanner = true;
            });
          },
          child: const Text('Button'),
        ),
        if (_showScanner)
          Expanded(child: MobileScanner(controller: controller)),
      ],
    );
  }
}

GOOD:

class ScannerExample extends StatefulWidget {
  const ScannerExample({super.key});

  @override
  State<ScannerExample> createState() => _ScannerExampleState();
}

class _ScannerExampleState extends State<ScannerExample> {
  final MobileScannerController controller = MobileScannerController();

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        ElevatedButton(
          // The MobileScanner is already in the widget tree.
          onPressed: controller.start,
          child: const Text('Button'),
        ),
        Expanded(child: MobileScanner(controller: controller)),
      ],
    );
  }
}

GOOD:

class ScannerExample extends StatefulWidget {
  const ScannerExample({super.key});

  @override
  State<ScannerExample> createState() => _ScannerExampleState();
}

class _ScannerExampleState extends State<ScannerExample> {
  final MobileScannerController controller = MobileScannerController();

  bool _showScanner = false;

  void start() {
    if (_showScanner) return;

    setState(() {
      _showScanner = true;
    });

    // The MobileScanner will be in the widget tree in the next frame.
    controller.start();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        ElevatedButton(onPressed: start, child: const Text('Button')),
        if (_showScanner)
          Expanded(child: MobileScanner(controller: controller)),
      ],
    );
  }
}

Properties

hashCode int
The hash code for this object.
no setterinherited
index int
A numeric identifier for the enumerated value.
no setterinherited
message String
Returns a human-readable error message for the given MobileScannerErrorCode.
no setter
name String

Available on Enum, provided by the EnumName extension

The name of the enum value.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

values → const List<MobileScannerErrorCode>
A constant List of the values in this enum, in order of their declaration.