Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 颤振自定义键盘(假软键盘)_Android_Ios_Keyboard_Dart_Flutter - Fatal编程技术网

Android 颤振自定义键盘(假软键盘)

Android 颤振自定义键盘(假软键盘),android,ios,keyboard,dart,flutter,Android,Ios,Keyboard,Dart,Flutter,我正在开发一个金融应用程序,我想要一个自定义的文本输入字段和键盘,用于内置计算器的货币输入 我尝试过使用底部表单,包括持久性和模态。模态行为是理想的,但它总是显示出障碍。持久性是我现在拥有的,使用焦点节点来显示和隐藏它,但它会抛出奇怪的错误: I/flutter (30319): The following NoSuchMethodError was thrown while dispatching notifications for FocusNode: I/flutter (30319):

我正在开发一个金融应用程序,我想要一个自定义的文本输入字段和键盘,用于内置计算器的货币输入

我尝试过使用底部表单,包括持久性和模态。模态行为是理想的,但它总是显示出障碍。持久性是我现在拥有的,使用焦点节点来显示和隐藏它,但它会抛出奇怪的错误:

I/flutter (30319): The following NoSuchMethodError was thrown while dispatching notifications for FocusNode:
I/flutter (30319): The method 'removeLocalHistoryEntry' was called on null.
I/flutter (30319): Receiver: null
I/flutter (30319): Tried calling: removeLocalHistoryEntry(Instance of 'LocalHistoryEntry')
I/flutter (30319):
I/flutter (30319): When the exception was thrown, this was the stack:
I/flutter (30319): #0      Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:46:5)
I/flutter (30319): #1      LocalHistoryEntry.remove (package:flutter/src/widgets/routes.dart:296:12)
I/flutter (30319): #2      _NumpadFieldState.initState.<anonymous closure> (file:///D:/code/financepie/lib/widgets/numpad/numpadfield.dart:30:32)
...
I/flatter(30319):为FocusNode发送通知时引发以下NoSuchMethodError:
I/flatter(30319):对null调用了方法“removeLocalHistoryEntry”。
I/颤振(30319):接收器:空
I/flatter(30319):尝试调用:removeLocalHistoryEntry(LocalHistoryEntry的实例)
I/颤振(30319):
I/flatter(30319):当抛出异常时,这是堆栈:
I/flatter(30319):#0 Object.noSuchMethod(dart:core/runtime/libobject_patch.dart:46:5)
I/flatter(30319):#1 LocalHistoryEntry.remove(包:flatter/src/widgets/routes.dart:296:12)
I/颤振(30319):#2 _NumpadFieldState.initState。(file:///D:/code/financepie/lib/widgets/numpad/numpadfield.dart:30:32)
...
在任何情况下,底层工作表行为(向下拖动)都不是复制android/ios软键盘的理想方式。有更好的解决办法吗?当前代码如下:

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

class NumpadField extends StatefulWidget {

  @override
  _NumpadFieldState createState() {
    return new _NumpadFieldState();
  }
}

class _NumpadFieldState extends State<NumpadField> {
  ValueNotifier<List<String>> state;
  FocusNode focusNode;
  PersistentBottomSheetController bottomSheetController;

  @override initState() {
    super.initState();
    state = ValueNotifier<List<String>>([]);
    state.addListener(() => setState((){}));
    focusNode = FocusNode();
    focusNode.addListener(() {
      print(focusNode);
      if (focusNode.hasFocus) {
        bottomSheetController = showBottomSheet(
          context: context,
          builder: (context) => Numpad(state: state),
        );
      } else {
        bottomSheetController?.close(); ///this line causing the error
      }
    }); 
  }
  @override dispose() {
    state.dispose();
    focusNode.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        FocusScope.of(context).requestFocus(focusNode);
      },
      child: Container(
        child: Text(state.value.fold<String>("", (str, e) => "$str $e")),
        constraints: BoxConstraints.expand(height: 24.0),
        decoration: BoxDecoration(
          border: BorderDirectional(bottom: BorderSide())
        ),
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
输入“numpad.dart”;
类NumpadField扩展StatefulWidget{
@凌驾
_NumpadFieldState createState(){
返回新的_NumpadFieldState();
}
}
类_NumpadFieldState扩展状态{
估价师状态;
焦点节点;
PersistentBottomSheetController bottomSheetController;
@重写initState(){
super.initState();
状态=ValueNotifier([]);
state.addListener(()=>setState((){}));
focusNode=focusNode();
focusNode.addListener(){
打印(焦点节点);
if(focusNode.hasFocus){
bottomSheetController=showBottomSheet(
上下文:上下文,
生成器:(上下文)=>Numpad(state:state),
);
}否则{
bottomSheetController?.close();///导致错误的此行
}
}); 
}
@重写dispose(){
state.dispose();
focusNode.dispose();
super.dispose();
}
@凌驾
小部件构建(构建上下文){
返回手势检测器(
onTap:(){
FocusScope.of(context).requestFocus(focusNode);
},
子:容器(
子:文本(state.value.fold(“,(str,e)=>“$str$e”),
约束:BoxConstraints.expand(高度:24.0),
装饰:盒子装饰(
边框:BorderDirective(底部:BorderSide())
),
),
);
}
}

我认为您不应该使用底页。你可以将它集成到你的布局中,也可以使用它(我链接的只是你的一个起点)。@creativecreatormormaybeno我认为你是对的。一个想法-我可以使用ModalRoute吗?键盘打开时,文本字段是否会在“后台”路径中更新?我已尝试运行,但系统在导入“numpad.dart”时检测到错误。你能提供更多关于这个特殊导入的上下文吗?它是你创建的插件还是单独的类?它是键盘实现。然而,最后我用了一个覆盖或类似的东西,恐怕我现在记不起来了