Skip to content

Instantly share code, notes, and snippets.

@martynov-alex
Last active February 1, 2024 02:52
Show Gist options
  • Select an option

  • Save martynov-alex/ddb4a9b451b167a734076abab368643c to your computer and use it in GitHub Desktop.

Select an option

Save martynov-alex/ddb4a9b451b167a734076abab368643c to your computer and use it in GitHub Desktop.
Example of Flutter text styles organization
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