Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/kids 1008 child details state not updating #785

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/features/children/details/models/profile_ext.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:equatable/equatable.dart';
import 'package:givt_app/features/children/details/models/giving_allowance.dart';
import 'package:givt_app/features/children/overview/models/profile.dart';
import 'package:givt_app/features/children/overview/models/wallet.dart';

class ProfileExt extends Equatable {
const ProfileExt({
Expand All @@ -26,8 +27,9 @@ class ProfileExt extends Equatable {
walletMap['givingAllowance'] as Map<String, dynamic>;
final givingAllowance = GivingAllowance.fromMap(givingAllowanceMap);
final pendingAllowance = walletMap['pendingAllowance'] ?? false;
final wallet = Wallet.fromMap(walletMap);
return ProfileExt(
profile: profile,
profile: profile.copyWith(wallet: wallet),
givingAllowance: givingAllowance,
dateOfBirth: map['dateOfBirth'] as String,
firstName: map['firstName'] as String,
Expand Down
24 changes: 0 additions & 24 deletions lib/features/children/details/pages/child_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ class ChildDetailsPage extends StatelessWidget {
width: double.maxFinite,
color: AppTheme.givtLightBackgroundGreen,
child: ChildDetailsItem(
//ugly fix, for some reason ChildDetailsCubit doesnt update
balance: getBalance(context),
profileDetails: state.profileDetails,
),
),
Expand Down Expand Up @@ -194,28 +192,6 @@ class ChildDetailsPage extends StatelessWidget {
);
}

double getBalance(BuildContext context) {
var family = context.watch<FamilyOverviewCubit>().state;
if (family is FamilyOverviewUpdatedState) {
return family.profiles
.firstWhere((element) =>
element.id ==
(context.watch<ChildDetailsCubit>().state
as ChildDetailsFetchedState)
.profileDetails
.profile
.id)
.wallet
.balance;
}
return (context.watch<ChildDetailsCubit>().state
as ChildDetailsFetchedState)
.profileDetails
.profile
.wallet
.balance;
}

Future<void> _navigateToTopUpScreen(
BuildContext context,
) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import 'package:givt_app/utils/utils.dart';
class ChildDetailsItem extends StatelessWidget {
const ChildDetailsItem({
required this.profileDetails,
required this.balance,
super.key,
});
final double balance;

final ProfileExt profileDetails;

@override
Expand Down Expand Up @@ -46,7 +45,7 @@ class ChildDetailsItem extends StatelessWidget {
),
),
Text(
'${currency.currencySymbol}${balance.toStringAsFixed(0)}${context.l10n.childInWalletPostfix}',
'${currency.currencySymbol}${profileDetails.profile.wallet.balance.toStringAsFixed(0)}${context.l10n.childInWalletPostfix}',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: AppTheme.inputFieldBorderSelected,
Expand Down
22 changes: 22 additions & 0 deletions lib/features/children/overview/models/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ class Profile extends Equatable {
);
}

Profile copyWith({
String? id,
String? firstName,
String? lastName,
String? nickname,
String? comment,
Wallet? wallet,
String? pictureURL,
ProfileType? type,
}) {
return Profile(
id: id ?? this.id,
firstName: firstName ?? this.firstName,
lastName: lastName ?? this.lastName,
nickname: nickname ?? this.nickname,
comment: comment ?? this.comment,
wallet: wallet ?? this.wallet,
pictureURL: pictureURL ?? this.pictureURL,
type: type ?? this.type,
);
}

final String id;
final String firstName;
final String lastName;
Expand Down