Repository on GitHub |
Report an Issue
A Flutter package to simplify the management of asynchronous operations with loading, error, and empty data states.
- FutureWorker: Simplified wrapper for FutureBuilder
- StreamWorker: Simplified wrapper for StreamBuilder
- State Widgets: OptionLoading, OptionEmpty, OptionError
- Error Handling: Automatic error management with retry option
- Production Mode: Hides empty states in production
dependencies:
builder_plus: <version_code>
import 'package:data_builder/data_builder.dart';
FutureWorker<User>(
future: userService.getUser(id),
builder: (context, user) => UserCard(user: user),
errorBuilder: (context, error) => ErrorWidget(error.toString()),
loadingBuilder: (context) => CircularProgressIndicator(),
)
import 'package:workers/workers_helper.dart';
StreamWorker<User>(
stream: userService.userStream,
builder: (context, user) => UserCard(user: user),
errorBuilder: (context, error) => ErrorWidget(error.toString()),
loadingBuilder: (context) => CircularProgressIndicator(),
)
// Loading with customization
const OptionLoading(
size: 32.0,
color: Colors.blue,
)
// Empty with icon
const OptionEmpty(
text: 'No users found',
icon: Icons.person_off,
iconSize: 64.0,
)
// Error with retry
OptionError(
error: 'Connection error',
onRetry: () => userService.refresh(),
retryButtonText: 'Refresh',
)
| Parameter |
Type |
Description |
| `future |
stream` |
`Future |
builder |
Widget Function(BuildContext, T) |
Builder for the data |
isProd |
bool |
Production mode (hides empty states) |
initialData |
T? |
Initial data |
emptyBuilder |
Widget Function(BuildContext)? |
Builder for empty state |
errorBuilder |
Widget Function(BuildContext, Object?)? |
Builder for error |
loadingBuilder |
Widget Function(BuildContext)? |
Builder for loading |
| Parameter |
Type |
Default |
Description |
size |
double |
24.0 |
Indicator size |
color |
Color? |
null |
Color (uses theme if null) |
| Parameter |
Type |
Default |
Description |
text |
String |
- |
Text to display |
icon |
IconData? |
null |
Optional icon |
textStyle |
TextStyle? |
null |
Text style |
iconSize |
double |
48.0 |
Icon size |
iconColor |
Color? |
null |
Icon color |
spacing |
double |
16.0 |
Spacing |
| Parameter |
Type |
Default |
Description |
error |
String |
- |
Error message |
onRetry |
VoidCallback? |
null |
Retry callback |
textStyle |
TextStyle? |
null |
Text style |
iconSize |
double |
48.0 |
Icon size |
iconColor |
Color? |
null |
Icon color |
spacing |
double |
16.0 |
Spacing |
showRetryButton |
bool |
true |
Show retry button |
retryButtonText |
String |
` |
|