From 6581736ca3db116b90a7750c51c2c01187179cdb Mon Sep 17 00:00:00 2001 From: erick Date: Fri, 19 Jul 2024 09:03:32 +0200 Subject: [PATCH] feat: dialog parameters added. Bump sdk and deps title text style added, surface tint color added. Bumped dart sdk and libraries --- example/lib/main.dart | 23 +++--- example/pubspec.lock | 119 ++++++++++++++++++++--------- example/pubspec.yaml | 4 +- lib/dialog/mult_select_dialog.dart | 51 ++++++------- pubspec.lock | 114 +++++++++++++++++++-------- pubspec.yaml | 2 +- 6 files changed, 205 insertions(+), 108 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 104cb60..d8abb99 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -24,13 +24,13 @@ class Animal { final String name; Animal({ - this.id, - this.name, + required this.id, + required this.name, }); } class MyHomePage extends StatefulWidget { - MyHomePage({Key key, this.title}) : super(key: key); + MyHomePage({Key? key, required this.title}) : super(key: key); final String title; @override _MyHomePageState createState() => _MyHomePageState(); @@ -66,9 +66,7 @@ class _MyHomePageState extends State { Animal(id: 26, name: "Dragonfly"), Animal(id: 27, name: "Dolphin"), ]; - final _items = _animals - .map((animal) => MultiSelectItem(animal, animal.name)) - .toList(); + final _items = _animals.map((animal) => MultiSelectItem(animal, animal.name)).toList(); //List _selectedAnimals = []; List _selectedAnimals2 = []; List _selectedAnimals3 = []; @@ -140,7 +138,7 @@ class _MyHomePageState extends State { ), child: Column( children: [ - MultiSelectBottomSheetField( + MultiSelectBottomSheetField( initialChildSize: 0.4, listType: MultiSelectListType.CHIP, searchable: true, @@ -158,7 +156,7 @@ class _MyHomePageState extends State { }, ), ), - _selectedAnimals2 == null || _selectedAnimals2.isEmpty + _selectedAnimals2.isEmpty ? Container( padding: EdgeInsets.all(10), alignment: Alignment.centerLeft, @@ -196,14 +194,14 @@ class _MyHomePageState extends State { setState(() { _selectedAnimals3 = values; }); - _multiSelectKey.currentState.validate(); + _multiSelectKey.currentState?.validate(); }, chipDisplay: MultiSelectChipDisplay( onTap: (item) { setState(() { _selectedAnimals3.remove(item); }); - _multiSelectKey.currentState.validate(); + _multiSelectKey.currentState?.validate(); }, ), ), @@ -217,7 +215,7 @@ class _MyHomePageState extends State { title: Text("Animals"), headerColor: Colors.blue.withOpacity(0.5), decoration: BoxDecoration( - border: Border.all(color: Colors.blue[700], width: 1.8), + border: Border.all(color: Colors.blue[700]!, width: 1.8), ), selectedChipColor: Colors.blue.withOpacity(0.5), selectedTextStyle: TextStyle(color: Colors.blue[800]), @@ -235,8 +233,7 @@ class _MyHomePageState extends State { }, dialogWidth: MediaQuery.of(context).size.width * 0.7, items: _items, - initialValue: - _selectedAnimals5, // setting the value of this in initState() to pre-select values. + initialValue: _selectedAnimals5, // setting the value of this in initState() to pre-select values. ), ], ), diff --git a/example/pubspec.lock b/example/pubspec.lock index 76cd661..5a228fe 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,49 +5,56 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.9.0" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.18.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.dartlang.org" + sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6 + url: "https://pub.dev" source: hosted - version: "0.1.3" + version: "1.0.8" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted version: "1.3.1" flutter: @@ -60,27 +67,54 @@ packages: description: flutter source: sdk version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + url: "https://pub.dev" + source: hosted + version: "10.0.4" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + url: "https://pub.dev" + source: hosted + version: "3.0.3" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" source: hosted - version: "0.12.12" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" source: hosted - version: "0.1.5" + version: "0.8.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.12.0" multi_select_flutter: dependency: "direct main" description: @@ -92,9 +126,10 @@ packages: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.9.0" sky_engine: dependency: transitive description: flutter @@ -104,50 +139,66 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.9.0" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + url: "https://pub.dev" source: hosted - version: "0.4.12" + version: "0.7.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + url: "https://pub.dev" + source: hosted + version: "14.2.1" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 24a1c77..3343a52 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -8,7 +8,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: ">=2.7.0 <3.0.0" + sdk: '>=2.19.2 <3.0.0' dependencies: flutter: @@ -18,7 +18,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.3 + cupertino_icons: ^1.0.8 dev_dependencies: flutter_test: diff --git a/lib/dialog/mult_select_dialog.dart b/lib/dialog/mult_select_dialog.dart index 433539f..989dfd5 100644 --- a/lib/dialog/mult_select_dialog.dart +++ b/lib/dialog/mult_select_dialog.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; + import '../util/multi_select_actions.dart'; import '../util/multi_select_item.dart'; import '../util/multi_select_list_type.dart'; @@ -51,6 +52,9 @@ class MultiSelectDialog extends StatefulWidget with MultiSelectActions { /// The background color of the dialog. final Color? backgroundColor; + ///Tint color introduced in flutter with material 3 + final Color? surfaceTintColor; + /// The color of the chip body or checkbox border while not selected. final Color? unselectedColor; @@ -60,6 +64,9 @@ class MultiSelectDialog extends StatefulWidget with MultiSelectActions { /// Icon button that hides the search field final Icon? closeSearchIcon; + /// Style the text for the dialog title. + final TextStyle? titleTextStyle; + /// Style the text on the chips or list tiles. final TextStyle? itemsTextStyle; @@ -94,6 +101,7 @@ class MultiSelectDialog extends StatefulWidget with MultiSelectActions { this.width, this.colorator, this.backgroundColor, + this.surfaceTintColor, this.unselectedColor, this.searchIcon, this.closeSearchIcon, @@ -103,6 +111,7 @@ class MultiSelectDialog extends StatefulWidget with MultiSelectActions { this.selectedItemsTextStyle, this.separateSelectedItems = false, this.checkColor, + this.titleTextStyle, }); @override @@ -142,20 +151,16 @@ class _MultiSelectDialogState extends State> { child: CheckboxListTile( checkColor: widget.checkColor, value: item.selected, - activeColor: widget.colorator != null - ? widget.colorator!(item.value) ?? widget.selectedColor - : widget.selectedColor, + activeColor: + widget.colorator != null ? widget.colorator!(item.value) ?? widget.selectedColor : widget.selectedColor, title: Text( item.label, - style: item.selected - ? widget.selectedItemsTextStyle - : widget.itemsTextStyle, + style: item.selected ? widget.selectedItemsTextStyle : widget.itemsTextStyle, ), controlAffinity: ListTileControlAffinity.leading, onChanged: (checked) { setState(() { - _selectedValues = widget.onItemCheckedChange( - _selectedValues, item.value, checked!); + _selectedValues = widget.onItemCheckedChange(_selectedValues, item.value, checked!); if (checked) { item.selected = true; @@ -203,8 +208,7 @@ class _MultiSelectDialogState extends State> { item.selected = false; } setState(() { - _selectedValues = widget.onItemCheckedChange( - _selectedValues, item.value, checked); + _selectedValues = widget.onItemCheckedChange(_selectedValues, item.value, checked); }); if (widget.onSelectionChanged != null) { widget.onSelectionChanged!(_selectedValues); @@ -218,6 +222,8 @@ class _MultiSelectDialogState extends State> { Widget build(BuildContext context) { return AlertDialog( backgroundColor: widget.backgroundColor, + surfaceTintColor: widget.surfaceTintColor, + titleTextStyle: widget.titleTextStyle, title: widget.searchable == false ? widget.title ?? const Text("Select") : Row( @@ -234,19 +240,16 @@ class _MultiSelectDialogState extends State> { hintText: widget.searchHint ?? "Search", focusedBorder: UnderlineInputBorder( borderSide: BorderSide( - color: widget.selectedColor ?? - Theme.of(context).primaryColor, + color: widget.selectedColor ?? Theme.of(context).primaryColor, ), ), ), onChanged: (val) { List> filteredList = []; - filteredList = - widget.updateSearchQuery(val, widget.items); + filteredList = widget.updateSearchQuery(val, widget.items); setState(() { if (widget.separateSelectedItems) { - _items = - widget.separateSelected(filteredList); + _items = widget.separateSelected(filteredList); } else { _items = filteredList; } @@ -275,15 +278,13 @@ class _MultiSelectDialogState extends State> { ), ], ), - contentPadding: - widget.listType == null || widget.listType == MultiSelectListType.LIST - ? EdgeInsets.only(top: 12.0) - : EdgeInsets.all(20), + contentPadding: widget.listType == null || widget.listType == MultiSelectListType.LIST + ? EdgeInsets.only(top: 12.0) + : EdgeInsets.all(20), content: Container( height: widget.height, width: widget.width ?? MediaQuery.of(context).size.width * 0.73, - child: widget.listType == null || - widget.listType == MultiSelectListType.LIST + child: widget.listType == null || widget.listType == MultiSelectListType.LIST ? ListView.builder( itemCount: _items.length, itemBuilder: (context, index) { @@ -302,8 +303,7 @@ class _MultiSelectDialogState extends State> { Text( "CANCEL", style: TextStyle( - color: (widget.selectedColor != null && - widget.selectedColor != Colors.transparent) + color: (widget.selectedColor != null && widget.selectedColor != Colors.transparent) ? widget.selectedColor!.withOpacity(1) : Theme.of(context).primaryColor, ), @@ -317,8 +317,7 @@ class _MultiSelectDialogState extends State> { Text( 'OK', style: TextStyle( - color: (widget.selectedColor != null && - widget.selectedColor != Colors.transparent) + color: (widget.selectedColor != null && widget.selectedColor != Colors.transparent) ? widget.selectedColor!.withOpacity(1) : Theme.of(context).primaryColor, ), diff --git a/pubspec.lock b/pubspec.lock index 8a01ee3..eca24af 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,42 +5,48 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.9.0" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted version: "1.1.1" collection: dependency: "direct main" description: name: collection - url: "https://pub.dartlang.org" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.18.0" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted version: "1.3.1" flutter: @@ -53,34 +59,62 @@ packages: description: flutter source: sdk version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + url: "https://pub.dev" + source: hosted + version: "10.0.4" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + url: "https://pub.dev" + source: hosted + version: "3.0.3" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" source: hosted - version: "0.12.12" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" source: hosted - version: "0.1.5" + version: "0.8.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.12.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.9.0" sky_engine: dependency: transitive description: flutter @@ -90,50 +124,66 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.9.0" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + url: "https://pub.dev" source: hosted - version: "0.4.12" + version: "0.7.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + url: "https://pub.dev" + source: hosted + version: "14.2.1" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.yaml b/pubspec.yaml index 1e676fd..7165716 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,7 +7,7 @@ documentation: https://github.com/CHB61/flutter-multi-select homepage: https://github.com/CHB61/flutter-multi-select environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.19.2 <3.0.0' dependencies: flutter: