Skip to content

Commit 74de34c

Browse files
chrisbobbegnprice
authored andcommitted
code_block: Fix null-check ! errors during hot reloads
On hot-reload, `lerp` is triggered even when the theme has not changed. Discussion: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Exceptions.20during.20hot.20reloads/near/1846095 I considered just going ahead with placing the web app's current light-theme styles for code blocks (#754), but pretty soon I realized there would still be some nulls in there after doing so, and those would need to be treated like we're treating the nulls here.
1 parent 8a4900e commit 74de34c

File tree

2 files changed

+72
-17
lines changed

2 files changed

+72
-17
lines changed

lib/widgets/code_block.dart

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -842,23 +842,23 @@ class CodeBlockTextStyles {
842842
hll: TextStyle.lerp(a._hll, b._hll, t)!,
843843
c: TextStyle.lerp(a._c, b._c, t)!,
844844
err: TextStyle.lerp(a._err, b._err, t)!,
845-
esc: TextStyle.lerp(a._esc, b._esc, t)!,
846-
g: TextStyle.lerp(a._g, b._g, t)!,
845+
esc: TextStyle.lerp(a._esc, b._esc, t),
846+
g: TextStyle.lerp(a._g, b._g, t),
847847
k: TextStyle.lerp(a._k, b._k, t)!,
848-
l: TextStyle.lerp(a._l, b._l, t)!,
849-
n: TextStyle.lerp(a._n, b._n, t)!,
848+
l: TextStyle.lerp(a._l, b._l, t),
849+
n: TextStyle.lerp(a._n, b._n, t),
850850
o: TextStyle.lerp(a._o, b._o, t)!,
851-
x: TextStyle.lerp(a._x, b._x, t)!,
852-
p: TextStyle.lerp(a._p, b._p, t)!,
853-
ch: TextStyle.lerp(a._ch, b._ch, t)!,
851+
x: TextStyle.lerp(a._x, b._x, t),
852+
p: TextStyle.lerp(a._p, b._p, t),
853+
ch: TextStyle.lerp(a._ch, b._ch, t),
854854
cm: TextStyle.lerp(a._cm, b._cm, t)!,
855855
cp: TextStyle.lerp(a._cp, b._cp, t)!,
856-
cpf: TextStyle.lerp(a._cpf, b._cpf, t)!,
856+
cpf: TextStyle.lerp(a._cpf, b._cpf, t),
857857
c1: TextStyle.lerp(a._c1, b._c1, t)!,
858858
cs: TextStyle.lerp(a._cs, b._cs, t)!,
859859
gd: TextStyle.lerp(a._gd, b._gd, t)!,
860860
ge: TextStyle.lerp(a._ge, b._ge, t)!,
861-
ges: TextStyle.lerp(a._ges, b._ges, t)!,
861+
ges: TextStyle.lerp(a._ges, b._ges, t),
862862
gr: TextStyle.lerp(a._gr, b._gr, t)!,
863863
gh: TextStyle.lerp(a._gh, b._gh, t)!,
864864
gi: TextStyle.lerp(a._gi, b._gi, t)!,
@@ -873,7 +873,7 @@ class CodeBlockTextStyles {
873873
kp: TextStyle.lerp(a._kp, b._kp, t)!,
874874
kr: TextStyle.lerp(a._kr, b._kr, t)!,
875875
kt: TextStyle.lerp(a._kt, b._kt, t)!,
876-
ld: TextStyle.lerp(a._ld, b._ld, t)!,
876+
ld: TextStyle.lerp(a._ld, b._ld, t),
877877
m: TextStyle.lerp(a._m, b._m, t)!,
878878
s: TextStyle.lerp(a._s, b._s, t)!,
879879
na: TextStyle.lerp(a._na, b._na, t)!,
@@ -889,19 +889,19 @@ class CodeBlockTextStyles {
889889
nt: TextStyle.lerp(a._nt, b._nt, t)!,
890890
nv: TextStyle.lerp(a._nv, b._nv, t)!,
891891
nx: TextStyle.lerp(a._nx, b._nx, t)!,
892-
py: TextStyle.lerp(a._py, b._py, t)!,
892+
py: TextStyle.lerp(a._py, b._py, t),
893893
ow: TextStyle.lerp(a._ow, b._ow, t)!,
894-
pm: TextStyle.lerp(a._pm, b._pm, t)!,
894+
pm: TextStyle.lerp(a._pm, b._pm, t),
895895
w: TextStyle.lerp(a._w, b._w, t)!,
896-
mb: TextStyle.lerp(a._mb, b._mb, t)!,
896+
mb: TextStyle.lerp(a._mb, b._mb, t),
897897
mf: TextStyle.lerp(a._mf, b._mf, t)!,
898898
mh: TextStyle.lerp(a._mh, b._mh, t)!,
899899
mi: TextStyle.lerp(a._mi, b._mi, t)!,
900900
mo: TextStyle.lerp(a._mo, b._mo, t)!,
901-
sa: TextStyle.lerp(a._sa, b._sa, t)!,
901+
sa: TextStyle.lerp(a._sa, b._sa, t),
902902
sb: TextStyle.lerp(a._sb, b._sb, t)!,
903903
sc: TextStyle.lerp(a._sc, b._sc, t)!,
904-
dl: TextStyle.lerp(a._dl, b._dl, t)!,
904+
dl: TextStyle.lerp(a._dl, b._dl, t),
905905
sd: TextStyle.lerp(a._sd, b._sd, t)!,
906906
s2: TextStyle.lerp(a._s2, b._s2, t)!,
907907
se: TextStyle.lerp(a._se, b._se, t)!,
@@ -912,11 +912,11 @@ class CodeBlockTextStyles {
912912
s1: TextStyle.lerp(a._s1, b._s1, t)!,
913913
ss: TextStyle.lerp(a._ss, b._ss, t)!,
914914
bp: TextStyle.lerp(a._bp, b._bp, t)!,
915-
fm: TextStyle.lerp(a._fm, b._fm, t)!,
915+
fm: TextStyle.lerp(a._fm, b._fm, t),
916916
vc: TextStyle.lerp(a._vc, b._vc, t)!,
917917
vg: TextStyle.lerp(a._vg, b._vg, t)!,
918918
vi: TextStyle.lerp(a._vi, b._vi, t)!,
919-
vm: TextStyle.lerp(a._vm, b._vm, t)!,
919+
vm: TextStyle.lerp(a._vm, b._vm, t),
920920
il: TextStyle.lerp(a._il, b._il, t)!,
921921
);
922922
}

test/widgets/code_block_test.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import 'package:checks/checks.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter_test/flutter_test.dart';
4+
import 'package:zulip/widgets/app.dart';
5+
import 'package:zulip/widgets/code_block.dart';
6+
import 'package:zulip/widgets/page.dart';
7+
8+
import '../model/binding.dart';
9+
10+
void main() {
11+
TestZulipBinding.ensureInitialized();
12+
13+
group('CodeBlockTextStyles', () {
14+
group('lerp', () {
15+
Future<BuildContext> contextWithZulipTheme(WidgetTester tester) async {
16+
addTearDown(testBinding.reset);
17+
await tester.pumpWidget(const ZulipApp());
18+
await tester.pump();
19+
final navigator = await ZulipApp.navigator;
20+
navigator.push(MaterialWidgetRoute(page: Builder(
21+
builder: (context) => const Placeholder())));
22+
await tester.pumpAndSettle();
23+
return tester.element(find.byType(Placeholder));
24+
}
25+
26+
testWidgets('light -> light', (tester) async {
27+
final context = await contextWithZulipTheme(tester);
28+
final a = CodeBlockTextStyles.light(context);
29+
final b = CodeBlockTextStyles.light(context);
30+
check(() => CodeBlockTextStyles.lerp(a, b, 0.5)).returnsNormally();
31+
});
32+
33+
testWidgets('light -> dark', (tester) async {
34+
final context = await contextWithZulipTheme(tester);
35+
final a = CodeBlockTextStyles.light(context);
36+
final b = CodeBlockTextStyles.dark(context);
37+
check(() => CodeBlockTextStyles.lerp(a, b, 0.5)).returnsNormally();
38+
});
39+
40+
testWidgets('dark -> light', (tester) async {
41+
final context = await contextWithZulipTheme(tester);
42+
final a = CodeBlockTextStyles.dark(context);
43+
final b = CodeBlockTextStyles.light(context);
44+
check(() => CodeBlockTextStyles.lerp(a, b, 0.5)).returnsNormally();
45+
});
46+
47+
testWidgets('dark -> dark', (tester) async {
48+
final context = await contextWithZulipTheme(tester);
49+
final a = CodeBlockTextStyles.dark(context);
50+
final b = CodeBlockTextStyles.dark(context);
51+
check(() => CodeBlockTextStyles.lerp(a, b, 0.5)).returnsNormally();
52+
});
53+
});
54+
});
55+
}

0 commit comments

Comments
 (0)