Git Product home page Git Product logo

flutter_parsed_text's Introduction

In Rust and TypeScript, I code, young developer. Currently building, a Digital Nervous System for the New Web at Coasys, hmmm. Powerful tools, they are, hmmm.

Interested in collaborating? Send me a message

flutter_parsed_text's People

Contributors

erickjtorres avatar fayeed avatar gliheng avatar huobazi avatar josh-burton avatar pincheira avatar seanoconnor3000 avatar smitsonani avatar trietbui85 avatar vitaly-v avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flutter_parsed_text's Issues

renderText argument/parameter Type mismatch

renderText is saying there is a type mismatch (dart(argument_type_not_assignable))even though I copied this directly from the main documentation example

interestingly enough, everything actually works when I flutter run - no issue compiling and everything renders as expected in my iOS simulator

I'm not able to get the error in my editor to go away no matter what I try, so figure this is some sort of issue (I just recently upgraded to flutter 2 and using version ^2.1.0 of this package)

Screen Shot 2021-03-25 at 9 25 14 PM

Global regexOptions

In version 2.2.0 you have a breaking change (Please follow semver)

Removed regexOptions property from MatchText and now comes with a global regexOptions property for ParsedText Widget.

Why? I think it's totally wrong! Assume we have two MatchText , and want to set caseSensitive: false for first and caseSensitive: true for second, how is it possible with a global regexOptions?

Phone number regex can be improved

The regular expression used for phone numbers does not take into account escape characters that might come before the phone number. Also if a user wants to input an extension sthe regex won't work but that is less of a concern.

Some regex patterns are not working

Hi,
There are some pattern issues i couldnt figure it out myself.

this is working as expected:

final str =  "--- spoiler ---\r\n\r\n spoiler content \r\n--- spoiler ---\r\n\r";
Iterable<Match> matches = RegExp(
            r"(---( )?(`)?spoiler(`)?( )?---)(.*?)(---( )?(`)?spoiler(`)?( )?---)",
            dotAll: true,
            multiLine: true,
            caseSensitive: false)
        .allMatches(str);
matches.forEach((m) => print(m.group(6)));
// output: "spoiler content"

however this is not working. renderText method is not called:

Widget build(BuildContext context) {
    return ParsedText(
      text: str,
      style: TextStyle(color: Colors.black),
      parse: [
        MatchText(
            type: ParsedType.CUSTOM,
            pattern:
                r"(---( )?(`)?spoiler(`)?( )?---)(.*?)(---( )?(`)?spoiler(`)?( )?---)",
            regexOptions: RegexOptions(
              dotAll: true,
              multiLine: true,
              caseSensitive: false,
            ),
            style: TextStyle(
              color: Colors.red,
              fontSize: 10,
            ),
            renderText: ({String str, String pattern}) {
              Map<String, String> map = Map<String, String>();
              Match match = RegExp(pattern).firstMatch(str);
              map['display'] = "(${match.group(6).trim()})";
              map['value'] = match.group(6).trim();
              return map;
            },
            onTap: (url) {
              print(url);
            }),
      ],
    );

same goes for positive lookbehind
this is working:

final str =
        "(lookup: testtest1) content content (lookup: testtest2) content content";
    Iterable<Match> matches =
        RegExp(r"(?<=\(lookup:)(.*?)(?=\))").allMatches(str);
    matches.forEach((m) => print(m.group(0)));
// output: testtest1
// output: testtest2

this is not:

Widget build(BuildContext context) {
    return ParsedText(
      text: str,
      style: TextStyle(color: Colors.black),
      parse: [
        MatchText(
            type: ParsedType.CUSTOM,
            pattern:
                r"(?<=\(lookup:)(.*?)(?=\))",
            style: TextStyle(
              color: Colors.red,
              fontSize: 10,
            ),
            renderText: ({String str, String pattern}) {
              Map<String, String> map = Map<String, String>();
              Match match = RegExp(pattern).firstMatch(str);
              map['display'] = "(${match.group(2).trim()})";
              map['value'] = match.group(2).trim();
              return map;
            },
            onTap: (url) {
              print(url);
            }),
      ],
    );

im using flutter_parsed_text: ^1.2.3
sdk environment for flutter sdk: ">=2.5.2 <3.0.0"

new feature suggest

There is often a need for long press copying. If there is a feature like selectabletext, it's cool

Support for HTML tags

Hi,

There is a ready-to-use support for html tags (any constant like email, url etc)?

Or i will need create some regexp?

Thanks.

onTap uses matchText instead of result['value'] when using renderText

According to the readme file in the renderText function you're supposed to return a Map with 'display' and 'value' entries where the 'value' entry is the value used. However, in the current version the 'value' entry is never even used. I can see that it was previously used but this was changed in commit f5051f5. Was this on purpose or just a slight mistake? If it was on purpose then it does not make sense to return a map from renderText since only the 'display' entry is used.

Selecte and copy CUSTOM widgetSpan then paste the text is an unknown character of an obj.

I add a MatchText to ParsedText's parse. but I want copy it. but cant't copy text from renderWidget.

return MatchText(
        pattern: TextEntity.emoPattern.pattern,
        renderWidget: ({text, pattern}) {
          Widget child = Text('$text ');
          if (text.startsWith('[') && text.endsWith(']') && text.length >= 3) {
            final content =
                text.substring(1, text.length - 1).replaceAll(nullChar, '');

            if (EmoUtil.instance.allEmoMap[content] != null) {
              final Widget emoji =
                  EmoUtil.instance.getEmoIcon(content, size: fontSize);

              child = Padding(
                padding: fontSize == 48
                    ? const EdgeInsets.fromLTRB(2, 4, 2, 4)
                    : const EdgeInsets.fromLTRB(2, 2, 2, 2),
                child: emoji,
              );
            }
          }
          return child;
        });
Capturer_video_20220610_161930_905.mp4

Is it possible to have custom options with selectable enabled?

I tried your package. flutter_parsed_text is a very good package. Just one thing make me hesitate to use. Could you kindly help?

I need to allow users of my app to select a word with different features working on the selected word.

When I set true to "selectable" of ParsedText widget, after a word is selected, there are only options of "Copy" and "Select All". Is it possible to have custom options when a word is selected?

Alternatively, is it possible to have "onLongPress" function for the parsed word when "selected" is turned off?

Project is abandoned?

Hi,

I see some bugs related here.

The project is abandoned?

Only to understand if is secure to use a project that is maintened.

Thanks.

Null Check operator on Null value error

image

onTap function is marked as nullable, but ! null check operator is used on it, which results in an error in one of my apps.

If this is a legit issue, can I make an MR fixing this?

Can click event add style response?

Thank you for creating this package, I really like it.
I often use it to do some rich text work, it works very well. But one thing, we have some rich text that needs to be clicked, and these clicks need to match the material style to give users visual feedback. So we need to change the style of the text when we click.

So can such a function be added?

thx.

Customization

it is possible to customize rendering Text for example I want to insert an Icon before numbers

maxLines bug

if maxLines set null it's mean unlimited in flutter

~/flutter/packages/flutter/lib/src/widgets/basic.dart

/// The [maxLines] property may be null (and indeed defaults to null), but if /// it is not null, it must be greater than zero.

properties.add(IntProperty('maxLines', maxLines, ifNull: 'unlimited'));

but in ParsedText, write like maxLines: null it's show 1 line
bug ?

ParsedText( alignment: TextAlign.start, maxLines: null, overflow: TextOverflow.ellipsis, text:

Not working while trying to parse utf8 unicode data.

I have unicode data i am trying to parse.

I have following regex (?<=ژژ).*(?=ژژ) its working fine on regex101 as you can see following image.
Capture
I am using following code:
ParsedText( text: ''' ژژ صفحہ نمبر 15ژژص ژ1 ’’وَلَقَدْ اَرْسَلْنَا نُوْحاً وَّاِبْرَاہِیْمَ وَجَعَلْنَافِیْ ذُرِّیَّتِہِمَاالنُّبُوَّۃَ وَالْکِتٰبَ فَمِنْہُمْ مُھْتَدٍ۔وَکَثِیْرٌ مِّنْہُمْ فٰسِقُوْنَ۔ ثُمَّ قَفَّیْنَا عَلیٰٓ اٰثَارِہِمْ بِرُسُلِنَا صژص ژ8 (حدید:۲۶،۲۷)‘‘ صژص''', style: Get.textTheme.headline6, parse: <MatchText>[ MatchText( pattern: r'(?<=ژژ).*(?=ژژ)', style: TextStyle( color: Colors.red, fontSize: 24, ), renderText: ({String str, String pattern}) { Map<String, String> map = Map<String, String>(); RegExp customRegExp = RegExp(pattern); Match match = customRegExp.firstMatch(str); map['display'] = '\n'; map['value'] = match.group(2); print(match.group(1)); print(match.group(2)); return map; }, ), ], ),

Commas in URL

Trying to parse a URL with a , in it can mess it up pretty bad:
Screenshot_3
(It detected the first bit, then it stopped, then it detected a bunch of phone numbers).

Is there anything that can be done about this?
Thank you!

onTap not work in matches

Hello. on tap not work in matches.
but if i add onTap in ParsedText it work.
And i have this in code on top

Scaffold(
        body: GestureDetector(
          behavior: HitTestBehavior.opaque,
      onTap: () {
         WidgetsBinding.instance.focusManager.primaryFocus?.unfocus();
        /*FocusScopeNode currentFocus = FocusScope.of(context);
        if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
          currentFocus.focusedChild.unfocus();
        }*/
      },
      onDoubleTap: (){
        _scrollController.animateTo(
                _scrollController.position.maxScrollExtent,
                curve: Curves.easeOut,
                duration: const Duration(milliseconds: 300),
              );
      },
      child:...
)
)

and this parsed text

matches = [
                    new MatchText(
                    type: ParsedType.URL,
                    style: TextStyle(
                      color: Colors.blue,
                      
                    ),
                    onTap: (url) async {
                      print(url);
                      var a = await canLaunch(url);

                      if (a) {
                        launch(url);
                      }
                      
                    }),
                    new MatchText(
                    type: ParsedType.PHONE,
                    style: TextStyle(
                      color: Colors.purple,
                      
                    ),
                    onTap: (url) {
                      launch("tel:" + url);
                    }),
                  ];

ParsedText(
                  alignment: TextAlign.start,
                  selectable: true,
                  text: message,
                  parse:matches,
                  onTap: () {print("Text Tap Tap Tap");},
                )

Editable ParsedText

Is it possible to make ParsedText optionally editable, like with a boolean? I understand RichText doesn't allow for it, since there's preset spans with fixed portions of texts and textstyles, but it makes sense conceptually for parsed text, where the spans are built by matching the text, thus in a case of the text being edited, simply reparse it with the changes.

Programmatically, might be difficult to implement though. Is this a possible feature or would it require too much of an overhaul? Thanks either way!

Nested or Overlapped MatchText

As it is now, it seems I'm unable to nest multiple matchtext without specifically writing a regex pattern to match for the amalgamation of the two. Let's say I have italics and I check for it with "(i) Test (i)" (test), and bold with "(b) Test (b)" (test) . A combination of the two simply seems to match the outer set and ignore anything within. A bold and italicized text writted as "(b) (i) Test (i) (b) " simply parses as "(i) Test (i)" in bold.

That's straightforward nesting, disregarding partial overlapping such as "(i) This is (b) a test (i) to check (b)" But this is likely far more complicated to do.

I understand allowing for applying multiple text matching to a single portion of text might conflict with multiple text styles, but why not have a list of parsed with the order of parsing, overwriting the previous one matched, in case of any conflicting parameters, the same for the onTap() function. Is this a feasible request? Thanks!

Extending to TextField

Thanks for developing this is a great package!

I was wondering if it's possible to add a ParsedTextField widget to this package, to cater a multiline TextField to have such styling.
I am a newbie to flutter. If I can gather some information around it, will contribute.

Just putting out the idea here for now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.