Skip to content

Commit df5f1e9

Browse files
committed
feat(ui): wrap premium icon with tooltip for screen readers
- Add AppLocalizations import for localization support - Rename getPremiumIcon method and add AppLocalizations parameter - Wrap premium icon with Tooltip widget for accessibility - Update tooltip message using localization
1 parent 9028e5a commit df5f1e9

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

lib/shared/extensions/app_user_role_ui.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import 'package:core/core.dart';
22
import 'package:flutter/material.dart';
3+
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/app_localizations.dart';
34

45
/// An extension on [AppUserRole] to provide UI-related helpers.
56
extension AppUserRoleUI on AppUserRole {
67
/// A convenience getter to check if the user role is premium.
78
bool get isPremium => this == AppUserRole.premiumUser;
89

9-
/// Returns a premium indicator icon if the user is a premium user.
10+
/// Returns a premium indicator icon wrapped in a tooltip if the user is a
11+
/// premium user.
1012
///
1113
/// Returns a gold star icon for premium users, otherwise returns null.
12-
Widget? get premiumIcon {
14+
Widget? getPremiumIcon(AppLocalizations l10n) {
1315
if (isPremium) {
14-
return const Padding(
15-
padding: EdgeInsets.only(left: 8),
16+
return Tooltip(
17+
message: l10n.premiumUserTooltip,
1618
child: Icon(Icons.star, color: Colors.amber, size: 16),
1719
);
1820
}

lib/user_management/view/dashboard_user_role_ui.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import 'package:core/core.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/app_localizations.dart';
24

35
/// An extension on [DashboardUserRole] to provide UI-related helpers.
46
extension DashboardUserRoleUI on DashboardUserRole {
@@ -7,4 +9,30 @@ extension DashboardUserRoleUI on DashboardUserRole {
79
return this == DashboardUserRole.admin ||
810
this == DashboardUserRole.publisher;
911
}
12+
13+
/// Returns a role indicator icon wrapped in a tooltip.
14+
Widget? getRoleIcon(AppLocalizations l10n) {
15+
switch (this) {
16+
case DashboardUserRole.admin:
17+
return Tooltip(
18+
message: l10n.adminUserTooltip,
19+
child: const Icon(
20+
Icons.admin_panel_settings,
21+
color: Colors.blueAccent,
22+
size: 16,
23+
),
24+
);
25+
case DashboardUserRole.publisher:
26+
return Tooltip(
27+
message: l10n.publisherUserTooltip,
28+
child: const Icon(
29+
Icons.publish,
30+
color: Colors.green,
31+
size: 16,
32+
),
33+
);
34+
case DashboardUserRole.none:
35+
return null;
36+
}
37+
}
1038
}

0 commit comments

Comments
 (0)