mobile_nebula/lib/components/SimplePage.dart

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

114 lines
3.5 KiB
Dart
Raw Permalink Normal View History

2020-07-27 20:43:58 +00:00
import 'package:flutter/cupertino.dart' as cupertino;
import 'package:flutter/material.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:mobile_nebula/services/utils.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
enum SimpleScrollable {
none,
vertical,
horizontal,
both,
}
class SimplePage extends StatelessWidget {
const SimplePage(
{Key? key,
required this.title,
required this.child,
2020-07-27 20:43:58 +00:00
this.leadingAction,
this.trailingActions = const [],
this.scrollable = SimpleScrollable.vertical,
this.scrollbar = true,
this.scrollController,
this.bottomBar,
this.onRefresh,
this.onLoading,
this.alignment,
2020-07-27 20:43:58 +00:00
this.refreshController})
: super(key: key);
final Widget title;
2020-07-27 20:43:58 +00:00
final Widget child;
final SimpleScrollable scrollable;
final ScrollController? scrollController;
final AlignmentGeometry? alignment;
2020-07-27 20:43:58 +00:00
2022-07-27 16:38:02 +00:00
/// Set this to true to force draw a scrollbar without a scroll view, this is helpful for pages with Reorder-able listviews
2020-07-27 20:43:58 +00:00
/// This is set to true if you have any scrollable other than none
final bool scrollbar;
final Widget? bottomBar;
2020-07-27 20:43:58 +00:00
/// If no leading action is provided then a default "Back" widget than pops the page will be provided
final Widget? leadingAction;
2020-07-27 20:43:58 +00:00
final List<Widget> trailingActions;
final VoidCallback? onRefresh;
final VoidCallback? onLoading;
final RefreshController? refreshController;
2020-07-27 20:43:58 +00:00
@override
Widget build(BuildContext context) {
Widget realChild = child;
var addScrollbar = this.scrollbar;
if (scrollable == SimpleScrollable.vertical || scrollable == SimpleScrollable.both) {
realChild = SingleChildScrollView(
scrollDirection: Axis.vertical,
child: realChild,
controller: refreshController == null ? scrollController : null);
addScrollbar = true;
}
if (scrollable == SimpleScrollable.horizontal || scrollable == SimpleScrollable.both) {
realChild = SingleChildScrollView(scrollDirection: Axis.horizontal, child: realChild);
addScrollbar = true;
}
if (refreshController != null) {
realChild = RefreshConfiguration(
headerTriggerDistance: 100,
footerTriggerDistance: -100,
maxUnderScrollExtent: 100,
child: SmartRefresher(
scrollController: scrollController,
onRefresh: onRefresh,
onLoading: onLoading,
controller: refreshController!,
2020-07-27 20:43:58 +00:00
child: realChild,
enablePullUp: onLoading != null,
enablePullDown: onRefresh != null,
footer: ClassicFooter(loadStyle: LoadStyle.ShowWhenLoading),
));
addScrollbar = true;
}
if (addScrollbar) {
realChild = Scrollbar(child: realChild);
}
if (alignment != null) {
realChild = Align(alignment: this.alignment!, child: realChild);
}
2020-07-27 20:43:58 +00:00
if (bottomBar != null) {
realChild = Column(children: [
Expanded(child: realChild),
bottomBar!,
2020-07-27 20:43:58 +00:00
]);
}
return PlatformScaffold(
backgroundColor: cupertino.CupertinoColors.systemGroupedBackground.resolveFrom(context),
appBar: PlatformAppBar(
title: title,
2020-07-27 20:43:58 +00:00
leading: leadingAction != null ? leadingAction : Utils.leadingBackWidget(context),
trailingActions: trailingActions,
2021-04-23 17:33:28 +00:00
cupertino: (_, __) => CupertinoNavigationBarData(
2020-07-27 20:43:58 +00:00
transitionBetweenRoutes: false,
),
),
body: SafeArea(child: realChild));
}
}