【问题标题】:Convert text widget to text field widget on particular text click在特定文本单击时将文本小部件转换为文本字段小部件
【发布时间】:2021-04-29 10:34:33
【问题描述】:

如果用户点击特定文本,它应该被转换为文本字段,我需要从用户那里获取输入值,到目前为止,我已经使用 split 将字符串添加到列表中,并使用 listview 显示列表项。

我有两个疑问。 1.如何在特定文本点击时将文本转换为文本字段。 2.如果我在listview中重新运行文本字段它需要全宽,我不能通过给定宽度将文本字段包装在容器内,因为文本宽度可能会根据API响应而改变

任何建议都将不胜感激。

this is what i need to achieve

  String demoString = 'You might want to try eating more healthy food.';

  new Row(children: <Widget>[
              Expanded(
                  child: SizedBox(
                      height: 150.0,
                      child: ListView(
                        padding: EdgeInsets.all(20),
                        scrollDirection: Axis.horizontal,
                        children: demoString
                            .split(' ')
                            .map((String text) => Padding(
                                padding: const EdgeInsets.all(18.0),
                                child: Text(text)))
                            .toList(),
                      )))
            ])

【问题讨论】:

    标签: flutter dart text textfield


    【解决方案1】:

    为了能够点击并获得一个文本字段,您应该创建一个小部件(例如),它将检测他是否收到点击(gestureDetector / inkWell ...),然后将一个小部件更改为另一个。

    例如,MySwapWidget 将包含这个想法:

    MySwapWidget(
      selected: (default value, could be useful, false by default) true / false,
      childIfSelected: TextField(),
      childIfNotSelected: Text(),
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-11
      • 1970-01-01
      • 2020-06-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多