a49b59a2bc
On a wide window (both sides at least 600 logical px) every SegmentedBar keeps the floating tab bar's 16px from the top and the sides, in every pane and page. A root WindowMargins scope adds the extra 8px to the top media padding, so Cupertino's fixed reserved bar height, list clearances, pinned headers and measured overlays all move together; the bar and the TopGlassStrip read the 16px side inset from the same scope, and sticky section chevrons keep 16px from the trailing edge. Phones keep 8/12.
110 lines
3.4 KiB
Dart
110 lines
3.4 KiB
Dart
import '../ui/adaptive/platform.dart';
|
|
import '../ui/adaptive/window_margins.dart';
|
|
import '../ui/theme/app_font_controller.dart';
|
|
import '../ui/theme/app_theme.dart';
|
|
import '../ui/scale/ui_scale.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../shell/adaptive_shell.dart';
|
|
import '../shell/destination.dart';
|
|
|
|
/// The injectable application shell. Composition supplies the live feature
|
|
/// bodies and, when it owns a route, the selected destination; widget tests
|
|
/// can continue to pass a small map or no bodies at all.
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({
|
|
super.key,
|
|
this.destinationBodies = const {},
|
|
this.cupertino,
|
|
this.destination,
|
|
this.onDestinationSelected,
|
|
this.fonts,
|
|
}) : routerConfig = null;
|
|
|
|
/// A host for a [Router]-owned location, so browser Back/Forward and deep
|
|
/// links use Flutter's multi-entry web history instead of a second, competing
|
|
/// history implementation.
|
|
const MyApp.router({
|
|
super.key,
|
|
required RouterConfig<Object> this.routerConfig,
|
|
this.cupertino,
|
|
this.fonts,
|
|
}) : destinationBodies = const {},
|
|
destination = null,
|
|
onDestinationSelected = null;
|
|
|
|
final Map<AppDestination, WidgetBuilder> destinationBodies;
|
|
final bool? cupertino;
|
|
final AppDestination? destination;
|
|
final ValueChanged<AppDestination>? onDestinationSelected;
|
|
final RouterConfig<Object>? routerConfig;
|
|
|
|
/// The device's interface font; defaults to the app's shared controller.
|
|
/// A change rebuilds the themes in place, without a restart.
|
|
final AppFontController? fonts;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final fonts = this.fonts ?? AppFontController.instance;
|
|
return ListenableBuilder(
|
|
listenable: fonts,
|
|
builder: (context, _) => _host(fonts.family),
|
|
);
|
|
}
|
|
|
|
Widget _host(String? fontFamily) {
|
|
final router = routerConfig;
|
|
if (cupertino ?? _platformIsCupertino) {
|
|
final theme = appCupertinoThemeWith(fontFamily: fontFamily);
|
|
if (router != null) {
|
|
return CupertinoApp.router(
|
|
title: 'Pipelines',
|
|
builder: _scaled,
|
|
theme: theme,
|
|
routerConfig: router,
|
|
);
|
|
}
|
|
return CupertinoApp(
|
|
title: 'Pipelines',
|
|
builder: _scaled,
|
|
theme: theme,
|
|
home: AdaptiveShell(
|
|
destinationBodies: destinationBodies,
|
|
cupertino: true,
|
|
destination: destination,
|
|
onDestinationSelected: onDestinationSelected,
|
|
),
|
|
);
|
|
}
|
|
if (router != null) {
|
|
return MaterialApp.router(
|
|
title: 'Pipelines',
|
|
builder: _scaled,
|
|
theme: appLightTheme(fontFamily: fontFamily),
|
|
darkTheme: appDarkTheme(fontFamily: fontFamily),
|
|
themeMode: ThemeMode.system,
|
|
routerConfig: router,
|
|
);
|
|
}
|
|
return MaterialApp(
|
|
title: 'Pipelines',
|
|
builder: _scaled,
|
|
theme: appLightTheme(fontFamily: fontFamily),
|
|
darkTheme: appDarkTheme(fontFamily: fontFamily),
|
|
themeMode: ThemeMode.system,
|
|
home: AdaptiveShell(
|
|
destinationBodies: destinationBodies,
|
|
destination: destination,
|
|
onDestinationSelected: onDestinationSelected,
|
|
),
|
|
);
|
|
}
|
|
|
|
bool get _platformIsCupertino => prefersCupertino();
|
|
|
|
static Widget _scaled(BuildContext context, Widget? child) => UiScaleHost(
|
|
child: WindowMargins(child: child ?? const SizedBox.shrink()),
|
|
);
|
|
}
|