使用现有答案作为提示文本

发布于 2025-01-11 11:00:53 字数 450 浏览 3 评论 0原文

我正在尝试显示存储在列表 List中的现有答案data = []; 作为提示文本(如果可用)。目前我正在使用这个代码https://pastecode.io/s/bj9jkx06

错误是,如果我回答第二个问题,提示文本将显示在第一个文本字段中。

输入图片此处描述

i'm trying to display the existing answers that are stored in the list List<Data> data = []; as a hint text if they're available. currently i'm using this code: https://pastecode.io/s/bj9jkx06

the error is that if i answer the question number two, the hint text will show in the textfield number one.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

非要怀念 2025-01-18 11:00:53

我认为数据对象不是必需的。
我会简单地使用另一个映射关键就是问题,就像你其他人的地图一样。

Map<String, String> data = {}

这需要对 read 方法内的数据加载进行如下更改:

raw.forEach((key, value) {
   data[key] = value;
});

现在您的数据已加载,您可以使用问题作为键以这种方式检索问题的提示:

String hint = data[question] != null? data[question] : 'write something';

如果数据不包含与以下内容相关的记录一个具体的问题,它会返回“写一些东西”字符串

I think the Data object is not required.
I would simply use another map<String, String> where the key is the question, exactly as your others maps.

Map<String, String> data = {}

This requires the data loading inside the read method to be changed as follows:

raw.forEach((key, value) {
   data[key] = value;
});

Now that your data are loaded, you can retrive the hint for the question in this way, using the question as the key:

String hint = data[question] != null? data[question] : 'write something';

If data doesn't contains record related to a specific question, it will return 'write something' string

屌丝范 2025-01-18 11:00:53

尝试在hintText的InputDecoration属性上提供TextField,它需要一个像这样的字符串

hintText: "Hint Text"

Try to give the TextField on the InputDecoration property of hintText it takes a string like

hintText: "Hint Text"
灯角 2025-01-18 11:00:53

只是提醒您,索引从 0 开始。所以你落后了一个textfield

just to remind you, index starts with 0. So you are getting one textfield behind.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文