I'm getting error "A value of type 'Null' can't be assigned to a parameter of type 'String' in a const constructor." from const Text().
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title, required this.subTitle});
final String title;
final String subTitle;
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
widget.title,
textAlign: TextAlign.center,
),
),
body: Column(
children: <Widget>[
const Text(
widget.subTitle,
),
),
)
}
}
I already know I have to remove const to resolve the error. But Could anyone explain why does only const constructor have this error?