perf(app): quick slide page transitions, close work after the page leaves, instant star/close/reopen
This commit is contained in:
@@ -25,8 +25,58 @@ abstract final class AppColors {
|
||||
|
||||
const _seed = Color(0xFF6750A4);
|
||||
|
||||
ThemeData appLightTheme() =>
|
||||
ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: _seed));
|
||||
ThemeData appLightTheme() => ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: _seed),
|
||||
pageTransitionsTheme: appPageTransitions,
|
||||
);
|
||||
|
||||
/// Pages slide in and out quickly. Android's default fades the whole page,
|
||||
/// which is costly for long pages (a chat) and made Back feel slow; iOS keeps
|
||||
/// its native transition and swipe-back.
|
||||
const appPageTransitions = PageTransitionsTheme(
|
||||
builders: {
|
||||
TargetPlatform.android: FastSlidePageTransitionsBuilder(),
|
||||
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() {
|
||||
@@ -47,6 +97,7 @@ ThemeData appDarkTheme() {
|
||||
return ThemeData(
|
||||
colorScheme: scheme,
|
||||
scaffoldBackgroundColor: scheme.surface,
|
||||
pageTransitionsTheme: appPageTransitions,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user