Skip to content

Instantly share code, notes, and snippets.

@JaveedIshaq
Created March 8, 2021 12:36
Show Gist options
  • Save JaveedIshaq/e297a8d711665de377e491608b5e6277 to your computer and use it in GitHub Desktop.
Save JaveedIshaq/e297a8d711665de377e491608b5e6277 to your computer and use it in GitHub Desktop.
How to set text color theme for entire app in flutter
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
const Color PRIMARY_COLOR = Colors.indigo;
const Color ACCENT_COLOR = Colors.indigoAccent;
const Color BACKGROUND_COLOR = Colors.grey;
ThemeData _buildTheme() {
final ThemeData base = ThemeData.light();
return base.copyWith(
primaryColor: PRIMARY_COLOR,
accentColor: ACCENT_COLOR,
backgroundColor: BACKGROUND_COLOR,
appBarTheme: _appBarTheme(base.appBarTheme),
textTheme: _textTheme(base.textTheme),
buttonTheme: base.buttonTheme.copyWith(
buttonColor: PRIMARY_COLOR,
),
);
}
AppBarTheme _appBarTheme(AppBarTheme base) => base.copyWith(
color: BACKGROUND_COLOR,
brightness: Brightness.light,
textTheme: TextTheme(
headline1: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18.0,
fontFamily: 'Montserrat',
color: ACCENT_COLOR),),
iconTheme: IconThemeData(color: ACCENT_COLOR));
TextTheme _textTheme(TextTheme base) {
return base.copyWith(
headline1: base.headline1.copyWith(
fontWeight: FontWeight.w500,
fontFamily: 'Montserrat',
color: ACCENT_COLOR),
subtitle1: base.subtitle1.copyWith(
fontSize: 20,
// fontWeight: FontWeight.w600,
fontFamily: 'Montserrat',
color: ACCENT_COLOR),
caption: base.caption.copyWith(
fontWeight: FontWeight.w400,
fontFamily: 'Montserrat',
// fontSize: TEXT_FONT_SIZE,
color: ACCENT_COLOR),
bodyText1: base.bodyText1.copyWith(
fontWeight: FontWeight.w400,
fontFamily: 'Montserrat',
// fontSize: TEXT_FONT_SIZE,
color: ACCENT_COLOR),
bodyText2: base.bodyText2.copyWith(
fontWeight: FontWeight.w500,
fontFamily: 'Montserrat',
// fontSize: TEXT_LARGE_FONT_SIZE,
color: ACCENT_COLOR),
button: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
fontFamily: 'Montserrat',
fontSize: 16),
);
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: _buildTheme(),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Text('Hello, World!', style: Theme.of(context).textTheme.headline1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment