列表中的数据在应用重启时会消失吗?

问题描述 投票:0回答:2

这里是代码这是列表

List<String> favourites = [];

这是将项目添加到列表的代码

Padding(
 padding: const EdgeInsets.all(15.0),
 child: Container(
 color: Colors.black87,
  height: 400.0,
                  width: 100.0,
                  child: ListView.builder(
                      itemCount: favourites.length,
                      itemBuilder: (context, index) {
                        return Card(
                          color: Colors.black87,
                          child: Center(
                            child: Text(
                              favourites[index],
                              style: TextStyle(
                                  color: Colors.white, fontSize: 22.0),
                            ),
                          ),
                        );
                      }),
                ),
              ),

所以当我重新启动应用程序时,列表的先前内容消​​失了,所以请告诉我如何将保存的项目永久保存在列表中。

flutter flutter-layout
2个回答
0
投票

我给你一个非常基本的想法,怎么做


0
投票

您需要将列表保存在SharedPreferences中。我建议您使用在这里可以找到的shared_preferences插件:https://pub.dev/packages/shared_preferences

© www.soinside.com 2019 - 2024. All rights reserved.