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

Code before:

    // 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'),
        ),
      ),
    );

    // 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 respects foregroundColor when disabled', (
    WidgetTester tester,
  ) async {
    const Color customForegroundColor = Color(0xFF5500FF);

    await tester.pumpWidget(

Review comment (suggestion):
```suggestion
  testWidgets('CupertinoButton.filled foregroundColor applies to its text', (WidgetTester tester) async {
```

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

    await tester.pumpWidget(
      boilerplate(
        child: const CupertinoButton(
          onPressed: null, // disabled button
          foregroundColor: customForegroundColor,
          child: Text('Button'),
        ),
      ),
    );

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