Flutter SliverchildBuilderDelegate not showing anything

Viewed 239

Since my code is quite long, I'll just mostly show the overall structure and where the problem occurs.

If you need to see the full code, feel free to go here https://github1s.com/davidp918/KZStats/blob/main/lib/pages/homepage.dart

return MaterialApp(
      home: Scaffold(
        body: BlocConsumer<ModeCubit, ModeState>(
            listener: ...,
            builder: (context, state) {
              return FutureBuilder(
                  future: ..., // an HTTP request
                  builder: (
                    BuildContext context,
                    AsyncSnapshot snapshot,
                  ) =>
                      body(context, snapshot));
            }),
      ),
    );

And the body is down here

Widget body(
  BuildContext context,
  AsyncSnapshot snapshot,
) {
  return Padding(
    padding: EdgeInsets.only(top: 10),
    child: snapshot.connectionState == ConnectionState.done
        ? ListView.builder(
            itemCount: snapshot.data.length,
            itemBuilder: (context, index) =>
                snippet(context, snapshot, index),
          )
          /*
          SliverList(
            delegate: SliverChildBuilderDelegate(
              (context, index) => snippet(context, snapshot, index),
              childCount: snapshot.data.length,
            ),
          )
          */
        : ..., // a loading indicator awaiting connection to be done
  );
}

The SliverList code commented is the issue, The whole page after loaded is blank if I use the sliverlist instead of listView.

What am I doing wrong?

Btw I want to replace the listView with the sliverlist is because I want to create a pull-down to refresh feature, and I'm looking to use flutter_easyrefresh here https://pub.dev/packages/flutter_easyrefresh

If there's a better alternative or improvements please kindly comment

0 Answers
Related