0

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};
4
  • use widget.id because your id is not in the State class so you have to access it by using widget.id Commented Mar 27, 2020 at 1:25
  • thanks it seems working, no errors now. Is it normal the value passed is in the stateclass ??? Commented Mar 27, 2020 at 2:05
  • Yes it has to be that way because you get your values in your class and then you can use them in your state class where you build different widgets. So it’s absolutely normal Commented Mar 27, 2020 at 2:13
  • ok. Thanks for all my friend :) Commented Mar 27, 2020 at 3:03

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.