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

73 lines
1.9 KiB
Dart
Raw Normal View History

2019-02-03 08:50:17 +01:00
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/widgets.dart';
import '../providers/settings.dart';
import '../widgets/loading.dart';
2019-02-03 08:50:17 +01:00
typedef RefreshCallback = Future<void> Function();
2019-02-06 12:14:11 +01:00
typedef WidgetBuilder = Widget Function();
2019-02-03 08:50:17 +01:00
// This is a scaffold for normal screens
// Users can pull to refresh
2019-02-06 14:35:52 +01:00
class RefreshScaffold extends StatelessWidget {
final Widget title;
2019-02-06 12:14:11 +01:00
final WidgetBuilder bodyBuilder;
2019-02-03 08:50:17 +01:00
final RefreshCallback onRefresh;
2019-02-06 14:35:52 +01:00
final bool loading;
final Widget trailing;
final List<Widget> actions;
2019-02-07 13:28:48 +01:00
final PreferredSizeWidget bottom;
2019-02-03 08:50:17 +01:00
RefreshScaffold({
@required this.title,
@required this.bodyBuilder,
2019-02-03 08:50:17 +01:00
@required this.onRefresh,
2019-02-06 14:35:52 +01:00
@required this.loading,
this.trailing,
this.actions,
2019-02-07 13:28:48 +01:00
this.bottom,
2019-02-03 08:50:17 +01:00
});
2019-02-06 14:35:52 +01:00
Widget _buildBody() {
2019-02-03 08:50:17 +01:00
if (loading) {
2019-02-06 14:35:52 +01:00
return Loading(more: true);
2019-02-03 08:50:17 +01:00
} else {
2019-02-06 14:35:52 +01:00
return bodyBuilder();
2019-02-03 08:50:17 +01:00
}
}
@override
Widget build(BuildContext context) {
2019-02-07 07:35:19 +01:00
switch (SettingsProvider.of(context).theme) {
case ThemeMap.cupertino:
2019-02-03 08:50:17 +01:00
return CupertinoPageScaffold(
2019-02-06 14:35:52 +01:00
navigationBar:
CupertinoNavigationBar(middle: title, trailing: trailing),
2019-02-03 08:50:17 +01:00
child: SafeArea(
child: CustomScrollView(
slivers: <Widget>[
2019-02-06 14:35:52 +01:00
CupertinoSliverRefreshControl(onRefresh: onRefresh),
SliverToBoxAdapter(child: _buildBody())
2019-02-03 08:50:17 +01:00
],
),
),
);
default:
2019-02-07 13:28:48 +01:00
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: title,
actions: actions,
bottom: bottom,
),
body: RefreshIndicator(
onRefresh: onRefresh,
child: SingleChildScrollView(child: _buildBody()),
),
2019-02-03 08:50:17 +01:00
),
);
}
}
}