axis-medias
axis-medias

Reputation: 587

Undefined name of a variable in flutter class

I have a problem with a value which is passed from an another page, it is the value called "id". As you can see i set a string value called "id" which is required. Value is sent by an another page of the app and i want use this value for use at this line : var data = {'id_grille': id}; But it says undefined name "id"

I think i need to learn a lot again on dart and flutter because i think it is easy to find the solution but i Don't see for the moment.

class Affiche_grille extends StatefulWidget {

@override
  String id;

  Affiche_grille({Key key, @required this.id}) : super(key: key);

  _Affiche_grille_State createState() {
    return _Affiche_grille_State();
  }
}

// Create a corresponding State class.
// This class holds data related to the form.

class _Affiche_grille_State extends State<Affiche_grille> {
  @override
  final _formKey = GlobalKey<FormState>();
  List<String> radioValues = [];
  Future<List<Match>> grid;


  Future <List<Match>> Grille_display() async {
    // SERVER LOGIN API URL
    var url = 'http://www.axis-medias.fr/game_app/display_grid.php';

    // Store all data with Param Name.
    var data = {'id_grille': id};

Upvotes: 0

Views: 5192

Answers (1)

Josteve Adekanbi
Josteve Adekanbi

Reputation: 12673

Try

    var data = {'id_grille': widget.id};

The problem is id was not defined in the State class. It was defined in the Stateful class so you have to pass the id from the Stateful class to the State. Flutter allows you to do it by using

widget.theFieldYouWantFromTheStatefulClass

Upvotes: 2

Related Questions