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

defaultSelected is not working in CustomRadioButton ^1.0.6+1 #38

Closed IamAKX closed 3 years ago

IamAKX commented 3 years ago

I am building a quiz app, where all the question, options and its correct answer are stored in a List. User can move on to next question or previous question using button, which will update the index position and rebuild the widget tree to load question of that particular index. When the widget tree is rebuilt, the select option for previously attempted question is not highlighted. I am using defaultSelected for this. However, on debugging I found that correct value is passed in the defaultSelected parameters, even then the value is not selected.

I have my attached my app screen and code. Kindly fix it as soon as possibly. Nice work for the library by the way!.

CustomRadioButton( selectedBorderColor: THEME_COLOR, unSelectedBorderColor: Colors.grey.withOpacity(0.3), selectedColor: THEME_COLOR, unSelectedColor: Colors.grey.withOpacity(0.3), buttonTextStyle: ButtonTextStyle( selectedColor: Colors.white, unSelectedColor: Colors.black, textStyle: TextStyle( fontSize: 16, ), ), absoluteZeroSpacing: false, enableButtonWrap: true, padding: 20, spacing: 20, width: (width - 240) * 0.6 / 2, enableShape: true, defaultSelected: getDefaultSelectedButton(), buttonLables: quizDetail.questionList .elementAt(selectedIndex - 1) .options, buttonValues: quizDetail.questionList .elementAt(selectedIndex - 1) .options .map((e) => quizDetail.questionList .elementAt(selectedIndex - 1) .options .indexOf(e)) .toList(), radioButtonValue: (value) { setState(() { attemptedQuestionList[selectedIndex - 1] = value; }); }),

getDefaultSelectedButton() { int val = attemptedQuestionList.elementAt(selectedIndex - 1) == -1 ? null : attemptedQuestionList.elementAt(selectedIndex - 1); print(val); return val; }

Play the video with sound on.

https://user-images.githubusercontent.com/17857031/109754887-de897680-7c0a-11eb-9324-e64c892056a1.mov

ketanchoyal commented 3 years ago

Can you confirm if you are able to get required data from this function ?

getDefaultSelectedButton() { int val = attemptedQuestionList.elementAt(selectedIndex - 1) == -1 ? null : attemptedQuestionList.elementAt(selectedIndex - 1); print(val); return val; }

IamAKX commented 3 years ago

yes, I am able to get correct data from the function

IamAKX commented 3 years ago

Any update on the issue?

ketanchoyal commented 3 years ago

Any update on the issue?

I'll upgrade this package to null safety asap, which might resolve this issue.

IamAKX commented 3 years ago

Sure, thanks. I would be very grateful if you can do it ASAP. Thanks in advance! Cheers

MuhammadDicky commented 3 years ago

Any update on the issue?

I'll upgrade this package to null safety asap, which might resolve this issue.

Any update on this?

ketanchoyal commented 3 years ago

Any update on the issue?

I'll upgrade this package to null safety asap, which might resolve this issue.

Any update on this?

Jut published it, thanks