Last active
August 4, 2022 14:37
-
-
Save craiglabenz/87f1f9cff36d28daffc3e05a836491dc to your computer and use it in GitHub Desktop.
TextStyle basic usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.light().copyWith( | |
scaffoldBackgroundColor: darkBlue, | |
textTheme: const TextTheme( | |
headline4: TextStyle( | |
color: Colors.white, | |
), | |
), | |
), | |
debugShowCheckedModeBanner: false, | |
// Default functionality with a Scaffold, which provides a Material widget | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
// Comment the above and uncomment the below to enjoy Flutter's jarring default | |
// TextStyle, meant to be unattractive so you choose your own values! | |
// home: Center(child: const Text('Error theme', style: TextStyle(color: Colors.blue))), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text( | |
'Hello, World!', | |
style: Theme.of(context).textTheme.headline4, | |
), | |
Text( | |
'Hello, World!', | |
style: Theme.of(context).textTheme.headline4!.copyWith( | |
color: Colors.red, | |
fontStyle: FontStyle.italic, | |
), | |
), | |
const Text( | |
'Hello, Flutter!', | |
style: TextStyle(color: Colors.blue, fontSize: 48), | |
), | |
const Text( | |
'inherit: true (the default)', | |
style: TextStyle(), | |
), | |
const Text( | |
'inherit: false', | |
style: TextStyle(inherit: false), | |
), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment