Skip to content

Boot and Loading #117

Answered by agordn52
andim27 asked this question in General
Discussion options

You must be logged in to vote

Hi @andim27,

You need to ensure that any async tasks use await in the boot method.

@override
boot() async {
    await loadItems();
}

Future loadItems() async {
    await sleep(2); // fetch your data here
}

Or you can use the view method which would look like this.

class _TestPageState extends NyState<TestPage> {
  
  @override
  boot() async {
    await loadItems();
  }
  
  Future loadItems() async {
    await sleep(2);
  }

  @override
  Widget loading(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SizedBox(
          width: 80,
          height: 80,
          child: CircularProgressIndicator(),
        ),
      ),
    );
  }

  @override
  Widget view(B…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by andim27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants