2000calories / flutter_easy_rich_text

The EasyRichText widget provides an easy way to use RichText.
https://pub.dev/packages/easy_rich_text
MIT License
79 stars 34 forks source link

FormatException: Range out of order in character class #40

Closed Alexander-TM closed 1 year ago

Alexander-TM commented 1 year ago

Flutter throwing this exception:

The following FormatException was thrown building EasyRichText(dirty):
Range out of order in character class((?<!\w)qu'y a-t-il? [ou qu'est-ce qu'il y a?] ― il y a que j'ai faim!(?!\w))
2000calories commented 1 year ago

Please show your flutter doctor output.

Alexander-TM commented 1 year ago

I'm using VS Code and testing on android device.

[✓] Flutter (Channel stable, 3.3.10, on Mac OS X 10.15.7 19H2026 darwin-x64, locale en-CA) [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [!] Xcode - develop for iOS and macOS (Xcode 12.4) ✗ Flutter requires Xcode 13 or higher. Download the latest version or update via the Mac App Store. ! CocoaPods 1.10.1 out of date (1.11.0 is recommended). CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side. Without CocoaPods, plugins will not work on iOS or macOS. For more info, see https://flutter.dev/platform-plugins To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions. [✓] Chrome - develop for the web [✓] Android Studio (version 4.1) [✓] IntelliJ IDEA Community Edition (version 2022.1.2) [✓] VS Code (version 1.74.2) [✓] Connected device (3 available) [✓] HTTP Host Availability

2000calories commented 1 year ago

I do not see any error after upgrading to 3.3.10. Please show your widget code.

Alexander-TM commented 1 year ago

The code:

Flexible(
              child: EasyRichText(
                trans.source + ": " + trans.targetObj.text!,
                patternList: [
                  EasyRichTextPattern(
                      targetString: trans.source,
                      style: const TextStyle(
                        fontStyle: FontStyle.italic, fontSize: 15,
                        // color: Colors.grey.shade700
                      )),
                  EasyRichTextPattern(
                      targetString: trans.targetObj.text,
                      style: TextStyle(
                          fontWeight: FontWeight.bold,
                          fontSize: 15,
                          // backgroundColor: globals.genderColors[trans.targetObj.gender]
                          color: globals.genderColors[trans.targetObj.gender]))
                ],
              ),
            ),

===============================================================

It works perfectly until it stumbles upon this following text in french and english, is there a character that's causing this exception? is it the bracket ']' character in the middle of part1? I think the bracket confuses the widget into processing it as part of a regex? does it make sense?

==================================================================

Part 1: "qu'y a-t-il? ou qu'est-ce qu'il y a?] ― il y a que j'ai faim!", Part 2: "what's the matter? ― I'm hungry, that's what!"

2000calories commented 1 year ago
EasyRichTextPattern(
  targetString: trans.source,
  //set hasSpecialCharacters
  hasSpecialCharacters: true,
  style: const TextStyle(
    fontStyle: FontStyle.italic, fontSize: 15,
    // color: Colors.grey.shade700
)),
Alexander-TM commented 1 year ago

It worked thank you