I have the below Riverpod annotation for the provider. I would like to update the values in one page and get the updated value in next page.
@riverpod
class UserCardSheetInfo extends _$UserCardSheetInfo {
@override
UserCardInputSheet build() => UserCardInputSheet();
void updateIssuer(String value) {
state.issuerKey = value;
}
void updateCard(String value) {
state.setCardKey = value;
}
}
class UserCardInputSheet {
String _issuerKey = "";
String _cardKey = "";
String get issuerKey => _issuerKey;
set issuerKey(String value) {
_issuerKey = value;
}
String get cardKey => _cardKey;
set setCardKey(String val) {
_cardKey = val;
}
}
I the first page, I am updating the value as below.
class _SelectableIssuersList extends ConsumerStatefulWidget {
const _SelectableIssuersList();
@override
ConsumerState<_SelectableIssuersList> createState() => _SelectableCardsListState();
}
class _SelectableCardsListState extends ConsumerState<_SelectableIssuersList> {
@override
Widget build(BuildContext context) {
return SomeWidget(
onClick: (newIssuer) => setState(() {
ref.watch(userCardSheetInfoProvider.notifier).updateIssuer(newIssuer);
}),
);
}
}
In the next page, I am trying to read the updated value. But I am always getting an empty class without the values.
class _SelectableCardsList extends ConsumerStatefulWidget {
const _SelectableCardsList();
@override
ConsumerState<_SelectableCardsList> createState() => _SelectableCardsListState();
}
class _SelectableCardsListState extends ConsumerState<_SelectableCardsList> {
@override
Widget build(BuildContext context) {
List<Cards> cards = ref.read(cardsProvider).requireValue;
// ====> Always Empty
print(ref.watch(userCardSheetInfoProvider).issuerKey);
return AnotherWidget();
}
}
How should I be handling the value read/write using Riverpod?