In a flutter app I have a ThemeData()
applied to the Material app. Since setting useMaterial3: true
, some colors across the app have changed. Namely, the Text color for CupertinoDialogAction
in CupertinoAlertDialog
has turned purple (0xFFD0BCFF
).
I don't want to set the color manually for all dialogs across the app. How do I set the default color for the dialog action text? I want to keep using material 3 and not disable it.
In the theme I have tried to set colorSchemeSeed: Colors.blue
but there is no change. I just can't seem to get rid of the ugly purple.
After digging into the source code of CupertinoDialogAction
, the text color is computed by:
color: CupertinoDynamicColor.resolve(
isDestructiveAction ? CupertinoColors.systemRed : CupertinoTheme.of(context).primaryColor,
context,
),
To change the CupertinoTheme
's primaryColor
when using MaterialApp
, you could either change the ThemeData.colorScheme.primary
since the CupertinoTheme
is derived from the MaterialTheme (check out MaterialBasedCupertinoThemeData).
theme: ThemeData(
colorScheme: const ColorScheme.light(
primary: Colors.blue,
),
useMaterial3: true,
),
or
if you want to decouple the Cupertino styling from Material theme, you could provide a CupertinoThemeData
to the ThemeData.cupertinoOverrideTheme
.
theme: ThemeData(
cupertinoOverrideTheme: const CupertinoThemeData(
primaryColor: Colors.blue,
),
useMaterial3: true,
),