【问题标题】:passcode input hideen by keyboard被键盘隐藏的密码输入
【发布时间】:2021-05-17 10:48:12
【问题描述】:

我创建了六位密码字段组件,它在更大尺寸的模拟器中按预期工作,但是当我使用小尺寸模拟器检查时,密码输入被键盘隐藏。

child: TextField(
            enableInteractiveSelection: false,
            focusNode: focusNode,
            controller: widget.controller,
            keyboardType: TextInputType.number,
            inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly],
            style: const TextStyle(
              height: 0.1,
              color: Colors.transparent,
            ),
            decoration: const InputDecoration(
              focusedErrorBorder: transparentBorder,
              errorBorder: transparentBorder,
              disabledBorder: transparentBorder,
              enabledBorder: transparentBorder,
              focusedBorder: transparentBorder,
              helperStyle: TextStyle(
                color: Colors.transparent,
              ),
              fillColor: Colors.transparent,
              border: InputBorder.none,
            ),
            cursorColor: Colors.transparent,
            showCursor: false,
            maxLength: widget.maxLength,
            onChanged: _onTextChanged,
          ),

【问题讨论】:

  • 请同时发布截图。
  • 你能发布你的脚手架小部件吗?

标签: flutter dart flutter-textinputfield


【解决方案1】:

使用SingleChildScrollView 将整个列包裹在脚手架内,属性为reverse: true

像这样:

【讨论】:

    【解决方案2】:

    你能检查一下这个包吗:keyboard_visibility 您可以获得键盘的状态,并基于该隐藏/显示您的文本小部件。考虑以下代码:

    class _LoginPageState extends State<LoginPage> {
      bool _isKeyboardVisible = false;
      StreamSubscription _subscription;
    
      @override
      void initState() {
        super.initState();
    
        _subscription =
            KeyboardVisibilityController().onChange.listen((bool visible) {
          setState(() => _isKeyboardVisible = visible);
        });
      }
    
      @override
      void dispose() {
        _subscription.cancel();
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        return Column(
          children: [
            Visibility(
              visible: !_isKeyboardVisible,
              child: Text("Your header text"),
            ),
            Visibility(
              visible: !_isKeyboardVisible,
              child: Text("Your description text"),
            )
            TextField(
              ...
            ) // Your PIN widgets
          ]
        );
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-07-20
      • 1970-01-01
      • 2014-04-07
      • 2014-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-19
      相关资源
      最近更新 更多