FutureListBuilder<T> class
A Flutter widget that makes it easy to load and display a list of data from a future.
It takes care of all the boilerplate code, such as handling loading and error states, pagination, and rebuilding the list when the data changes.
To use FutureListBuilder, simply pass it a future that returns a list of data, and a converter function that converts each item in the list to a widget. FutureListBuilder will then take care of displaying the list of widgets.
FutureListBuilder also supports pagination. If you set the pagination
property
to true
, FutureListBuilder will automatically load more data when the user
reaches the bottom of the list.
Here is an example of how to use FutureListBuilder to display a list of users:
import 'package:flutter/material.dart';
import 'package:future_list/future_list_builder.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Future List Builder Example'),
),
body: FutureListBuilder<User>(
url: 'https://api.github.com/users',
httpMethod: HttpMethod.get,
converter: User.fromJson,
itemBuilder: (context, user) => ListTile(
title: Text(user.name),
subtitle: Text(user.login),
),
),
),
);
}
}
class User {
final String name;
final String login;
User(this.name, this.login);
factory User.fromJson(Map<String, dynamic> json) {
return User(json['name'], json['login']);
}
}
This example will display a list of users, with each user represented by a ListTile widget. The name and login of the user will be displayed in the title and subtitle of the ListTile widget, respectively.
You can customize the FutureListBuilder widget by setting the following properties:
url
: The URL of the endpoint to fetch the data from.httpMethod
: The HTTP method to use to fetch the data.header
: A map of headers to send with the request.body
: A map of body parameters to send with the request.converter
: A function that converts each item in the list from json to an object.itemBuilder
: A function that builds a widget for each item in the list.scrollDirection
: The direction in which the list scrolls.shimmerBuilder
: A function that builds a widget to display while the data is loading.shimmerCardsCount
: The number of shimmer cards to display while the data is loading.paginationShimmerCardsCount
: The number of shimmer cards to display when the user reaches the bottom of the list and is waiting for more data to load.onError
: A function that is called if an error occurs while fetching the data.callBack
: A function that is called after the data has been fetched and converted.pagination
: Whether to enable pagination.skipKey
: The name of the query parameter to use for the skip value in the pagination request.limitKey
: The name of the query parameter to use for the limit value in the pagination request.skip
: The initial skip value for the pagination request.limit
: The initial limit value for the pagination request.successStatusCode
: The HTTP status code that indicates success.
FutureListBuilder is a powerful and flexible widget that can be used to display a variety of data from a future. It is a good choice for any app that needs to display a list of data that is loaded from a remote server.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- FutureListBuilder
Constructors
-
FutureListBuilder.new({Key? key, required String url, required HttpMethod httpMethod, Map<
String, String> ? header, Map<String, dynamic> ? body, List<Map> ? dataGetter(Map)?, int? countGetter(Map)?, required T converter(Map<String, dynamic> ), required Widget itemBuilder(T data), Axis scrollDirection = Axis.vertical, Widget shimmerBuilder()?, int shimmerCardsCount = 3, int paginationShimmerCardsCount = 3, Widget? onError(String?)?, void callBack(List<T> )?, bool pagination = false, String skipKey = "skip", String limitKey = "limit", int skip = 0, int limit = 6, int? successStatusCode = 200, required List<String> dataPath, List<String> ? countPath, ScrollPhysics scrollPhysics = const BouncingScrollPhysics()}) -
const
Properties
-
body
→ Map<
String, dynamic> ? -
final
-
callBack
→ void Function(List<
T> )? -
final
-
converter
→ T Function(Map<
String, dynamic> ) -
Converter
final
- countGetter → int? Function(Map)?
-
final
-
countPath
→ List<
String> ? -
final
-
dataGetter
→ List<
Map> ? Function(Map)? -
Response
final
-
dataPath
→ List<
String> -
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
header
→ Map<
String, String> ? -
final
- httpMethod → HttpMethod
-
final
- itemBuilder → Widget Function(T data)
-
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- limit → int
-
final
- limitKey → String
-
final
- onError → Widget? Function(String?)?
-
Call back..
final
- pagination → bool
-
Pagination
final
- paginationShimmerCardsCount → int
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scrollDirection → Axis
-
List attributes
final
- scrollPhysics → ScrollPhysics
-
final
- shimmerBuilder → Widget Function()?
-
Simmer
final
- shimmerCardsCount → int
-
final
- skip → int
-
final
- skipKey → String
-
final
- successStatusCode → int?
-
final
- url → String
-
Futures
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< FutureListBuilder< T> > -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited