This app uses a green theme color for text and buttons. The text and button colors come from the theme, so they look consistent across the app.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Theming Demo',
theme: ThemeData(
primaryColor: Colors.green,
textTheme: const TextTheme(
bodyText1: TextStyle(fontSize: 18, color: Colors.green),
),
),
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Consistent UI with Theming'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('This text uses theme color', style: Theme.of(context).textTheme.bodyText1),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {},
child: const Text('Button with theme color'),
),
],
),
),
);
}
}