I’m trying to style my app globally and I have some questions about hot the properly retrieve the value like this!
This code it’s not working because there is no context
at this point, but is there some way to get this value?
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
ThemeData lightTheme = ThemeData(
useMaterial3: true,
// Text Style
textTheme: TextTheme(
titleMedium: GoogleFonts.nunito(fontWeight: FontWeight.bold, letterSpacing: -1, fontSize: 16),
),
// AppBar
appBarTheme: AppBarTheme(
titleTextStyle: Theme.of(context).textTheme.titleMedium,
),
);
2
Answers
Create dark & light mode extension
Create your them file
Instead of globally declaring theme data, use a class with static method returning themeData with context as parameter: