Created
June 2, 2026 14:26
-
-
Save rena2019/855c302220b03b84bee7ac24ab674725 to your computer and use it in GitHub Desktop.
fontWeight: TextStyle vs GoogleFonts
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'; | |
| import 'package:google_fonts/google_fonts.dart'; | |
| //fontWeight: TextStyle vs GoogleFonts | |
| void main() { | |
| runApp(const MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| const MyApp({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| debugShowCheckedModeBanner: false, | |
| home: Scaffold( | |
| appBar: AppBar(title: const Text("Roboto FontWeights")), | |
| body: ListView( | |
| padding: const EdgeInsets.all(20), | |
| children: [ | |
| Text("700 TextStyle", style: TextStyle(fontFamily: GoogleFonts.roboto().fontFamily, fontSize: 24, fontWeight: FontWeight.w700)), | |
| Text("900 TextStyle", style: TextStyle(fontFamily: GoogleFonts.roboto().fontFamily, fontSize: 24, fontWeight: FontWeight.w900)), | |
| Text("900 GoogleFonts.roboto", style: GoogleFonts.roboto(fontWeight: FontWeight.w900, fontSize: 24,)), | |
| _buildRobotoText("W100 Thin", FontWeight.w100), | |
| _buildRobotoText("W200 ExtraLight", FontWeight.w200), | |
| _buildRobotoText("W300 Light", FontWeight.w300), | |
| _buildRobotoText("W400 Regular", FontWeight.w400), | |
| _buildRobotoText("W500 Medium", FontWeight.w500), | |
| _buildRobotoText("W600 SemiBold", FontWeight.w600), | |
| _buildRobotoText("W700 Bold", FontWeight.w700), | |
| _buildRobotoText("W800 ExtraBold", FontWeight.w800), | |
| _buildRobotoText("W900 Black", FontWeight.w900), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| // Hilfsmethode, um den Code übersichtlich zu halten | |
| Widget _buildRobotoText(String text, FontWeight weight) { | |
| return Padding( | |
| padding: const EdgeInsets.symmetric(vertical: 8.0), | |
| child: Text( | |
| text, | |
| style: GoogleFonts.roboto( | |
| fontSize: 24, | |
| fontWeight: weight, | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment