Skip to content

Commit

Permalink
Added a getter in Mistake class to get the name. Resolved the non nul…
Browse files Browse the repository at this point in the history
…l assertion issue as suggested by Yuri
  • Loading branch information
Sammy275 committed May 12, 2023
1 parent df7afca commit 6a6c12d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 7 additions & 9 deletions lib/core/controllers/colored_text_editing_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ColoredTextEditingController extends TextEditingController {
/// An [OverlayEntry] for the [Overlay] class.
/// This entry represents the floating popup
/// that appears on a mistake.
OverlayEntry? overlayEntry;
OverlayEntry? _overlayEntry;

/// Represents the maximum numbers of suggestions allowed.
final int suggestionsLimit;
Expand Down Expand Up @@ -104,8 +104,7 @@ class ColoredTextEditingController extends TextEditingController {
: mistake.replacements.sublist(0, suggestionsLimit);

/// Parsing the mistake enum types to string type
final String mistakeName =
mistake.type.name[0].toUpperCase() + mistake.type.name.substring(1);
final String mistakeName = mistake.name;

/// Mistake highlighted TextSpan
yield TextSpan(
Expand All @@ -131,7 +130,7 @@ class ColoredTextEditingController extends TextEditingController {
/// To remove overlay if present.
_removeHighlightOverlay();

overlayEntry = OverlayEntry(
final overlayEntry = OverlayEntry(
builder: (BuildContext context) {
return SuggestionsPopup(
mistakeName: mistakeName,
Expand All @@ -153,9 +152,8 @@ class ColoredTextEditingController extends TextEditingController {
},
);

Overlay.of(context).insert(
overlayEntry ?? OverlayEntry(builder: (_) => Container()),
);
_overlayEntry = overlayEntry;
Overlay.of(context).insert(overlayEntry);
},
text:
text.substring(mistake.offset, mistake.offset + mistake.length),
Expand Down Expand Up @@ -183,8 +181,8 @@ class ColoredTextEditingController extends TextEditingController {
}

void _removeHighlightOverlay() {
overlayEntry?.remove();
overlayEntry = null;
_overlayEntry?.remove();
_overlayEntry = null;
}

/// Returns color for mistake TextSpan style
Expand Down
4 changes: 4 additions & 0 deletions lib/domain/mistake.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class Mistake {
/// Sorted by probability.
final List<String> replacements;

/// Name of the mistake in string form.
/// The first letter will be capitalized
String get name => type.name[0].toUpperCase() + type.name.substring(1);

/// Creates a new instance of the [Mistake] class.
const Mistake({
required this.message,
Expand Down

0 comments on commit 6a6c12d

Please sign in to comment.