Files
pipelines/app/lib/application/app.dart
T

86 lines
2.6 KiB
Dart

import '../ui/theme/app_theme.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.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,
}) : 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,
}) : 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;
@override
Widget build(BuildContext context) {
final router = routerConfig;
if (cupertino ?? _platformIsCupertino) {
if (router != null) {
return CupertinoApp.router(
title: 'Pipelines',
theme: appCupertinoTheme,
routerConfig: router,
);
}
return CupertinoApp(
title: 'Pipelines',
theme: appCupertinoTheme,
home: AdaptiveShell(
destinationBodies: destinationBodies,
cupertino: true,
destination: destination,
onDestinationSelected: onDestinationSelected,
),
);
}
if (router != null) {
return MaterialApp.router(
title: 'Pipelines',
theme: appLightTheme(),
darkTheme: appDarkTheme(),
themeMode: ThemeMode.system,
routerConfig: router,
);
}
return MaterialApp(
title: 'Pipelines',
theme: appLightTheme(),
darkTheme: appDarkTheme(),
themeMode: ThemeMode.system,
home: AdaptiveShell(
destinationBodies: destinationBodies,
destination: destination,
onDestinationSelected: onDestinationSelected,
),
);
}
bool get _platformIsCupertino =>
defaultTargetPlatform == TargetPlatform.iOS ||
defaultTargetPlatform == TargetPlatform.macOS;
}