flutter_easy_refresh

repository·v3·Indexed 26 days ago

https://github.com/xuelongqy/flutter_easy_refresh

A pull-to-refresh framework for Flutter supporting pull-down refresh and pull-up load for most Scrollable widgets. It features highly customizable headers and footers, including specialized animation styles like Bow, Bubbles, Halloween, Skating, Space, and Squats. The framework includes EasyRefreshController for manual state control and a companion package, easy_paging, for automatic pagination integration via the EasyPaging widget and EasyPagingState.

Tokens
10.1K
Snippets
27
Records
57
Agent score
86%

What's inside flutter_easy_refresh

  1. Use EasyPaging for automatic pagination

    v3

    The EasyPaging<DataType, ItemType> widget provides automatic integration with the EasyRefresh refresh/load lifecycle. It handles isNoMore calculations based on total or page/totalPage values.

    To implement pagination, extend EasyPaging and implement its corresponding EasyPagingState.

    class CustomPaging extends EasyPaging<List<String>, String> {
      const CustomPaging({super.key});
    
      @override
      EasyPagingState<List<String>, String, CustomPaging> createState() =>
          _CustomPagingState();
    }
    
    class _CustomPagingState
        extends EasyPagingState<List<String>, String, CustomPaging> {
      @override
      int get count => data?.length ?? 0;
    
      @override
      String getItem(int index) => data![index];
    
      @override
      int? page;
    
      @override
      int? total;
    
      @override
      int? totalPage;
    
      @override
      Widget buildItem(BuildContext context, int index, String item) {
        return ListTile(title: Text(item));
      }
    
      @override
      Future onRefresh() async {
        setState(() {
          data = List.generate(10, (index) => 'Item $index');
          total = 30;
          page = 1;
        });
      }
    
      @override
      Future onLoad() async {
        final nextPage = page! + 1;
        setState(() {
          data!.addAll(List.generate(10, (index) => 'Item ${data!.length + index}'));
          page = nextPage;
        });
      }
    }
  2. Use easy_paging for pagination capabilities

    v3

    Pagination logic has been moved to a separate package called easy_paging. To use it, add easy_paging to your dependencies and import it alongside easy_refresh.

    import 'package:easy_paging/easy_paging.dart';
    import 'package:easy_refresh/easy_refresh.dart';
  3. Use the EasyRefresh widget for pull-to-refresh

    v3

    The EasyRefresh widget is the primary entry point for implementing pull-down refresh and pull-up load functionality in Flutter. You can use it in two ways:

    1. Standard Mode: Pass a child (typically a ListView, GridView, or other ScrollView).
    2. Builder Mode: Use EasyRefresh.builder and provide a childBuilder. This is recommended if you need to provide specific ScrollPhysics to your ScrollView to ensure proper interaction with the refresh indicators.

    Key properties:

    • onRefresh: A callback triggered on refresh. If null, refresh is disabled. Returns a FutureOr.
    • onLoad: A callback triggered on load. If null, load is disabled. Returns a FutureOr.
    • header / footer: Custom indicators for the refresh and load states.
    • controller: An EasyRefreshController to programmatically control refresh/load states.
    • isNested: Set to true if using EasyRefresh inside a NestedScrollView to ensure correct event triggering.