将本地数据保存在扑朔迷离上的列表中
我有一个播放声音的应用程序。有声音列表,我将其显示到listView。因此,用户可以单击listTile并播放声音。我添加了一个“最喜欢的”部分。而且效果很好。但是,当用户关闭应用程序时,它会消失。我试图使用共享prefence,但我无法做到这一点。因为我需要保存整个列表,所以我不知道如何保存。
当我关闭应用程序时,我所有的“最喜欢”列表都消失了。
我将只分享所有代码以更好地理解:
这是图片解释:
I have an app that plays a sound. There is a list of sounds and I show that to an listview. So user can click a listtile and plays a sound. And I added a "Favourite" section. And it works fine. But when user closes the app it goes away. I tried to use SharedPrefences but I couldnt manage to do it. Because I need to save the whole list and I dont know how.
When I close the app, all my 'favourite' list goes away.
I will just share all the codes for better understanding:
Here is the explaining with the pictures:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于保存歌曲的列表是可以从共享prefences中使用setStringList()方法的字符串列表。当您要保存列表时,请使用:
然后,当应用程序启动时,您可以使用以下方式加载歌曲:
然后您可以使用for-loop来获取已保存的索引,尽管我建议您仅尝试使用一个仅使用一个列表保存的歌曲。
Since the list of saved songs is a list of Strings you can use setStringList() method from SharedPrefences. When you want to save the list, use:
Then when the application starts you load the songs by using:
Then you can use a for-loop to also get the saved indexes, although I would recommend you to try only using one list of the saved songs.
您可以使用
sharon_preferences
https://pub.dev/packages/ppackages/ppackages/ppackages/shared_preferences 如果您不介意使用FutureBuilder列出保存的列表。//保存声音
读取
您可以在应用程序中使用未来的构建器窗口小部件在listView中填充声音,我建议将ListTile窗口小部件用作返回小部件
或者
您可以使用
get_storage
不需要以后的构建器小部件的库保存
https://pub.dev/packages/packages/get_storage/exame/example/example
you can either use
shared_preferences
https://pub.dev/packages/shared_preferences if you don't mind using FutureBuilder to list saved list.//saving sound
Reading
you can use Future Builder widget in your app to populate sounds in a Listview, i recommend using ListTile widget as a return widget
Or
you can use
get_storage
library which doesn't require Future builder widgethttps://pub.dev/packages/get_storage/example
Saving list
Reading list
您可以使用SQFlite软件包在本地存储列表项目。这是包裹:
https://pub.dev/packages/packages/sqflite
You can use the SQFlite package to store your List items locally. Here is the package:
https://pub.dev/packages/sqflite