import "package:flutter/widgets.dart"; import "package:flutter_test/flutter_test.dart"; import "package:garage_ui/garage_ui.dart"; import "support/test_scheme.dart"; // `.iconSmall` and friends set a SIZE. They used to set the tier's colour too - // the global scheme foreground - which beat whatever IconTheme enclosed the // icon. Inside a button that meant the button's variant colour lost: a primary // button hands its leading icon primaryForeground, and the wrapper put // scheme.foreground back over it. On a dark scheme thats near-white on a // near-white fill, so the icon vanished. Color? _resolved(WidgetTester tester, Key key) { final finder = find.descendant( of: find.byKey(key), matching: find.byType(Icon), ); final element = finder.evaluate().first; final icon = element.widget as Icon; return icon.color ?? IconTheme.of(element).color; } void main() { testWidgets("a size helper doesnt take the button's colour off its icon", ( tester, ) async { await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, child: GarageTheme( data: ThemeData(colorScheme: testScheme, density: const Density()), child: Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ Button( key: const Key("bare"), style: const ButtonStyle.primary(), leading: const Icon(LucideIcons.user), onPressed: () {}, child: const Text("bare"), ), Button( key: const Key("sized"), style: const ButtonStyle.primary(), leading: const Icon(LucideIcons.user).iconSmall, onPressed: () {}, child: const Text("sized"), ), ], ), ), ), ), ); await tester.pump(); expect( _resolved(tester, const Key("sized")), _resolved(tester, const Key("bare")), reason: "wrapping in .iconSmall should only change the size", ); expect( _resolved(tester, const Key("sized")), testScheme.primaryForeground, reason: "a primary button's icon comes off primaryForeground", ); }); testWidgets("outside a button it still falls through to the app theme", ( tester, ) async { await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, child: GarageTheme( data: ThemeData(colorScheme: testScheme, density: const Density()), child: Center( child: KeyedSubtree( key: const Key("loose"), child: const Icon(LucideIcons.user).iconSmall, ), ), ), ), ); await tester.pump(); expect(_resolved(tester, const Key("loose")), testScheme.foreground); }); testWidgets("the size still comes off the density", (tester) async { for (final density in const [Density(), Density.normal()]) { await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, child: GarageTheme( data: ThemeData(colorScheme: testScheme, density: density), child: Center( child: KeyedSubtree( key: const Key("sized"), child: const Icon(LucideIcons.user).iconSmall, ), ), ), ), ); await tester.pump(); final element = find .descendant( of: find.byKey(const Key("sized")), matching: find.byType(Icon), ) .evaluate() .first; expect(IconTheme.of(element).size, density.iconSize); } }); }