feat: new ui (#1455)

This commit is contained in:
Levi authored and GitHub committed 2026-09-05 19:53:41 +08:00
1 parent 3be8db664c
commit 177c225f16
742 files changed
+59951 -5934

No files matched your search

@@ -0,0 +1,96 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:gopeed/shared/theme/app_component_themes.dart';
import 'package:gopeed/shared/theme/app_design_tokens.dart';
import 'package:gopeed/shared/theme/app_palette.dart';
import 'package:gopeed/shared/theme/app_theme.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
void main() {
testWidgets('provides the standard checkbox metrics', (tester) async {
late shad.CheckboxTheme checkboxTheme;
await tester.pumpWidget(
shad.ShadcnApp(
theme: AppTheme.light(),
materialTheme: AppTheme.materialLight(),
home: AppComponentThemes(
child: Builder(
builder: (context) {
checkboxTheme = shad.ComponentTheme.of<shad.CheckboxTheme>(context);
return const SizedBox();
},
),
),
),
);
expect(checkboxTheme.size, AppDesignTokens.checkboxSize);
expect(checkboxTheme.gap, AppDesignTokens.checkboxLabelGap);
});
testWidgets('uses a high-contrast checkbox border in the dark theme', (tester) async {
late shad.CheckboxTheme checkboxTheme;
await tester.pumpWidget(
shad.ShadcnApp(
theme: AppTheme.dark(),
materialTheme: AppTheme.materialDark(),
home: AppComponentThemes(
child: Builder(
builder: (context) {
checkboxTheme = shad.ComponentTheme.of<shad.CheckboxTheme>(context);
return const SizedBox();
},
),
),
),
);
expect(checkboxTheme.borderColor, AppPalette.dark.textMuted);
expect(_contrastRatio(checkboxTheme.borderColor!, AppPalette.dark.bg), greaterThanOrEqualTo(3));
});
testWidgets('uses distinct borderless secondary button fills in the light theme', (tester) async {
late shad.SecondaryButtonTheme buttonTheme;
late BuildContext themedContext;
await tester.pumpWidget(
shad.ShadcnApp(
theme: AppTheme.light(),
materialTheme: AppTheme.materialLight(),
home: AppComponentThemes(
child: Builder(
builder: (context) {
themedContext = context;
buttonTheme = shad.ComponentTheme.of<shad.SecondaryButtonTheme>(context);
return const SizedBox();
},
),
),
),
);
final decoration =
buttonTheme.decoration!(themedContext, const <WidgetState>{}, const BoxDecoration()) as BoxDecoration;
final hoveredDecoration =
buttonTheme.decoration!(themedContext, const <WidgetState>{WidgetState.hovered}, const BoxDecoration())
as BoxDecoration;
final disabledDecoration =
buttonTheme.decoration!(themedContext, const <WidgetState>{WidgetState.disabled}, const BoxDecoration())
as BoxDecoration;
expect(decoration.border, isNull);
expect(hoveredDecoration.border, isNull);
expect(disabledDecoration.border, isNull);
expect(decoration.color, isNot(AppPalette.light.surfaceSoft));
expect(hoveredDecoration.color, isNot(decoration.color));
});
}
double _contrastRatio(Color first, Color second) {
final firstLuminance = first.computeLuminance();
final secondLuminance = second.computeLuminance();
final lighter = firstLuminance > secondLuminance ? firstLuminance : secondLuminance;
final darker = firstLuminance > secondLuminance ? secondLuminance : firstLuminance;
return (lighter + 0.05) / (darker + 0.05);
}
@@ -0,0 +1,127 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:gopeed/shared/theme/app_component_themes.dart';
import 'package:gopeed/shared/theme/app_palette.dart';
import 'package:gopeed/shared/theme/app_theme.dart';
import 'package:gopeed/shared/widgets/app_loading_button.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
void main() {
testWidgets('loading buttons replace only the icon and preserve their color family', (tester) async {
await tester.pumpWidget(
shad.ShadcnApp(
theme: AppTheme.dark(),
materialTheme: AppTheme.materialDark(),
home: AppComponentThemes(
child: Column(
children: [
AppLoadingButton(
key: const ValueKey('secondary-loading-button'),
onPressed: () {},
loading: true,
icon: const Icon(shad.LucideIcons.refreshCw),
child: const Text('Check for Updates'),
),
AppLoadingButton(
key: const ValueKey('brand-loading-button'),
onPressed: () {},
loading: true,
variant: AppLoadingButtonVariant.brand,
icon: const Icon(shad.LucideIcons.download),
child: const Text('Update'),
),
AppLoadingButton(
key: const ValueKey('primary-loading-button'),
onPressed: () {},
loading: true,
variant: AppLoadingButtonVariant.primary,
icon: const Icon(shad.LucideIcons.save),
child: const Text('Save'),
),
],
),
),
),
);
await tester.pump();
final secondary = find.byKey(const ValueKey('secondary-loading-button'));
final brand = find.byKey(const ValueKey('brand-loading-button'));
final primary = find.byKey(const ValueKey('primary-loading-button'));
expect(find.descendant(of: secondary, matching: find.text('Check for Updates')), findsOneWidget);
expect(find.descendant(of: brand, matching: find.text('Update')), findsOneWidget);
expect(find.descendant(of: primary, matching: find.text('Save')), findsOneWidget);
expect(find.descendant(of: secondary, matching: find.byIcon(shad.LucideIcons.refreshCw)), findsNothing);
expect(find.descendant(of: brand, matching: find.byIcon(shad.LucideIcons.download)), findsNothing);
expect(find.descendant(of: primary, matching: find.byIcon(shad.LucideIcons.save)), findsNothing);
final secondaryProgress = tester.widget<shad.CircularProgressIndicator>(
find.descendant(of: secondary, matching: find.byType(shad.CircularProgressIndicator)),
);
final brandProgress = tester.widget<shad.CircularProgressIndicator>(
find.descendant(of: brand, matching: find.byType(shad.CircularProgressIndicator)),
);
final primaryProgress = tester.widget<shad.CircularProgressIndicator>(
find.descendant(of: primary, matching: find.byType(shad.CircularProgressIndicator)),
);
expect(
tester.widget<shad.Clickable>(find.descendant(of: primary, matching: find.byType(shad.Clickable))).enabled,
isFalse,
);
expect(secondaryProgress.color, AppPalette.dark.textMuted);
expect(secondaryProgress.color, isNot(AppPalette.dark.brand));
expect(brandProgress.color, AppPalette.dark.brandForeground);
expect(primaryProgress.color, AppPalette.dark.primaryActionForeground);
final secondaryDecoration =
tester
.widget<shad.Clickable>(find.descendant(of: secondary, matching: find.byType(shad.Clickable)))
.decoration!
.resolve({WidgetState.disabled})
as BoxDecoration;
final brandDecoration =
tester
.widget<shad.Clickable>(find.descendant(of: brand, matching: find.byType(shad.Clickable)))
.decoration!
.resolve({WidgetState.disabled})
as BoxDecoration;
expect(secondaryDecoration.color, AppPalette.dark.surfaceSoft);
expect(brandDecoration.color, AppPalette.dark.brand);
});
testWidgets('text-only loading buttons replace their label with a centered loader', (tester) async {
await tester.pumpWidget(
shad.ShadcnApp(
theme: AppTheme.dark(),
materialTheme: AppTheme.materialDark(),
home: AppComponentThemes(
child: Center(
child: SizedBox(
key: const ValueKey('text-only-loading-bounds'),
width: 148,
height: 40,
child: AppLoadingButton(
key: const ValueKey('text-only-loading-button'),
onPressed: () {},
loading: true,
alignment: Alignment.center,
variant: AppLoadingButtonVariant.primary,
child: const Text('Login'),
),
),
),
),
),
);
await tester.pump();
final bounds = tester.getRect(find.byKey(const ValueKey('text-only-loading-bounds')));
final loader = find.descendant(
of: find.byKey(const ValueKey('text-only-loading-button')),
matching: find.byType(shad.CircularProgressIndicator),
);
expect(find.text('Login'), findsNothing);
expect(loader, findsOneWidget);
expect(tester.getRect(loader).center, bounds.center);
});
}
@@ -0,0 +1,43 @@
import 'dart:io';
import 'package:flutter/material.dart' show MaterialApp, Tooltip;
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:gopeed/shared/widgets/app_tooltip.dart';
void main() {
testWidgets('AppTooltip delegates product tooltips to Flutter Tooltip', (tester) async {
await tester.pumpWidget(
const MaterialApp(
home: AppTooltip(message: 'Details', child: SizedBox.square(dimension: 24)),
),
);
expect(tester.widget<Tooltip>(find.byType(Tooltip)).message, 'Details');
});
test('product source does not instantiate Tooltip directly', () {
final violations = <String>[];
final tooltipConstructor = RegExp(r'\b(?:\w+\.)?Tooltip\s*\(');
for (final entity in Directory('lib').listSync(recursive: true)) {
if (entity is! File || !entity.path.endsWith('.dart') || entity.path.endsWith('app_tooltip.dart')) {
continue;
}
final lines = entity.readAsLinesSync();
for (var index = 0; index < lines.length; index++) {
if (tooltipConstructor.hasMatch(lines[index])) {
violations.add('${entity.path}:${index + 1}');
}
}
}
expect(
violations,
isEmpty,
reason:
'Use AppTooltip so product tooltip styling stays centralized. Direct Tooltip usage found at: '
'${violations.join(', ')}',
);
});
}