smart_select 3.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 92

smart_select #

Smart select allows you to easily convert your usual form selects into dynamic pages with various choices input. This widget is inspired by Smart Select component from Framework7.

Demo #

Preview #

Watch the demo

Download #

Demo App

Features #

  • Select single or multiple choice
  • Open choices modal in full page, bottom sheet, or popup dialog
  • Various choices input (radio, checkbox, switch, chips)
  • Grouping choices with sticky header
  • Customizable trigger/tile widget
  • Customizable modal style
  • Customizable modal header style
  • Customizable choices style
  • Flexible option input
  • Filterable option
  • Async option
  • and many more

TODO #

  • Full support async option using Future

Usage #

For a complete usage, please see the example.

To read more about classes and other references used by smart_select, see the API Reference.

Single Choice #

SmartSelect<T>.single()

String value = 'flutter';
List<SmartSelectOption<String>> options = [
  SmartSelectOption<String>(value: 'ion', title: 'Ionic'),
  SmartSelectOption<String>(value: 'flu', title: 'Flutter'),
  SmartSelectOption<String>(value: 'rea', title: 'React Native'),
];

@override
Widget build(BuildContext context) {
  return SmartSelect<String>.single(
    title: 'Frameworks',
    value: value,
    options: options,
    onChange: (val) => setState(() => value = val)
  );
}

Multiple Choice #

SmartSelect<T>.multiple()

List<int> value = [2];
List<SmartSelectOption<int>> frameworks = [
  SmartSelectOption<int>(value: 1, title: 'Ionic'),
  SmartSelectOption<int>(value: 2, title: 'Flutter'),
  SmartSelectOption<int>(value: 3, title: 'React Native'),
];

@override
Widget build(BuildContext context) {
  return SmartSelect<int>.multiple(
    title: 'Frameworks',
    value: value,
    options: options,
    onChange: (val) => setState(() => value = val),
  );
}

Build Option List #

options property is List<SmartSelectOption<T>>, it can be input directly as in the example below, more info about SmartSelectOption can be found on the API Reference

SmartSelect<T>.single/multiple(
  ...,
  ...,
  options: <SmartSelectOption<int>>[
    SmartSelectOption<int>(value: 1, title: 'Ionic'),
    SmartSelectOption<int>(value: 2, title: 'Flutter'),
    SmartSelectOption<int>(value: 3, title: 'React Native'),
  ],
);

options also can be created from any list using helper provided by this package, like the example below

List<Map<String, String>> days = [
  { 'value': 'mon', 'title': 'Monday' },
  { 'value': 'tue', 'title': 'Tuesday' },
  { 'value': 'wed', 'title': 'Wednesday' },
  { 'value': 'thu', 'title': 'Thursday' },
  { 'value': 'fri', 'title': 'Friday' },
  { 'value': 'sat', 'title': 'Saturday' },
  { 'value': 'sun', 'title': 'Sunday' },
];

SmartSelect<T>.single/multiple(
  ...,
  ...,
  options: SmartSelectOption.listFrom<T, Map<String, String>>(
    source: days,
    value: (index, item) => item['value'],
    title: (index, item) => item['title'],
  ),
);

By default SmartSelect will open choices modal in full page. You can change it by changing the modalType property with this value:

SmartSelect<T>.single/multiple(
  ...,
  ...,
  // open in full page
  modalType: SmartSelectModalType.fullPage,
  // open in popup dialog
  modalType: SmartSelectModalType.popupDialog,
  // open in bottom sheet
  modalType: SmartSelectModalType.bottomSheet,
);

Choice Type #

By default SmartSelect will use radio for single choice and checkbox for multiple choice, but it can change by changing the choiceType with this value:

SmartSelect<T>.single(
  ...,
  ...,
  // default use radio
  choiceType: SmartSelectChoiceType.radios,
  // use chips
  choiceType: SmartSelectChoiceType.chips,
);
SmartSelect<T>.multiple(
  ...,
  ...,
  // default use checkbox
  choiceType: SmartSelectChoiceType.checkboxes,
  // use chips
  choiceType: SmartSelectChoiceType.chips,
  // use switch
  choiceType: SmartSelectChoiceType.switches,
);

Thanks #

License #

Copyright (c) 2019 Irfan Vigma Taufik

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

[3.0.3] - 2020-01-22 #

  • Swap position generic type helper function for create list option from any list

[3.0.2] - 2020-01-22 #

  • Support disabled and hidden option
  • Customizable choices wrapper padding
  • Single choice chips now use checkmark by default, can be configure by choiceConfig.useCheckmark
  • Improve documentation
  • Update example

[3.0.0] - 2020-01-22 #

  • Breaking changes, more type safety, add more features, and simplify few properties
  • Remove isMultiChoice property, instead use SmartSelect<T>.single() or SmartSelect<T>.multiple()
  • Remove option property, instead use options property and change its value from SmartSelectOptionConfig to List<SmartSelectOption<T>>
  • Remove modal property, instead use modalType to change how to open modal and modalConfig to configure modal header, modal style, etc
  • Remove choice property, instead use choiceType to change choice widget and choiceConfig to configure choice style, etc
  • Choice modal can have different title with trigger/tile widget by configuring modalConfig.title
  • Choice modal can have leading and trailing widget by configuring modalConfig.leading and modalConfig.trailing

[2.0.2] - 2019-12-25 #

  • Upgrade Provider package to 4.0.0

[2.0.1] - 2019-12-21 #

  • fix bug when value is null for multiple choice
  • update demo and add video preview example

[2.0.0] - 2019-12-20 #

  • Use Provider as state management
  • Remove SmartSelect.popup and SmartSelect.sheet constructor
  • Split option configuration into option, modal, and choices
  • Support Chips and Switches as choices widget
  • Add more configurable parameter and remove some option
  • Fix some bugs

[1.0.3] - 2019-12-12 #

  • Change SmartSelectOptionGroupHeaderTheme titleStyle to textStyle
  • Better documentation

[1.0.2] - 2019-12-12 #

  • Move and rename files for better documentation

[1.0.1] - 2019-12-11 #

  • Fully rewrite code
  • Support filterable option item
  • Support grouping options with sticky header
  • Support stats loading
  • More customizable trigger widget
  • Support customize option header widget (theme or builder)
  • Support customize option item widget (theme or builder)
  • Support customize option item divider widget
  • Support customizable label, value, and group field

[0.1.1] - 2019-11-26 #

  • Add values field to SmartMultiSelectBuilderInfo class
  • Update default SmartMultiSelect placeholder
  • Update example

[0.1.0] - 2019-11-26 #

  • Fixed bug return value multi select not updated from popup and bottom sheet options
  • Update example
  • Format documents

[0.0.1] - 2019-11-25 #

  • A description for people who will use that package or version.
  • Add single choice select using page, popup, or bottom sheet
  • Add multiple choice select using page, popup, or bottom sheet

example/lib/main.dart

import 'package:flutter/material.dart';
import 'features.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Smart Select',
      home: Features(),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  smart_select: ^3.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:smart_select/smart_select.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
85
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
92
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/src/choices.dart.

Run flutter format to format lib/src/choices.dart.

Format lib/src/choices_empty.dart.

Run flutter format to format lib/src/choices_empty.dart.

Format lib/src/choices_grouped.dart.

Run flutter format to format lib/src/choices_grouped.dart.

Fix additional 16 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/choices_item.dart (Run flutter format to format lib/src/choices_item.dart.)
  • lib/src/choices_list.dart (Run flutter format to format lib/src/choices_list.dart.)
  • lib/src/modal.dart (Run flutter format to format lib/src/modal.dart.)
  • lib/src/modal_header.dart (Run flutter format to format lib/src/modal_header.dart.)
  • lib/src/model/choice_config.dart (Run flutter format to format lib/src/model/choice_config.dart.)
  • lib/src/model/choice_theme.dart (Run flutter format to format lib/src/model/choice_theme.dart.)
  • lib/src/model/modal_config.dart (Run flutter format to format lib/src/model/modal_config.dart.)
  • lib/src/model/modal_theme.dart (Run flutter format to format lib/src/model/modal_theme.dart.)
  • lib/src/model/option.dart (Run flutter format to format lib/src/model/option.dart.)
  • lib/src/model/option_list.dart (Run flutter format to format lib/src/model/option_list.dart.)
  • lib/src/model/state.dart (Run flutter format to format lib/src/model/state.dart.)
  • lib/src/model/state_filter.dart (Run flutter format to format lib/src/model/state_filter.dart.)
  • lib/src/model/state_selected.dart (Run flutter format to format lib/src/model/state_selected.dart.)
  • lib/src/state_provider.dart (Run flutter format to format lib/src/state_provider.dart.)
  • lib/src/tile.dart (Run flutter format to format lib/src/tile.dart.)
  • lib/src/widget.dart (Run flutter format to format lib/src/widget.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
provider >=4.0.0 <5.0.0 4.0.4 4.1.0-dev+2
sticky_headers >=0.1.8+1 <1.0.0 0.1.8+1
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
nested 0.0.4
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test