Choice<T>.inline constructor

Choice<T>.inline({
  1. Key? key,
  2. List<T> value = const [],
  3. ValueChanged<List<T>>? onChanged,
  4. bool multiple = false,
  5. bool clearable = false,
  6. bool loading = false,
  7. bool error = false,
  8. required int itemCount,
  9. required IndexedChoiceStateBuilder<T> itemBuilder,
  10. ChoiceGroupResolver? itemGroup,
  11. ChoiceSkipResolver<T>? itemSkip,
  12. ChoiceStateBuilder<T>? dividerBuilder,
  13. ChoiceStateBuilder<T>? leadingBuilder,
  14. ChoiceStateBuilder<T>? trailingBuilder,
  15. ChoiceStateBuilder<T>? placeholderBuilder,
  16. ChoiceStateBuilder<T>? errorBuilder,
  17. ChoiceStateBuilder<T>? loaderBuilder,
  18. ChoiceGroupSortResolver? groupSort,
  19. ChoiceGroupBuilder? groupBuilder,
  20. ChoiceGroupItemBuilder? groupItemBuilder,
  21. ChoiceGroupHeaderBuilder<T>? groupHeaderBuilder,
  22. ChoiceListBuilder? listBuilder,
})

Create inline choice widget with single or multiple selection

The value prop is the initial selection value

The onChanged prop called when the choice selection should change

The clearable prop determines whether the choice can be cleared

The multiple prop determines whether the choice is multiple or single selection

The itemCount prop is the total number of item, this choice list can provide

The itemSkip prop called to specify which indices to skip when building choice item

The itemBuilder prop called to build choice item

The dividerBuilder prop called to build divider item

The leadingBuilder prop called to build leading item of the item collection

The trailingBuilder prop called to build trailing item of the item collection

The placeholderBuilder prop called to build placeholder when there are no choice items

The listBuilder prop called to build the list of choice items

A StatefulWidget that illustrates use of an Choice.inline usage.

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

class InlineWrapped extends StatefulWidget {
  const InlineWrapped({super.key});

  @override
  State<InlineWrapped> createState() => _InlineWrappedState();
}

class _InlineWrappedState extends State<InlineWrapped> {
  List<String> choices = [
    'News',
    'Entertainment',
    'Politics',
    'Automotive',
    'Sports',
  ];

  String? selectedValue;

  void setSelectedValue(String? value) {
    setState(() => selectedValue = value);
  }

  @override
  Widget build(BuildContext context) {
    return Choice<String>.inline(
      multiple: true,
      clearable: true,
      value: ChoiceSingle.value(selectedValue),
      onChanged: ChoiceSingle.onChanged(setSelectedValue),
      itemCount: choices.length,
      itemBuilder: (state, i) {
        return ChoiceChip(
          selected: state.selected(choices[i]),
          onSelected: state.onSelected(choices[i]),
          label: Text(choices[i]),
        );
      },
      listBuilder: ChoiceList.createWrapped(
        spacing: 10,
        runSpacing: 10,
        padding: const EdgeInsets.symmetric(
          horizontal: 20,
          vertical: 25,
        ),
      ),
    );
  }
}

Implementation

Choice.inline({
  super.key,
  this.value = const [],
  this.onChanged,
  this.multiple = false,
  this.clearable = false,
  bool loading = false,
  bool error = false,
  required int itemCount,
  required IndexedChoiceStateBuilder<T> itemBuilder,
  ChoiceGroupResolver? itemGroup,
  ChoiceSkipResolver<T>? itemSkip,
  ChoiceStateBuilder<T>? dividerBuilder,
  ChoiceStateBuilder<T>? leadingBuilder,
  ChoiceStateBuilder<T>? trailingBuilder,
  ChoiceStateBuilder<T>? placeholderBuilder,
  ChoiceStateBuilder<T>? errorBuilder,
  ChoiceStateBuilder<T>? loaderBuilder,
  ChoiceGroupSortResolver? groupSort,
  ChoiceGroupBuilder? groupBuilder,
  ChoiceGroupItemBuilder? groupItemBuilder,
  ChoiceGroupHeaderBuilder<T>? groupHeaderBuilder,
  ChoiceListBuilder? listBuilder,
})  : title = null,
      confirmation = false,
      child = InlineChoice<T>(
        value: value,
        onChanged: onChanged,
        multiple: multiple,
        clearable: clearable,
        loading: loading,
        error: error,
        itemCount: itemCount,
        itemBuilder: itemBuilder,
        itemGroup: itemGroup,
        itemSkip: itemSkip,
        dividerBuilder: dividerBuilder,
        leadingBuilder: leadingBuilder,
        trailingBuilder: trailingBuilder,
        placeholderBuilder: placeholderBuilder,
        errorBuilder: errorBuilder,
        loaderBuilder: loaderBuilder,
        groupSort: groupSort,
        groupBuilder: groupBuilder,
        groupItemBuilder: groupItemBuilder,
        groupHeaderBuilder: groupHeaderBuilder,
        listBuilder: listBuilder,
      );