Skip to content

Commit

Permalink
add expert icon logic (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ida631 authored Dec 13, 2024
1 parent 73ca079 commit d932a7e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class SettingsViewModel extends ChangeNotifier {
String version = '';
User? user;
String submission = '';
bool isExpert = false;



int _tapCount = 0;
Expand Down Expand Up @@ -60,7 +62,8 @@ class SettingsViewModel extends ChangeNotifier {
Future<void> fetchUser() async {
try {
user = await userUserCase.fetchMe();
isLoggedIn = true; // Ensure isLoggedIn is updated correctly
isLoggedIn = true;
isExpert = user!.isCompositeExpert;// Ensure isLoggedIn is updated correctly
} catch (e) {
if (kDebugMode) {
print(e);
Expand Down
6 changes: 3 additions & 3 deletions lib/presentation/settings/views/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ class _SettingsPageState extends State<SettingsPage> {
fontWeight: FontWeight.bold,
),
),
/*if (viewModel.user?.isCompositeExpert == true) // Check if the user is verified
if (viewModel.user?.isCompositeExpert == true) // Check if the user is verified
Padding(
padding: const EdgeInsets.only(left: 4.0), // Add spacing between name and icon
child: Icon(
Icons.verified, // Use a verified checkmark icon
color: Colors.blue, // Make it blue to represent verification
size: 16, // Adjust the size to fit nicely
),
),*/
),
],
),

Expand All @@ -118,7 +118,7 @@ class _SettingsPageState extends State<SettingsPage> {
await _fetchAuthSession();
},
),
if (viewModel.isLoggedIn)
if (viewModel.isLoggedIn && !viewModel.isExpert)
MoreRow(leadingIcon: Icons.account_box_outlined,
title: "Request to Become an Expert",
onTap: () async {
Expand Down
27 changes: 20 additions & 7 deletions lib/presentation/settings/views/user_profile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,27 @@ class UserProfilePage extends StatelessWidget {
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
viewModel.user?.name ?? '',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.black,
),
Row(
children: [
Text(
viewModel.user?.name ?? "",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
if (viewModel.user?.isCompositeExpert == true) // Check if the user is verified
Padding(
padding: const EdgeInsets.only(left: 4.0), // Add spacing between name and icon
child: Icon(
Icons.verified, // Use a verified checkmark icon
color: Colors.blue, // Make it blue to represent verification
size: 16, // Adjust the size to fit nicely
),
),
],
),

SizedBox(height: 8),
Text(
viewModel.user?.email ?? '',
Expand Down
1 change: 1 addition & 0 deletions packages/data/lib/repositories/user_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class UserRepositoryImpl implements UserRepository {
// Check the response status and handle accordingly
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
print(User.fromJson(data));
return User.fromJson(data);

} else {
Expand Down
30 changes: 18 additions & 12 deletions packages/domain/lib/entities/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@ class User {
String? name;
final String? description;
final String? avatarUrl;
final bool isAdmin; // Value from the database
bool isCompositeExpert;

User(
{this.username,
required this.email,
this.name,
this.description,
this.avatarUrl});
User({
this.username,
required this.email,
this.name,
this.description,
this.avatarUrl,
this.isAdmin = false, // Optional: Provide a default in Dart
this.isCompositeExpert = false,
});

// Factory constructor to create a User instance from JSON
factory User.fromJson(Map<String, dynamic> json) {
return User(
username: json['username'] ?? '',
email: json['email'] ?? '',
name: json['name'],
description: json['description'],
avatarUrl: json['avatarUrl'],
);
username: json['username'] ?? '',
email: json['email'] ?? '',
name: json['name'],
description: json['description'],
avatarUrl: json['avatarUrl'],
isAdmin: json['isAdmin'],
isCompositeExpert: json['isCompositeExpert']);
}
}

0 comments on commit d932a7e

Please sign in to comment.