当前位置: 首页 > 知识库问答 >
问题:

如何在从底部工作表弹出后更改文本字段文本值

贺季
2023-03-14

单击文本字段时,我的代码将显示底部的工作表小部件。底纸上有一些按钮,点击后会弹出底纸。但是,弹出后,它会获取值,但不会将文本字段文本更改为该值。

我的代码:

  Widget _additionInformation() {
    TextEditingController statusController = TextEditingController();
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 40),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          TextFormField(
            onTap: () {
              showModalBottomSheet(
                  context: context,
                  isScrollControlled: false,
                  isDismissible: false,
                  builder: (context) => BottomSheetSettingWidget(
                      ['None', 'Yes', 'No'])).then((value) {
                setState(() {
                  print(value);
                  statusController.text = value;
                });
              });
            },
            controller: statusController,
            decoration: InputDecoration(
              fillColor: Colors.white,
              filled: true,
              contentPadding: EdgeInsets.symmetric(vertical: 0, horizontal: 10),
              enabledBorder: OutlineInputBorder(
                  borderSide: BorderSide(color: Colors.grey[400])),
              border: OutlineInputBorder(
                  borderSide: BorderSide(color: Colors.grey[400])),
            ),
          ),
          
        ],
      ),
    );
  }

共有2个答案

宋景福
2023-03-14
showModalBottomSheet(
    context: context,
    builder: (context) {
      return StatefulBuilder(
          builder: (BuildContext context, StateSetter setState /*You can rename this!*/) {
        return Container(
          height: heightOfModalBottomSheet,
          child: RaisedButton(onPressed: () {
            setState(() {
              heightOfModalBottomSheet += 10;
            });
          }),
        );
      });
});
丁良骏
2023-03-14

上下文控制作为参数传递给您创建的_additionInformation`小部件,我在下面添加了一个演示代码:

Widget _additionInformation(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 40),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          TextFormField(
            onTap: () {
              showModalBottomSheet(
                  context: context,
                  isScrollControlled: false,
                  isDismissible: false,
                  builder: (context) => BottomSheetSettingWidget(
                      ['None', 'Yes', 'No'])).then((value) {
                  print(value);
                  statusController.text = value;
              });
            },
            controller: statusController,
            decoration: InputDecoration(
              fillColor: Colors.white,
              filled: true,
              contentPadding: EdgeInsets.symmetric(vertical: 0, horizontal: 10),
              enabledBorder: OutlineInputBorder(
                  borderSide: BorderSide(color: Colors.grey[400])),
              border: OutlineInputBorder(
                  borderSide: BorderSide(color: Colors.grey[400])),
            ),
          ),
          
        ],
      ),
    );
  }

完成后,在档案编辑页面中创建一个文本编辑控制器。比如TextEditingController statusController=TextEditingController()

瞧!!快乐编码:)

 类似资料:
  • 我在javaFX中有一个文本字段,在该字段中键入的任何内容都必须以蓝色显示,这可以通过css实现吗?如果是,那么如何?

  • 我正在尝试检查文本字段何时更改,也相当于用于text View-的函数,到目前为止我已经这样做了: 哪种方法有效,但是一旦按下文本字段,,我希望仅在实际键入文本时才启用它?

  • 我正在编写一个应用程序,它使用PDFbox库来填充PDF文件中的字段。 在其中一个字段中,我将文本设置为希伯来字母。 当我在Android设备上运行代码时,我会得到以下日志: 我试图在堆栈溢出中找到一些关于它的信息,但我找到的答案都与填充表单有关。它都与有关。 你能帮我解决这个错误并用PDFBox在表格中填写希伯来字母吗?

  • 我在中有一个,底线颜色不是我想要的,我不知道如何更改它。 这是我到目前为止所拥有的。 出于某种不起作用的奇怪原因,应该是它。

  • 我对这两个都不熟悉 在我所有的表单中,textField的下划线都显示为蓝色。我想把它换成其他颜色。我使用的代码就像。。。 无法理解如何实现这一点。 注意:我知道这里有一个类似的问题,在flifter中更改TextField的下划线。但是,在那里也没有完全解决。另外,还有一个链接看起来与我的类似,它在这里使用appcompat v7更改EditText底线颜色,但实际上是属于Android开发的,

  • 在我的Android项目中,我必须将TextChangedListener(TextWatcher)添加到编辑文本视图中。它有三个部分: < Li > < code > ontext changed() < Li > < code > beforeTextChanged() < Li > < code > afterTextChanged() 这三个有什么区别?我必须在键侦听器上实现一个表搜索,对