text
stringlengths
1
372
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
widget build(BuildContext context) {
const appName = 'custom themes';
return MaterialApp(
title: appName,
theme: ThemeData(
useMaterial3: true,
// define the default brightness and colors.
colorScheme: ColorScheme.fromSeed(
seedColor: colors.purple,
// TRY THIS: change to "brightness.light"
// and see that all colors change
// to better contrast a light background.
brightness: brightness.dark,
),
// define the default `texttheme`. use this to specify the default
// text styling for headlines, titles, bodies of text, and more.
textTheme: TextTheme(
displayLarge: const TextStyle(
fontSize: 72,
fontWeight: FontWeight.bold,
),
// TRY THIS: change one of the GoogleFonts
// to "lato", "poppins", or "lora".
// the title uses "titlelarge"
// and the middle text uses "bodymedium".
titleLarge: GoogleFonts.oswald(
fontSize: 30,
fontStyle: FontStyle.italic,
),
bodyMedium: GoogleFonts.merriweather(),
displaySmall: GoogleFonts.pacifico(),
),
),
home: const MyHomePage(
title: appName,
),
);
}
}
class MyHomePage extends StatelessWidget {
final string title;
const MyHomePage({super.key, required this.title});
@override
widget build(BuildContext context) {
return scaffold(
appBar: AppBar(
title: text(title,
style: Theme.of(context).textTheme.titleLarge!.copyWith(
color: Theme.of(context).colorScheme.onSecondary,
)),
backgroundColor: Theme.of(context).colorScheme.secondary,
),
body: center(
child: container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 12,
),
color: Theme.of(context).colorScheme.primary,
child: text(
'text with a background color',
// TRY THIS: change the text value
// or change the Theme.of(context).textTheme
// to "displaylarge" or "displaysmall".
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: Theme.of(context).colorScheme.onPrimary,
),
),
),
),
floatingActionButton: theme(
data: Theme.of(context).copyWith(
// TRY THIS: change the seedColor to "colors.red" or
// "colors.blue".
colorScheme: ColorScheme.fromSeed(
seedColor: colors.pink,
brightness: brightness.dark,
),
),
child: FloatingActionButton(
onPressed: () {},
child: const Icon(Icons.add),
),
),
);
}
}
<code_end>
<topic_end>
<topic_start>
material design for flutter
material design is an open-source design system built
and supported by google designers and developers.
the latest version, material 3, enables personal,
adaptive, and expressive experiences—from dynamic color