How to use a getter in another class?
161
In the case of Stateful widgets you can access the associated widget from its state:
class Tabelle extends StatefulWidget {
Tabelle({Key key, this.title}) : super(key: key);
final String title;
@override
_TabelleState createState() => _TabelleState();
}
class _TabelleState extends State<Tabelle> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),// Here is the magic 🪄
Author by
Dalon
Updated on December 30, 2022Comments
-
Dalon over 1 year
In my class
Tabelle
I handed over a title. Now i want to output aText(this.title)
in the class_TabelleState
. But i get the error 'the getter title isnt defined for the type _TabelleState'How can I use this.title in the _TabelleState class?
class Tabelle extends StatefulWidget { Tabelle({Key key, this.title}) : super(key: key); final String title; @override _TabelleState createState() => _TabelleState(); } class _TabelleState extends State<Tabelle> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(this.title),