Flutter 颤振类中变量的未定义名称

Flutter 颤振类中变量的未定义名称,flutter,Flutter,我对从另一个页面传递的值有问题,它是名为“id”的值。 如您所见,我设置了一个名为“id”的字符串值,这是必需的。值由应用程序的另一个页面发送,我希望在此行中使用此值: 变量数据={'id_':id}; 但上面写着未定义的名字“id” 我认为我需要再次学习很多关于飞镖和颤振的知识,因为我认为很容易找到解决方案,但我现在还不明白 class Affiche_grille extends StatefulWidget { @override String id; Affiche_gril

我对从另一个页面传递的值有问题,它是名为“id”的值。 如您所见,我设置了一个名为“id”的字符串值,这是必需的。值由应用程序的另一个页面发送,我希望在此行中使用此值: 变量数据={'id_':id}; 但上面写着未定义的名字“id”

我认为我需要再次学习很多关于飞镖和颤振的知识,因为我认为很容易找到解决方案,但我现在还不明白

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};
class-Affiche\u扩展StatefulWidget{
@凌驾
字符串id;
Affiche_格栅({Key Key,@required this.id}):super(Key:Key);
_粘贴格栅状态createState(){
返回_Affiche_grill_State();
}
}
//创建相应的状态类。
//此类保存与表单相关的数据。
类(粘贴)(格栅)(状态)扩展状态{
@凌驾
final _formKey=GlobalKey();
列出radioValues=[];
未来电网;
Future grillu display()异步{
//服务器登录API URL
var url='1〕http://www.axis-medias.fr/game_app/display_grid.php';
//使用参数名称存储所有数据。
变量数据={'id_':id};
试试看

问题是id未在State类中定义。它是在Stateful类中定义的,因此您必须将idStateful类传递到State。flatter允许您使用

widget.theFieldYouWantFromTheStatefulClass

使用widget.id是因为您的id不在State类中,所以您必须使用widget.id访问它。谢谢,它似乎可以工作,现在没有错误。传递的值在State类中是正常的吗???是的,必须这样,因为您在类中获取值,然后您可以在您构建不同widget的State类中使用它们。因此很正常。谢谢我所有的朋友:)
widget.theFieldYouWantFromTheStatefulClass