【发布时间】:2026-02-08 18:35:01
【问题描述】:
。您好,我希望我的程序将我的列表保存在本地,这样当应用程序启动时,列表就会加载,并且每个新条目都会保存列表。(删除/删除功能应该将列表保存到)。我在 Internet 上搜索,但没有人以我想要的方式显示它。我希望有人可以帮助我。
编辑:我也想知道如何保存布尔值
这里是列表,下面是按钮,用于将文本字段中的输入添加到列表中
class TimescheduleData {
static List<String> time = [];
static List<String> who = [];
static List<String> when = [];
static List<String> where = [];
} ```
TextButton(
child: Icon(
Icons.check_circle_outline_rounded,
color: Colors.green,
size: 120,
),
TimescheduleData.time.add(myControllertime.text);
TimescheduleData.who.add(myControllerwho.text);
TimescheduleData.when.add(myControllerwhen.text);
TimescheduleData.where.add(myControllerwhere.text);
myControllertime.clear();
myControllerwho.clear();
myControllerwhen.clear();
myControllerwhere.clear();
Navigator.push(
context, MaterialPageRoute(builder: (context) => App()));
})
void deleteDate(int Index) {
setState(() {
TimescheduleData.time.removeAt(Index);
TimescheduleData.when.removeAt(Index);
TimescheduleData.where.removeAt(Index);
TimescheduleData.who.removeAt(Index);
});
}
GestureDetector(
onDoubleTap: () => deleteDate(Index),
【问题讨论】:
-
您可以在这本食谱flutter.dev/docs/cookbook/persistence/sqlite 中找到所需的一切,您需要使用所有这些字段定义自己的模型,而不是 Dog 对象。这样您就必须维护单个列表而不是 4 个字符串。在这里的答案中也提到过:*.com/a/66582978/7910735