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

Code before:
      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(
      find.descendant(of: find.byType(CupertinoButton), matching: find.byType(RichText)),
    );
    expect(text.text.style?.color, customForegroundColor);
  });

  testWidgets('CupertinoButton uses default color when foregroundColor 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;

    final RichText text = tester.widget(find.byType(RichText));
    expect(text.text.style?.color, primaryColor);
  });

  testWidgets('CupertinoButton.filled respects foregroundColor', (WidgetTester tester) async {
    const Color customForegroundColor = Color(0xFF5500FF);

    await tester.pumpWidget(
      boilerplate(
        child: CupertinoButton.filled(
          onPressed: () {},
          foregroundColor: customForegroundColor,
          child: const Text('Button'),

Review comment (suggestion):
```suggestion
  testWidgets('CupertinoButton uses the theme's primaryColor when foregroundColor is not specified', (
```

Code after:
      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;

      final RichText text = tester.widget(find.byType(RichText));
      expect(text.text.style?.color, primaryColor);
    },
  );

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

    await tester.pumpWidget(
      boilerplate(
        child: CupertinoButton.filled(
          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 text when disabled', (
    WidgetTester tester,
  ) async {
    const Color customForegroundColor = Color(0xFF5500FF);