Flutter:本地保存列表 [英] Flutter: Save Lists local

查看:57
本文介绍了Flutter:本地保存列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.您好,我希望我的程序将列表保存在本地,以使应用程序启动时就加载列表,并在保存每个新条目时保存列表.(删除/删除功能应将列表保存到).我在互联网上搜索,但没有人显示出我想要的样子.我希望有人能帮助我.

. Hello, I want that my program save my lists locally, that when ever the App gets startet the list gets load and with every new entry the list gets saved .(Delete/Remove Funktion should save the list to). I search on the Internet but no one show it excatly how I want. I hope someone can help me.

我也想知道如何保存布尔值

I also would like to know how to save a bool

在列表中,在该按钮下将来自文本字段的输入添加到列表中

Here the List and under that the Button to add Input from a Textfield to the list

 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),

推荐答案

要在本地保存列表或任何内容,您需要某种方式来保留数据.有多种选择.取决于您是需要重型关系模型还是仅需要存储一些数据.

In order to save lists or anything locally you need some way to persist data. There are multiple options out there. Depends if you need heavy relational models or just some data to store.

我以前使用过Hive,这是一个很好的数据库(基于键,基于值).但是您还具有SQL选项和shared_preferences,它们也是基于键值的,但比配置单元更简单.

I've used Hive before and it's a great databse (key, value based). But you also have SQL options and shared_preferences that is also key value based but simpler than hive.

这是codemagic撰写的精彩文章,解释了这些选项

Here is a great article by codemagic that explains the options

https://blog.codemagic.io/为您的Flutter应用程序选择正确的数据库

这篇关于Flutter:本地保存列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆