vertical_load_more 0.0.1 copy "vertical_load_more: ^0.0.1" to clipboard
vertical_load_more: ^0.0.1 copied to clipboard

outdated

This package can use for load more data inside the list and refresh or reset the data

example/lib/main.dart

import 'dart:developer' as log;
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:vertical_load_more/vertical_load_more.dart';
import 'package:vertical_load_more/vertical_load_more_view.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late List<Map<String, dynamic>> data;

  Random randomColor = Random();
  VerticalLoadMore verticalLoadMore = VerticalLoadMore();
  @override
  void initState() {
    verticalLoadMore.hasMore = true;
    setData();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Vertical Load More Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        body: SafeArea(
          child: VerticalLoadMoreView(
            child: ListView.builder(
              itemBuilder: (_, index) {
                log.log(data[index].toString());
                return Container(
                  margin: const EdgeInsets.all(10),
                  padding: const EdgeInsets.all(16),
                  decoration: BoxDecoration(
                    color: data[index]["color"],
                    borderRadius: BorderRadius.circular(10),
                  ),
                  child: Text(
                    data[index]["value"].toString(),
                    style: Theme.of(context).textTheme.headline1,
                  ),
                );
              },
              itemCount: data.length,
            ),
            onLoadMore: onMoreData,
            onRefresh: onRefresh,
            controller: verticalLoadMore,
          ),
        ),
      ),
    );
  }

  Future<void> onMoreData() async {
    await Future.delayed(const Duration(milliseconds: 500), () {
      setState(() {
        verticalLoadMore.hasMore = true;
        data.addAll(
          List.generate(
            10,
            (index) => {
              "value": index + data.length,
              "color": Color.fromRGBO(
                randomColor.nextInt(255),
                randomColor.nextInt(255),
                randomColor.nextInt(255),
                1,
              ),
            },
          ),
        );
      });
    });
  }

  Future<void> onRefresh() async {
    setData();
    setState(() {
      verticalLoadMore.hasMore = true;
    });
  }

  void setData() {
    data = List.generate(
      10,
      (index) => {
        "value": index,
        "color": Color.fromRGBO(
          randomColor.nextInt(255),
          randomColor.nextInt(255),
          randomColor.nextInt(255),
          1,
        ),
      },
    );
  }
}
5
likes
0
points
49
downloads

Publisher

verified publishersivhongdeab.com

Weekly Downloads

This package can use for load more data inside the list and refresh or reset the data

License

unknown (license)

Dependencies

flutter

More

Packages that depend on vertical_load_more