Skip to content

Instantly share code, notes, and snippets.

@JaveedIshaq
Created August 15, 2023 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JaveedIshaq/c53291e9a4e23378aeea29ed83073a27 to your computer and use it in GitHub Desktop.
Save JaveedIshaq/c53291e9a4e23378aeea29ed83073a27 to your computer and use it in GitHub Desktop.
Flutter Default Text Font Sizes and Font weight
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: const Scaffold(
body: SingleChildScrollView(child: Center(
child: TextList(),
),
)),
);
}
}
class TextList extends StatelessWidget {
const TextList({super.key});
@override
Widget build(BuildContext context) {
return Column(
children: [
BuildTextWidget(
textStyleName: 'displayLarge',
textStyle: Theme.of(context).textTheme.displayLarge!,
),
BuildTextWidget(
textStyleName: 'displayMedium',
textStyle: Theme.of(context).textTheme.displayMedium!,
),
BuildTextWidget(
textStyleName: 'displaySmall',
textStyle: Theme.of(context).textTheme.displaySmall!,
),
BuildTextWidget(
textStyleName: 'headlineLarge',
textStyle: Theme.of(context).textTheme.headlineLarge!,
),
BuildTextWidget(
textStyleName: 'headlineMedium',
textStyle: Theme.of(context).textTheme.headlineMedium!,
),
BuildTextWidget(
textStyleName: 'headlineSmall',
textStyle: Theme.of(context).textTheme.headlineSmall!,
),
BuildTextWidget(
textStyleName: 'titleLarge',
textStyle: Theme.of(context).textTheme.titleLarge!,
),
BuildTextWidget(
textStyleName: 'titleMedium',
textStyle: Theme.of(context).textTheme.titleMedium!,
),
BuildTextWidget(
textStyleName: 'titleSmall',
textStyle: Theme.of(context).textTheme.titleSmall!,
),
BuildTextWidget(
textStyleName: 'bodyLarge',
textStyle: Theme.of(context).textTheme.bodyLarge!,
),
BuildTextWidget(
textStyleName: 'bodyMedium',
textStyle: Theme.of(context).textTheme.bodyMedium!,
),
BuildTextWidget(
textStyleName: 'bodySmall',
textStyle: Theme.of(context).textTheme.bodySmall!,
),
BuildTextWidget(
textStyleName: 'labelLarge',
textStyle: Theme.of(context).textTheme.labelLarge!,
),
BuildTextWidget(
textStyleName: 'labelMedium',
textStyle: Theme.of(context).textTheme.labelMedium!,
),
BuildTextWidget(
textStyleName: 'labelSmall',
textStyle: Theme.of(context).textTheme.labelSmall!,
),
],
);
}
}
class BuildTextWidget extends StatelessWidget {
const BuildTextWidget({
super.key,
required this.textStyle,
required this.textStyleName,
});
final TextStyle textStyle;
final String textStyleName;
@override
Widget build(BuildContext context) {
return Card(
elevation: 20,
margin: const EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
textStyleName,
style: textStyle,
),
Text(
"fontSize: ${textStyle.fontSize}",
style: textStyle,
),
Text(
"fontWeight: ${textStyle.fontWeight}",
style: textStyle,
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment