Last active
August 22, 2022 16:28
-
-
Save nythrox/cda5dde9799b31a60b36a7752a73a7e2 to your computer and use it in GitHub Desktop.
Flutter custom typography with smart defaults and configuration using Dart's call() method
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
extension on BuildContext { | |
TextStyle get paragraph => TextStyle(fontSize: 22, color: Colors.grey[900]); | |
} | |
Widget build(BuildContext context) { | |
return Column( | |
children: [ | |
Text("Hello world", style: context.paragraph), | |
Text("Hello world, again", style: context.paragraph(color: Colors.red)), | |
], | |
); | |
} |
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 'dart:ui' as ui show Shadow, FontFeature, TextLeadingDistribution; | |
extension Call on TextStyle { | |
TextStyle call({ | |
bool? inherit, | |
Color? color, | |
Color? backgroundColor, | |
double? fontSize, | |
FontWeight? fontWeight, | |
FontStyle? fontStyle, | |
double? letterSpacing, | |
double? wordSpacing, | |
TextBaseline? textBaseline, | |
double? height, | |
ui.TextLeadingDistribution? leadingDistribution, | |
Locale? locale, | |
Paint? foreground, | |
Paint? background, | |
List<ui.Shadow>? shadows, | |
List<ui.FontFeature>? fontFeatures, | |
TextDecoration? decoration, | |
Color? decorationColor, | |
TextDecorationStyle? decorationStyle, | |
double? decorationThickness, | |
String? debugLabel, | |
String? fontFamily, | |
List<String>? fontFamilyFallback, | |
String? package, | |
TextOverflow? overflow, | |
}) { | |
return copyWith( | |
inherit: inherit, | |
color: color, | |
backgroundColor: backgroundColor, | |
fontSize: fontSize, | |
fontWeight: fontWeight, | |
fontStyle: fontStyle, | |
letterSpacing: letterSpacing, | |
wordSpacing: wordSpacing, | |
textBaseline: textBaseline, | |
height: height, | |
leadingDistribution: leadingDistribution, | |
locale: locale, | |
foreground: foreground, | |
background: background, | |
shadows: shadows, | |
fontFeatures: fontFeatures, | |
decoration: decoration, | |
decorationColor: decorationColor, | |
decorationStyle: decorationStyle, | |
decorationThickness: decorationThickness, | |
debugLabel: debugLabel, | |
fontFamily: fontFamily, | |
fontFamilyFallback: fontFamilyFallback, | |
package: package, | |
overflow: overflow, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment