bloc_infinity_list 0.0.4 copy "bloc_infinity_list: ^0.0.4" to clipboard
bloc_infinity_list: ^0.0.4 copied to clipboard

Infinite scrolling ListView with BLoC integration for Flutter applications.

example/lib/main.dart

import 'dart:async';

import 'package:bloc_infinity_list/bloc_infinity_list.dart';
import 'package:bloc_infinity_list/infinite_list_bloc/infinite_list_bloc.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class ListItem {
  static int staticId = 0;

  final int id;
  final String name;

  ListItem({required this.name}) : id = ++staticId;
}

class MyCustomBloc extends InfiniteListBloc<ListItem> {
  @override
  Future<List<ListItem>> fetchItems(
      {required int limit, required int offset}) async {
    try {
      await Future.delayed(Durations.long1);

      return [
        ListItem(name: "Test"),
        ListItem(name: "Test"),
        ListItem(name: "Test"),
        ListItem(name: "Test"),
        ListItem(name: "Test"),
      ];
    } on Exception {
      rethrow;
    }
  }
}

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

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

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

class _MyAppState extends State<MyApp> {
  final MyCustomBloc bloc = MyCustomBloc();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Infinite List'),
        ),
        body: BlocProvider.value(
          value: bloc,
          child: InfiniteListView<ListItem>(
            bloc: bloc,
            color: Colors.black12,
            borderRadius: BorderRadius.circular(10),
            padding: const EdgeInsets.only(
              top: 20,
              bottom: 20 * 3,
              left: 20,
              right: 20,
            ),
            itemBuilder: (context, item) {
              return ListTile(
                title: Text(item.name),
                subtitle: Text(item.id.toString()),
              );
            },
            loadingWidget: (context) => Container(
              alignment: Alignment.center,
              padding: const EdgeInsets.all(20),
              child: CircularProgressIndicator.adaptive(
                strokeWidth: 2.0,
                valueColor: AlwaysStoppedAnimation<Color>(
                  Theme.of(context).colorScheme.secondary,
                ),
              ),
            ),
            errorWidget: (context, error) => Center(child: Text(error)),
            emptyWidget: (context) => const Center(child: Text('No items')),
          ),
        ),
      ),
    );
  }
}
2
likes
0
pub points
44%
popularity

Publisher

verified publisherfrancescodema.dev

Infinite scrolling ListView with BLoC integration for Flutter applications.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

equatable, flutter, flutter_bloc, plugin_platform_interface

More

Packages that depend on bloc_infinity_list