Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SmartSelect allows you to easily convert your usual form select or dropdown into dynamic page, popup dialog, or sliding bottom sheet with various choices input such as radio, checkbox, switch, chips, or even custom input. Supports single and multiple choice.

License

NotificationsYou must be signed in to change notification settings

davigmacode/flutter_smart_select

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pub VersionGitHub

Buy Me A Coffee

Important

Hi everyone,

I'm sorry to announce that I'm no longer maintaining thesmart_select package. It's been a great project, but it's become too difficult to maintain.

In its place, I've released a new package calledchoice. The combination tosmart_select andchips_choice with cleaner, more flexible, and composable API for creating inline or prompted choice widgets with single or multiple selection.

I hope you'll check outchoice. I think you'll find it to be a great replacement forsmart_select.

Thanks for your understanding.

SmartSelect allows you to easily convert your usual form select or dropdown into dynamic page, popup dialog, or sliding bottom sheet with various choices input such as radio, checkbox, switch, chips, or even custom input. Supports single and multiple choice. Inspired by Smart Select component fromFramework7.

What's New in Version 4.x.x

  • Customizable every part on modal widget (header, footer, searchbar, confirm button, searchbar toggle) using style configuration or widget builder
  • Validate before confirm
  • Auto search on type
  • Accent marks handler on search
  • Highlight search result
  • Chips tile widget
  • Grid choice layout
  • Horizotal or vertical choice list scroll direction
  • Simplify class name and enum
  • Configurations supportscopyWith andmerge
  • UseStatefulWidget as state management
  • Easy shortcut to define configuration
  • Soft depends to other package

To Do

  • Right-To-Left parameter support, currently this can be achieved using widget builder
  • Internally handle async choice items loader
  • Custom search handler
  • Choice items pagination (pull to refresh and pull to load more)
  • Add more test

Migration from 4.0.0 to 4.2.0

  • modalValidation function nows should returnString to indicates the changes value is not valid andnull or emptyString to indicates the changes value is valid

  • To display tile with chips use paramS2Tile.body andS2TileChips, instead ofS2ChipsTile

Migration from 3.0.x to 4.0.0

  • The parameteroptions is removed, instead usechoiceItems

  • Simplify class name and enum

    • SmartSelectTile toS2Tile
    • SmartSelectOption toS2Choice
    • SmartSelectChoiceConfig toS2ChoiceConfig
    • SmartSelectChoiceStyle toS2ChoiceStyle
    • SmartSelectChoiceType toS2ChoiceType
    • SmartSelectModalConfig toS2ModalConfig
    • SmartSelectModalStyle toS2ModalStyle
    • SmartSelectModalHeaderStyle toS2ModalHeaderStyle
    • SmartSelectModalType toS2ModalType
  • The parameterbuilder now is a collection of builder (S2SingleBuilder orS2MultiBuilder), instead usetileBuilder to create trigger tile widget.

  • The parametersdense,enabled,isLoading,isTwoLine,leading,loadingText,padding,selected,trailing is removed fromSmartSelect class, instead usebuilder.tile ortileBuilder and returnS2Tile widget, it's has all these parameters.

  • The parameteronChange nows returnS2SingleState state orS2MultiState state instead ofT value orList<T> value

  • The parameterchoiceConfig.useWrap is removed, instead usechoiceConfig.layout = S2ChoiceLayout.wrap

  • The parameterchoiceConfig.builder moved tobuilder.choice orchoiceBuilder

  • The parameterchoiceConfig.titleBuilder moved tobuilder.choiceTitle orchoiceTitleBuilder

  • The parameterchoiceConfig.subtitleBuilder moved tobuilder.choiceSubtitle orchoiceSubtitleBuilder

  • The parameterchoiceConfig.secondaryBuilder moved tobuilder.choiceSecondary orchoiceSecondaryBuilder

  • The parameterchoiceConfig.dividerBuilder moved tobuilder.choiceDivider orchoiceDividerBuilder

  • The parameterchoiceConfig.emptyBuilder moved tobuilder.choiceEmpty orchoiceEmptybuilder

  • The parameterchoiceConfig.glowingOverscrollIndicatorColor is removed, instead usechoiceConfig.overscrollColor

  • The parameterchoiceConfig.spacing andchoiceConfig.runSpacing moved tochoiceConfig.style.spacing andchoiceConfig.style.runSpacing

  • The parameterchoiceConfig.useCheckmark moved tochoiceConfig.style.showCheckmark

  • The parameterchoiceConfig.padding moved tochoiceConfig.style.wrapperPadding

  • The default of grouped choice is not using sticky header now, instead usegroupBuilder like this:

    dependencies:  sticky_headers:"^0.1.8"
    import'package:sticky_headers/sticky_headers.dart';SmartSelect<T>.single/multiple(  ...,  ...,  choiceGroupBuilder: (context, header, choices) {returnStickyHeader(      header: header,      content: choices,    );  },);

Preview

Single ChoiceMultiple Choice
Modal TypeSingle Choice ModalMultiple Choice Modal
Chips WidgetSingle Choice ChipsMultiple Choice Chips
Switch Widget NoneMultiple Choice Switch
Custom TileCustomize Tile
Modal FilterModal Filter
Modal ConfirmModal Confirm
Modal ValidationModal Validation
Modal SelectorModal Selector
Modal ShapeModal Shape
Choice ItemsChoice Items
Choice GroupedChoice Grouped
Choice BuilderChoice Builder
Download APKDemo 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, or custom widget)
  • Various choices layout (list, wrap, or grid)
  • Grouping choices with easy support to sticky header
  • Searchable choices with highlighted result
  • Disabled or hidden choices
  • Customizable trigger/tile widget
  • Customizable modal style
  • Customizable modal header style
  • Customizable modal footer
  • Customizable choices style
  • Build choice items from anyList
  • Easy load async choice items
  • and many more

Usage

For a complete usage, please see theexample.

To read more about classes and other references used bysmart_select, see theAPI Reference.

Single Choice

// available configuration for single choiceSmartSelect<T>.single({// The primary content of the widget.// Used in trigger widget and header optionString title,// The text displayed when the value is nullString placeholder='Select one',// The current value of the single choice widget.@requiredT value,// Called when single choice value changed@requiredValueChanged<S2SingleState<T>> onChange,// choice item listList<S2Choice<T>> choiceItems,// other available configuration// explained below  ...,  ...,})
// simple usageString value='flutter';List<S2Choice<String>> options= [S2Choice<String>(value:'ion', title:'Ionic'),S2Choice<String>(value:'flu', title:'Flutter'),S2Choice<String>(value:'rea', title:'React Native'),];@overrideWidgetbuild(BuildContext context) {returnSmartSelect<String>.single(    title:'Frameworks',    value: value,    choiceItems: options,    onChange: (state)=>setState(()=> value= state.value)  );}

Multiple Choice

// available configuration for multiple choiceSmartSelect<T>.multiple({// The primary content of the widget.// Used in trigger widget and header optionString title,// The text displayed when the value is nullString placeholder='Select one',// The current value of the single choice widget.@requiredList<T> value,// Called when single choice value changed@requiredValueChanged<S2MultiState<T>> onChange,// choice item listList<S2Choice<T>> choiceItems,// other available configuration// explained below  ...,  ...,})
// a simple usageList<int> value= [2];List<S2Choice<int>> frameworks= [S2Choice<int>(value:1, title:'Ionic'),S2Choice<int>(value:2, title:'Flutter'),S2Choice<int>(value:3, title:'React Native'),];@overrideWidgetbuild(BuildContext context) {returnSmartSelect<int>.multiple(    title:'Frameworks',    value: value,    choiceItems: options,    onChange: (state)=>setState(()=> value= state.value),  );}

Choices

// configurationSmartSelect<T>.[single|multiple]({// other configuration  ...,  ...,// choice item listList<S2Choice<T>> choiceItems,// other configuration  ...,  ...,});

choiceItems can be input directly as in the example below, more info aboutS2Choice can be found on theAPI Reference

SmartSelect<T>.[single|multiple](  ...,  ...,  choiceItems:<S2Choice<T>>[S2Choice<T>(value:1, title:'Ionic'),S2Choice<T>(value:2, title:'Flutter'),S2Choice<T>(value:3, title:'React Native'),  ],);

choiceItems 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<String>.[single|multiple](  ...,  ...,  choiceItems:S2Choice.listFrom<String,Map<String,String>>(    source: days,    value: (index, item)=> item['value'],    title: (index, item)=> item['title'],  ),);

Load Choice Item Asynchronously

Please follow theseexample

Modal Configuration

More info aboutS2ModalConfig can be found on theAPI Reference

// available configurationSmartSelect<T>.[single|multiple]({// other configuration  ...,  ...,// Modal validation of single choice widgetValidationCallback<T> modalValidation,// Modal configurationS2ModalConfig modalConfig,// Configure modal style// shortcut to [modalConfig.style]S2ModalStyle modalStyle,// Configure modal header style// shortcut to [modalConfig.headerStyle]S2ModalHeaderStyle modalHeaderStyle,// Modal type to display choices// shortcut to [modalConfig.type]S2ModalType modalType,// Use different title with the trigger widget title// shortcut to [modalConfig.title]String modalTitle,// Whether the option list need to confirm// to return the changed value// shortcut to [modalConfig.useConfirm]bool modalConfirm,// Whether the options list modal use header or not// shortcut to [modalConfig.useHeader]bool modalHeader,// Whether the option list is filterable or not// shortcut to [modalConfig.useFilter]bool modalFilter,// Whether the filter is autocomplete or need confirmation// shortcut to [modalConfig.filterAuto]bool modalFilterAuto,// Custom searchbar hint// shortcut to [modalConfig.filterHint]String modalFilterHint,// other configuration  ...,  ...,});

Modal Type

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

// Available optionenumS2ModalType {// open in full page  fullPage,// open in popup dialog  popupDialog,// open in sliding bottom sheet  bottomSheet,}

Modal Style

// Available option to configure modal styleS2ModalStyle({// Modal border shape// used in popup dialog and bottom sheetShapeBorder shape,// Modal elevation// used in popup dialog and bottom sheetdouble elevation,// Modal background colorColor backgroundColor,// Modal clip behaviorClip clipBehavior,})

Modal Header Style

// Available option to configure modal header styleS2ModalHeaderStyle({// Header border shapeShapeBorder shape,// Header elevationdouble elevation,// Header background colorColor backgroundColor,// Header brightnessBrightness brightness,// Whether the header title is centeredbool centerTitle,// Whether the header use automaticallyImplyLeading or notbool useLeading,// Header text style// used by title and search fieldTextStyle textStyle,// Header icon themeIconThemeData iconTheme,// Header actions icon themeIconThemeData actionsIconTheme,})

Choices Configuration

More info aboutS2ChoiceConfig can be found on theAPI Reference

// Available option to configure choicesSmartSelect<T>.[single|multiple]({// other configuration  ...,  ...,// choice configurationS2ChoiceConfig choiceConfig,// configure choice style// shortcut to [choiceConfig.style]S2ChoiceStyle choiceStyle,// configure choices group header style// shortcut to [choiceConfig.headerStyle]S2ChoiceHeaderStyle choiceHeaderStyle,// choice widget type// shortcut to [choiceConfig.type]S2ChoiceType choiceType,// choice layout to display items// shortcut to [choiceConfig.layout]S2ChoiceLayout choiceLayout,// choice list scroll direction// currently only support when// [layout] is [S2ChoiceLayout.wrap]// shortcut to [choiceConfig.direction]Axis choiceDirection,// Whether the choices list is grouped// shortcut to [choiceConfig.isGrouped]bool choiceGrouped,// Whether the choices item use divider or not// shortcut to [choiceConfig.useDivider]bool choiceDivider,// For grid choice layout// shortcut to [choiceConfig.gridDelegate]SliverGridDelegate choiceGrid,// other configuration  ...,  ...,});

Choice Type

By default SmartSelect will useradios for single choice andcheckboxes for multiple choice, but it can change by changing with this value:

// Type of choice inputenumS2ChoiceType {// use radio widget// for single choice  radios,// use checkbox widget// for multiple choice  checkboxes,// use switch widget// for multiple choice  switches,// use chip widget// for single and multiple choice  chips,}

Choice Layout

By default SmartSelect will uselist, but it can change by changing with this value:

// Layout of choice itemenumS2ChoiceLayout {// use list view widget  list,// use wrap view widget  wrap,// use grid view widget  grid,}

Choice Styles

// Available option to configure choice styleS2ChoiceStyle({// How much space to place between children in a run in the main axis.// When use [SmartSelectChoiceType.chips] or [useWrap] is [true]double spacing,// How much space to place between the runs themselves in the cross axis.// When use [SmartSelectChoiceType.chips] or [useWrap] is [true]double runSpacing,// choices wrapper paddingEdgeInsetsGeometry wrapperPadding,// Choices item paddingEdgeInsetsGeometry padding,// choices item title styleTextStyle titleStyle,// choices item subtitle styleTextStyle subtitleStyle,// whether the chips use checkmark or notbool showCheckmark,// Where to place the control in widgets that use// [ListTile] to position a control next to a label.S2ChoiceControl control,// Highlight colorColor highlightColor,// Primary color of selected choice itemColor activeColor,// Primary color of unselected choice itemColor color,// Secondary color of selected choice itemColor activeAccentColor,// Secondary color of unselected choice itemColor accentColor,// Brightness for selected ChipBrightness activeBrightness,// Brightness for unselected ChipBrightness brightness,// Opacity for selected Chip border, only effect when// [activeBrightness] is [Brightness.light]double activeBorderOpacity,// Opacity for unselected chip border, only effect when// [brightness] is [Brightness.light]double borderOpacity,// Shape clip behaviorClip clipBehavior,})

Choice Header Style

// Available option to configure choices group header widget styleS2ChoiceHeaderStyle({// Group header background colorColor backgroundColor,// Highlight colorColor highlightColor,// Group header text styleTextStyle textStyle,// Group header paddingEdgeInsetsGeometry padding,// Group header heightdouble height,})

Builder Widget

Builder for Single Choice

// available builder configuration// for single choiceSmartSelect<T>.single({// other configuration  ...,  ...,// Builder collection of single choice widgetS2SingleBuilder<T> builder,// Builder for custom tile widget// shortcut to [builder.tile]S2WidgetBuilder<S2SingleState<T>> tileBuilder,// Builder for custom modal widget// shortcut to [builder.modal]S2WidgetBuilder<S2SingleState<T>> modalBuilder,// Builder for custom modal header widget// shortcut to [builder.modalHeader]S2WidgetBuilder<S2SingleState<T>> modalHeaderBuilder,// Builder for custom modal actions widget// shortcut to [builder.modalActions]S2ListWidgetBuilder<S2SingleState<T>> modalActionsBuilder,// Builder for custom modal confirm action widget// shortcut to [builder.modalConfirm]S2WidgetBuilder<S2SingleState<T>> modalConfirmBuilder,// Builder for divider widget between header, body, and footer modal// shortcut to [builder.modalDivider]S2WidgetBuilder<S2SingleState<T>> modalDividerBuilder,// Builder for custom footer widget// shortcut to [builder.modalFooter]S2WidgetBuilder<S2SingleState<T>> modalFooterBuilder,// other configuration  ...,  ...,});

Builder for Multiple Choice

// available builder configuration// for multiple choiceSmartSelect<T>.multiple({// other configuration  ...,  ...,// Builder collection of single choice widgetS2MultiBuilder<T> builder,// Builder for custom tile widget// shortcut to [builder.tile]S2WidgetBuilder<S2MultiState<T>> tileBuilder,// Builder for custom modal widget// shortcut to [builder.modal]S2WidgetBuilder<S2MultiState<T>> modalBuilder,// Builder for custom modal header widget// shortcut to [builder.modalHeader]S2WidgetBuilder<S2MultiState<T>> modalHeaderBuilder,// Builder for custom modal actions widget// shortcut to [builder.modalActions]S2ListWidgetBuilder<S2MultiState<T>> modalActionsBuilder,// Builder for custom modal confirm action widget// shortcut to [builder.modalConfirm]S2WidgetBuilder<S2MultiState<T>> modalConfirmBuilder,// Builder for divider widget between header, body, and footer modal// shortcut to [builder.modalDivider]S2WidgetBuilder<S2MultiState<T>> modalDividerBuilder,// Builder for custom footer widget// shortcut to [builder.modalFooter]S2WidgetBuilder<S2MultiState<T>> modalFooterBuilder,// other configuration  ...,  ...,});

Other Builder

// another builder configurationSmartSelect<T>.[single|multiple]({// other configuration  ...,  ...,// Builder for modal filter widget// shortcut to [builder.modalFilter]S2WidgetBuilder<S2Filter> modalFilterBuilder,// Builder for modal filter toggle widget// shortcut to [builder.modalFilterToggle]S2WidgetBuilder<S2Filter> modalFilterToggleBuilder,// Builder for each custom choices item widget// shortcut to [builder.choice]S2ChoiceBuilder<T> choiceBuilder,// Builder for each custom choices item title widget// shortcut to [builder.choiceTitle]S2ChoiceBuilder<T> choiceTitleBuilder,// Builder for each custom choices item subtitle widget// shortcut to [builder.choiceSubtitle]S2ChoiceBuilder<T> choiceSubtitleBuilder,// Builder for each custom choices item secondary widget// shortcut to [builder.choiceSecondary]S2ChoiceBuilder<T> choiceSecondaryBuilder,/// Builder for custom divider widget between choices item// shortcut to [builder.choiceDivider]IndexedWidgetBuilder choiceDividerBuilder,// Builder for custom empty display// shortcut to [builder.choiceEmpty]S2WidgetBuilder<String> choiceEmptyBuilder,// A widget builder for custom choices group// shortcut to [builder.choiceGroup]S2ChoiceGroupBuilder choiceGroupBuilder,// A widget builder for custom header choices group// shortcut to [builder.choiceHeader]S2ChoiceHeaderBuilder choiceHeaderBuilder,// other configuration  ...,  ...,});

Tile Widget

Default Tile

// Default tile/trigger widgetS2Tile<T>({// The value of the selected option.String value,// The primary content of the list tile.Widget title,// A widget to display before the title.// Typically an [Icon] or a [CircleAvatar] widget.Widget leading,// A widget to display after the title.// Typically an [Icon] widget.Widget trailing,// Whether this list tile is intended to display loading stats.bool isLoading,// String text used as loading textString loadingText,// Whether this list tile is intended to display two lines of text.bool isTwoLine,// Whether this list tile is interactive.bool enabled,// If this tile is also [enabled] then icons and text are rendered with the same color.bool selected,// Whether this list tile is part of a vertically dense list.bool dense,// Whether the [value] is displayed or notbool hideValue,// The tile's internal padding.EdgeInsetsGeometry padding,// Called when the user taps this list tile.GestureTapCallback onTap,// widget to display below the tile// usually used to display chips with S2TileChipsWidget body,})
// usage exampleSmartSelect<T>.single(  ...,  ...,  tileBuilder: (context, state) {returnS2Tile(      title: state.titleWidget,      value: state.valueDisplay,      onTap: state.showModal,      isLoading:true,    );  },);// usage example from stateSmartSelect<T>.multiple(  ...,  ...,  tileBuilder: (context, state) {returnS2Tile.fromState(      state,      isLoading:true,    );  },);

Tile With Chips

// Chips tile/trigger widgetS2TileChips({// List of value of the selected choices.int chipLength,// Widget builder for chip label itemIndexedWidgetBuilder chipLabelBuilder,// Widget builder for chip avatar itemIndexedWidgetBuilder chipAvatarBuilder,// Widget builder for chip itemIndexedWidgetBuilder chipBuilder,// Called when the user delete the chip item.ValueChanged<int> chipOnDelete,// Chip colorColor chipColor,// Chip border opacitydouble chipBorderOpacity,// Chip brightnessBrightness chipBrightness,// Chip delete button colorColor chipDeleteColor,// Chip delete button iconIcon chipDeleteIcon,// Chip spacingdouble chipSpacing,// Chip run spacingdouble chipRunSpacing,// Chip shape borderShapeBorder chipShape,// The [Widget] displayed when the [values] is nullWidget placeholder,// Whether the chip list is scrollable or notbool scrollable,// Chip list paddingEdgeInsetsGeometry padding,})
/// usage exampleSmartSelect<String>.multiple(  ...,  ...,  value: users,  tileBuilder: (context, state) {returnS2Tile.fromState(      state,      hideValue:true,      body:S2TileChips(        chipLength: state.valueObject.length,        chipLabelBuilder: (context, i) {returnText(state.valueObject[i].title);        },        chipAvatarBuilder: (context, i) {returnCircleAvatar(            backgroundImage:NetworkImage(state.valueObject[i].meta['picture']['thumbnail'])          );        },        chipOnDelete: (i) {setState(()=> users.remove(state.valueObject[i].value));        },        chipColor:Colors.blue,        chipBrightness:Brightness.dark,        chipBorderOpacity: .5,      ),    );  },);

License

Copyright (c) 2020 Irfan Vigma TaufikPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, 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 THESOFTWARE.

About

SmartSelect allows you to easily convert your usual form select or dropdown into dynamic page, popup dialog, or sliding bottom sheet with various choices input such as radio, checkbox, switch, chips, or even custom input. Supports single and multiple choice.

Topics

Resources

License

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp