Flutter Data Passage

Asked

Viewed 76 times

0

I have a button that makes a request get on a server. Data passing is correct however at the time I try to recover in the build class of error.

class Layout_ResultadoExames extends StatefulWidget{

  String Dados;

  Layout_ResultadoExames({this.Dados});

  @override
  _Layout_ResultadoExames createState() => _Layout_ResultadoExames();

}
  • Post and detail the error, and mainly the code where the error occurs.

  • In the Class that contains the build I try to recover what arrived.

  • class _Layout_resultswears extends State<Layout_resultswears> with Singletickerproviderstatemixin { var Data = widget. Data; }

  • But this error appears "only Static Members can be accessed in initializers"

1 answer

0


You must do this assignment in the method initState:

String Dados;
@override
void initState() {
    super.initState();
    Dados = widget.Dados;
}

Explanation: At the time you assigned the value to the variable Dados , that is, at class initialization, it had not yet been completed and therefore references to the object itself (this) cannot be accessed.

  • Solved, thank you very much!!!

  • No problem! If the answer is correct and pleases you, do not forget to mark as correct to better indicate who has this question in the future.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.