1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-20 21:40:44 +01:00

54 lines
1.2 KiB
Dart
Raw Normal View History

2019-09-25 17:06:36 +08:00
import 'package:flutter/cupertino.dart';
2019-09-29 16:39:30 +08:00
import 'package:git_touch/widgets/error_reload.dart';
2019-09-25 18:47:34 +08:00
import 'package:git_touch/widgets/loading.dart';
2019-09-25 17:06:36 +08:00
class RefreshWrapper extends StatelessWidget {
final Widget body;
final void Function() onRefresh;
2022-09-07 00:28:12 +08:00
const RefreshWrapper({
2021-05-16 15:16:35 +08:00
required this.onRefresh,
required this.body,
2019-09-25 17:06:36 +08:00
});
@override
Widget build(BuildContext context) {
2022-09-17 20:35:45 +08:00
return CupertinoScrollbar(
child: CustomScrollView(
slivers: <Widget>[
CupertinoSliverRefreshControl(
onRefresh: onRefresh as Future<void> Function()?),
SliverToBoxAdapter(child: body),
],
),
);
2019-09-25 17:06:36 +08:00
}
}
2019-09-25 18:47:34 +08:00
class ErrorLoadingWrapper extends StatelessWidget {
final String error;
final bool loading;
final void Function() reload;
2021-05-16 15:16:35 +08:00
final Widget? Function() bodyBuilder;
2019-09-25 18:47:34 +08:00
2022-09-07 00:28:12 +08:00
const ErrorLoadingWrapper({
2021-05-16 15:16:35 +08:00
required this.error,
required this.loading,
required this.reload,
required this.bodyBuilder,
2019-09-25 18:47:34 +08:00
});
@override
Widget build(BuildContext context) {
if (error.isNotEmpty) {
2019-09-29 16:39:30 +08:00
return ErrorReload(text: error, onTap: reload);
2019-09-25 18:47:34 +08:00
}
if (loading) {
2022-09-07 00:28:12 +08:00
return const Loading();
2019-09-25 18:47:34 +08:00
}
2021-05-16 15:16:35 +08:00
return bodyBuilder()!;
2019-09-25 18:47:34 +08:00
}
}