text stringlengths 1 372 |
|---|
fontStyle: FontStyle.italic, |
), |
bodyMedium: GoogleFonts.merriweather(), |
displaySmall: GoogleFonts.pacifico(), |
), |
), |
home: const MyHomePage( |
title: appName, |
), |
); |
<code_end> |
most instances of ThemeData set values for the following two properties. these properties affect the entire app. |
to learn what colors, fonts, and other properties, you can define, |
check out the ThemeData documentation. |
<topic_end> |
<topic_start> |
apply a theme |
to apply your new theme, use the theme.of(context) method |
when specifying a widget’s styling properties. |
these can include, but are not limited to, style and color. |
the theme.of(context) method looks up the widget tree and retrieves |
the nearest theme in the tree. |
if you have a standalone theme, that’s applied. |
if not, flutter applies the app’s theme. |
in the following example, the container constructor uses this technique to set its color. |
<code_start> |
container( |
padding: const EdgeInsets.symmetric( |
horizontal: 12, |
vertical: 12, |
), |
color: Theme.of(context).colorScheme.primary, |
child: text( |
'text with a background color', |
// ··· |
style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
color: Theme.of(context).colorScheme.onPrimary, |
), |
), |
), |
<code_end> |
<topic_end> |
<topic_start> |
override a theme |
to override the overall theme in part of an app, |
wrap that section of the app in a theme widget. |
you can override a theme in two ways: |
<topic_end> |
<topic_start> |
set a unique ThemeData instance |
if you want a component of your app to ignore the overall theme, |
create a ThemeData instance. |
pass that instance to the theme widget. |
<code_start> |
theme( |
// create a unique theme with `themedata`. |
data: ThemeData( |
colorScheme: ColorScheme.fromSeed( |
seedColor: colors.pink, |
), |
), |
child: FloatingActionButton( |
onPressed: () {}, |
child: const Icon(Icons.add), |
), |
); |
<code_end> |
<topic_end> |
<topic_start> |
extend the parent theme |
instead of overriding everything, consider extending the parent theme. |
to extend a theme, use the copyWith() method. |
<code_start> |
theme( |
// find and extend the parent theme using `copywith`. |
// to learn more, check out the section on `theme.of`. |
data: Theme.of(context).copyWith( |
colorScheme: ColorScheme.fromSeed( |
seedColor: colors.pink, |
), |
), |
child: const FloatingActionButton( |
onPressed: null, |
child: Icon(Icons.add), |
), |
); |
<code_end> |
<topic_end> |
<topic_start> |
watch a video on theme |
to learn more, watch this short widget of the week video on the theme widget: |
<topic_end> |
<topic_start> |
try an interactive example |
<code_start> |
import 'package:flutter/material.dart'; |
// include the google fonts package to provide more text format options |
// https://pub.dev/packages/google_fonts |
import 'package:google_fonts/google_fonts.dart'; |
void main() { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.