Git Product home page Git Product logo

i_pagy's Introduction

ipagy

ipagy offers a powerful tool for Flutter developers with its main features, making paging easy and effective. Developed to meet your paging needs, this package adapts to various usage scenarios by supporting common widgets such as Grid View, List View, Separated ListView.

One of the main advantages of ipagy is that it optimizes paging operations and improves performance. When working with large datasets or pulling data from web services, you can choose ipagy to efficiently manage paging operations. It also makes the paging experience more user-friendly with animated transitions.

ipagy's flexible structure offers developers easy customization. You can customize paging controls and views to suit your needs. This ensures a paging solution that matches the design and functionality of your application.

No need to define a ScrollController, we have already integrated the controller for you! Your pagination is ready with very few arguments!

Table of contents

Installation

dependencies:
  ipagy: <latest version>

Import

import 'package:ipagy/ipagy.dart';

Usage

final class PostView extends StatefulWidget {
  const PostView({super.key});

  @override
  State<PostView> createState() => _PostViewState();
}

class _PostViewState extends State<PostView> {
  final PagyType _paginationListType = PagyType.listView;

  final PostService _postService = PostService();
  List<Post>? _posts;
  late int currentPage;

  @override
  void initState() {
    super.initState();
    currentPage = 1;
    _loadPosts();
  }

  Future<void> _loadPosts() async {
    final List<Post>? response = await _postService.fetchAllPosts(page: currentPage);
    if (response?.isNotEmpty ?? false) {
      setState(() {
        _posts ??= [];
        _posts!.addAll(response!);
        currentPage++;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('ipagy'),
      ),
      body: switch (_paginationListType) {
        PagyType.listView || PagyType.animated => Pagy<Post>(
            items: _posts,
            loadMoreItems: _loadPosts,
            listType: _paginationListType,
            padding: const EdgeInsets.symmetric(horizontal: 20),
            itemBuilder: (BuildContext context, int index) => Card(
              child: ListTile(
                leading: Text(_posts![index].id.toString()),
                title: Text(_posts![index].title ?? ''),
                subtitle: Text(_posts![index].body ?? ''),
              ),
            ),
          ),
        PagyType.grid => Pagy<Post>(
            items: _posts,
            loadMoreItems: _loadPosts,
            listType: _paginationListType,
            firstLoadingItemCount: 6,
            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 2,
              mainAxisSpacing: 20,
              crossAxisSpacing: 20,
            ),
            itemBuilder: (BuildContext context, int index) => Card(
              child: ListTile(
                leading: Text(_posts![index].id.toString()),
                title: Text(_posts![index].title ?? ''),
              ),
            ),
          ),
        PagyType.separated => SizedBox(
            child: Pagy<Post>(
              items: _posts,
              loadMoreItems: _loadPosts,
              loadingWidget: SizedBox(
                height: MediaQuery.sizeOf(context).height * .7,
                child: const CircularProgressIndicator.adaptive(),
              ),
              listType: _paginationListType,
              separatedWidget: Divider(color: Theme.of(context).primaryColor),
              itemBuilder: (BuildContext context, int index) => Card(
                child: ListTile(
                  leading: CircleAvatar(
                    child: Text(_posts![index].id.toString()),
                  ),
                  title: Text(_posts![index].title ?? ''),
                  subtitle: Text(_posts![index].body ?? ''),
                ),
              ),
            ),
          ),
      },
    );
  }
}

License

MIT

Copyright (c) 2024 iWallet Türkiye

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

i_pagy's People

Contributors

bedirhanssaglam avatar

Stargazers

Ahmet Zeki İnce avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.