artflutter / flutter_awesome_select

Forked from https://github.com/davigmacode/flutter_smart_select, updated legacy code, migrated to null safety and more. AwesomeSelect 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.
https://pub.dev/packages/flutter_awesome_select
MIT License
15 stars 30 forks source link

Null check operator used on a null value when use choiceType: S2ChoiceType.chips #13

Closed limsocheat closed 2 years ago

limsocheat commented 2 years ago
SmartSelect<String?>.single(
    key: _timeKey,
    title: 'Selected time'.tr,
    choiceItems: controller.times.map((time) {
      return S2Choice(
        value: time.value,
        title: time.text,
        group: time.name,
      );
    }).toList(),
    selectedValue: field.value,
    onChange: (selected) => field.didChange(selected.value),
    modalType: S2ModalType.bottomSheet,
    modalTitle: 'Select the reservation time'.tr,
    choiceType: S2ChoiceType.chips,
    choiceDirection: Axis.horizontal,
    choiceStyle: S2ChoiceStyle(
      outlined: true,
      shape: RoundedRectangleBorder(
        borderRadius: const BorderRadius.all(Radius.circular(5)),
        side: BorderSide(
          color: Colors.grey.shade300,
        ),
      ),
    ),
    choiceActiveStyle: const S2ChoiceStyle(
      color: Colors.black,
      raised: true,
    ),
    groupEnabled: true,
    groupHeaderBuilder: (context, state, group) {
      return Container(
        color: ColorConfig.gold,
        padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
        alignment: Alignment.centerLeft,
        child: S2Text(
          text: group.name?.toUpperCase(),
          style: const TextStyle(
            color: Colors.white,
            fontWeight: FontWeight.bold,
          ),
        ),
      );
    },
    groupBuilder: (context, state, group) {
      return StickyHeader(
        header: state.groupHeader(group),
        content: state.groupChoices(group),
      );
    },
    tileBuilder: (context, state) {
      return S2Tile.fromState(
        state,
        isLoading: controller.loadingTimes.value,
        loadingText: 'loading'.tr,
        isError: field.errorText != null,
        body: ConditionalBuilder(
          condition: field.errorText != null,
          builder: (context) => Padding(
            padding: const EdgeInsets.only(left: 15.0),
            child: Text(
              '${field.errorText}',
              style: Theme.of(context).textTheme.caption?.copyWith(
                    color: Colors.red,
                  ),
            ),
          ),
        ),
      );
    },
  )

Simulator Screen Shot - iPhone 13 Pro Max - 2022-04-01 at 10 08 22

vasilich6107 commented 2 years ago

@limsocheat could you provide an example which can be copy pasted and tested this one is not runnable

vasilich6107 commented 2 years ago

This is the errors that I see when copy paste into example project for reproduction

image
chrisvidal commented 2 years ago

same issue with flutter_awesome_select: ^6.1.2-beta and S2Chips used in S2Tile.fromState(

somehow with the beta version, state.selected.choice is null

vasilich6107 commented 2 years ago

@chrisvidal Could you provide working reproduction code?

chrisvidal commented 2 years ago

sorry I don't have time to create a specific code for this :( It was working fine before updating to the flutter_awesome_select: ^6.1.2-beta

my code is directly inherited from the examples actually with single choice with modal sheet selection

vasilich6107 commented 2 years ago

Closing issue due to the missing reproduction Feel free to reopen with runnable reproduction code