From 6b5d7a6fe2f5bfcc9285b239a3b54ac82f2e4ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 29 Sep 2020 22:34:30 +0200 Subject: [PATCH 1/2] case insensitive suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- lib/src/suggestions_textfield.dart | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/src/suggestions_textfield.dart b/lib/src/suggestions_textfield.dart index cd641c6..a9c8328 100644 --- a/lib/src/suggestions_textfield.dart +++ b/lib/src/suggestions_textfield.dart @@ -151,12 +151,31 @@ class _SuggestionsTextFieldState extends State { ///Check onChanged void _checkOnChanged(String str) { if (_suggestions != null) { - _matches = - _suggestions.where((String sgt) => sgt.startsWith(str)).toList(); + _matches = _suggestions + .where( + (String sgt) => sgt.toLowerCase().startsWith(str.toLowerCase())) + .toList(); if (str.isEmpty) _matches = []; - if (_matches.length > 1) _matches.removeWhere((String mtc) => mtc == str); + if (_matches.length > 1) + _matches.removeWhere( + (String mtc) => mtc.toLowerCase() == str.toLowerCase()); + + if (_matches.isNotEmpty && str.isNotEmpty) { + final _newValue = _matches.first.substring(0, str.length); + // Set value instead of text and subsequent selection + // to prevent recreating the widget. This prevents the + // cursor from moving to the beginnin. + _controller.value = TextEditingValue( + // use the same casing as the first match + text: _newValue, + // and place curser to the end of the line + selection: TextSelection.fromPosition( + TextPosition(offset: _newValue.length), + ), + ); + } setState(() { _helperCheck = From 257e206ca8e2fb5cd79f34c7d4dc1522ae410bb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Sun, 31 Oct 2021 20:41:42 +0100 Subject: [PATCH 2/2] nullsafe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- .../plugins/GeneratedPluginRegistrant.java | 2 + example/android/local.properties | 2 +- .../ios/Flutter/flutter_export_environment.sh | 6 +- lib/src/item_tags.dart | 162 +++++++++--------- lib/src/suggestions_textfield.dart | 66 +++---- lib/src/tags.dart | 66 +++---- lib/src/util/custom_wrap.dart | 72 ++++---- pubspec.lock | 38 ++-- pubspec.yaml | 2 +- 9 files changed, 204 insertions(+), 212 deletions(-) diff --git a/example/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java b/example/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java index afa3bb6..539ab02 100644 --- a/example/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java +++ b/example/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java @@ -2,6 +2,7 @@ import androidx.annotation.Keep; import androidx.annotation.NonNull; +import io.flutter.Log; import io.flutter.embedding.engine.FlutterEngine; @@ -12,6 +13,7 @@ */ @Keep public final class GeneratedPluginRegistrant { + private static final String TAG = "GeneratedPluginRegistrant"; public static void registerWith(@NonNull FlutterEngine flutterEngine) { } } diff --git a/example/android/local.properties b/example/android/local.properties index f1ed385..72742c0 100644 --- a/example/android/local.properties +++ b/example/android/local.properties @@ -1,4 +1,4 @@ -sdk.dir=C:\\Users\\NINU0\\AppData\\Local\\Android\\Sdk +sdk.dir=C:\\Users\\jfd\\AppData\\Local\\Android\\sdk flutter.sdk=C:\\flutter flutter.buildMode=debug flutter.versionName=1.0.0 diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index ed2333f..746e571 100644 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -1,12 +1,10 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. export "FLUTTER_ROOT=C:\flutter" -export "FLUTTER_APPLICATION_PATH=D:\Android\Flutter\package\flutter_tags\example" +export "FLUTTER_APPLICATION_PATH=C:\Users\jfd\Repositories\flutter_tags\example" +export "COCOAPODS_PARALLEL_CODE_SIGN=true" export "FLUTTER_TARGET=lib\main.dart" export "FLUTTER_BUILD_DIR=build" -export "SYMROOT=${SOURCE_ROOT}/../build\ios" -export "OTHER_LDFLAGS=$(inherited) -framework Flutter" -export "FLUTTER_FRAMEWORK_DIR=C:\flutter\bin\cache\artifacts\engine\ios" export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NUMBER=1" export "DART_OBFUSCATION=false" diff --git a/lib/src/item_tags.dart b/lib/src/item_tags.dart index 816cbe4..dcbc53b 100644 --- a/lib/src/item_tags.dart +++ b/lib/src/item_tags.dart @@ -23,8 +23,8 @@ enum ItemTagsCombine { class ItemTags extends StatefulWidget { ItemTags( - {@required this.index, - @required this.title, + {required this.index, + required this.title, this.textScaleFactor, this.active = true, this.pressEnabled = true, @@ -50,7 +50,7 @@ class ItemTags extends StatefulWidget { this.colorShowDuplicate = Colors.red, this.onPressed, this.onLongPressed, - Key key}) + Key? key}) : assert(index != null), assert(title != null), super(key: key); @@ -62,7 +62,7 @@ class ItemTags extends StatefulWidget { final String title; /// Scale Factor of [ItemTags] - double - final double textScaleFactor; + final double? textScaleFactor; /// Initial bool value final bool active; @@ -77,13 +77,13 @@ class ItemTags extends StatefulWidget { final ItemTagsCombine combine; /// Icon of [ItemTags] - final ItemTagsIcon icon; + final ItemTagsIcon? icon; /// Image of [ItemTags] - final ItemTagsImage image; + final ItemTagsImage? image; /// Custom Remove Button of [ItemTags] - final ItemTagsRemoveButton removeButton; + final ItemTagsRemoveButton? removeButton; /// TextStyle of the [ItemTags] final TextStyle textStyle; @@ -92,10 +92,10 @@ class ItemTags extends StatefulWidget { final MainAxisAlignment alignment; /// border-radius of [ItemTags] - final BorderRadius borderRadius; + final BorderRadius? borderRadius; /// custom border-side of [ItemTags] - final BoxBorder border; + final BoxBorder? border; /// padding of the [ItemTags] final EdgeInsets padding; @@ -122,19 +122,19 @@ class ItemTags extends StatefulWidget { final Color activeColor; /// highlight Color [ItemTags] - final Color highlightColor; + final Color? highlightColor; /// Splash color [ItemTags] - final Color splashColor; + final Color? splashColor; /// Color show duplicate [ItemTags] final Color colorShowDuplicate; /// callback - final OnPressedCallback onPressed; + final OnPressedCallback? onPressed; /// callback - final OnLongPressedCallback onLongPressed; + final OnLongPressedCallback? onLongPressed; @override _ItemTagsState createState() => _ItemTagsState(); @@ -143,12 +143,12 @@ class ItemTags extends StatefulWidget { class _ItemTagsState extends State { final double _initBorderRadius = 50; - DataListInherited _dataListInherited; - DataList _dataList; + late DataListInherited _dataListInherited; + DataList? _dataList; void _setDataList() { // Get List from Tags widget - _dataListInherited = DataListInherited.of(context); + _dataListInherited = DataListInherited.of(context)!; // set List length if (_dataListInherited.list.length < _dataListInherited.itemCount) @@ -156,13 +156,15 @@ class _ItemTagsState extends State { if (_dataListInherited.list.length > (widget.index + 1) && _dataListInherited.list.elementAt(widget.index) != null && - _dataListInherited.list.elementAt(widget.index).title != widget.title) { + _dataListInherited.list.elementAt(widget.index)?.title != + widget.title) { // when an element is removed from the data source _dataListInherited.list.removeAt(widget.index); // when all item list changed in data source if (_dataListInherited.list.elementAt(widget.index) != null && - _dataListInherited.list.elementAt(widget.index).title != widget.title) + _dataListInherited.list.elementAt(widget.index)?.title != + widget.title) _dataListInherited.list .removeRange(widget.index, _dataListInherited.list.length); } @@ -194,17 +196,17 @@ class _ItemTagsState extends State { //print(_dataListInherited.list.length); // update Listener - if (_dataList != null) _dataList.removeListener(_didValueChange); + if (_dataList != null) _dataList!.removeListener(_didValueChange); _dataList = _dataListInherited.list.elementAt(widget.index); - _dataList.addListener(_didValueChange); + _dataList!.addListener(_didValueChange); } _didValueChange() => setState(() {}); @override void dispose() { - _dataList.removeListener(_didValueChange); + _dataList!.removeListener(_didValueChange); super.dispose(); } @@ -212,11 +214,11 @@ class _ItemTagsState extends State { Widget build(BuildContext context) { _setDataList(); - final double fontSize = widget.textStyle.fontSize; + final double? fontSize = widget.textStyle.fontSize; - Color color = _dataList.active ? widget.activeColor : widget.color; + Color color = _dataList!.active == true ? widget.activeColor : widget.color; - if (_dataList.showDuplicate) color = widget.colorShowDuplicate; + if (_dataList!.showDuplicate == true) color = widget.colorShowDuplicate; return Material( color: color, @@ -237,29 +239,29 @@ class _ItemTagsState extends State { Border.all(color: widget.activeColor, width: 0.5), borderRadius: widget.borderRadius ?? BorderRadius.circular(_initBorderRadius)), - padding: widget.padding * (fontSize / 14), + padding: widget.padding * ((fontSize ?? 14) / 14), child: _combine), onTap: widget.pressEnabled ? () { if (widget.singleItem) { - _singleItem(_dataListInherited, _dataList); - _dataList.active = true; + _singleItem(_dataListInherited, _dataList!); + _dataList!.active = true; } else - _dataList.active = !_dataList.active; + _dataList!.active = !_dataList!.active; if (widget.onPressed != null) - widget.onPressed(Item( + widget.onPressed!(Item( index: widget.index, - title: _dataList.title, - active: _dataList.active, + title: _dataList!.title, + active: _dataList!.active, customData: widget.customData)); } : null, onLongPress: widget.onLongPressed != null - ? () => widget.onLongPressed(Item( + ? () => widget.onLongPressed!(Item( index: widget.index, - title: _dataList.title, - active: _dataList.active, + title: _dataList!.title, + active: _dataList!.active, customData: widget.customData)) : null, ), @@ -268,8 +270,8 @@ class _ItemTagsState extends State { Widget get _combine { if (widget.image != null) - assert((widget.image.image != null && widget.image.child == null) || - (widget.image.child != null && widget.image.image == null)); + assert((widget.image!.image != null && widget.image!.child == null) || + (widget.image!.child != null && widget.image!.image == null)); final Widget text = Text( widget.title, softWrap: false, @@ -280,7 +282,7 @@ class _ItemTagsState extends State { ); final Widget icon = widget.icon != null ? Container( - padding: widget.icon.padding ?? + padding: widget.icon!.padding ?? (widget.combine == ItemTagsCombine.onlyIcon || widget.combine == ItemTagsCombine.imageOrIconOrText ? null @@ -288,32 +290,32 @@ class _ItemTagsState extends State { ? EdgeInsets.only(right: 5) : EdgeInsets.only(left: 5)), child: Icon( - widget.icon.icon, + widget.icon!.icon, color: _textStyle.color, - size: _textStyle.fontSize * 1.2, + size: (_textStyle.fontSize ?? 14) * 1.2, ), ) : text; final Widget image = widget.image != null ? Container( - padding: widget.image.padding ?? + padding: widget.image?.padding ?? (widget.combine == ItemTagsCombine.onlyImage || widget.combine == ItemTagsCombine.imageOrIconOrText ? null : widget.combine == ItemTagsCombine.withTextAfter ? EdgeInsets.only(right: 5) : EdgeInsets.only(left: 5)), - child: widget.image.child ?? + child: widget.image!.child ?? CircleAvatar( - radius: - widget.image.radius * (widget.textStyle.fontSize / 14), + radius: widget.image!.radius * + ((widget.textStyle.fontSize ?? 14) / 14), backgroundColor: Colors.transparent, - backgroundImage: widget.image.image, + backgroundImage: widget.image!.image, ), ) : text; - final List list = List(); + final List list = List.empty(growable: true); switch (widget.combine) { case ItemTagsCombine.onlyText: @@ -376,28 +378,27 @@ class _ItemTagsState extends State { fit: BoxFit.fill, child: GestureDetector( child: Container( - margin: widget.removeButton.margin ?? + margin: widget.removeButton!.margin ?? EdgeInsets.only(left: 5), - padding: - (widget.removeButton.padding ?? EdgeInsets.all(2)) * - (widget.textStyle.fontSize / 14), + padding: (widget.removeButton!.padding ?? + EdgeInsets.all(2)) * + ((widget.textStyle.fontSize ?? 14) / 14), decoration: BoxDecoration( - color: widget.removeButton.backgroundColor ?? + color: widget.removeButton!.backgroundColor ?? Colors.black, - borderRadius: widget.removeButton.borderRadius ?? + borderRadius: widget.removeButton!.borderRadius ?? BorderRadius.circular(_initBorderRadius), ), - child: widget.removeButton.padding ?? - Icon( - Icons.clear, - color: widget.removeButton.color ?? Colors.white, - size: (widget.removeButton.size ?? 12) * - (widget.textStyle.fontSize / 14), - ), + child: Icon( + widget.removeButton!.icon ?? Icons.clear, + color: widget.removeButton!.color ?? Colors.white, + size: (widget.removeButton!.size ?? 12) * + ((widget.textStyle.fontSize ?? 14) / 14), + ), ), onTap: () { - if (widget.removeButton.onRemoved != null) { - if (widget.removeButton.onRemoved()) + if (widget.removeButton!.onRemoved != null) { + if (widget.removeButton!.onRemoved!()) _dataListInherited.list.removeAt(widget.index); } }, @@ -413,40 +414,37 @@ class _ItemTagsState extends State { case MainAxisAlignment.spaceBetween: case MainAxisAlignment.start: return TextAlign.start; - break; case MainAxisAlignment.end: return TextAlign.end; - break; case MainAxisAlignment.spaceAround: case MainAxisAlignment.spaceEvenly: case MainAxisAlignment.center: return TextAlign.center; } - return null; } ///TextStyle TextStyle get _textStyle { return widget.textStyle.apply( - color: _dataList.active ? widget.textActiveColor : widget.textColor, + color: _dataList!.active ? widget.textActiveColor : widget.textColor, ); } /// Single item selection void _singleItem(DataListInherited dataSetIn, DataList dataSet) { dataSetIn.list - .where((tg) => tg.active) + .where((tg) => tg?.active == true) .where((tg2) => tg2 != dataSet) - .forEach((tg) => tg.active = false); + .forEach((tg) => tg?.active = false); } } ///callback class Item { Item({this.index, this.title, this.active, this.customData}); - final int index; - final String title; - final bool active; + final int? index; + final String? title; + final bool? active; final dynamic customData; @override @@ -460,16 +458,16 @@ class ItemTagsImage { ItemTagsImage({this.radius = 8, this.padding, this.image, this.child}); final double radius; - final EdgeInsets padding; - final ImageProvider image; - final Widget child; + final EdgeInsets? padding; + final ImageProvider? image; + final Widget? child; } /// ItemTag Icon class ItemTagsIcon { - ItemTagsIcon({this.padding, @required this.icon}); + ItemTagsIcon({this.padding, required this.icon}); - final EdgeInsets padding; + final EdgeInsets? padding; final IconData icon; } @@ -485,14 +483,14 @@ class ItemTagsRemoveButton { this.margin, this.onRemoved}); - final IconData icon; - final double size; - final Color backgroundColor; - final Color color; - final BorderRadius borderRadius; - final EdgeInsets padding; - final EdgeInsets margin; + final IconData? icon; + final double? size; + final Color? backgroundColor; + final Color? color; + final BorderRadius? borderRadius; + final EdgeInsets? padding; + final EdgeInsets? margin; /// callback - final OnRemovedCallback onRemoved; + final OnRemovedCallback? onRemoved; } diff --git a/lib/src/suggestions_textfield.dart b/lib/src/suggestions_textfield.dart index a9c8328..b46d7b0 100644 --- a/lib/src/suggestions_textfield.dart +++ b/lib/src/suggestions_textfield.dart @@ -13,12 +13,12 @@ typedef OnSubmittedCallback = void Function(String string); class SuggestionsTextField extends StatefulWidget { SuggestionsTextField( - {@required this.tagsTextField, this.onSubmitted, Key key}) + {required this.tagsTextField, this.onSubmitted, Key? key}) : assert(tagsTextField != null), super(key: key); final TagsTextField tagsTextField; - final OnSubmittedCallback onSubmitted; + final OnSubmittedCallback? onSubmitted; @override _SuggestionsTextFieldState createState() => _SuggestionsTextFieldState(); @@ -27,14 +27,14 @@ class SuggestionsTextField extends StatefulWidget { class _SuggestionsTextFieldState extends State { final _controller = TextEditingController(); - List _matches = List(); - String _helperText; + List _matches = List.empty(growable: true); + late String _helperText; bool _helperCheck = true; - List _suggestions; - bool _constraintSuggestion; - double _fontSize; - InputDecoration _inputDecoration; + List? _suggestions; + late bool _constraintSuggestion; + late double? _fontSize; + InputDecoration? _inputDecoration; @override void initState() { @@ -57,10 +57,10 @@ class _SuggestionsTextFieldState extends State { child: Container( //width: double.infinity, padding: _inputDecoration != null - ? _inputDecoration.contentPadding + ? _inputDecoration!.contentPadding : EdgeInsets.symmetric( - vertical: 6 * (_fontSize / 14), - horizontal: 6 * (_fontSize / 14)), + vertical: 6 * ((_fontSize ?? 14) / 14), + horizontal: 6 * ((_fontSize ?? 14) / 14)), child: Text( _matches.isNotEmpty ? (_matches.first) : "", softWrap: false, @@ -101,20 +101,20 @@ class _SuggestionsTextFieldState extends State { disabledBorder: InputBorder.none, errorBorder: InputBorder.none, contentPadding: EdgeInsets.symmetric( - vertical: 6 * (_fontSize / 14), - horizontal: 6 * (_fontSize / 14)), + vertical: 6 * ((_fontSize ?? 14) / 14), + horizontal: 6 * ((_fontSize ?? 14) / 14)), focusedBorder: UnderlineInputBorder( borderSide: BorderSide( - color: Colors.blueGrey[300], + color: Colors.blueGrey[300]!, ), ), enabledBorder: UnderlineInputBorder( borderSide: - BorderSide(color: Colors.blueGrey[400].withOpacity(0.3)), + BorderSide(color: Colors.blueGrey[400]!.withOpacity(0.3)), ), border: UnderlineInputBorder( borderSide: - BorderSide(color: Colors.blueGrey[400].withOpacity(0.3)), + BorderSide(color: Colors.blueGrey[400]!.withOpacity(0.3)), )); return input.copyWith( @@ -151,7 +151,7 @@ class _SuggestionsTextFieldState extends State { ///Check onChanged void _checkOnChanged(String str) { if (_suggestions != null) { - _matches = _suggestions + _matches = _suggestions! .where( (String sgt) => sgt.toLowerCase().startsWith(str.toLowerCase())) .toList(); @@ -187,7 +187,7 @@ class _SuggestionsTextFieldState extends State { } if (widget.tagsTextField.onChanged != null) - widget.tagsTextField.onChanged(str); + widget.tagsTextField.onChanged!(str); } } @@ -217,26 +217,26 @@ class TagsTextField { this.onChanged}); final double width; - final EdgeInsets padding; + final EdgeInsets? padding; final bool enabled; final bool duplicates; final TextStyle textStyle; - final InputDecoration inputDecoration; - final bool autocorrect; - final List suggestions; + final InputDecoration? inputDecoration; + final bool? autocorrect; + final List? suggestions; /// Allows you to insert tags not present in the list of suggestions final bool constraintSuggestion; final bool lowerCase; - final bool autofocus; - final String hintText; - final Color hintTextColor; - final Color suggestionTextColor; - final String helperText; - final TextStyle helperTextStyle; - final TextInputType keyboardType; - final TextCapitalization textCapitalization; - final int maxLength; - final OnSubmittedCallback onSubmitted; - final OnChangedCallback onChanged; + final bool? autofocus; + final String? hintText; + final Color? hintTextColor; + final Color? suggestionTextColor; + final String? helperText; + final TextStyle? helperTextStyle; + final TextInputType? keyboardType; + final TextCapitalization? textCapitalization; + final int? maxLength; + final OnSubmittedCallback? onSubmitted; + final OnChangedCallback? onChanged; } diff --git a/lib/src/tags.dart b/lib/src/tags.dart index 0542abb..f5b3369 100644 --- a/lib/src/tags.dart +++ b/lib/src/tags.dart @@ -21,19 +21,14 @@ class Tags extends StatefulWidget { this.direction = Axis.horizontal, this.verticalDirection = VerticalDirection.down, this.textDirection = TextDirection.ltr, - this.itemBuilder, + required this.itemBuilder, this.textField, - Key key}) + Key? key}) : assert(itemCount >= 0), - assert(alignment != null), - assert(runAlignment != null), - assert(direction != null), - assert(verticalDirection != null), - assert(textDirection != null), super(key: key); ///specific number of columns - final int columns; + final int? columns; ///numer of item List final int itemCount; @@ -76,7 +71,7 @@ class Tags extends StatefulWidget { final ItemBuilder itemBuilder; /// custom TextField - final TagsTextField textField; + final TagsTextField? textField; @override TagsState createState() => TagsState(); @@ -87,16 +82,16 @@ class TagsState extends State { Orientation _orientation = Orientation.portrait; double _width = 0; - final List _list = List(); + final List _list = List.empty(growable: true); - List get getAllItem => _list.toList(); + List get getAllItem => _list.toList(); //get the current width of the screen void _getWidthContext() { - WidgetsBinding.instance.addPostFrameCallback((_) { + WidgetsBinding.instance?.addPostFrameCallback((_) { final keyContext = _containerKey.currentContext; if (keyContext != null) { - final RenderBox box = keyContext.findRenderObject(); + final RenderBox box = keyContext.findRenderObject() as RenderBox; final size = box.size; setState(() { _width = size.width; @@ -155,32 +150,32 @@ class TagsState extends State { /*if(_list.length < widget.itemCount) _list.clear();*/ - final Widget textField = widget.textField != null + final Widget? textField = widget.textField != null ? Container( alignment: Alignment.center, - width: widget.symmetry ? _widthCalc() : widget.textField.width, - padding: widget.textField.padding, + width: widget.symmetry ? _widthCalc() : widget.textField!.width, + padding: widget.textField!.padding, child: SuggestionsTextField( - tagsTextField: widget.textField, + tagsTextField: widget.textField!, onSubmitted: (String str) { - if (!widget.textField.duplicates) { - final List lst = - _list.where((l) => l.title == str).toList(); + if (!widget.textField!.duplicates) { + final List lst = + _list.where((l) => l?.title == str).toList(); if (lst.isNotEmpty) { - lst.forEach((d) => d.showDuplicate = true); + lst.forEach((d) => d?.showDuplicate = true); return; } } - if (widget.textField.onSubmitted != null) - widget.textField.onSubmitted(str); + if (widget.textField!.onSubmitted != null) + widget.textField!.onSubmitted!(str); }, ), ) : null; - List finalList = List(); + List finalList = List.empty(growable: true); List itemList = List.generate(widget.itemCount, (i) { final Widget item = widget.itemBuilder(i); @@ -233,10 +228,14 @@ class TagsState extends State { /// Inherited Widget class DataListInherited extends InheritedWidget { DataListInherited( - {Key key, this.list, this.symmetry, this.itemCount, Widget child}) + {Key? key, + required this.list, + required this.symmetry, + required this.itemCount, + required Widget child}) : super(key: key, child: child); - final List list; + final List list; final bool symmetry; final int itemCount; @@ -248,14 +247,14 @@ class DataListInherited extends InheritedWidget { /*static DataListInherited of(BuildContext context) => context.inheritFromWidgetOfExactType(DataListInherited);*/ - static DataListInherited of(BuildContext context) => - context.dependOnInheritedWidgetOfExactType(); + static DataListInherited? of(BuildContext context) => + context.dependOnInheritedWidgetOfExactType(); } /// Data List class DataList extends ValueNotifier implements Item { DataList( - {@required this.title, + {required this.title, this.index, bool highlights = false, bool active = true, @@ -266,9 +265,9 @@ class DataList extends ValueNotifier implements Item { final String title; final dynamic customData; - final int index; + final int? index; - get showDuplicate { + bool get showDuplicate { final val = _showDuplicate; _showDuplicate = false; return val; @@ -281,7 +280,10 @@ class DataList extends ValueNotifier implements Item { notifyListeners(); } - get active => _active; + bool get active { + return _active; + } + bool _active; set active(bool a) { _active = a; diff --git a/lib/src/util/custom_wrap.dart b/lib/src/util/custom_wrap.dart index cad2050..d4c2c9f 100644 --- a/lib/src/util/custom_wrap.dart +++ b/lib/src/util/custom_wrap.dart @@ -5,7 +5,7 @@ import 'package:flutter/widgets.dart'; /// Custom Wrap class CustomWrap extends MultiChildRenderObjectWidget { CustomWrap({ - Key key, + Key? key, this.column, this.symmetry, this.direction = Axis.horizontal, @@ -19,9 +19,9 @@ class CustomWrap extends MultiChildRenderObjectWidget { List children = const [], }) : super(key: key, children: children); - final int column; + final int? column; - final bool symmetry; + final bool? symmetry; final Axis direction; @@ -35,7 +35,7 @@ class CustomWrap extends MultiChildRenderObjectWidget { final WrapCrossAlignment crossAxisAlignment; - final TextDirection textDirection; + final TextDirection? textDirection; final VerticalDirection verticalDirection; @@ -93,16 +93,16 @@ class CustomRenderWrap extends RenderBox ContainerRenderObjectMixin, RenderBoxContainerDefaultsMixin { CustomRenderWrap({ - List children, - int column, - bool symmetry, + List? children, + int? column, + bool? symmetry, Axis direction = Axis.horizontal, WrapAlignment alignment = WrapAlignment.start, double spacing = 0.0, WrapAlignment runAlignment = WrapAlignment.start, double runSpacing = 0.0, WrapCrossAlignment crossAxisAlignment = WrapCrossAlignment.start, - TextDirection textDirection, + TextDirection? textDirection, VerticalDirection verticalDirection = VerticalDirection.down, }) : assert(direction != null), assert(alignment != null), @@ -123,17 +123,17 @@ class CustomRenderWrap extends RenderBox addAll(children); } - int get column => _column; - int _column; - set column(int value) { + int? get column => _column; + int? _column; + set column(int? value) { if (column == value) return; _column = value; markNeedsLayout(); } - bool get symmetry => _symmetry; - bool _symmetry; - set symmetry(bool value) { + bool? get symmetry => _symmetry; + bool? _symmetry; + set symmetry(bool? value) { if (symmetry == value) return; _symmetry = value; markNeedsLayout(); @@ -193,9 +193,9 @@ class CustomRenderWrap extends RenderBox markNeedsLayout(); } - TextDirection get textDirection => _textDirection; - TextDirection _textDirection; - set textDirection(TextDirection value) { + TextDirection? get textDirection => _textDirection; + TextDirection? _textDirection; + set textDirection(TextDirection? value) { if (_textDirection != value) { _textDirection = value; markNeedsLayout(); @@ -283,7 +283,7 @@ class CustomRenderWrap extends RenderBox double runWidth = 0.0; double runHeight = 0.0; int childCount = 0; - RenderBox child = firstChild; + RenderBox? child = firstChild; while (child != null) { final double childWidth = child.getMaxIntrinsicWidth(double.infinity); final double childHeight = child.getMaxIntrinsicHeight(childWidth); @@ -312,7 +312,7 @@ class CustomRenderWrap extends RenderBox double runHeight = 0.0; double runWidth = 0.0; int childCount = 0; - RenderBox child = firstChild; + RenderBox? child = firstChild; while (child != null) { final double childHeight = child.getMaxIntrinsicHeight(double.infinity); final double childWidth = child.getMaxIntrinsicWidth(childHeight); @@ -339,7 +339,7 @@ class CustomRenderWrap extends RenderBox switch (direction) { case Axis.horizontal: double width = 0.0; - RenderBox child = firstChild; + RenderBox? child = firstChild; while (child != null) { width = math.max(width, child.getMinIntrinsicWidth(double.infinity)); child = childAfter(child); @@ -348,7 +348,6 @@ class CustomRenderWrap extends RenderBox case Axis.vertical: return _computeIntrinsicWidthForHeight(height); } - return null; } @override @@ -356,7 +355,7 @@ class CustomRenderWrap extends RenderBox switch (direction) { case Axis.horizontal: double width = 0.0; - RenderBox child = firstChild; + RenderBox? child = firstChild; while (child != null) { width += child.getMaxIntrinsicWidth(double.infinity); child = childAfter(child); @@ -365,7 +364,6 @@ class CustomRenderWrap extends RenderBox case Axis.vertical: return _computeIntrinsicWidthForHeight(height); } - return null; } @override @@ -375,7 +373,7 @@ class CustomRenderWrap extends RenderBox return _computeIntrinsicHeightForWidth(width); case Axis.vertical: double height = 0.0; - RenderBox child = firstChild; + RenderBox? child = firstChild; while (child != null) { height = math.max(height, child.getMinIntrinsicHeight(double.infinity)); @@ -383,7 +381,6 @@ class CustomRenderWrap extends RenderBox } return height; } - return null; } @override @@ -393,18 +390,17 @@ class CustomRenderWrap extends RenderBox return _computeIntrinsicHeightForWidth(width); case Axis.vertical: double height = 0.0; - RenderBox child = firstChild; + RenderBox? child = firstChild; while (child != null) { height += child.getMaxIntrinsicHeight(double.infinity); child = childAfter(child); } return height; } - return null; } @override - double computeDistanceToActualBaseline(TextBaseline baseline) { + double? computeDistanceToActualBaseline(TextBaseline baseline) { return defaultComputeDistanceToHighestActualBaseline(baseline); } @@ -415,7 +411,6 @@ class CustomRenderWrap extends RenderBox case Axis.vertical: return child.size.height; } - return 0.0; } double _getCrossAxisExtent(RenderBox child) { @@ -425,7 +420,6 @@ class CustomRenderWrap extends RenderBox case Axis.vertical: return child.size.width; } - return 0.0; } Offset _getOffset(double mainAxisOffset, double crossAxisOffset) { @@ -435,7 +429,6 @@ class CustomRenderWrap extends RenderBox case Axis.vertical: return Offset(crossAxisOffset, mainAxisOffset); } - return Offset.zero; } double _getChildCrossAxisOffset(bool flipCrossAxis, double runCrossAxisExtent, @@ -449,7 +442,6 @@ class CustomRenderWrap extends RenderBox case WrapCrossAlignment.center: return freeSpace / 2.0; } - return 0.0; } bool _hasVisualOverflow = false; @@ -458,7 +450,7 @@ class CustomRenderWrap extends RenderBox void performLayout() { assert(_debugHasNecessaryDirections); _hasVisualOverflow = false; - RenderBox child = firstChild; + RenderBox? child = firstChild; if (child == null) { size = constraints.smallest; return; @@ -481,8 +473,6 @@ class CustomRenderWrap extends RenderBox if (textDirection == TextDirection.rtl) flipCrossAxis = true; break; } - assert(childConstraints != null); - assert(mainAxisLimit != null); final double spacing = this.spacing; final double runSpacing = this.runSpacing; final List<_RunMetrics> runMetrics = <_RunMetrics>[]; @@ -516,7 +506,7 @@ class CustomRenderWrap extends RenderBox if (childCount > 0) runMainAxisExtent += spacing; runCrossAxisExtent = math.max(runCrossAxisExtent, childCrossAxisExtent); childCount += 1; - final WrapParentData childParentData = child.parentData; + final WrapParentData childParentData = child.parentData as WrapParentData; childParentData._runIndex = runMetrics.length; child = childParentData.nextSibling; } @@ -597,11 +587,12 @@ class CustomRenderWrap extends RenderBox //print(symmetry); switch (alignment) { case WrapAlignment.start: - if (symmetry) childLeadingSpace = spacing / 2; + if (symmetry == true) childLeadingSpace = spacing / 2; break; case WrapAlignment.end: childLeadingSpace = mainAxisFreeSpace; - if (symmetry) childLeadingSpace = mainAxisFreeSpace - spacing / 2; + if (symmetry == true) + childLeadingSpace = mainAxisFreeSpace - spacing / 2; break; case WrapAlignment.center: childLeadingSpace = mainAxisFreeSpace / 2.0; @@ -628,7 +619,8 @@ class CustomRenderWrap extends RenderBox if (flipCrossAxis) crossAxisOffset -= runCrossAxisExtent; while (child != null) { - final WrapParentData childParentData = child.parentData; + final WrapParentData childParentData = + child.parentData as WrapParentData; if (childParentData._runIndex != i) break; final double childMainAxisExtent = _getMainAxisExtent(child); final double childCrossAxisExtent = _getCrossAxisExtent(child); @@ -652,7 +644,7 @@ class CustomRenderWrap extends RenderBox } @override - bool hitTestChildren(HitTestResult result, {Offset position}) { + bool hitTestChildren(BoxHitTestResult result, {required Offset position}) { return defaultHitTestChildren(result, position: position); } diff --git a/pubspec.lock b/pubspec.lock index 9477cdd..8077d23 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,49 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.2" + version: "2.8.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.3" + version: "1.3.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.13" + version: "1.15.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -66,21 +66,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.8" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.7.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -92,55 +92,55 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.5" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.17" + version: "0.4.2" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0" sdks: - dart: ">=2.9.0-14.0.dev <3.0.0" + dart: ">=2.12.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 7c5ca02..162cb34 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ author: Antonino Di Natale homepage: https://github.com/Dn-a/flutter_tags environment: - sdk: ">=2.0.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: flutter: