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 🪄
Share:
161
Dalon
Author by

Dalon

Updated on December 30, 2022

Comments

  • Dalon
    Dalon over 1 year

    In my class Tabelle I handed over a title. Now i want to output a Text(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),