Repository: flutter/flutter
File: packages/flutter/test/cupertino/button_test.dart (Dart)

Code before:
      find.descendant(of: find.byType(CupertinoButton), matching: find.byType(RichText)),
    );
    expect(text.text.style?.color, customForegroundColor);
  });

  testWidgets('CupertinoButton foregroundColor applies to Icon', (WidgetTester tester) async {
    const Color customForegroundColor = Color(0xFF5500FF);

    await tester.pumpWidget(
      boilerplate(
        child: CupertinoButton(
          onPressed: () {},
          foregroundColor: customForegroundColor,
          child: const Icon(IconData(0xE000)),
        ),
      ),
    );

    // Check that the icon has the custom foreground color
    final IconTheme iconTheme = tester.widget(
      find.descendant(of: find.byType(CupertinoButton), matching: find.byType(IconTheme)),
    );
    expect(iconTheme.data.color, customForegroundColor);
  });

  testWidgets('CupertinoButton foregroundColor applies to both Text and Icon', (
    WidgetTester tester,
  ) async {
    const Color customForegroundColor = Color(0xFF5500FF);

    await tester.pumpWidget(
      boilerplate(
        child: CupertinoButton(
          onPressed: () {},
          foregroundColor: customForegroundColor,
          child: const Row(
            mainAxisSize: MainAxisSize.min,
            children: [Icon(IconData(0xE000)), SizedBox(width: 8), Text('Button')],
          ),
        ),
      ),
    );

    // Check that the icon has the custom foreground color
    final IconTheme iconTheme = tester.widget(
      find.descendant(of: find.byType(CupertinoButton), matching: find.byType(IconTheme)),
    );
    expect(iconTheme.data.color, customForegroundColor);

    // Check that the text has the custom foreground color
    final RichText text = tester.widget(

Review comment (suggestion):
```suggestion
  testWidgets('CupertinoButton foregroundColor applies to both its text and its icon', (
```

(Honestly not sure how useful this test case is but we can keep it)

Code after:
      boilerplate(
        child: CupertinoButton(
          onPressed: () {},
          foregroundColor: customForegroundColor,
          child: const Text('Button'),
        ),
      ),
    );

    // Check that the text has the custom foreground color
    final RichText text = tester.widget(
      find.descendant(of: find.byType(CupertinoButton), matching: find.byType(RichText)),
    );
    expect(text.text.style?.color, customForegroundColor);
  });

  testWidgets('CupertinoButton foregroundColor applies to its icon', (WidgetTester tester) async {
    const Color customForegroundColor = Color(0xFF5500FF);

    await tester.pumpWidget(
      boilerplate(
        child: CupertinoButton(
          onPressed: () {},
          foregroundColor: customForegroundColor,
          child: const Icon(IconData(0xE000)),
        ),
      ),
    );

    // Check that the icon has the custom foreground color
    final IconTheme iconTheme = tester.widget(
      find.descendant(of: find.byType(CupertinoButton), matching: find.byType(IconTheme)),
    );
    expect(iconTheme.data.color, customForegroundColor);
  });

  testWidgets(
    "CupertinoButton uses the theme's primaryColor when foregroundColor is not specified",
    (WidgetTester tester) async {
      await tester.pumpWidget(
        CupertinoApp(
          home: Center(
            child: CupertinoButton(onPressed: () {}, child: const Text('Button')),
          ),
        ),
      );

      // The default color should be the primary color from the theme
      final BuildContext context = tester.element(find.text('Button'));
      final Color primaryColor = CupertinoTheme.of(context).primaryColor;