Skip to content

Commit

Permalink
code_block: Fix null-check ! errors during hot reloads
Browse files Browse the repository at this point in the history
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 (zulip#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.
  • Loading branch information
chrisbobbe authored and gnprice committed Jul 5, 2024
1 parent 8a4900e commit 74de34c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 17 deletions.
34 changes: 17 additions & 17 deletions lib/widgets/code_block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -842,23 +842,23 @@ class CodeBlockTextStyles {
hll: TextStyle.lerp(a._hll, b._hll, t)!,
c: TextStyle.lerp(a._c, b._c, t)!,
err: TextStyle.lerp(a._err, b._err, t)!,
esc: TextStyle.lerp(a._esc, b._esc, t)!,
g: TextStyle.lerp(a._g, b._g, t)!,
esc: TextStyle.lerp(a._esc, b._esc, t),
g: TextStyle.lerp(a._g, b._g, t),
k: TextStyle.lerp(a._k, b._k, t)!,
l: TextStyle.lerp(a._l, b._l, t)!,
n: TextStyle.lerp(a._n, b._n, t)!,
l: TextStyle.lerp(a._l, b._l, t),
n: TextStyle.lerp(a._n, b._n, t),
o: TextStyle.lerp(a._o, b._o, t)!,
x: TextStyle.lerp(a._x, b._x, t)!,
p: TextStyle.lerp(a._p, b._p, t)!,
ch: TextStyle.lerp(a._ch, b._ch, t)!,
x: TextStyle.lerp(a._x, b._x, t),
p: TextStyle.lerp(a._p, b._p, t),
ch: TextStyle.lerp(a._ch, b._ch, t),
cm: TextStyle.lerp(a._cm, b._cm, t)!,
cp: TextStyle.lerp(a._cp, b._cp, t)!,
cpf: TextStyle.lerp(a._cpf, b._cpf, t)!,
cpf: TextStyle.lerp(a._cpf, b._cpf, t),
c1: TextStyle.lerp(a._c1, b._c1, t)!,
cs: TextStyle.lerp(a._cs, b._cs, t)!,
gd: TextStyle.lerp(a._gd, b._gd, t)!,
ge: TextStyle.lerp(a._ge, b._ge, t)!,
ges: TextStyle.lerp(a._ges, b._ges, t)!,
ges: TextStyle.lerp(a._ges, b._ges, t),
gr: TextStyle.lerp(a._gr, b._gr, t)!,
gh: TextStyle.lerp(a._gh, b._gh, t)!,
gi: TextStyle.lerp(a._gi, b._gi, t)!,
Expand All @@ -873,7 +873,7 @@ class CodeBlockTextStyles {
kp: TextStyle.lerp(a._kp, b._kp, t)!,
kr: TextStyle.lerp(a._kr, b._kr, t)!,
kt: TextStyle.lerp(a._kt, b._kt, t)!,
ld: TextStyle.lerp(a._ld, b._ld, t)!,
ld: TextStyle.lerp(a._ld, b._ld, t),
m: TextStyle.lerp(a._m, b._m, t)!,
s: TextStyle.lerp(a._s, b._s, t)!,
na: TextStyle.lerp(a._na, b._na, t)!,
Expand All @@ -889,19 +889,19 @@ class CodeBlockTextStyles {
nt: TextStyle.lerp(a._nt, b._nt, t)!,
nv: TextStyle.lerp(a._nv, b._nv, t)!,
nx: TextStyle.lerp(a._nx, b._nx, t)!,
py: TextStyle.lerp(a._py, b._py, t)!,
py: TextStyle.lerp(a._py, b._py, t),
ow: TextStyle.lerp(a._ow, b._ow, t)!,
pm: TextStyle.lerp(a._pm, b._pm, t)!,
pm: TextStyle.lerp(a._pm, b._pm, t),
w: TextStyle.lerp(a._w, b._w, t)!,
mb: TextStyle.lerp(a._mb, b._mb, t)!,
mb: TextStyle.lerp(a._mb, b._mb, t),
mf: TextStyle.lerp(a._mf, b._mf, t)!,
mh: TextStyle.lerp(a._mh, b._mh, t)!,
mi: TextStyle.lerp(a._mi, b._mi, t)!,
mo: TextStyle.lerp(a._mo, b._mo, t)!,
sa: TextStyle.lerp(a._sa, b._sa, t)!,
sa: TextStyle.lerp(a._sa, b._sa, t),
sb: TextStyle.lerp(a._sb, b._sb, t)!,
sc: TextStyle.lerp(a._sc, b._sc, t)!,
dl: TextStyle.lerp(a._dl, b._dl, t)!,
dl: TextStyle.lerp(a._dl, b._dl, t),
sd: TextStyle.lerp(a._sd, b._sd, t)!,
s2: TextStyle.lerp(a._s2, b._s2, t)!,
se: TextStyle.lerp(a._se, b._se, t)!,
Expand All @@ -912,11 +912,11 @@ class CodeBlockTextStyles {
s1: TextStyle.lerp(a._s1, b._s1, t)!,
ss: TextStyle.lerp(a._ss, b._ss, t)!,
bp: TextStyle.lerp(a._bp, b._bp, t)!,
fm: TextStyle.lerp(a._fm, b._fm, t)!,
fm: TextStyle.lerp(a._fm, b._fm, t),
vc: TextStyle.lerp(a._vc, b._vc, t)!,
vg: TextStyle.lerp(a._vg, b._vg, t)!,
vi: TextStyle.lerp(a._vi, b._vi, t)!,
vm: TextStyle.lerp(a._vm, b._vm, t)!,
vm: TextStyle.lerp(a._vm, b._vm, t),
il: TextStyle.lerp(a._il, b._il, t)!,
);
}
Expand Down
55 changes: 55 additions & 0 deletions test/widgets/code_block_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import 'package:checks/checks.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:zulip/widgets/app.dart';
import 'package:zulip/widgets/code_block.dart';
import 'package:zulip/widgets/page.dart';

import '../model/binding.dart';

void main() {
TestZulipBinding.ensureInitialized();

group('CodeBlockTextStyles', () {
group('lerp', () {
Future<BuildContext> contextWithZulipTheme(WidgetTester tester) async {
addTearDown(testBinding.reset);
await tester.pumpWidget(const ZulipApp());
await tester.pump();
final navigator = await ZulipApp.navigator;
navigator.push(MaterialWidgetRoute(page: Builder(
builder: (context) => const Placeholder())));
await tester.pumpAndSettle();
return tester.element(find.byType(Placeholder));
}

testWidgets('light -> light', (tester) async {
final context = await contextWithZulipTheme(tester);
final a = CodeBlockTextStyles.light(context);
final b = CodeBlockTextStyles.light(context);
check(() => CodeBlockTextStyles.lerp(a, b, 0.5)).returnsNormally();
});

testWidgets('light -> dark', (tester) async {
final context = await contextWithZulipTheme(tester);
final a = CodeBlockTextStyles.light(context);
final b = CodeBlockTextStyles.dark(context);
check(() => CodeBlockTextStyles.lerp(a, b, 0.5)).returnsNormally();
});

testWidgets('dark -> light', (tester) async {
final context = await contextWithZulipTheme(tester);
final a = CodeBlockTextStyles.dark(context);
final b = CodeBlockTextStyles.light(context);
check(() => CodeBlockTextStyles.lerp(a, b, 0.5)).returnsNormally();
});

testWidgets('dark -> dark', (tester) async {
final context = await contextWithZulipTheme(tester);
final a = CodeBlockTextStyles.dark(context);
final b = CodeBlockTextStyles.dark(context);
check(() => CodeBlockTextStyles.lerp(a, b, 0.5)).returnsNormally();
});
});
});
}

0 comments on commit 74de34c

Please sign in to comment.