Choice value always displays null when loading page first
i expect that the init value would be from SharedPreferences,so i invoke initSoundSetting,but when loading page ,it always displays null
class _StudyModelSoundSettingState extends State<StudyModelSoundSetting>{
int soundSetting;
void initState(){
super.initState();
initSoundSetting();
}
void initSoundSetting()async{
final SharedPreferences prefs = await widget.sp;
final soundSettingValue = prefs.getInt('soundSetting');
this.setState(() {
this.soundSetting = soundSettingValue==null?4:soundSettingValue;
});
}
void changeSoundSetting(int newValue)async{
final SharedPreferences prefs = await widget.sp;
setState(() {
this.soundSetting = newValue;
});
prefs.setInt('soundSetting', newValue);
}
List<S2Choice<int>> soundSettingOptions=[
S2Choice<int>(value:1,title:'正常'),
S2Choice<int>(value:2,title:'震动'),
S2Choice<int>(value:3,title:'静音'),
S2Choice<int>(value:4,title:'系统预设'),
];
Widget build(BuildContext context){
print(this.soundSetting);
return SmartSelect<int>.single(
title:'铃声模式',
choiceItems:soundSettingOptions,
modalType: S2ModalType.bottomSheet,
value: this.soundSetting,
onChange: (state){
changeSoundSetting(state.value);
},
);
}
}
I released https://pub.dev/packages/flutter_awesome_select with fixed null safety. Could you check that everything works for you?
i expect that the init value would be from SharedPreferences,so i invoke initSoundSetting,but when loading page ,it always displays null
class _StudyModelSoundSettingState extends State<StudyModelSoundSetting>{ int soundSetting; void initState(){ super.initState(); initSoundSetting(); } void initSoundSetting()async{ final SharedPreferences prefs = await widget.sp; final soundSettingValue = prefs.getInt('soundSetting'); this.setState(() { this.soundSetting = soundSettingValue==null?4:soundSettingValue; }); } void changeSoundSetting(int newValue)async{ final SharedPreferences prefs = await widget.sp; setState(() { this.soundSetting = newValue; }); prefs.setInt('soundSetting', newValue); } List<S2Choice<int>> soundSettingOptions=[ S2Choice<int>(value:1,title:'正常'), S2Choice<int>(value:2,title:'震动'), S2Choice<int>(value:3,title:'静音'), S2Choice<int>(value:4,title:'系统预设'), ]; Widget build(BuildContext context){ print(this.soundSetting); return SmartSelect<int>.single( title:'铃声模式', choiceItems:soundSettingOptions, modalType: S2ModalType.bottomSheet, value: this.soundSetting, onChange: (state){ changeSoundSetting(state.value); }, ); } }
Same problem here, any solution?
Hi everyone,
I'm really sorry for not maintaining the smart_select package in a long time. It's been a great project, but it's become too difficult for me to maintain, especially since I've been going through a tough time for the past few years.
In its place, I've released a new package called choice. The combination to smart_select and chips_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 out choice. I think you'll find it to be a great replacement for smart_select.
Thanks for your understanding.