git-touch-android-ios-app/lib/scaffolds/utils.dart

52 lines
1.2 KiB
Dart
Raw Permalink Normal View History

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