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 'loading.dart';
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-02-06 14:35:52 +01:00
|
|
|
class RefreshScaffold extends StatelessWidget {
|
2019-02-03 16:10:10 +01:00
|
|
|
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-03 08:50:17 +01:00
|
|
|
|
|
|
|
RefreshScaffold({
|
|
|
|
@required this.title,
|
2019-02-03 16:10:10 +01:00
|
|
|
@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-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:
|
|
|
|
return Scaffold(
|
2019-02-06 14:35:52 +01:00
|
|
|
appBar: AppBar(
|
|
|
|
title: title,
|
|
|
|
actions: actions,
|
|
|
|
),
|
2019-02-03 08:50:17 +01:00
|
|
|
body: RefreshIndicator(
|
2019-02-06 14:35:52 +01:00
|
|
|
onRefresh: onRefresh,
|
|
|
|
child: SingleChildScrollView(child: _buildBody()),
|
2019-02-03 08:50:17 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|