Skip to content

Commit 1252915

Browse files
committed
theme [nfc]: Collect Figma design variables into one new ThemeExtension
It's possible that there's a different organization we may end up preferring -- for example, if we find ourselves wanting to create our own variables that are not in the Figma design. But this seems like a helpful thing to try, for paving the way to implement the Figma design.
1 parent f0c1db7 commit 1252915

File tree

1 file changed

+77
-8
lines changed

1 file changed

+77
-8
lines changed

lib/widgets/theme.dart

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,27 @@ import 'content.dart';
44
import 'text.dart';
55

66
ThemeData zulipThemeData(BuildContext context) {
7+
final designVariables = DesignVariables();
78
return ThemeData(
89
typography: zulipTypography(context),
9-
extensions: [ContentTheme(context)],
10+
extensions: [ContentTheme(context), designVariables],
1011
appBarTheme: AppBarTheme(
1112
// Set these two fields to prevent a color change in [AppBar]s when
1213
// there is something scrolled under it. If an app bar hasn't been
1314
// given a backgroundColor directly or by theme, it uses
1415
// ColorScheme.surfaceContainer for the scrolled-under state and
1516
// ColorScheme.surface otherwise, and those are different colors.
1617
scrolledUnderElevation: 0,
17-
backgroundColor: const Color(0xfff5f5f5), // `bg-top-bar` in Figma
18+
backgroundColor: designVariables.bgTopBar,
1819

1920
// TODO match layout to Figma
20-
actionsIconTheme: const IconThemeData(
21-
color: Color(0xff666699), // `icon` in Figma
21+
actionsIconTheme: IconThemeData(
22+
color: designVariables.icon,
2223
),
2324

2425
titleTextStyle: TextStyle(
2526
inherit: false,
26-
color: const Color(0xff1a1a1a), // `title` in Figma
27+
color: designVariables.title,
2728
fontSize: 20,
2829
letterSpacing: 0.0,
2930
height: (30 / 20),
@@ -40,8 +41,8 @@ ThemeData zulipThemeData(BuildContext context) {
4041
// that it looks reasonable with different system text-size settings.
4142
// Also the back button will look too big and need adjusting.
4243

43-
shape: const Border(bottom: BorderSide(
44-
color: Color(0x33000000), // `border-bar` in Figma
44+
shape: Border(bottom: BorderSide(
45+
color: designVariables.borderBar,
4546
strokeAlign: BorderSide.strokeAlignInside, // (default restated for explicitness)
4647
)),
4748
),
@@ -56,7 +57,7 @@ ThemeData zulipThemeData(BuildContext context) {
5657
colorScheme: ColorScheme.fromSeed(
5758
seedColor: kZulipBrandColor,
5859
),
59-
scaffoldBackgroundColor: const Color(0xfff0f0f0), // `bg-main` in Figma
60+
scaffoldBackgroundColor: designVariables.bgMain,
6061
tooltipTheme: const TooltipThemeData(preferBelow: false),
6162
);
6263
}
@@ -66,3 +67,71 @@ ThemeData zulipThemeData(BuildContext context) {
6667
/// This is chosen as the sRGB midpoint of the Zulip logo's gradient.
6768
// As computed by Anders: https://github.com/zulip/zulip-mobile/pull/4467
6869
const kZulipBrandColor = Color.fromRGBO(0x64, 0x92, 0xfe, 1);
70+
71+
/// Variables from the Figma design.
72+
///
73+
/// For how to export these from the Figma, see:
74+
/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=2945-49492&t=MEb4vtp7S26nntxm-0
75+
class DesignVariables extends ThemeExtension<DesignVariables> {
76+
DesignVariables() :
77+
bgMain = const Color(0xfff0f0f0),
78+
bgTopBar = const Color(0xfff5f5f5),
79+
borderBar = const Color(0x33000000),
80+
icon = const Color(0xff666699),
81+
title = const Color(0xff1a1a1a);
82+
83+
DesignVariables._({
84+
required this.bgMain,
85+
required this.bgTopBar,
86+
required this.borderBar,
87+
required this.icon,
88+
required this.title,
89+
});
90+
91+
/// The [DesignVariables] from the context's active theme.
92+
///
93+
/// The [ThemeData] must include [DesignVariables] in [ThemeData.extensions].
94+
static DesignVariables of(BuildContext context) {
95+
final theme = Theme.of(context);
96+
final extension = theme.extension<DesignVariables>();
97+
assert(extension != null);
98+
return extension!;
99+
}
100+
101+
final Color bgMain;
102+
final Color bgTopBar;
103+
final Color borderBar;
104+
final Color icon;
105+
final Color title;
106+
107+
@override
108+
DesignVariables copyWith({
109+
Color? bgMain,
110+
Color? bgTopBar,
111+
Color? borderBar,
112+
Color? icon,
113+
Color? title,
114+
}) {
115+
return DesignVariables._(
116+
bgMain: bgMain ?? this.bgMain,
117+
bgTopBar: bgTopBar ?? this.bgTopBar,
118+
borderBar: borderBar ?? this.borderBar,
119+
icon: icon ?? this.icon,
120+
title: title ?? this.title,
121+
);
122+
}
123+
124+
@override
125+
DesignVariables lerp(DesignVariables? other, double t) {
126+
if (identical(this, other)) {
127+
return this;
128+
}
129+
return DesignVariables._(
130+
bgMain: Color.lerp(bgMain, other?.bgMain, t)!,
131+
bgTopBar: Color.lerp(bgTopBar, other?.bgTopBar, t)!,
132+
borderBar: Color.lerp(borderBar, other?.borderBar, t)!,
133+
icon: Color.lerp(icon, other?.icon, t)!,
134+
title: Color.lerp(title, other?.title, t)!,
135+
);
136+
}
137+
}

0 commit comments

Comments
 (0)