Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

feat: appflowy theme lerp (#7771)

Richard Shiue28e89beb4326
diff --git a/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart b/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart
index 0ef21267aa..98b76802d4 100644
--- a/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart
+++ b/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart
@@ -234,27 +234,34 @@ class _ApplicationWidgetState extends State<ApplicationWidget> {
supportedLocales: context.supportedLocales,
locale: state.locale,
routerConfig: routerConfig,
- builder: (context, child) => AppFlowyTheme(
- data: Theme.of(context).brightness == Brightness.light
- ? AppFlowyThemeData.light()
- : AppFlowyThemeData.dark(),
- child: MediaQuery(
- // use the 1.0 as the textScaleFactor to avoid the text size
- // affected by the system setting.
- data: MediaQuery.of(context).copyWith(
- textScaler: TextScaler.linear(state.textScaleFactor),
- ),
- child: overlayManagerBuilder(
- context,
- !UniversalPlatform.isMobile && FeatureFlag.search.isOn
- ? CommandPalette(
- notifier: _commandPaletteNotifier,
- child: child,
- )
- : child,
+ builder: (context, child) {
+ final themeBuilder = AppFlowyDefaultTheme();
+ final brightness = Theme.of(context).brightness;
+
+ return AnimatedAppFlowyTheme(
+ data: brightness == Brightness.light
+ ? themeBuilder.light()
+ : themeBuilder.dark(),
+ child: MediaQuery(
+ // use the 1.0 as the textScaleFactor to avoid the text size
+ // affected by the system setting.
+ data: MediaQuery.of(context).copyWith(
+ textScaler:
+ TextScaler.linear(state.textScaleFactor),
+ ),
+ child: overlayManagerBuilder(
+ context,
+ !UniversalPlatform.isMobile &&
+ FeatureFlag.search.isOn
+ ? CommandPalette(
+ notifier: _commandPaletteNotifier,
+ child: child,
+ )
+ : child,
+ ),
),
- ),
- ),
+ );
+ },
),
),
),
diff --git a/frontend/appflowy_flutter/lib/workspace/application/settings/appearance/mobile_appearance.dart b/frontend/appflowy_flutter/lib/workspace/application/settings/appearance/mobile_appearance.dart
index eda3153459..46eddd53ab 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/settings/appearance/mobile_appearance.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/settings/appearance/mobile_appearance.dart
@@ -28,13 +28,12 @@ class MobileAppearance extends BaseAppearance {
fontWeight: FontWeight.w400,
);
+ final isLight = brightness == Brightness.light;
final codeFontStyle = getFontStyle(fontFamily: codeFontFamily);
- final theme = brightness == Brightness.light
- ? appTheme.lightTheme
- : appTheme.darkTheme;
+ final theme = isLight ? appTheme.lightTheme : appTheme.darkTheme;
- final colorTheme = brightness == Brightness.light
+ final colorTheme = isLight
? ColorScheme(
brightness: brightness,
primary: _primaryColor,
@@ -71,13 +70,9 @@ class MobileAppearance extends BaseAppearance {
onSurface: const Color(0xffC5C6C7), // text/body color
surfaceContainerHighest: theme.sidebarBg,
);
- final hintColor = brightness == Brightness.light
- ? const Color(0x991F2329)
- : _hintColorInDarkMode;
- final onBackground =
- brightness == Brightness.light ? _onBackgroundColor : Colors.white;
- final background =
- brightness == Brightness.light ? Colors.white : const Color(0xff121212);
+ final hintColor = isLight ? const Color(0x991F2329) : _hintColorInDarkMode;
+ final onBackground = isLight ? _onBackgroundColor : Colors.white;
+ final background = isLight ? Colors.white : const Color(0xff121212);
return ThemeData(
useMaterial3: false,
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/example/lib/main.dart b/frontend/appflowy_flutter/packages/appflowy_ui/example/lib/main.dart
index c02001745d..0d23746ebd 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/example/lib/main.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/example/lib/main.dart
@@ -26,16 +26,20 @@ class MyApp extends StatelessWidget {
return ValueListenableBuilder(
valueListenable: themeMode,
builder: (context, themeMode, child) {
+ final themeBuilder = AppFlowyDefaultTheme();
final themeData =
themeMode == ThemeMode.light ? ThemeData.light() : ThemeData.dark();
- return AppFlowyTheme(
+
+ return AnimatedAppFlowyTheme(
data: themeMode == ThemeMode.light
- ? AppFlowyThemeData.light()
- : AppFlowyThemeData.dark(),
+ ? themeBuilder.light()
+ : themeBuilder.dark(),
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'AppFlowy UI Example',
- theme: themeData.copyWith(visualDensity: VisualDensity.standard),
+ theme: themeData.copyWith(
+ visualDensity: VisualDensity.standard,
+ ),
home: const MyHomePage(
title: 'AppFlowy UI',
),
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/textfield/textfield.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/textfield/textfield.dart
index 9e61b71709..3f5ad4cfed 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/textfield/textfield.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/textfield/textfield.dart
@@ -233,7 +233,7 @@ enum AFTextFieldSize {
m,
l;
- EdgeInsetsGeometry contentPadding(AppFlowyBaseThemeData theme) {
+ EdgeInsetsGeometry contentPadding(AppFlowyThemeData theme) {
return EdgeInsets.symmetric(
vertical: switch (this) {
AFTextFieldSize.m => theme.spacing.s,
@@ -243,7 +243,7 @@ enum AFTextFieldSize {
);
}
- BorderRadius borderRadius(AppFlowyBaseThemeData theme) {
+ BorderRadius borderRadius(AppFlowyThemeData theme) {
return BorderRadius.circular(
switch (this) {
AFTextFieldSize.m => theme.borderRadius.m,
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/appflowy_theme.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/appflowy_theme.dart
index 8a99b737ec..26e45ca8f1 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/appflowy_theme.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/appflowy_theme.dart
@@ -1,5 +1,6 @@
-import 'package:appflowy_ui/src/theme/definition/base_theme.dart';
-import 'package:flutter/widgets.dart';
+import 'package:appflowy_ui/src/theme/theme.dart';
+import 'package:flutter/foundation.dart';
+import 'package:flutter/material.dart';
class AppFlowyTheme extends StatelessWidget {
const AppFlowyTheme({
@@ -8,10 +9,10 @@ class AppFlowyTheme extends StatelessWidget {
required this.child,
});
- final AppFlowyBaseThemeData data;
+ final AppFlowyThemeData data;
final Widget child;
- static AppFlowyBaseThemeData of(BuildContext context, {bool listen = true}) {
+ static AppFlowyThemeData of(BuildContext context, {bool listen = true}) {
final provider = maybeOf(context, listen: listen);
if (provider == null) {
throw FlutterError(
@@ -26,26 +27,26 @@ class AppFlowyTheme extends StatelessWidget {
return provider;
}
- static AppFlowyBaseThemeData? maybeOf(
+ static AppFlowyThemeData? maybeOf(
BuildContext context, {
bool listen = true,
}) {
if (listen) {
return context
.dependOnInheritedWidgetOfExactType<AppFlowyInheritedTheme>()
- ?.theme;
+ ?.themeData;
}
final provider = context
.getElementForInheritedWidgetOfExactType<AppFlowyInheritedTheme>()
?.widget;
- return (provider as AppFlowyInheritedTheme?)?.theme;
+ return (provider as AppFlowyInheritedTheme?)?.themeData;
}
@override
Widget build(BuildContext context) {
return AppFlowyInheritedTheme(
- theme: data,
+ themeData: data,
child: child,
);
}
@@ -54,18 +55,98 @@ class AppFlowyTheme extends StatelessWidget {
class AppFlowyInheritedTheme extends InheritedTheme {
const AppFlowyInheritedTheme({
super.key,
- required this.theme,
+ required this.themeData,
required super.child,
});
- final AppFlowyBaseThemeData theme;
+ final AppFlowyThemeData themeData;
@override
Widget wrap(BuildContext context, Widget child) {
- return AppFlowyTheme(data: theme, child: child);
+ return AppFlowyTheme(data: themeData, child: child);
}
@override
bool updateShouldNotify(AppFlowyInheritedTheme oldWidget) =>
- theme != oldWidget.theme;
+ themeData != oldWidget.themeData;
+}
+
+/// An interpolation between two [AppFlowyThemeData]s.
+///
+/// This class specializes the interpolation of [Tween<AppFlowyThemeData>] to
+/// call the [AppFlowyThemeData.lerp] method.
+///
+/// See [Tween] for a discussion on how to use interpolation objects.
+class AppFlowyThemeDataTween extends Tween<AppFlowyThemeData> {
+ /// Creates a [AppFlowyThemeData] tween.
+ ///
+ /// The [begin] and [end] properties must be non-null before the tween is
+ /// first used, but the arguments can be null if the values are going to be
+ /// filled in later.
+ AppFlowyThemeDataTween({super.begin, super.end});
+
+ @override
+ AppFlowyThemeData lerp(double t) => AppFlowyThemeData.lerp(begin!, end!, t);
+}
+
+class AnimatedAppFlowyTheme extends ImplicitlyAnimatedWidget {
+ /// Creates an animated theme.
+ ///
+ /// By default, the theme transition uses a linear curve.
+ const AnimatedAppFlowyTheme({
+ super.key,
+ required this.data,
+ super.curve,
+ super.duration = kThemeAnimationDuration,
+ super.onEnd,
+ required this.child,
+ });
+
+ /// Specifies the color and typography values for descendant widgets.
+ final AppFlowyThemeData data;
+
+ /// The widget below this widget in the tree.
+ ///
+ /// {@macro flutter.widgets.ProxyWidget.child}
+ final Widget child;
+
+ @override
+ AnimatedWidgetBaseState<AnimatedAppFlowyTheme> createState() =>
+ _AnimatedThemeState();
+}
+
+class _AnimatedThemeState
+ extends AnimatedWidgetBaseState<AnimatedAppFlowyTheme> {
+ AppFlowyThemeDataTween? data;
+
+ @override
+ void forEachTween(TweenVisitor<dynamic> visitor) {
+ data = visitor(
+ data,
+ widget.data,
+ (dynamic value) =>
+ AppFlowyThemeDataTween(begin: value as AppFlowyThemeData),
+ )! as AppFlowyThemeDataTween;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return AppFlowyTheme(
+ data: data!.evaluate(animation),
+ child: widget.child,
+ );
+ }
+
+ @override
+ void debugFillProperties(DiagnosticPropertiesBuilder description) {
+ super.debugFillProperties(description);
+ description.add(
+ DiagnosticsProperty<AppFlowyThemeDataTween>(
+ 'data',
+ data,
+ showName: false,
+ defaultValue: null,
+ ),
+ );
+ }
}
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/appflowy_default/primitive.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/appflowy_default/primitive.dart
index 1eee06953f..790db31660 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/appflowy_default/primitive.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/appflowy_default/primitive.dart
@@ -3,7 +3,7 @@
// AUTO-GENERATED - DO NOT EDIT DIRECTLY
//
// This file is auto-generated by the generate_theme.dart script
-// Generation time: 2025-04-15T23:05:39.278903
+// Generation time: 2025-04-16T22:13:33.297893
//
// To modify these colors, edit the source JSON files and run the script:
//
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/appflowy_default/semantic.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/appflowy_default/semantic.dart
index 08206a6572..03e80da962 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/appflowy_default/semantic.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/appflowy_default/semantic.dart
@@ -3,7 +3,7 @@
// AUTO-GENERATED - DO NOT EDIT DIRECTLY
//
// This file is auto-generated by the generate_theme.dart script
-// Generation time: 2025-04-15T23:05:39.288085
+// Generation time: 2025-04-16T22:13:33.307397
//
// To modify these colors, edit the source JSON files and run the script:
//
@@ -12,30 +12,16 @@
import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:flutter/material.dart';
-import '../builder.dart';
+import '../shared.dart';
import 'primitive.dart';
-class AppFlowyThemeData implements AppFlowyBaseThemeData {
- const AppFlowyThemeData._({
- required this.textStyle,
- required this.textColorScheme,
- required this.borderColorScheme,
- required this.fillColorScheme,
- required this.surfaceColorScheme,
- required this.borderRadius,
- required this.spacing,
- required this.shadow,
- required this.brandColorScheme,
- required this.iconColorScheme,
- required this.backgroundColorScheme,
- required this.otherColorsColorScheme,
- });
-
- factory AppFlowyThemeData.light() {
+class AppFlowyDefaultTheme implements AppFlowyThemeBuilder {
+ @override
+ AppFlowyThemeData light() {
final textStyle = AppFlowyBaseTextStyle();
- final borderRadius = themeBuilder.buildBorderRadius();
- final spacing = themeBuilder.buildSpacing();
- final shadow = themeBuilder.buildShadow(Brightness.light);
+ final borderRadius = AppFlowySharedTokens.buildBorderRadius();
+ final spacing = AppFlowySharedTokens.buildSpacing();
+ final shadow = AppFlowySharedTokens.buildShadow(Brightness.light);
final textColorScheme = AppFlowyTextColorScheme(
primary: AppFlowyPrimitiveTokens.neutral1000,
@@ -168,7 +154,7 @@ class AppFlowyThemeData implements AppFlowyBaseThemeData {
textHighlight: AppFlowyPrimitiveTokens.blue200,
);
- return AppFlowyThemeData._(
+ return AppFlowyThemeData(
textStyle: textStyle,
textColorScheme: textColorScheme,
borderColorScheme: borderColorScheme,
@@ -184,11 +170,12 @@ class AppFlowyThemeData implements AppFlowyBaseThemeData {
);
}
- factory AppFlowyThemeData.dark() {
+ @override
+ AppFlowyThemeData dark() {
final textStyle = AppFlowyBaseTextStyle();
- final borderRadius = themeBuilder.buildBorderRadius();
- final spacing = themeBuilder.buildSpacing();
- final shadow = themeBuilder.buildShadow(Brightness.dark);
+ final borderRadius = AppFlowySharedTokens.buildBorderRadius();
+ final spacing = AppFlowySharedTokens.buildSpacing();
+ final shadow = AppFlowySharedTokens.buildShadow(Brightness.dark);
final textColorScheme = AppFlowyTextColorScheme(
primary: AppFlowyPrimitiveTokens.neutral200,
@@ -321,7 +308,7 @@ class AppFlowyThemeData implements AppFlowyBaseThemeData {
textHighlight: AppFlowyPrimitiveTokens.blue200,
);
- return AppFlowyThemeData._(
+ return AppFlowyThemeData(
textStyle: textStyle,
textColorScheme: textColorScheme,
borderColorScheme: borderColorScheme,
@@ -336,42 +323,4 @@ class AppFlowyThemeData implements AppFlowyBaseThemeData {
shadow: shadow,
);
}
-
- static const AppFlowyThemeBuilder themeBuilder = AppFlowyThemeBuilder();
-
- @override
- final AppFlowyBaseTextStyle textStyle;
-
- @override
- final AppFlowyTextColorScheme textColorScheme;
-
- @override
- final AppFlowyBorderColorScheme borderColorScheme;
-
- @override
- final AppFlowyFillColorScheme fillColorScheme;
-
- @override
- final AppFlowySurfaceColorScheme surfaceColorScheme;
-
- @override
- final AppFlowyBorderRadius borderRadius;
-
- @override
- final AppFlowySpacing spacing;
-
- @override
- final AppFlowyShadow shadow;
-
- @override
- final AppFlowyBrandColorScheme brandColorScheme;
-
- @override
- final AppFlowyIconColorScheme iconColorScheme;
-
- @override
- final AppFlowyBackgroundColorScheme backgroundColorScheme;
-
- @override
- final AppFlowyOtherColorsColorScheme otherColorsColorScheme;
}
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/custom/custom_theme.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/custom/custom_theme.dart
new file mode 100644
index 0000000000..6ef43076c5
--- /dev/null
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/custom/custom_theme.dart
@@ -0,0 +1,23 @@
+import 'package:appflowy_ui/appflowy_ui.dart';
+
+class CustomTheme implements AppFlowyThemeBuilder {
+ const CustomTheme({
+ required this.lightThemeJson,
+ required this.darkThemeJson,
+ });
+
+ final Map<String, dynamic> lightThemeJson;
+ final Map<String, dynamic> darkThemeJson;
+
+ @override
+ AppFlowyThemeData light() {
+ // TODO: implement light
+ throw UnimplementedError();
+ }
+
+ @override
+ AppFlowyThemeData dark() {
+ // TODO: implement dark
+ throw UnimplementedError();
+ }
+}
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/builder.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/shared.dart
similarity index 92%
rename from frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/builder.dart
rename to frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/shared.dart
index a4f83109cb..c9c3c3adb0 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/builder.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/shared.dart
@@ -21,10 +21,10 @@ class AppFlowyBorderRadiusConstant {
static const double radius600 = 20;
}
-class AppFlowyThemeBuilder {
- const AppFlowyThemeBuilder();
+class AppFlowySharedTokens {
+ const AppFlowySharedTokens();
- AppFlowyBorderRadius buildBorderRadius() {
+ static AppFlowyBorderRadius buildBorderRadius() {
return AppFlowyBorderRadius(
xs: AppFlowyBorderRadiusConstant.radius100,
s: AppFlowyBorderRadiusConstant.radius200,
@@ -35,7 +35,7 @@ class AppFlowyThemeBuilder {
);
}
- AppFlowySpacing buildSpacing() {
+ static AppFlowySpacing buildSpacing() {
return AppFlowySpacing(
xs: AppFlowySpacingConstant.spacing100,
s: AppFlowySpacingConstant.spacing200,
@@ -46,7 +46,7 @@ class AppFlowyThemeBuilder {
);
}
- AppFlowyShadow buildShadow(
+ static AppFlowyShadow buildShadow(
Brightness brightness,
) {
return switch (brightness) {
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/base_theme.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/base_theme.dart
deleted file mode 100644
index ca06c8da1b..0000000000
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/base_theme.dart
+++ /dev/null
@@ -1,33 +0,0 @@
-import 'border_radius/border_radius.dart';
-import 'color_scheme/color_scheme.dart';
-import 'shadow/shadow.dart';
-import 'spacing/spacing.dart';
-import 'text_style/text_style.dart';
-
-abstract class AppFlowyBaseThemeData {
- const AppFlowyBaseThemeData();
-
- AppFlowyTextColorScheme get textColorScheme;
-
- AppFlowyBaseTextStyle get textStyle;
-
- AppFlowyIconColorScheme get iconColorScheme;
-
- AppFlowyBorderColorScheme get borderColorScheme;
-
- AppFlowyBackgroundColorScheme get backgroundColorScheme;
-
- AppFlowyFillColorScheme get fillColorScheme;
-
- AppFlowySurfaceColorScheme get surfaceColorScheme;
-
- AppFlowyBorderRadius get borderRadius;
-
- AppFlowySpacing get spacing;
-
- AppFlowyShadow get shadow;
-
- AppFlowyBrandColorScheme get brandColorScheme;
-
- AppFlowyOtherColorsColorScheme get otherColorsColorScheme;
-}
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/background_color_scheme.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/background_color_scheme.dart
index 547c7f1635..c7324c34fe 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/background_color_scheme.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/background_color_scheme.dart
@@ -12,4 +12,16 @@ class AppFlowyBackgroundColorScheme {
final Color secondary;
final Color tertiary;
final Color quaternary;
+
+ AppFlowyBackgroundColorScheme lerp(
+ AppFlowyBackgroundColorScheme other,
+ double t,
+ ) {
+ return AppFlowyBackgroundColorScheme(
+ primary: Color.lerp(primary, other.primary, t)!,
+ secondary: Color.lerp(secondary, other.secondary, t)!,
+ tertiary: Color.lerp(tertiary, other.tertiary, t)!,
+ quaternary: Color.lerp(quaternary, other.quaternary, t)!,
+ );
+ }
}
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/border_color_scheme.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/border_color_scheme.dart
index d1618b6cff..28eee5b145 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/border_color_scheme.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/border_color_scheme.dart
@@ -46,4 +46,40 @@ class AppFlowyBorderColorScheme {
final Color errorThickHover;
final Color purpleThick;
final Color purpleThickHover;
+
+ AppFlowyBorderColorScheme lerp(
+ AppFlowyBorderColorScheme other,
+ double t,
+ ) {
+ return AppFlowyBorderColorScheme(
+ greyPrimary: Color.lerp(greyPrimary, other.greyPrimary, t)!,
+ greyPrimaryHover:
+ Color.lerp(greyPrimaryHover, other.greyPrimaryHover, t)!,
+ greySecondary: Color.lerp(greySecondary, other.greySecondary, t)!,
+ greySecondaryHover:
+ Color.lerp(greySecondaryHover, other.greySecondaryHover, t)!,
+ greyTertiary: Color.lerp(greyTertiary, other.greyTertiary, t)!,
+ greyTertiaryHover:
+ Color.lerp(greyTertiaryHover, other.greyTertiaryHover, t)!,
+ greyQuaternary: Color.lerp(greyQuaternary, other.greyQuaternary, t)!,
+ greyQuaternaryHover:
+ Color.lerp(greyQuaternaryHover, other.greyQuaternaryHover, t)!,
+ transparent: Color.lerp(transparent, other.transparent, t)!,
+ themeThick: Color.lerp(themeThick, other.themeThick, t)!,
+ themeThickHover: Color.lerp(themeThickHover, other.themeThickHover, t)!,
+ infoThick: Color.lerp(infoThick, other.infoThick, t)!,
+ infoThickHover: Color.lerp(infoThickHover, other.infoThickHover, t)!,
+ successThick: Color.lerp(successThick, other.successThick, t)!,
+ successThickHover:
+ Color.lerp(successThickHover, other.successThickHover, t)!,
+ warningThick: Color.lerp(warningThick, other.warningThick, t)!,
+ warningThickHover:
+ Color.lerp(warningThickHover, other.warningThickHover, t)!,
+ errorThick: Color.lerp(errorThick, other.errorThick, t)!,
+ errorThickHover: Color.lerp(errorThickHover, other.errorThickHover, t)!,
+ purpleThick: Color.lerp(purpleThick, other.purpleThick, t)!,
+ purpleThickHover:
+ Color.lerp(purpleThickHover, other.purpleThickHover, t)!,
+ );
+ }
}
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/brand_color_scheme.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/brand_color_scheme.dart
index 8374d2bbfd..4140f6924a 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/brand_color_scheme.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/brand_color_scheme.dart
@@ -22,4 +22,21 @@ class AppFlowyBrandColorScheme {
final Color golden;
final Color amber;
final Color lemon;
+
+ AppFlowyBrandColorScheme lerp(
+ AppFlowyBrandColorScheme other,
+ double t,
+ ) {
+ return AppFlowyBrandColorScheme(
+ skyline: Color.lerp(skyline, other.skyline, t)!,
+ aqua: Color.lerp(aqua, other.aqua, t)!,
+ violet: Color.lerp(violet, other.violet, t)!,
+ amethyst: Color.lerp(amethyst, other.amethyst, t)!,
+ berry: Color.lerp(berry, other.berry, t)!,
+ coral: Color.lerp(coral, other.coral, t)!,
+ golden: Color.lerp(golden, other.golden, t)!,
+ amber: Color.lerp(amber, other.amber, t)!,
+ lemon: Color.lerp(lemon, other.lemon, t)!,
+ );
+ }
}
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/fill_color_scheme.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/fill_color_scheme.dart
index 8616bde4eb..3faac64dfc 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/fill_color_scheme.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/fill_color_scheme.dart
@@ -90,4 +90,63 @@ class AppFlowyFillColorScheme {
final Color purpleLightHover;
final Color purpleThick;
final Color purpleThickHover;
+
+ AppFlowyFillColorScheme lerp(
+ AppFlowyFillColorScheme other,
+ double t,
+ ) {
+ return AppFlowyFillColorScheme(
+ primary: Color.lerp(primary, other.primary, t)!,
+ primaryHover: Color.lerp(primaryHover, other.primaryHover, t)!,
+ secondary: Color.lerp(secondary, other.secondary, t)!,
+ secondaryHover: Color.lerp(secondaryHover, other.secondaryHover, t)!,
+ tertiary: Color.lerp(tertiary, other.tertiary, t)!,
+ tertiaryHover: Color.lerp(tertiaryHover, other.tertiaryHover, t)!,
+ quaternary: Color.lerp(quaternary, other.quaternary, t)!,
+ quaternaryHover: Color.lerp(quaternaryHover, other.quaternaryHover, t)!,
+ transparent: Color.lerp(transparent, other.transparent, t)!,
+ primaryAlpha5: Color.lerp(primaryAlpha5, other.primaryAlpha5, t)!,
+ primaryAlpha5Hover:
+ Color.lerp(primaryAlpha5Hover, other.primaryAlpha5Hover, t)!,
+ primaryAlpha80: Color.lerp(primaryAlpha80, other.primaryAlpha80, t)!,
+ primaryAlpha80Hover:
+ Color.lerp(primaryAlpha80Hover, other.primaryAlpha80Hover, t)!,
+ white: Color.lerp(white, other.white, t)!,
+ whiteAlpha: Color.lerp(whiteAlpha, other.whiteAlpha, t)!,
+ whiteAlphaHover: Color.lerp(whiteAlphaHover, other.whiteAlphaHover, t)!,
+ black: Color.lerp(black, other.black, t)!,
+ themeLight: Color.lerp(themeLight, other.themeLight, t)!,
+ themeLightHover: Color.lerp(themeLightHover, other.themeLightHover, t)!,
+ themeThick: Color.lerp(themeThick, other.themeThick, t)!,
+ themeThickHover: Color.lerp(themeThickHover, other.themeThickHover, t)!,
+ themeSelect: Color.lerp(themeSelect, other.themeSelect, t)!,
+ infoLight: Color.lerp(infoLight, other.infoLight, t)!,
+ infoLightHover: Color.lerp(infoLightHover, other.infoLightHover, t)!,
+ infoThick: Color.lerp(infoThick, other.infoThick, t)!,
+ infoThickHover: Color.lerp(infoThickHover, other.infoThickHover, t)!,
+ successLight: Color.lerp(successLight, other.successLight, t)!,
+ successLightHover:
+ Color.lerp(successLightHover, other.successLightHover, t)!,
+ successThick: Color.lerp(successThick, other.successThick, t)!,
+ successThickHover:
+ Color.lerp(successThickHover, other.successThickHover, t)!,
+ warningLight: Color.lerp(warningLight, other.warningLight, t)!,
+ warningLightHover:
+ Color.lerp(warningLightHover, other.warningLightHover, t)!,
+ warningThick: Color.lerp(warningThick, other.warningThick, t)!,
+ warningThickHover:
+ Color.lerp(warningThickHover, other.warningThickHover, t)!,
+ errorLight: Color.lerp(errorLight, other.errorLight, t)!,
+ errorLightHover: Color.lerp(errorLightHover, other.errorLightHover, t)!,
+ errorThick: Color.lerp(errorThick, other.errorThick, t)!,
+ errorThickHover: Color.lerp(errorThickHover, other.errorThickHover, t)!,
+ errorSelect: Color.lerp(errorSelect, other.errorSelect, t)!,
+ purpleLight: Color.lerp(purpleLight, other.purpleLight, t)!,
+ purpleLightHover:
+ Color.lerp(purpleLightHover, other.purpleLightHover, t)!,
+ purpleThick: Color.lerp(purpleThick, other.purpleThick, t)!,
+ purpleThickHover:
+ Color.lerp(purpleThickHover, other.purpleThickHover, t)!,
+ );
+ }
}
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/icon_color_scheme.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/icon_color_scheme.dart
index 245a02aadb..efe59b8b99 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/icon_color_scheme.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/icon_color_scheme.dart
@@ -18,4 +18,20 @@ class AppFlowyIconColorScheme {
final Color white;
final Color purpleThick;
final Color purpleThickHover;
+
+ AppFlowyIconColorScheme lerp(
+ AppFlowyIconColorScheme other,
+ double t,
+ ) {
+ return AppFlowyIconColorScheme(
+ primary: Color.lerp(primary, other.primary, t)!,
+ secondary: Color.lerp(secondary, other.secondary, t)!,
+ tertiary: Color.lerp(tertiary, other.tertiary, t)!,
+ quaternary: Color.lerp(quaternary, other.quaternary, t)!,
+ white: Color.lerp(white, other.white, t)!,
+ purpleThick: Color.lerp(purpleThick, other.purpleThick, t)!,
+ purpleThickHover:
+ Color.lerp(purpleThickHover, other.purpleThickHover, t)!,
+ );
+ }
}
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/other_color_scheme.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/other_color_scheme.dart
index ed9b94695c..9bb21e54e6 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/other_color_scheme.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/other_color_scheme.dart
@@ -6,4 +6,13 @@ class AppFlowyOtherColorsColorScheme {
});
final Color textHighlight;
+
+ AppFlowyOtherColorsColorScheme lerp(
+ AppFlowyOtherColorsColorScheme other,
+ double t,
+ ) {
+ return AppFlowyOtherColorsColorScheme(
+ textHighlight: Color.lerp(textHighlight, other.textHighlight, t)!,
+ );
+ }
}
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/surface_color_scheme.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/surface_color_scheme.dart
index 8fdc21adef..67be450a04 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/surface_color_scheme.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/surface_color_scheme.dart
@@ -8,4 +8,14 @@ class AppFlowySurfaceColorScheme {
final Color primary;
final Color overlay;
+
+ AppFlowySurfaceColorScheme lerp(
+ AppFlowySurfaceColorScheme other,
+ double t,
+ ) {
+ return AppFlowySurfaceColorScheme(
+ primary: Color.lerp(primary, other.primary, t)!,
+ overlay: Color.lerp(overlay, other.overlay, t)!,
+ );
+ }
}
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/text_color_scheme.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/text_color_scheme.dart
index 486378643f..17e1f057ce 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/text_color_scheme.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/color_scheme/text_color_scheme.dart
@@ -44,4 +44,32 @@ class AppFlowyTextColorScheme {
final Color errorHover;
final Color purple;
final Color purpleHover;
+
+ AppFlowyTextColorScheme lerp(
+ AppFlowyTextColorScheme other,
+ double t,
+ ) {
+ return AppFlowyTextColorScheme(
+ primary: Color.lerp(primary, other.primary, t)!,
+ secondary: Color.lerp(secondary, other.secondary, t)!,
+ tertiary: Color.lerp(tertiary, other.tertiary, t)!,
+ quaternary: Color.lerp(quaternary, other.quaternary, t)!,
+ inverse: Color.lerp(inverse, other.inverse, t)!,
+ onFill: Color.lerp(onFill, other.onFill, t)!,
+ theme: Color.lerp(theme, other.theme, t)!,
+ themeHover: Color.lerp(themeHover, other.themeHover, t)!,
+ action: Color.lerp(action, other.action, t)!,
+ actionHover: Color.lerp(actionHover, other.actionHover, t)!,
+ info: Color.lerp(info, other.info, t)!,
+ infoHover: Color.lerp(infoHover, other.infoHover, t)!,
+ success: Color.lerp(success, other.success, t)!,
+ successHover: Color.lerp(successHover, other.successHover, t)!,
+ warning: Color.lerp(warning, other.warning, t)!,
+ warningHover: Color.lerp(warningHover, other.warningHover, t)!,
+ error: Color.lerp(error, other.error, t)!,
+ errorHover: Color.lerp(errorHover, other.errorHover, t)!,
+ purple: Color.lerp(purple, other.purple, t)!,
+ purpleHover: Color.lerp(purpleHover, other.purpleHover, t)!,
+ );
+ }
}
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/theme_data.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/theme_data.dart
new file mode 100644
index 0000000000..515e6b2ecf
--- /dev/null
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/definition/theme_data.dart
@@ -0,0 +1,86 @@
+import 'border_radius/border_radius.dart';
+import 'color_scheme/color_scheme.dart';
+import 'shadow/shadow.dart';
+import 'spacing/spacing.dart';
+import 'text_style/text_style.dart';
+
+/// [AppFlowyThemeData] defines the structure of the design system, and contains
+/// the data that all child widgets will have access to.
+class AppFlowyThemeData {
+ const AppFlowyThemeData({
+ required this.textColorScheme,
+ required this.textStyle,
+ required this.iconColorScheme,
+ required this.borderColorScheme,
+ required this.backgroundColorScheme,
+ required this.fillColorScheme,
+ required this.surfaceColorScheme,
+ required this.borderRadius,
+ required this.spacing,
+ required this.shadow,
+ required this.brandColorScheme,
+ required this.otherColorsColorScheme,
+ });
+
+ final AppFlowyTextColorScheme textColorScheme;
+
+ final AppFlowyBaseTextStyle textStyle;
+
+ final AppFlowyIconColorScheme iconColorScheme;
+
+ final AppFlowyBorderColorScheme borderColorScheme;
+
+ final AppFlowyBackgroundColorScheme backgroundColorScheme;
+
+ final AppFlowyFillColorScheme fillColorScheme;
+
+ final AppFlowySurfaceColorScheme surfaceColorScheme;
+
+ final AppFlowyBorderRadius borderRadius;
+
+ final AppFlowySpacing spacing;
+
+ final AppFlowyShadow shadow;
+
+ final AppFlowyBrandColorScheme brandColorScheme;
+
+ final AppFlowyOtherColorsColorScheme otherColorsColorScheme;
+
+ static AppFlowyThemeData lerp(
+ AppFlowyThemeData begin,
+ AppFlowyThemeData end,
+ double t,
+ ) {
+ return AppFlowyThemeData(
+ textColorScheme: begin.textColorScheme.lerp(end.textColorScheme, t),
+ textStyle: end.textStyle,
+ iconColorScheme: begin.iconColorScheme.lerp(end.iconColorScheme, t),
+ borderColorScheme: begin.borderColorScheme.lerp(end.borderColorScheme, t),
+ backgroundColorScheme:
+ begin.backgroundColorScheme.lerp(end.backgroundColorScheme, t),
+ fillColorScheme: begin.fillColorScheme.lerp(end.fillColorScheme, t),
+ surfaceColorScheme:
+ begin.surfaceColorScheme.lerp(end.surfaceColorScheme, t),
+ borderRadius: end.borderRadius,
+ spacing: end.spacing,
+ shadow: end.shadow,
+ brandColorScheme: begin.brandColorScheme.lerp(end.brandColorScheme, t),
+ otherColorsColorScheme:
+ begin.otherColorsColorScheme.lerp(end.otherColorsColorScheme, t),
+ );
+ }
+}
+
+/// [AppFlowyThemeBuilder] is used to build the light and dark themes. Extend
+/// this class to create a built-in theme, or use the [CustomTheme] class to
+/// create a custom theme from JSON data.
+///
+/// See also:
+///
+/// - [AppFlowyThemeData] for the main theme data class.
+abstract class AppFlowyThemeBuilder {
+ const AppFlowyThemeBuilder();
+
+ AppFlowyThemeData light();
+ AppFlowyThemeData dark();
+}
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/theme.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/theme.dart
index 5f9f66cd2d..000b7a0372 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/theme.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/theme.dart
@@ -2,7 +2,7 @@ export 'appflowy_theme.dart';
export 'data/built_in_themes.dart';
export 'definition/border_radius/border_radius.dart';
export 'definition/color_scheme/color_scheme.dart';
-export 'definition/base_theme.dart';
+export 'definition/theme_data.dart';
export 'definition/spacing/spacing.dart';
export 'definition/shadow/shadow.dart';
export 'definition/text_style/text_style.dart';
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/script/generate_theme.dart b/frontend/appflowy_flutter/packages/appflowy_ui/script/generate_theme.dart
index 9c9c8a45ff..9d429f537e 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/script/generate_theme.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/script/generate_theme.dart
@@ -1,3 +1,5 @@
+// ignore_for_file: avoid_print, depend_on_referenced_packages
+
import 'dart:convert';
import 'dart:io';
@@ -90,34 +92,20 @@ void generateSemantic() {
import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:flutter/material.dart';
-import '../builder.dart';
+import '../shared.dart';
import 'primitive.dart';
-class AppFlowyThemeData implements AppFlowyBaseThemeData {
- const AppFlowyThemeData._({
- required this.textStyle,
- required this.textColorScheme,
- required this.borderColorScheme,
- required this.fillColorScheme,
- required this.surfaceColorScheme,
- required this.borderRadius,
- required this.spacing,
- required this.shadow,
- required this.brandColorScheme,
- required this.iconColorScheme,
- required this.backgroundColorScheme,
- required this.otherColorsColorScheme,
- });
-''');
+class AppFlowyDefaultTheme implements AppFlowyThemeBuilder {''');
// 3. Process light mode semantic tokens
- void writeThemeFactory(String brightness, Map<String, dynamic> jsonData) {
+ void writeThemeData(String brightness, Map<String, dynamic> jsonData) {
buffer.writeln('''
- factory AppFlowyThemeData.$brightness() {
+ @override
+ AppFlowyThemeData $brightness() {
final textStyle = AppFlowyBaseTextStyle();
- final borderRadius = themeBuilder.buildBorderRadius();
- final spacing = themeBuilder.buildSpacing();
- final shadow = themeBuilder.buildShadow(Brightness.$brightness);''');
+ final borderRadius = AppFlowySharedTokens.buildBorderRadius();
+ final spacing = AppFlowySharedTokens.buildSpacing();
+ final shadow = AppFlowySharedTokens.buildShadow(Brightness.$brightness);''');
jsonData.forEach((categoryName, categoryData) {
if (categoryData is Map<String, dynamic>) {
@@ -165,7 +153,7 @@ class AppFlowyThemeData implements AppFlowyBaseThemeData {
buffer.writeln();
buffer.writeln('''
- return AppFlowyThemeData._(
+ return AppFlowyThemeData(
textStyle: textStyle,
textColorScheme: textColorScheme,
borderColorScheme: borderColorScheme,
@@ -182,49 +170,9 @@ class AppFlowyThemeData implements AppFlowyBaseThemeData {
}''');
}
- writeThemeFactory('light', lightJsonData);
+ writeThemeData('light', lightJsonData);
buffer.writeln();
- writeThemeFactory('dark', darkJsonData);
-
- buffer.writeln('''
-
- static const AppFlowyThemeBuilder themeBuilder = AppFlowyThemeBuilder();
-
- @override
- final AppFlowyBaseTextStyle textStyle;
-
- @override
- final AppFlowyTextColorScheme textColorScheme;
-
- @override
- final AppFlowyBorderColorScheme borderColorScheme;
-
- @override
- final AppFlowyFillColorScheme fillColorScheme;
-
- @override
- final AppFlowySurfaceColorScheme surfaceColorScheme;
-
- @override
- final AppFlowyBorderRadius borderRadius;
-
- @override
- final AppFlowySpacing spacing;
-
- @override
- final AppFlowyShadow shadow;
-
- @override
- final AppFlowyBrandColorScheme brandColorScheme;
-
- @override
- final AppFlowyIconColorScheme iconColorScheme;
-
- @override
- final AppFlowyBackgroundColorScheme backgroundColorScheme;
-
- @override
- final AppFlowyOtherColorsColorScheme otherColorsColorScheme;''');
+ writeThemeData('dark', darkJsonData);
buffer.writeln('}');
// 4. Write the output to a Dart file.