32 lines
899 B
Dart
32 lines
899 B
Dart
import 'package:flutter/material.dart';
|
|
import 'package:mobile_scanner/mobile_scanner.dart';
|
|
|
|
class BarcodeScannerScreen extends StatefulWidget {
|
|
const BarcodeScannerScreen({super.key});
|
|
|
|
@override
|
|
State<BarcodeScannerScreen> createState() => _BarcodeScannerScreenState();
|
|
}
|
|
|
|
class _BarcodeScannerScreenState extends State<BarcodeScannerScreen> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text("バーコードスキャン"),
|
|
backgroundColor: Colors.black,
|
|
),
|
|
body: MobileScanner(
|
|
onDetect: (capture) {
|
|
final List<Barcode> barcodes = capture.barcodes;
|
|
if (barcodes.isNotEmpty) {
|
|
final String? code = barcodes.first.rawValue;
|
|
if (code != null) {
|
|
Navigator.pop(context, code);
|
|
}
|
|
}
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|