fayeed / flutter_parsed_text Goto Github PK
View Code? Open in Web Editor NEWA Flutter package to parse text and make them into linkified text widget
Home Page: https://pub.dev/packages/flutter_parsed_text
License: MIT License
A Flutter package to parse text and make them into linkified text widget
Home Page: https://pub.dev/packages/flutter_parsed_text
License: MIT License
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.
Trying to parse a URL with a ,
in it can mess it up pretty bad:
(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!
flutter markdown widget can also detect link etc...
pattern match text not showing unless putting space after string
Please use https://pub.dev/packages/email_validator instead.
Now that Flutter 2.0 has been released, this package should be migrated.
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!
It may have a function to show more and show less text.
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.
Text rendered by this widget use RichText and is not selectable. Can you add an option to use Selectable.rich widget? That may make text selectable.
I would like to be able to add keys to these widgets in order to be able to test them easily.
there should be see and see less button so it can be expand
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?
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.
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:
NoSuchMethodError (NoSuchMethodError: The method 'split' was called on null.
Receiver: null
Tried calling: split("%%%%"))
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.
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)
Email parsing is not working for email such as [email protected]
It consider abc.xyz as webpage url and [email protected] as email address
Hi
if there is a number in the url
e.g.
https://apps.apple.com/id/app/facebook/id284882215
it considers the trailing no as phone number.
Please check
TIA
There is often a need for long press copying. If there is a feature like selectabletext, it's cool
I have unicode data i am trying to parse.
I have following regex (?<=ژژ).*(?=ژژ)
its working fine on regex101 as you can see following image.
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; }, ), ], ),
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"
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.
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");},
)
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?
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;
});
Now it is not possible to work with ParsedText is there is no need to react to user clicks and onTap is null. Moreover, I cannot wrap ParsedText with another GestureDetector and handle other user gestures (Had to wrap with IgnorePointer)
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.
it's been 2 years to , this package has been updated & there are alot of issues.
when the next update of this package will release
I think this will be awesome to use with the expand_widget for very long text.
For now, it forces the display of complete long text, how about customizing to use expand widget to show more?
toolbarOptions
is missingtextScaleFactor
is not working for selectable rich textThanks a lot for your work. Your package is very practical. Just one thing may make it perfect. Can you support onLongPress on top of onTap?
it is possible to customize rendering Text
for example I want to insert an Icon
before numbers
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.