DEV Community

Alexandre Freire
Alexandre Freire

Posted on

3 1

Passando parâmetros para um Stateful Widget no Flutter

Aprenda a passar parâmetros para um Stateful Widget no Flutter. Não passe parâmetros para o estado usando seu construtor. Você só deve acessá-los usando this.widget.myField.

class MyStateful extends StatefulWidget {
  final String foo;

  const MyStateful({Key key, this.foo}): super(key: key);

  @override
  _MyStatefulState createState() => _MyStatefulState();
}

class _MyStatefulState extends State<MyStateful> {
  @override
  Widget build(BuildContext context) {
    return Text(widget.foo);
  }
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay