Hi why do I get an error "invalid constant value" when using Theme.of(context).themeText.headline4 inside a widget. It works everywhere else except inside my widget.
Here's my code: This one works
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
widget.title,
style: Theme.of(context).textTheme.headline1,
),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
const SizeBox(size: 20),
buildCalculator(),
const Text(
'You have pushed this buttons this many times:'
,
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4, //No error here
),
],
),
// ),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
But this one doesnt, it says invalid constant value
Widget buildConvertor() {
ThemeData:
defaultTheme;
return Row(
children: [
Container(
child: const Text(
"Text here",
style: Theme.of(context).textTheme.headline4, //this is where the error is
),
),
const Spacer(
flex: 1,
),
Column(
children: const <Widget>[Text("More text")],
),
],
);
}
There are both under the same class so why are they behaving different. And please help me with a solution. I just need help with the theme