2019-02-08 13:52:10 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/widgets.dart';
|
2019-09-02 15:52:32 +02:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2019-02-08 13:52:10 +01:00
|
|
|
import '../widgets/loading.dart';
|
|
|
|
import '../widgets/error_reload.dart';
|
|
|
|
|
|
|
|
// This is a scaffold for pull to refresh
|
|
|
|
class RefreshStatelessScaffold extends StatelessWidget {
|
|
|
|
final Widget title;
|
|
|
|
final Widget Function() bodyBuilder;
|
|
|
|
final Future<void> Function() onRefresh;
|
|
|
|
final bool loading;
|
|
|
|
final String error;
|
|
|
|
final Widget trailing;
|
|
|
|
final List<Widget> actions;
|
|
|
|
final PreferredSizeWidget bottom;
|
|
|
|
|
|
|
|
RefreshStatelessScaffold({
|
|
|
|
@required this.title,
|
|
|
|
@required this.bodyBuilder,
|
|
|
|
@required this.onRefresh,
|
|
|
|
@required this.loading,
|
|
|
|
@required this.error,
|
|
|
|
this.trailing,
|
|
|
|
this.actions,
|
|
|
|
this.bottom,
|
|
|
|
});
|
|
|
|
|
|
|
|
Widget _buildBody() {
|
|
|
|
if (error.isNotEmpty) {
|
2019-02-21 11:43:41 +01:00
|
|
|
return ErrorReload(text: error, onTap: onRefresh);
|
2019-02-08 13:52:10 +01:00
|
|
|
} else if (loading) {
|
2019-02-09 06:29:44 +01:00
|
|
|
return Loading(more: false);
|
2019-02-08 13:52:10 +01:00
|
|
|
} else {
|
|
|
|
return bodyBuilder();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-09-02 15:52:32 +02:00
|
|
|
switch (Provider.of<ThemeModel>(context).theme) {
|
2019-09-19 15:10:50 +02:00
|
|
|
case AppThemeType.cupertino:
|
2019-02-08 13:52:10 +01:00
|
|
|
return CupertinoPageScaffold(
|
|
|
|
navigationBar:
|
|
|
|
CupertinoNavigationBar(middle: title, trailing: trailing),
|
|
|
|
child: SafeArea(
|
|
|
|
child: CustomScrollView(
|
|
|
|
slivers: <Widget>[
|
|
|
|
CupertinoSliverRefreshControl(onRefresh: onRefresh),
|
|
|
|
SliverToBoxAdapter(child: _buildBody())
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return DefaultTabController(
|
|
|
|
length: 3,
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: title,
|
|
|
|
actions: actions,
|
|
|
|
bottom: bottom,
|
|
|
|
),
|
|
|
|
body: RefreshIndicator(
|
|
|
|
onRefresh: onRefresh,
|
|
|
|
child: SingleChildScrollView(child: _buildBody()),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|