Когда я использую текстовую тему из своего приложения, Theme.of(context).textTheme.subhead
Текст обновляется с указанием правильного размера и веса, но цвет также всегда черный. Как использовать определенную текстовую тему, позволяя при этом автоматически изменять цвет (например, с черного на белый при размещении на темной кнопке?
В теме моего приложения используется текстовая тема по умолчанию (минуспара изменений веса)
Я осмотрелся и думаю, что использую его правильно, но я не уверен.
TextTheme _customizeTextTheme(TextTheme base) {
return base.copyWith(
title: base.title.copyWith(
fontWeight: FontWeight.bold,
),
body2: base.body2.copyWith(
fontWeight: FontWeight.bold,
),
);
}
ThemeData _buildLightTheme() {
const Color primaryColor = Colors.white;
const Color secondaryColor = Colors.red;
final ColorScheme colorScheme = const ColorScheme.light().copyWith(
primary: primaryColor,
secondary: secondaryColor,
);
final ColorScheme buttonColorScheme = const ColorScheme.light().copyWith(
primary: secondaryColor,
secondary: primaryColor,
);
final ThemeData base = ThemeData(
// typography: Typography(
// englishLike: Typography.englishLike2018,
// dense: Typography.dense2018,
// tall: Typography.tall2018,
// ), //This is for another stackOverflowQuestion. I can't get this to do anything
fontFamily: 'Avenir',
brightness: Brightness.light,
accentColorBrightness: Brightness.dark,
colorScheme: colorScheme,
primaryColor: primaryColor,
buttonColor: primaryColor,
indicatorColor: Colors.white,
toggleableActiveColor: const Color(0xFF1E88E5),
splashColor: Colors.white24,
splashFactory: InkRipple.splashFactory,
accentColor: secondaryColor,
errorColor: const Color(0xFFB00020),
disabledColor: Colors.grey,
hintColor: ServerColors.greenAccent,
buttonTheme: ButtonThemeData(
colorScheme: buttonColorScheme,
textTheme: ButtonTextTheme.primary,
),
);
return base.copyWith(
textTheme: _customizeTextTheme(base.textTheme),
primaryTextTheme: _customizeTextTheme(base.primaryTextTheme),
accentTextTheme: _customizeTextTheme(base.accentTextTheme),
);
}
и когда я создаю свое приложение:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ServerThemes.lightTheme,
initialRoute: Routes.home,
routes: {
Routes.home: (context) => AppHomePage(),
},
onUnknownRoute: (settings) => MaterialPageRoute(
builder: (context) => UndefinedRoute(
badPathName: settings.name,
)),
),
);
}
}
и когда я его использую:
FloatingActionButton.extended(
onPressed: () {},
label: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"View Cart",
style: Theme.of(context).textTheme.title, // <---- RIGHT HERE
),
),
icon: Icon(Icons.shopping_cart),
),
В настоящее время FAB имеет красный цвет, и без стилевого оформления текст является белым, как и ожидалось, но когда я добавляю стилевую линию, текст отображаетсячерный.
Я бы предположил, что есть способ использовать текстовую тему без отключения автоматической регулировки цвета .?