107 lines
3.3 KiB
Dart
107 lines
3.3 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
/// The app's backgrounds. Dark mode uses a near-black gray rather than pure
|
|
/// black, so cards, sections and bars read as layers above the page.
|
|
abstract final class AppColors {
|
|
/// A page.
|
|
static const background = CupertinoDynamicColor.withBrightness(
|
|
color: Color(0xFFFFFFFF),
|
|
darkColor: Color(0xFF141416),
|
|
);
|
|
|
|
/// Behind grouped sections (Settings-style lists).
|
|
static const groupedBackground = CupertinoDynamicColor.withBrightness(
|
|
color: Color(0xFFF2F2F7),
|
|
darkColor: Color(0xFF141416),
|
|
);
|
|
|
|
/// Bars over the page.
|
|
static const bar = CupertinoDynamicColor.withBrightness(
|
|
color: Color(0xF0F9F9F9),
|
|
darkColor: Color(0xF01C1C1F),
|
|
);
|
|
}
|
|
|
|
const _seed = Color(0xFF6750A4);
|
|
|
|
ThemeData appLightTheme() => ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(seedColor: _seed),
|
|
pageTransitionsTheme: appPageTransitions,
|
|
);
|
|
|
|
/// Android and iOS keep their native transitions and interactive back gestures.
|
|
/// Desktop hosts use the short horizontal slide.
|
|
const appPageTransitions = PageTransitionsTheme(
|
|
builders: {
|
|
TargetPlatform.android: PredictiveBackPageTransitionsBuilder(),
|
|
TargetPlatform.fuchsia: FastSlidePageTransitionsBuilder(),
|
|
TargetPlatform.linux: FastSlidePageTransitionsBuilder(),
|
|
TargetPlatform.windows: FastSlidePageTransitionsBuilder(),
|
|
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
|
|
TargetPlatform.macOS: CupertinoPageTransitionsBuilder(),
|
|
},
|
|
);
|
|
|
|
/// A 200 ms horizontal slide with no fade: only the page moves, so nothing
|
|
/// has to be redrawn into an offscreen layer.
|
|
class FastSlidePageTransitionsBuilder extends PageTransitionsBuilder {
|
|
const FastSlidePageTransitionsBuilder();
|
|
|
|
@override
|
|
Duration get transitionDuration => const Duration(milliseconds: 200);
|
|
|
|
@override
|
|
Duration get reverseTransitionDuration => const Duration(milliseconds: 180);
|
|
|
|
@override
|
|
Widget buildTransitions<T>(
|
|
PageRoute<T> route,
|
|
BuildContext context,
|
|
Animation<double> animation,
|
|
Animation<double> secondaryAnimation,
|
|
Widget child,
|
|
) {
|
|
final curved = CurvedAnimation(
|
|
parent: animation,
|
|
curve: Curves.easeOutCubic,
|
|
reverseCurve: Curves.easeInCubic,
|
|
);
|
|
return SlideTransition(
|
|
position: Tween<Offset>(
|
|
begin: const Offset(1, 0),
|
|
end: Offset.zero,
|
|
).animate(curved),
|
|
child: child,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Material's dark scheme with gray surfaces stepping up from the page.
|
|
ThemeData appDarkTheme() {
|
|
final scheme =
|
|
ColorScheme.fromSeed(
|
|
seedColor: _seed,
|
|
brightness: Brightness.dark,
|
|
).copyWith(
|
|
surface: const Color(0xFF141416),
|
|
surfaceDim: const Color(0xFF141416),
|
|
surfaceBright: const Color(0xFF3A3B40),
|
|
surfaceContainerLowest: const Color(0xFF0F0F11),
|
|
surfaceContainerLow: const Color(0xFF1B1C1F),
|
|
surfaceContainer: const Color(0xFF202125),
|
|
surfaceContainerHigh: const Color(0xFF27282C),
|
|
surfaceContainerHighest: const Color(0xFF303136),
|
|
);
|
|
return ThemeData(
|
|
colorScheme: scheme,
|
|
scaffoldBackgroundColor: scheme.surface,
|
|
pageTransitionsTheme: appPageTransitions,
|
|
);
|
|
}
|
|
|
|
const appCupertinoTheme = CupertinoThemeData(
|
|
scaffoldBackgroundColor: AppColors.background,
|
|
barBackgroundColor: AppColors.bar,
|
|
);
|