1
0
mirror of https://github.com/git-touch/git-touch synced 2025-01-24 21:10:45 +01:00
git-touch-android-ios-app/lib/scaffolds/utils.dart

67 lines
1.6 KiB
Dart
Raw Normal View History

2019-09-25 11:06:36 +02:00
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:git_touch/models/theme.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
import 'package:provider/provider.dart';
class RefreshWrapper extends StatelessWidget {
final Widget body;
final void Function() onRefresh;
RefreshWrapper({
2021-05-16 09:16:35 +02:00
required this.onRefresh,
required this.body,
2019-09-25 11:06:36 +02:00
});
@override
Widget build(BuildContext context) {
switch (Provider.of<ThemeModel>(context).theme) {
case AppThemeType.cupertino:
2019-09-28 15:40:42 +02:00
return CupertinoScrollbar(
child: CustomScrollView(
slivers: <Widget>[
2021-05-16 09:16:35 +02:00
CupertinoSliverRefreshControl(
onRefresh: onRefresh as Future<void> Function()?),
2019-09-28 15:40:42 +02:00
SliverToBoxAdapter(child: body),
],
),
2019-09-25 11:06:36 +02:00
);
default:
return RefreshIndicator(
2021-05-16 09:16:35 +02:00
onRefresh: onRefresh as Future<void> Function(),
2019-09-28 15:40:42 +02:00
child: Scrollbar(
child: SingleChildScrollView(child: body),
),
2019-09-25 11:06:36 +02:00
);
}
}
}
2019-09-25 12:47:34 +02:00
class ErrorLoadingWrapper extends StatelessWidget {
final String error;
final bool loading;
final void Function() reload;
2021-05-16 09:16:35 +02:00
final Widget? Function() bodyBuilder;
2019-09-25 12:47:34 +02:00
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
});
@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) {
return Loading();
}
2021-05-16 09:16:35 +02:00
return bodyBuilder()!;
2019-09-25 12:47:34 +02:00
}
}