import 'package:flutter/material.dart'; class ItemBuilder extends StatelessWidget { final Future future; final AsyncWidgetBuilder successBuilder; final Future Function() onRefresh; final double? loadingHeight; final double? height; const ItemBuilder({ Key? key, required this.future, required this.successBuilder, required this.onRefresh, this.height, this.loadingHeight, }) : super(key: key); @override Widget build(BuildContext context) { return LayoutBuilder( builder: (BuildContext context, BoxConstraints constraints) { var _maxWidth = constraints.maxWidth; var _loadingHeight = height ?? loadingHeight ?? _maxWidth / 2; return FutureBuilder( future: future, builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasError) { print("${snapshot.error}"); print("${snapshot.stackTrace}"); return InkWell( onTap: onRefresh, child: Container( width: _maxWidth, height: _loadingHeight, child: Center( child: Icon(Icons.sync_problem, size: _loadingHeight / 1.5), ), ), ); } if (snapshot.connectionState != ConnectionState.done) { return Container( width: _maxWidth, height: _loadingHeight, child: Center( child: Icon(Icons.sync, size: _loadingHeight / 1.5), ), ); } return Container( width: _maxWidth, height: height, child: successBuilder(context, snapshot), ); }); }, ); } }