Skip to content

Commit c23220f

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 2d7581a commit c23220f

File tree

1 file changed

+77
-8
lines changed

1 file changed

+77
-8
lines changed

lib/widgets/theme.dart

+77-8
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,28 @@ 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,
2627

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

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

0 commit comments

Comments
 (0)