Skip to content

Commit

Permalink
fix latex widget crashing sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorunome committed Nov 20, 2020
1 parent 0b68a1d commit e41ffbc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [0.1.12] - 20th Nov 2020:
- Fix Latex widget crashing sometimes

## [0.1.11] - 16th Nov 2020:
- Fix empty code blocks

Expand Down
8 changes: 6 additions & 2 deletions lib/custom_catex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ final defaultCaTeXContext = CaTeXContext(
/// It simply means that CaTeX will start out in this mode.
const startParsingMode = CaTeXMode.math;

final _errorsMap = <String, Exception>{};

/// Widget that displays TeX using the CaTeX library.
///
/// You can style the base text color and text size using
Expand Down Expand Up @@ -92,7 +94,9 @@ class _CaTeXState extends State<CustomCaTeX> {

@override
Widget build(BuildContext context) {
exception ??= _errorsMap[widget.input];
if (exception != null) {
_errorsMap[widget.input] = exception;
// Throwing the parsing exception here will make sure that it is
// displayed by the Flutter ErrorWidget.
return Text(widget.input, style: TextStyle(fontFamily: 'monospace'));
Expand Down Expand Up @@ -144,7 +148,7 @@ class CustomSingleChildRenderObjectElement
super.mount(parent, newSlot);
} catch (e) {
SchedulerBinding.instance.addPostFrameCallback((_) {
state.setState(() => state.exception = e);
state.setState(() => state.exception = e is Exception ? e : Exception(e));
});
}
}
Expand All @@ -160,7 +164,7 @@ class CustomRenderTree extends RenderTree {
super.performLayout();
} catch (e) {
SchedulerBinding.instance.addPostFrameCallback((_) {
state.setState(() => state.exception = e);
state.setState(() => state.exception = e is Exception ? e : Exception(e));
});
}
}
Expand Down

0 comments on commit e41ffbc

Please sign in to comment.