Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ignore_for_file: public_member_api_docs, sort_constructors_first
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter_hooks/flutter_hooks.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:flutter_svg/svg.dart';
- import 'package:focus_detector/focus_detector.dart';
- import 'package:get/get_utils/src/extensions/context_extensions.dart';
- import '../../../config/theme/theme.dart';
- class ScanScannerBarcodeView extends HookWidget {
- const ScanScannerBarcodeView({
- Key? key,
- this.descText = '',
- required this.doOnBarcodeScanned,
- }) : super(key: key);
- final String? descText;
- final Function(String barcodeFound) doOnBarcodeScanned;
- @override
- Widget build(BuildContext context) {
- final scannedBarcode = useState('');
- final focusNode = useFocusNode();
- useEffect(() {
- focusNode.requestFocus();
- return null;
- }, []);
- void handleKeyEvent(KeyEvent event) {
- if (event is KeyDownEvent) {
- if (event.logicalKey == LogicalKeyboardKey.enter) {
- // Barcode input is complete
- if (scannedBarcode.value.isNotEmpty) {
- doOnBarcodeScanned(scannedBarcode.value);
- scannedBarcode.value = '';
- }
- } else {
- // Build the barcode string
- scannedBarcode.value += event.character ?? '';
- }
- }
- }
- return FocusDetector(
- onVisibilityGained: () {
- focusNode.requestFocus();
- },
- child: KeyboardListener(
- focusNode: focusNode,
- onKeyEvent: handleKeyEvent,
- child: Container(
- color: AccurateColor.grayBlue,
- height: 1.sh,
- width: 1.sw,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- SvgPicture.asset(
- 'assets/svg/scan/ic_scan_scanner_big.svg',
- ),
- Text(
- descText!,
- style: context.textTheme.bodyLarge!.copyWith(
- color: AccurateColor.grayA2,
- ),
- ),
- ],
- ),
- ),
- ),
- );
- /* return BarcodeKeyboardListener(
- bufferDuration: const Duration(milliseconds: 200),
- onBarcodeScanned: doOnBarcodeScanned,
- child: Container(
- color: AccurateColor.grayBlue,
- height: 1.sh,
- width: 1.sw,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- SvgPicture.asset(
- 'assets/svg/scan/ic_scan_scanner_big.svg',
- ),
- Text(
- descText!,
- style: context.textTheme.bodyLarge!.copyWith(
- color: AccurateColor.grayA2,
- ),
- ),
- ],
- ),
- ),
- );*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement