这里是代码这是列表
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),
),
),
);
}),
),
),
所以当我重新启动应用程序时,列表的先前内容消失了,所以请告诉我如何将保存的项目永久保存在列表中。
我给你一个非常基本的想法,怎么做
您需要将列表保存在SharedPreferences中。我建议您使用在这里可以找到的shared_preferences插件:https://pub.dev/packages/shared_preferences。