在Android条形码扫描仪上闪烁隐藏onscreenkeyboard

时间:2018-06-09 10:30:43

标签: android keyboard hide flutter external

我开发了一个Flutter应用程序,通过一个类似普通键盘的extrernal蓝牙扫描仪获取数字。

如果我点击TextInputField,弹出本机安卓键盘输入文字,这很好,但我需要压制键盘,因为我要扫描条形码,我需要全屏查看我扫描的条形码。

@Barcodes:这些只是12位数的长号。

到目前为止, AXP

1 个答案:

答案 0 :(得分:0)

//我创建了这个解决方案,它适用于 iOS 和 Android。

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class QRCodeScreen extends StatefulWidget {
  QRCodeScreen({Key key}) : super(key: key);

  @override
  _QRCodeScreenState createState() => _QRCodeScreenState();
}

class _QRCodeScreenState extends State<QRCodeScreen> {
  FocusNode node = NoKeyboardEditableTextFocusNode();
  TextEditingController scanController = TextEditingController();

  @override
  void initState() { 
    node.requestFocus();
    Future.delayed(
      const Duration(milliseconds: 300),
      () {
          SystemChannels.textInput.invokeMethod('TextInput.invisible');
      }
    );
    super.initState();
    
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Container(
         child: IgnorePointer(
           child: Padding(
             padding: const EdgeInsets.all(5.0),
             child: Column(
               children: [
                 TextField(
                   controller: scanController,
                   focusNode: node,
                   autofocus: true,
                   decoration: InputDecoration(hintText: "WAITING FOR QR CODE..."),
                   ),
  SizedBox(height:50),
               ],
             ),
               
           ),
         ),
      ),
    );
  }
  @override
  void dispose() {
    node.dispose();
    super.dispose();
  }
}


class NoKeyboardEditableTextFocusNode extends FocusNode {
  @override
  bool consumeKeyboardToken() {
    return false;
  }
}