Last active
February 1, 2024 02:52
-
-
Save martynov-alex/ddb4a9b451b167a734076abab368643c to your computer and use it in GitHub Desktop.
Example of Flutter text styles organization
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.dark().copyWith( | |
| scaffoldBackgroundColor: darkBlue, | |
| ), | |
| debugShowCheckedModeBanner: false, | |
| home: Scaffold( | |
| body: Center( | |
| child: MyWidget(), | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class MyWidget extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return Column( | |
| children: [ | |
| Text( | |
| 'Hello, World!', | |
| style: Typography.bold.size64, | |
| ), | |
| Text( | |
| 'Hello, World!', | |
| style: Typography.regular.size64, | |
| ), | |
| ], | |
| ); | |
| } | |
| } | |
| abstract class Typography { | |
| static final regular = _Regular(); | |
| static final bold = _Bold(); | |
| } | |
| class _Regular { | |
| TextStyle size20 = const TextStyle( | |
| fontSize: 20, | |
| ); | |
| TextStyle size64 = const TextStyle( | |
| fontSize: 64, | |
| ); | |
| } | |
| class _Bold { | |
| TextStyle size20 = const TextStyle( | |
| fontSize: 20, | |
| fontWeight: FontWeight.bold, | |
| ); | |
| TextStyle size64 = const TextStyle( | |
| fontSize: 64, | |
| fontWeight: FontWeight.bold, | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment