在页面加载之前,我该怎么做才能在flutter中悬挂一些数据
我正在写一个Simeple Todo List应用程序,该应用程序存储在sqlite中 SQFlite: ^2.0.0+3
立即。我想在加载“颤音”页面之前加载sqlite todo数据,这是我的初始代码在扑朔迷离中看起来像:
class _HomePageState extends State<HomePage> {
GlobalKey _inputViewKey = GlobalKey();
List<Todo> _todos = [];
@override
void initState() {
var _db = DBProvider.db;
_todos = await _db.getAllTodo();
super.initState();
}
}
这是从数据库加载数据的功能:
Future<List<Todo>> getAllTodo() async {
final db = await database;
var result = await db.query('Todo');
return result.map((it) => Todo.fromJson(it)).toList();
}
iDE告诉我应该在初始函数中添加异步。当我添加异步函数时,初始函数无法正常工作。我该怎么做才能使它起作用?如何在首页之前初始化异步数据?
I am writing a simeple todo list app, the todo item stored in sqlitesqflite: ^2.0.0+3
right now. I want to load the sqlite todo data before loading the flutter page, this is my initial code looks like in flutter:
class _HomePageState extends State<HomePage> {
GlobalKey _inputViewKey = GlobalKey();
List<Todo> _todos = [];
@override
void initState() {
var _db = DBProvider.db;
_todos = await _db.getAllTodo();
super.initState();
}
}
and this is the function to load data from database:
Future<List<Todo>> getAllTodo() async {
final db = await database;
var result = await db.query('Todo');
return result.map((it) => Todo.fromJson(it)).toList();
}
the IDE told that I should add async in the initial function. When I add the async function, the initial function could not work. What should I do to make it work? how to initial the async data before the HomePage?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能在无数上标记异步。您可以尝试
并在方法中
You cant mark async on inistate. You can try this
And in the method