Skip to content

Commit

Permalink
feat(user_avatar_details): change fromUserData to fromUser
Browse files Browse the repository at this point in the history
  • Loading branch information
CHOOSEIT committed May 25, 2024
1 parent 4476279 commit 7a9eeaf
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 45 deletions.
13 changes: 6 additions & 7 deletions lib/models/ui/user_avatar_details.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "package:flutter/foundation.dart";
import "package:proxima/models/database/user/user_data.dart";
import "package:proxima/models/database/user/user_firestore.dart";
import "package:proxima/models/database/user/user_id_firestore.dart";

/// A class that stores data for a user avatar UI.
Expand All @@ -19,14 +19,13 @@ class UserAvatarDetails {
required this.userID,
});

/// Converts a [UserData] object, [userData], to a [UserAvatarDetails] object.
factory UserAvatarDetails.fromUserData(
UserData userData,
UserIdFirestore userID,
/// Converts a [UserFirestore] object, [user], to a [UserAvatarDetails] object.
factory UserAvatarDetails.fromUser(
UserFirestore user,
) {
return UserAvatarDetails(
displayName: userData.displayName,
userID: userID,
displayName: user.data.displayName,
userID: user.uid,
);
}

Expand Down
5 changes: 1 addition & 4 deletions lib/viewmodels/dynamic_user_avatar_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ class DynamicUserAvatarViewModel extends AutoDisposeFamilyAsyncNotifier<

user = await userDataBase.getUser(userID);

return UserAvatarDetails.fromUserData(
user.data,
userID,
);
return UserAvatarDetails.fromUser(user);
}
}

Expand Down
18 changes: 5 additions & 13 deletions lib/views/pages/profile/components/profile_app_bar.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
import "package:flutter/material.dart";
import "package:proxima/models/database/user/user_data.dart";
import "package:proxima/models/database/user/user_id_firestore.dart";
import "package:proxima/models/database/user/user_firestore.dart";
import "package:proxima/views/navigation/leading_back_button/leading_back_button.dart";
import "package:proxima/views/pages/profile/components/logout_button.dart";
import "package:proxima/views/pages/profile/components/user_account.dart";

// This widget displays the profile of a user as an app bar.
class ProfileAppBar extends AppBar {
// The user data of the user to display
final UserData userData;

// The user id of the user to display
final UserIdFirestore userID;
// The user to display
final UserFirestore user;

ProfileAppBar({
super.key,
required this.userData,
required this.userID,
required this.user,
}) : super(
leading: const LeadingBackButton(),
title: UserAccount(
userData: userData,
userID: userID,
),
title: UserAccount(user: user),
actions: [
const LogoutButton(),
],
Expand Down
20 changes: 7 additions & 13 deletions lib/views/pages/profile/components/user_account.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "package:flutter/material.dart";
import "package:proxima/models/database/user/user_data.dart";
import "package:proxima/models/database/user/user_id_firestore.dart";
import "package:proxima/models/database/user/user_firestore.dart";
import "package:proxima/models/ui/user_avatar_details.dart";
import "package:proxima/views/components/content/user_avatar/user_avatar.dart";

Expand All @@ -11,20 +10,18 @@ class UserAccount extends StatelessWidget {

const UserAccount({
super.key,
required this.userData,
required this.userID,
required this.user,
});

// The user data of the user to display
final UserData userData;

// The user id of the user to display
final UserIdFirestore userID;
// The user to display
final UserFirestore user;

@override
Widget build(BuildContext context) {
final textStyle = Theme.of(context).textTheme.titleSmall;

final userData = user.data;

final displayName = Text(
userData.displayName,
style: textStyle,
Expand All @@ -38,10 +35,7 @@ class UserAccount extends StatelessWidget {
);

final profilePicture = UserAvatar(
details: UserAvatarDetails.fromUserData(
userData,
userID,
),
details: UserAvatarDetails.fromUser(user),
radius: 20,
);

Expand Down
5 changes: 1 addition & 4 deletions lib/views/pages/profile/profile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ class ProfilePage extends ConsumerWidget {
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: ProfileAppBar(
userData: user.data,
userID: user.uid,
),
appBar: ProfileAppBar(user: user),
body: Container(
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 8),
child: const Column(
Expand Down
5 changes: 1 addition & 4 deletions test/models/ui/user_avatar_details_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ void main() {
late UserAvatarDetails userAvatarDetails;

setUp(() {
userAvatarDetails = UserAvatarDetails.fromUserData(
testingUserData,
testingUserFirestoreId,
);
userAvatarDetails = UserAvatarDetails.fromUser(testingUserFirestore);
});

test("Hash overrides correctly", () {
Expand Down

0 comments on commit 7a9eeaf

Please sign in to comment.