As the title states, I have code I want to run at the beginning of my app loading and it's asynchronous and required for my HomeView, obviously I can't put it inside initState so where do I put it?
You put it inside a separate async function. And you call this function from the iniState method
oh
huh
that's confusing lol
If you don't want the page the load before then you can create a middle splash page
That's usually the way with stuff like this
lol
okay so
The following assertion was thrown building Builder:
_HomeViewState.initState() returned a Future.
State.initState() must be a void method without an `async` keyword.
Rather than awaiting on asynchronous work directly inside of initState, call a separate method to do this work without awaiting it.
Future<void> setupState() async {
model.User? account = await ref.read(authAPIProvider).currentUserAccount();
if (account != null) {
model.Document userDocument =
await ref.read(userAPIProvider).getUserData(account.$id);
UserModel userModel = UserModel.fromMap(userDocument.data);
needsLogin = userModel.sessionData.isNotEmpty;
print("needsLogin: $needsLogin");
if (!needsLogin) {
final userData =
await ref.read(dataAPIProvider).getUserData();
userData.fold(
(l) {
print("Error getting data: ${l.message}");
},
(r) {
setState(() {
userData = r;
});
},
);
}
}
}
@override
void initState() async {
super.initState();
await setupState();
}
this doesn't work and gives me an error
do I need to call a function normally and have that function call the async function?
InitState should remain sync
okay so I did
void doSetup() {
setupState();
}
@override
void initState() {
super.initState();
doSetup();
}
and that seems to work lmao
You just call the inner function. And you can use then if you need
Recommended threads
- Github Student org plan shows "Free Plan...
For few days, there is banner info appearing, says "Your Free plan includes up to 2 projects and limited resources" in github stundent org plan..?
- Migration Failed from 1.7.4 ā 1.8.1: "Co...
Hey everyone! š I'm trying to upgrade my self-hosted Appwrite from **1.7.4 to 1.8.1** and the migration is consistently failing **Environment:** - Current ve...
- Method EQUAL not wrking in REST API Quer...
Request: āØ``` postman request 'https://nyc.cloud.appwrite.io/v1/tablesdb/{databaseId}/tables/{tableId}/rows?queries[]={%22method%22%3A%22select%22%2C%22values%2...