mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
add copy constructor and properly update paynym account model, as well as fix desktop navigation on follow/unfollow
This commit is contained in:
parent
929723d0d5
commit
d957cad4ba
2 changed files with 39 additions and 16 deletions
|
@ -36,6 +36,22 @@ class PaynymAccount {
|
|||
PaynymAccountLite.fromMap(Map<String, dynamic>.from(e as Map)))
|
||||
.toList();
|
||||
|
||||
PaynymAccount copyWith({
|
||||
String? nymID,
|
||||
String? nymName,
|
||||
List<PaynymCode>? codes,
|
||||
List<PaynymAccountLite>? followers,
|
||||
List<PaynymAccountLite>? following,
|
||||
}) {
|
||||
return PaynymAccount(
|
||||
nymID ?? this.nymID,
|
||||
nymName ?? this.nymName,
|
||||
codes ?? this.codes,
|
||||
followers ?? this.followers,
|
||||
following ?? this.following,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() => {
|
||||
"nymID": nymID,
|
||||
"nymName": nymName,
|
||||
|
|
|
@ -87,7 +87,7 @@ class _PaynymFollowToggleButtonState
|
|||
|
||||
if (result.value!.following == followedAccount.value!.nymID) {
|
||||
if (!loadingPopped && mounted) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context, rootNavigator: isDesktop).pop();
|
||||
}
|
||||
|
||||
unawaited(
|
||||
|
@ -97,7 +97,10 @@ class _PaynymFollowToggleButtonState
|
|||
context: context,
|
||||
),
|
||||
);
|
||||
ref.read(myPaynymAccountStateProvider.state).state!.following.add(
|
||||
|
||||
final myAccount = ref.read(myPaynymAccountStateProvider.state).state!;
|
||||
|
||||
myAccount.following.add(
|
||||
PaynymAccountLite(
|
||||
followedAccount.value!.nymID,
|
||||
followedAccount.value!.nymName,
|
||||
|
@ -106,6 +109,8 @@ class _PaynymFollowToggleButtonState
|
|||
),
|
||||
);
|
||||
|
||||
ref.read(myPaynymAccountStateProvider.state).state = myAccount.copyWith();
|
||||
|
||||
setState(() {
|
||||
isFollowing = true;
|
||||
});
|
||||
|
@ -113,7 +118,7 @@ class _PaynymFollowToggleButtonState
|
|||
return true;
|
||||
} else {
|
||||
if (!loadingPopped && mounted) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context, rootNavigator: isDesktop).pop();
|
||||
}
|
||||
|
||||
unawaited(
|
||||
|
@ -181,7 +186,7 @@ class _PaynymFollowToggleButtonState
|
|||
|
||||
if (result.value!.unfollowing == followedAccount.value!.nymID) {
|
||||
if (!loadingPopped && mounted) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context, rootNavigator: isDesktop).pop();
|
||||
}
|
||||
|
||||
unawaited(
|
||||
|
@ -191,12 +196,14 @@ class _PaynymFollowToggleButtonState
|
|||
context: context,
|
||||
),
|
||||
);
|
||||
ref
|
||||
.read(myPaynymAccountStateProvider.state)
|
||||
.state!
|
||||
.following
|
||||
|
||||
final myAccount = ref.read(myPaynymAccountStateProvider.state).state!;
|
||||
|
||||
myAccount.following
|
||||
.removeWhere((e) => e.nymId == followedAccount.value!.nymID);
|
||||
|
||||
ref.read(myPaynymAccountStateProvider.state).state = myAccount.copyWith();
|
||||
|
||||
setState(() {
|
||||
isFollowing = false;
|
||||
});
|
||||
|
@ -204,7 +211,7 @@ class _PaynymFollowToggleButtonState
|
|||
return true;
|
||||
} else {
|
||||
if (!loadingPopped && mounted) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context, rootNavigator: isDesktop).pop();
|
||||
}
|
||||
|
||||
unawaited(
|
||||
|
|
Loading…
Reference in a new issue