From b83fa0b7c80fee76298aecf130c8579e187f234d Mon Sep 17 00:00:00 2001 From: Fayeed Date: Sat, 8 Aug 2020 21:30:24 +0530 Subject: [PATCH] Package updated to v0.1.1 --- CHANGELOG.md | 6 ++- analysis_options.yaml | 47 ++++++++++++++++++ example/lib/main.dart | 58 +++++++++++----------- lib/src/annotation_editing_controller.dart | 41 ++++++++------- lib/src/mention_view.dart | 36 +++++++------- lib/src/option_list.dart | 4 +- pubspec.yaml | 2 +- 7 files changed, 123 insertions(+), 71 deletions(-) create mode 100644 analysis_options.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c78fe0..0cf4116 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..aca88f2 --- /dev/null +++ b/analysis_options.yaml @@ -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 diff --git a/example/lib/main.dart b/example/lib/main.dart index 30d8ac9..99ef738 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -42,7 +42,7 @@ class _MyHomePageState extends State { mainAxisAlignment: MainAxisAlignment.end, children: [ RaisedButton( - child: Text("Get Text"), + child: Text('Get Text'), onPressed: () { print(key.currentState.controller.markupText); }, @@ -55,39 +55,39 @@ class _MyHomePageState extends State { 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, @@ -98,7 +98,7 @@ class _MyHomePageState extends State { children: [ CircleAvatar( backgroundImage: NetworkImage( - data["photo"], + data['photo'], ), ), SizedBox( @@ -106,8 +106,8 @@ class _MyHomePageState extends State { ), Column( children: [ - Text(data["full_name"]), - Text("@${data["display"]}"), + Text(data['full_name']), + Text('@${data['display']}'), ], ) ], @@ -115,14 +115,14 @@ class _MyHomePageState extends State { ); }), 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, ) diff --git a/lib/src/annotation_editing_controller.dart b/lib/src/annotation_editing_controller.dart index 974ac13..0e5aa73 100644 --- a/lib/src/annotation_editing_controller.dart +++ b/lib/src/annotation_editing_controller.dart @@ -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; @@ -39,18 +39,17 @@ class AnnotationEditingController extends TextEditingController { @override TextSpan buildTextSpan({TextStyle style, bool withComposing}) { - List children = []; + var children = []; 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( @@ -58,11 +57,11 @@ class AnnotationEditingController extends TextEditingController { 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); diff --git a/lib/src/mention_view.dart b/lib/src/mention_view.dart index 00cd620..8d339b7 100644 --- a/lib/src/mention_view.dart +++ b/lib/src/mention_view.dart @@ -225,37 +225,38 @@ class FlutterMentionsState extends State { AnnotationEditingController controller; bool _showSuggestions = false; LengthMap _selectedMention; - String _pattern = ""; + String _pattern = ''; @override void initState() { - final Map data = Map(); + final data = {}; // 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, ), @@ -269,12 +270,12 @@ class FlutterMentionsState extends State { final cursorPos = controller.selection.baseOffset; if (cursorPos - 1 > 0) { - int _pos = 0; + var _pos = 0; - final lengthMap = List(); + final 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)); @@ -282,7 +283,7 @@ class FlutterMentionsState extends State { }); 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)); @@ -320,10 +321,10 @@ class FlutterMentionsState extends State { 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(), @@ -379,8 +380,9 @@ class FlutterMentionsState extends State { controller: controller, onChanged: (text) { if (widget.onChanged != null) widget.onChanged(text); - if (widget.onMarkupChanged != null) + if (widget.onMarkupChanged != null) { widget.onMarkupChanged(controller.markupText); + } }, ), ), diff --git a/lib/src/option_list.dart b/lib/src/option_list.dart index 96fd35d..68d0e9c 100644 --- a/lib/src/option_list.dart +++ b/lib/src/option_list.dart @@ -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( @@ -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), ), ), diff --git a/pubspec.yaml b/pubspec.yaml index eaa7228..3d8e4bc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: