mirror of
https://github.com/DefinedNet/mobile_nebula.git
synced 2025-03-06 16:46:35 +00:00
* Enable `flutter_lints` linting * Fix unmarked deps, we aren't on web so we don't need a URL strategy * ` dart fix --apply --code=use_super_parameters` * `dart fix --apply --code=use_key_in_widget_constructors` * `dart fix --apply --code=use_function_type_syntax_for_parameters` * Ignore code-generated `lib/services/theme.dart` file * `dart fix --apply --code=unnecessary_this` * `dart fix --apply --code=unnecessary_null_in_if_null_operators` * `dart fix --apply --code=unnecessary_new` * `dart fix --apply --code=sort_child_properties_last` * `dart fix --apply --code=sized_box_for_whitespace` * `dart fix --apply --code=prefer_typing_uninitialized_variables` * `dart fix --apply --code=prefer_is_empty` * `dart fix --apply --code=prefer_interpolation_to_compose_strings` * `dart fix --apply --code=prefer_final_fields` * `dart fix --apply --code=prefer_const_constructors_in_immutables` * `dart fix --apply --code=prefer_collection_literals` * `dart fix --apply --code=no_leading_underscores_for_local_identifiers` * `dart fix --apply --code=curly_braces_in_flow_control_structures` * `dart fix --apply --code=avoid_function_literals_in_foreach_calls` * `dart fix --apply --code=annotate_overrides` * Add CI for dart linting * `dart format lib/` * Re-enable the `usePathUrlStrategy` call, with proper deps https://docs.flutter.dev/ui/navigation/url-strategies#configuring-the-url-strategy
110 lines
3.4 KiB
Dart
110 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
enum SimpleScrollable { none, vertical, horizontal, both }
|
|
|
|
class SimplePage extends StatelessWidget {
|
|
const SimplePage({
|
|
super.key,
|
|
required this.title,
|
|
required this.child,
|
|
this.leadingAction,
|
|
this.trailingActions = const [],
|
|
this.scrollable = SimpleScrollable.vertical,
|
|
this.scrollbar = true,
|
|
this.scrollController,
|
|
this.bottomBar,
|
|
this.onRefresh,
|
|
this.onLoading,
|
|
this.alignment,
|
|
this.refreshController,
|
|
});
|
|
|
|
final Widget title;
|
|
final Widget child;
|
|
final SimpleScrollable scrollable;
|
|
final ScrollController? scrollController;
|
|
final AlignmentGeometry? alignment;
|
|
|
|
/// Set this to true to force draw a scrollbar without a scroll view, this is helpful for pages with Reorder-able listviews
|
|
/// This is set to true if you have any scrollable other than none
|
|
final bool scrollbar;
|
|
final Widget? bottomBar;
|
|
|
|
/// If no leading action is provided then a default "Back" widget than pops the page will be provided
|
|
final Widget? leadingAction;
|
|
final List<Widget> trailingActions;
|
|
|
|
final VoidCallback? onRefresh;
|
|
final VoidCallback? onLoading;
|
|
final RefreshController? refreshController;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Widget realChild = child;
|
|
var addScrollbar = scrollbar;
|
|
|
|
if (scrollable == SimpleScrollable.vertical || scrollable == SimpleScrollable.both) {
|
|
realChild = SingleChildScrollView(
|
|
scrollDirection: Axis.vertical,
|
|
controller: refreshController == null ? scrollController : null,
|
|
child: realChild,
|
|
);
|
|
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!,
|
|
enablePullUp: onLoading != null,
|
|
enablePullDown: onRefresh != null,
|
|
footer: ClassicFooter(loadStyle: LoadStyle.ShowWhenLoading),
|
|
child: realChild,
|
|
),
|
|
);
|
|
addScrollbar = true;
|
|
}
|
|
|
|
if (addScrollbar) {
|
|
realChild = Scrollbar(child: realChild);
|
|
}
|
|
|
|
if (alignment != null) {
|
|
realChild = Align(alignment: alignment!, child: realChild);
|
|
}
|
|
|
|
if (bottomBar != null) {
|
|
realChild = Column(children: [Expanded(child: realChild), bottomBar!]);
|
|
}
|
|
|
|
return PlatformScaffold(
|
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
|
appBar: PlatformAppBar(
|
|
title: title,
|
|
leading: leadingAction,
|
|
trailingActions: trailingActions,
|
|
cupertino:
|
|
(_, __) => CupertinoNavigationBarData(
|
|
transitionBetweenRoutes: false,
|
|
// TODO: set title on route, show here instead of just "Back"
|
|
previousPageTitle: 'Back',
|
|
padding: EdgeInsetsDirectional.only(end: 8.0),
|
|
),
|
|
),
|
|
body: SafeArea(child: realChild),
|
|
);
|
|
}
|
|
}
|