import 'package:flutter/material.dart'; import 'ContentError.dart'; import 'ContentLoading.dart'; class ContentBuilder extends StatelessWidget { final Future future; final Future Function() onRefresh; final AsyncWidgetBuilder successBuilder; const ContentBuilder({ required Key? key, required this.future, required this.onRefresh, required this.successBuilder, }) : super(key: key); @override Widget build(BuildContext context) { return FutureBuilder( future: future, builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasError) { return ContentError( error: snapshot.error, stackTrace: snapshot.stackTrace, onRefresh: onRefresh, ); } if (snapshot.connectionState != ConnectionState.done) { return const ContentLoading(label: '加载中'); } return successBuilder(context, snapshot); }, ); } }