我想添加一个带有 flutter 的页面收藏夹按钮,即使在本地上下文中也能保存
I want to add a page favorites button with flutter that is saved even in local context
我正在制作一个学习应用程序。但在这里,我想在数百个问题中只收藏我想要的问题,以便下次在问题选择页面上显示标记。
问题是这是否只能在没有 firebase 或任何其他数据库的情况下在 flutter 中实现。
是否可以在本地实现?
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
title: Text('1-1',
style: TextStyle(
color: Colors.blueAccent,
fontSize: 20,
fontWeight: FontWeight.bold,
),),
centerTitle: true,
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
color: Colors.black,
iconSize: 25,
icon: Icon(Icons.arrow_back),
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.bookmark_outline),
iconSize: 25,
color: Colors.black,
onPressed: () {
//here
}
),
],
),
是的,在 Flutter 应用程序中,您可以选择将数据永久存储在本地存储中。例如,您可以使用以下选项之一:
- 共享首选项
将此包添加到您的
pubspec.yaml
文件:
dependencies:
shared_preferences: ^2.0.8
和 运行 flutter pub get
。现在,您可以基于此 example.
使用它
- SQLite
将此包添加到您的
pubspec.yaml
文件:
dependencies:
sqflite: ^2.0.0+4
和 运行 flutter pub get
。现在,您可以基于此 example.
使用它
注意:通常情况下,使用共享偏好存储少量数据和基于数据库table的大数据更好。就个人而言,我更喜欢您的应用程序的共享首选项。
我正在制作一个学习应用程序。但在这里,我想在数百个问题中只收藏我想要的问题,以便下次在问题选择页面上显示标记。
问题是这是否只能在没有 firebase 或任何其他数据库的情况下在 flutter 中实现。
是否可以在本地实现?
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
title: Text('1-1',
style: TextStyle(
color: Colors.blueAccent,
fontSize: 20,
fontWeight: FontWeight.bold,
),),
centerTitle: true,
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
color: Colors.black,
iconSize: 25,
icon: Icon(Icons.arrow_back),
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.bookmark_outline),
iconSize: 25,
color: Colors.black,
onPressed: () {
//here
}
),
],
),
是的,在 Flutter 应用程序中,您可以选择将数据永久存储在本地存储中。例如,您可以使用以下选项之一:
- 共享首选项
将此包添加到您的
pubspec.yaml
文件:
dependencies:
shared_preferences: ^2.0.8
和 运行 flutter pub get
。现在,您可以基于此 example.
- SQLite
将此包添加到您的
pubspec.yaml
文件:
dependencies:
sqflite: ^2.0.0+4
和 运行 flutter pub get
。现在,您可以基于此 example.
注意:通常情况下,使用共享偏好存储少量数据和基于数据库table的大数据更好。就个人而言,我更喜欢您的应用程序的共享首选项。