Skip to content

Commit

Permalink
Package updated to v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fayeed committed Aug 8, 2020
1 parent 184d42f commit b83fa0b
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 71 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [0.1.1] - 8 Aug 2020

* Static Analysis added.

## [0.1.0] - 8 Aug 2020

* Initial package released
* Initial package released.
47 changes: 47 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
linter:
rules:
- always_declare_return_types
- always_require_non_null_named_parameters
- annotate_overrides
- avoid_empty_else
- avoid_init_to_null
- avoid_null_checks_in_equality_operators
- avoid_relative_lib_imports
- avoid_return_types_on_setters
- avoid_shadowing_type_parameters
- avoid_types_as_parameter_names
- camel_case_extensions
- curly_braces_in_flow_control_structures
- empty_catches
- empty_constructor_bodies
- library_names
- library_prefixes
- no_duplicate_case_values
- null_closures
- omit_local_variable_types
- prefer_adjacent_string_concatenation
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_contains
- prefer_equal_for_default_values
- prefer_final_fields
- prefer_for_elements_to_map_fromIterable
- prefer_generic_function_type_aliases
- prefer_if_null_operators
- prefer_is_empty
- prefer_is_not_empty
- prefer_iterable_whereType
- prefer_single_quotes
- prefer_spread_collections
- recursive_getters
- slash_for_doc_comments
- type_init_formals
- unawaited_futures
- unnecessary_const
- unnecessary_new
- unnecessary_null_in_if_null_operators
- unnecessary_this
- unrelated_type_equality_checks
- use_function_type_syntax_for_parameters
- use_rethrow_when_possible
- valid_regexps
58 changes: 29 additions & 29 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class _MyHomePageState extends State<MyHomePage> {
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
RaisedButton(
child: Text("Get Text"),
child: Text('Get Text'),
onPressed: () {
print(key.currentState.controller.markupText);
},
Expand All @@ -55,39 +55,39 @@ class _MyHomePageState extends State<MyHomePage> {
minLines: 1,
mentions: [
Mention(
trigger: "@",
trigger: '@',
style: TextStyle(
color: Colors.amber,
),
data: [
{
"id": "61as61fsa",
"display": "fayeedP",
"full_name": "Fayeed Pawaskar",
"photo":
"https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940"
'id': '61as61fsa',
'display': 'fayeedP',
'full_name': 'Fayeed Pawaskar',
'photo':
'https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940'
},
{
"id": "61asasgasgsag6a",
"display": "khaled",
"full_name": "DJ Khaled",
"style": TextStyle(color: Colors.purple),
"photo":
"https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940"
'id': '61asasgasgsag6a',
'display': 'khaled',
'full_name': 'DJ Khaled',
'style': TextStyle(color: Colors.purple),
'photo':
'https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940'
},
{
"id": "asfgasga41",
"display": "markT",
"full_name": "Mark Twain",
"photo":
"https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940"
'id': 'asfgasga41',
'display': 'markT',
'full_name': 'Mark Twain',
'photo':
'https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940'
},
{
"id": "asfsaf451a",
"display": "JhonL",
"full_name": "Jhon Legend",
"photo":
"https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940"
'id': 'asfsaf451a',
'display': 'JhonL',
'full_name': 'Jhon Legend',
'photo':
'https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940'
},
],
matchAll: false,
Expand All @@ -98,31 +98,31 @@ class _MyHomePageState extends State<MyHomePage> {
children: <Widget>[
CircleAvatar(
backgroundImage: NetworkImage(
data["photo"],
data['photo'],
),
),
SizedBox(
width: 20.0,
),
Column(
children: <Widget>[
Text(data["full_name"]),
Text("@${data["display"]}"),
Text(data['full_name']),
Text('@${data['display']}'),
],
)
],
),
);
}),
Mention(
trigger: "#",
trigger: '#',
disableMarkup: true,
style: TextStyle(
color: Colors.blue,
),
data: [
{"id": "reactjs", "display": "reactjs"},
{"id": "javascript", "display": "javascript"},
{'id': 'reactjs', 'display': 'reactjs'},
{'id': 'javascript', 'display': 'javascript'},
],
matchAll: true,
)
Expand Down
41 changes: 20 additions & 21 deletions lib/src/annotation_editing_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ class AnnotationEditingController extends TextEditingController {
: _pattern = "(${_mapping.keys.map((key) => key).join('|')})";

/// Can be used to get the markup from the controller directly.
get markupText {
String get markupText {
final someVal = text.splitMapJoin(
RegExp("$_pattern"),
RegExp('$_pattern'),
onMatch: (Match match) {
final mention = _mapping[match[0]] != null
? _mapping[match[0]]
: _mapping[_mapping.keys.firstWhere((element) {
final reg = new RegExp(element);
final mention = _mapping[match[0]] ??
_mapping[_mapping.keys.firstWhere((element) {
final reg = RegExp(element);

return reg.hasMatch(match[0]);
})];
return reg.hasMatch(match[0]);
})];

// Default markup format for mentions
if (!mention.disableMarkup)
return "${mention.trigger}[__${mention.id}__](__${mention.display}__)";
else
if (!mention.disableMarkup) {
return '${mention.trigger}[__${mention.id}__](__${mention.display}__)';
} else {
return match[0];
}
},
onNonMatch: (String text) {
return text;
Expand All @@ -39,30 +39,29 @@ class AnnotationEditingController extends TextEditingController {

@override
TextSpan buildTextSpan({TextStyle style, bool withComposing}) {
List<InlineSpan> children = [];
var children = <InlineSpan>[];

text.splitMapJoin(
RegExp("$_pattern"),
RegExp('$_pattern'),
onMatch: (Match match) {
final mention = _mapping[match[0]] != null
? _mapping[match[0]]
: _mapping[_mapping.keys.firstWhere((element) {
final reg = new RegExp(element);
final mention = _mapping[match[0]] ??
_mapping[_mapping.keys.firstWhere((element) {
final reg = RegExp(element);

return reg.hasMatch(match[0]);
})];
return reg.hasMatch(match[0]);
})];

children.add(
TextSpan(
text: match[0],
style: style.merge(mention.style),
),
);
return "";
return '';
},
onNonMatch: (String text) {
children.add(TextSpan(text: text, style: style));
return "";
return '';
},
);
return TextSpan(style: style, children: children);
Expand Down
36 changes: 19 additions & 17 deletions lib/src/mention_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,37 +225,38 @@ class FlutterMentionsState extends State<FlutterMentions> {
AnnotationEditingController controller;
bool _showSuggestions = false;
LengthMap _selectedMention;
String _pattern = "";
String _pattern = '';

@override
void initState() {
final Map<String, Annotation> data = Map<String, Annotation>();
final data = <String, Annotation>{};

// Loop over all the mention items and generate a suggestions matching list
widget.mentions.forEach((element) {
// if matchAll is set to true add a general regex patteren to match with
if (element.matchAll)
data["${element.trigger}([A-Za-z0-9])*"] = Annotation(
if (element.matchAll) {
data['${element.trigger}([A-Za-z0-9])*'] = Annotation(
style: element.style,
id: null,
display: null,
trigger: element.trigger,
disableMarkup: element.disableMarkup,
);
}

element.data?.forEach(
(e) => data["${element.trigger}${e['display']}"] = e["style"] != null
(e) => data["${element.trigger}${e['display']}"] = e['style'] != null
? Annotation(
style: e["style"],
id: e["id"],
display: e["display"],
style: e['style'],
id: e['id'],
display: e['display'],
trigger: element.trigger,
disableMarkup: element.disableMarkup,
)
: Annotation(
style: element.style,
id: e["id"],
display: e["display"],
id: e['id'],
display: e['display'],
trigger: element.trigger,
disableMarkup: element.disableMarkup,
),
Expand All @@ -269,20 +270,20 @@ class FlutterMentionsState extends State<FlutterMentions> {
final cursorPos = controller.selection.baseOffset;

if (cursorPos - 1 > 0) {
int _pos = 0;
var _pos = 0;

final lengthMap = List<LengthMap>();
final lengthMap = <LengthMap>[];

// split on each word and generate a list with start & end position of each word.
controller.value.text.split(RegExp(r"(\s)")).forEach((element) {
controller.value.text.split(RegExp(r'(\s)')).forEach((element) {
lengthMap.add(
LengthMap(str: element, start: _pos, end: _pos + element.length));

_pos = _pos + element.length + 1;
});

final val = lengthMap.indexWhere((element) {
_pattern = widget.mentions.map((e) => e.trigger).join("|");
_pattern = widget.mentions.map((e) => e.trigger).join('|');

return element.end == cursorPos &&
element.str.toLowerCase().contains(RegExp(_pattern));
Expand Down Expand Up @@ -320,10 +321,10 @@ class FlutterMentionsState extends State<FlutterMentions> {
suggestionBuilder: list.suggestionBuilder,
suggestionListDecoration: widget.suggestionListDecoration,
data: list.data.where((element) {
final ele = element["display"].toLowerCase();
final ele = element['display'].toLowerCase();
final str = _selectedMention.str
.toLowerCase()
.replaceAll(RegExp(_pattern), "");
.replaceAll(RegExp(_pattern), '');

return ele == str ? false : ele.contains(str);
}).toList(),
Expand Down Expand Up @@ -379,8 +380,9 @@ class FlutterMentionsState extends State<FlutterMentions> {
controller: controller,
onChanged: (text) {
if (widget.onChanged != null) widget.onChanged(text);
if (widget.onMarkupChanged != null)
if (widget.onMarkupChanged != null) {
widget.onMarkupChanged(controller.markupText);
}
},
),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/option_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class OptionList extends StatelessWidget {
decoration:
suggestionListDecoration ?? BoxDecoration(color: Colors.white),
constraints: BoxConstraints(
maxHeight: this.suggestionListHeight,
maxHeight: suggestionListHeight,
),
width: MediaQuery.of(context).size.width,
child: ListView.builder(
Expand All @@ -41,7 +41,7 @@ class OptionList extends StatelessWidget {
: Container(
padding: EdgeInsets.all(20.0),
child: Text(
data[index]["display"],
data[index]['display'],
style: TextStyle(fontSize: 12),
),
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_mentions
description: A simple flutter input widget to add @ mentions functionality to your app.
version: 0.1.0
version: 0.1.1
homepage: https://github.com/fayeed/flutter_mentions

environment:
Expand Down

0 comments on commit b83fa0b

Please sign in to comment.