Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Let popup trailing icons inherit theme colors

AmanRajSinghMourya9abd4a67b9ca
diff --git a/mobile/packages/ente_components/lib/components/popup_menu_component.dart b/mobile/packages/ente_components/lib/components/popup_menu_component.dart
index ff9f1bd17a..7f32824215 100644
--- a/mobile/packages/ente_components/lib/components/popup_menu_component.dart
+++ b/mobile/packages/ente_components/lib/components/popup_menu_component.dart
@@ -244,31 +244,31 @@ class _EntePopupMenuRow<T> extends StatelessWidget {
return Opacity(
opacity: option.enabled ? 1 : 0.5,
- child: Row(
- children: [
- if (option.leadingWidget != null) ...[
- SizedBox.square(
- dimension: 24,
- child: Center(
- child: IconTheme.merge(
- data: IconThemeData(
- color: colors.textLight,
- size: IconSizes.small,
+ child: IconTheme.merge(
+ data: IconThemeData(color: colors.textLight),
+ child: Row(
+ children: [
+ if (option.leadingWidget != null) ...[
+ SizedBox.square(
+ dimension: 24,
+ child: Center(
+ child: IconTheme.merge(
+ data: const IconThemeData(size: IconSizes.small),
+ child: option.leadingWidget!,
),
- child: option.leadingWidget!,
),
),
- ),
- const SizedBox(width: 6),
+ const SizedBox(width: 6),
+ ],
+ Expanded(child: title),
+ if (option.trailingWidget != null)
+ option.trailingWidget!
+ else if (option.activeTrailingWidget != null)
+ option.isActive
+ ? option.activeTrailingWidget!
+ : const SizedBox(width: Spacing.md),
],
- Expanded(child: title),
- if (option.trailingWidget != null)
- option.trailingWidget!
- else if (option.activeTrailingWidget != null)
- option.isActive
- ? option.activeTrailingWidget!
- : const SizedBox(width: Spacing.md),
- ],
+ ),
),
);
}
diff --git a/mobile/packages/ente_components/test/components/popup_menu_component_test.dart b/mobile/packages/ente_components/test/components/popup_menu_component_test.dart
index eb0f042206..8b5f3db865 100644
--- a/mobile/packages/ente_components/test/components/popup_menu_component_test.dart
+++ b/mobile/packages/ente_components/test/components/popup_menu_component_test.dart
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:ente_components/ente_components.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
+import 'package:hugeicons/hugeicons.dart';
Future<void> pumpPopupMenu(
WidgetTester tester,
@@ -24,6 +25,106 @@ Future<void> pumpPopupMenu(
}
void main() {
+ testWidgets('open popup icons follow theme changes without changing sizes', (
+ tester,
+ ) async {
+ var optionsBuildCount = 0;
+
+ Widget app(ThemeMode themeMode) {
+ return MaterialApp(
+ theme: ComponentTheme.lightTheme().copyWith(
+ iconTheme: const IconThemeData(size: 30),
+ ),
+ darkTheme: ComponentTheme.darkTheme().copyWith(
+ iconTheme: const IconThemeData(size: 30),
+ ),
+ themeMode: themeMode,
+ home: Scaffold(
+ body: Align(
+ alignment: Alignment.topLeft,
+ child: EntePopupMenuButton<String>(
+ optionsBuilder: () {
+ optionsBuildCount++;
+ return const [
+ EntePopupMenuOption(
+ value: 'sort',
+ label: 'Sort',
+ secondaryLabel: 'Count',
+ leadingWidget: Icon(Icons.sort),
+ secondaryTrailingWidget: Icon(Icons.info_outline, size: 12),
+ isActive: true,
+ activeTrailingWidget: HugeIcon(
+ icon: HugeIcons.strokeRoundedArrowUp02,
+ size: 12,
+ strokeWidth: 3,
+ ),
+ ),
+ EntePopupMenuOption(
+ value: 'delete',
+ label: 'Delete',
+ leadingWidget: Icon(
+ Icons.delete,
+ color: Colors.red,
+ size: 20,
+ ),
+ trailingWidget: Icon(Icons.chevron_right),
+ ),
+ ];
+ },
+ onSelected: (_) {},
+ ),
+ ),
+ ),
+ );
+ }
+
+ TextStyle iconStyle(IconData icon) {
+ return tester
+ .widget<RichText>(
+ find.descendant(
+ of: find.byIcon(icon),
+ matching: find.byType(RichText),
+ ),
+ )
+ .text
+ .style!;
+ }
+
+ await tester.pumpWidget(app(ThemeMode.light));
+ await tester.tap(find.byType(EntePopupMenuButton<String>));
+ await tester.pumpAndSettle();
+
+ for (final mode in [ThemeMode.light, ThemeMode.dark, ThemeMode.light]) {
+ await tester.pumpWidget(app(mode));
+ await tester.pumpAndSettle();
+ final colors = mode == ThemeMode.dark
+ ? ColorTokens.dark
+ : ColorTokens.light;
+
+ for (final icon in [
+ Icons.sort,
+ Icons.info_outline,
+ Icons.chevron_right,
+ ]) {
+ expect(iconStyle(icon).color, colors.textLight);
+ }
+ expect(iconStyle(Icons.sort).fontSize, IconSizes.small);
+ expect(iconStyle(Icons.info_outline).fontSize, 12);
+ expect(iconStyle(Icons.chevron_right).fontSize, 30);
+ expect(iconStyle(Icons.delete).color, Colors.red);
+ expect(iconStyle(Icons.delete).fontSize, 20);
+
+ final arrow = find.descendant(
+ of: find.byType(PopupMenuItem<String>),
+ matching: find.byType(HugeIcon),
+ );
+ expect(IconTheme.of(tester.element(arrow)).color, colors.textLight);
+ expect(tester.getSize(arrow), const Size.square(12));
+ expect(optionsBuildCount, 1);
+ expect(tester.takeException(), isNull);
+ }
+ });
+
testWidgets(
'EntePopupMenuButton ignores async options after anchor unmounts',
(tester) async {