I have a radio button that doesn't update on Notify Listeners despite the groupValue is updated, the radio choice isn't updated. I use multiproviders.
Here is the Radio Choices
ListTile(
leading: Icon(
Icons.edit_outlined,
),
title: Text('Post now'),
trailing: Radio<PostOption>(
value: PostOption.now,
groupValue: Provider.of<Post>(context).postOption,
onChanged: (value) {
Provider.of<Post>(context, listen: false)
.choosePostOption(value);
},
),
),
ListTile(
leading: Icon(
Icons.drive_folder_upload,
),
title: Text('Save as Draft'),
trailing: Radio<PostOption>(
value: PostOption.draft,
groupValue: Provider.of<Post>(context).postOption,
onChanged: (value) {
Provider.of<Post>(context, listen: false)
.choosePostOption(value);
},
),
),
And Here is the provider class
class Post extends ChangeNotifier {
PostOption postOption;
void choosePostOption(PostOption option) {
postOption = option;
notifyListeners();
}
}
Here is the main where I set up my providers
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
Provider<Post>(
create: (context) => Post(),
),
Provider<Content>(
create: (context) => Content(),
),
],
child: MaterialApp(
),
);
}
}