1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Flutter SliverGrid population with API fetch

Discussão em 'Mobile' iniciado por Stack, Setembro 28, 2024 às 12:43.

  1. Stack

    Stack Membro Participativo

    is there any working example of a SliverGrid populated with a fetch? All examples I found are with static/typed content.

    What I want is to fill the SliverGrid with dynamic content pulled from API.

    EDIT

    This is the current structure I have, the SliverToBoxAdapter populates with a listView that scrolls horizontal, and below is the SliverGrid that I copied from and example an generate an infinite scroll with two columns.

    I tried to add another SliverToBoxAdapter with a ListView vertical, but then the scroll stop working and need a height to be defined.

    I want to know If I can populate SliverGrid in a same way than ListView and how to do that since I can't find any example.

    I don't want to look lazy, but I'm new in Flutter and dont know how to accomplish this.

    return Scaffold(
    body: CustomScrollView(
    slivers: [
    SliverAppBar(
    //SOME OPTIONS AND VALUES HERE
    ),
    SliverToBoxAdapter(
    // this is populated with a fetch
    //child: NiceWidgetHere(),
    ),
    SliverGrid(
    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
    crossAxisCount: 2,
    childAspectRatio: 1.5,
    ),
    delegate: SliverChildBuilderDelegate(
    // Don't know what to do here
    //(context, index) => AnotherNiceWidgetHere(),
    ),
    )
    ],
    )
    );


    In the image below you can see the layout I have. Both horizontal ListView and vertical GridView needs to fetch the content from json API, the fetch is not issue, since is already working in the horizontal ListView.

    [​IMG]

    Continue reading...

Compartilhe esta Página