CupertinoSliverRefreshControl In Flutter

CupertinoSliverRefreshControl In Flutter :

  • CustomScrollView in flutter
  • SliverFixedExtentList in flutter
  • SliverGrid in flutter
  • CupertinoSliverRefreshControl in flutter
  • SliverToBoxAdapter in flutter
CupertinoSliverRefreshControl In Flutter
Future<Null> _handleRefresh() async {
    //API CALL
  }

 Widget _listView() {
    return CustomScrollView(
      physics:
          const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
      slivers: <Widget>[
            CupertinoSliverRefreshControl(
              builder: (context, mode, v1, v2, v3) {
                return MainRefresh();
              },
              onRefresh: _handleRefresh,
            )
          ] +
          _buildList(),
    );
  }


List<Widget> _buildList() {
    final state = Provider.of<HomeProvider>(context);
    const padding = const EdgeInsets.fromLTRB(22, 5, 22, 5);

    if (state.data == null) return [];

    return state.data.modules.map((item) {
      final payload = item.payload;

      switch (item.type) {
        case "BANNER":
          return SliverToBoxAdapter(
            child: HomeBanner(BannerModel.fromJsonList(payload["banners"])),
          );
        case "QUICK_ENTRANCE":
          return SliverToBoxAdapter(
            child: Padding(
              padding:
                  const EdgeInsets.only(left: 5, right: 5, top: 10, bottom: 10),
              child: HomeQuickEntrance(HomeQuickEntranceModel.fromJsonList(
                  payload["quickEntrances"])),
            ),
          );
        case "HEADER":
          return SliverToBoxAdapter(
            child: Padding(
              padding: padding,
              child: HomeHeader(HeaderModel.fromJsonMap(payload)),
            ),
          );
        case "NORMAL_BOOK":
        case "RECOMMENDED_BOOK":
          return HomeNormalBook(BookModel.fromJsonList(payload["books"]));
        case "TINY_BANNER":
          return SliverToBoxAdapter(
            child: Padding(
              padding: padding,
              child: HomeTinyBanner(
                  BannerModel.fromJsonMap(payload["tinyBanners"][0])),
            ),
          );
        case "HIGHLY_RECOMMENDED_BOOK":
          return HomeHighlyRecommendedBook(
              BookModel.fromJsonList(payload["books"]));
        case "COLUMN":
          return HomeColumn(ColumnModel.fromJsonList(payload["column"]));
        case "SERIES":
          return HomeSeries(SeriesModel.fromJsonList(payload["series"]));
        default:
          break;
      }

      return SliverToBoxAdapter(
        child: Container(),
      );
    }).toList();
  }

class HomeNormalBook extends StatelessWidget {
  final List<BookModel> data;

  HomeNormalBook(this.data);

  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    return SliverPadding(
      padding: const EdgeInsets.fromLTRB(22, 0, 22, 0),
      sliver: SliverGrid(
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: (screenSize.width > screenSize.height) ? 6 : 3,
            mainAxisSpacing: 10.0,
            crossAxisSpacing: 10.0,
            childAspectRatio: 0.64),
        delegate: SliverChildBuilderDelegate(
          (_, int index) {
            return HomeNormalBookItem(data[index]);
          },
          childCount: data.length,
        ),
      ),
    );
  }
}

SliverFixedExtentList(
      itemExtent: 130.0,
      delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
        return HomeHighlyRecommendedBookItem(data[index]);
      }, childCount: data.length),
    );

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in