ketanchoyal / custom_radio_grouped_button

Custom Flutter widgets that makes Checkbox and Radio Buttons much cleaner and easier.
MIT License
150 stars 42 forks source link

Exception caught by widgets library:"Class 'String' has no instance method 'where'" #52

Closed lybgo closed 3 years ago

lybgo commented 3 years ago

Version: custom_radio_grouped_button: ^2.1.1 Flutter (Channel stable, 2.5.3, on Microsoft Windows [Version 10.0.19042.1288], locale zh-CN)

my code:

CustomCheckBoxGroup(
  buttonTextStyle: ButtonTextStyle(
    selectedColor: Colors.red,
    unSelectedColor: Colors.orange,
    textStyle: TextStyle(
      fontSize: 16,
    ),
  ),
  unSelectedColor: Theme.of(context).canvasColor,
  buttonLables: [
    "M",
    "T",
    "W",
    "T",
    "F",
    "S",
    "S",
  ],
  buttonValuesList: [
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday",
    "Sunday",
  ],
  checkBoxButtonValues: (values) {
    print(values);
  },
  spacing: 0,
  defaultSelected: "Monday",
  horizontal: false,
  enableButtonWrap: false,
  width: 40,
  absoluteZeroSpacing: false,
  selectedColor: Theme.of(context).accentColor,
  padding: 10, 
);

Exception:

======== Exception caught by widgets library =======================================================
The following NoSuchMethodError was thrown building _BodyBuilder:
Class 'String' has no instance method 'where'.
Receiver: "Monday"
Tried calling: where(Closure: (dynamic) => bool)

The relevant error-causing widget was: 
  Scaffold Scaffold:file:///E:/FlutterDev/YLAib/pages/device_pagee_time_switch/add_single_timeriew.dart:16:12
When the exception was thrown, this was the stack: 
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:63:5)
#1      _CustomCheckBoxGroupState.initState (package:custom_radio_grouped_button/CustomButtons/CustomCheckBoxGroup.dart:133:29)
ketanchoyal commented 3 years ago

Since it's a group button you need to pass List of defaultSelected so you should pass ["Monday"] instead of"Monday"

lybgo commented 3 years ago

@ketanchoyal thank you, According to your solution, the problem is solved. The code above is to directly use the code in your readme. It is recommended to modify the code in the readme.