Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Class 在其他类/颤振中使用变量信息_Class_Flutter_Dart - Fatal编程技术网

Class 在其他类/颤振中使用变量信息

Class 在其他类/颤振中使用变量信息,class,flutter,dart,Class,Flutter,Dart,非常感谢你的阅读和帮助 我目前正在开发一个应用程序,用户必须在其中创建一张卡片,然后该卡片将显示在主页的列表中。我的问题是,我无法将保存用户输入(姓名和生日)的两个变量的信息发送到完成的卡片 我想要导航的所需变量是contentname和contentbirthday 以下是用户输入信息的部分: import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'constants.da

非常感谢你的阅读和帮助

我目前正在开发一个应用程序,用户必须在其中创建一张卡片,然后该卡片将显示在主页的列表中。我的问题是,我无法将保存用户输入(姓名和生日)的两个变量的信息发送到完成的卡片

我想要导航的所需变量是contentname和contentbirthday

以下是用户输入信息的部分:

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'constants.dart';

class CardBasic extends StatefulWidget {
  @override
  _CardBasicState createState() => _CardBasicState();
}

class _CardBasicState extends State<CardBasic> {
  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: MediaQuery.of(context).size.height *
          0.58, //<-- set height of the card
      child: FirstCardCreation(
        //<-- new widget
        name: 'Erick Holz',
        birthday: '08.12.1998',
      ),
    );
  }
}

class FirstCardCreation extends StatelessWidget {
  final String name;
  final String birthday;

  const FirstCardCreation({
    Key key,
    @required this.name,
    @required this.birthday,
  }) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Card(
      color: Color(0xFFef9a9a),
      margin: EdgeInsets.all(8),
      elevation: 8,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(32)),
      child: Column(
        children: <Widget>[
          SizedBox(height: 8),
          Expanded(
            child:
                FirstCardContent(contentname: name, contentbirthday: birthday),
          )
        ],
      ),
    );
  }
}

class FirstCardContent extends StatelessWidget {
  String contentname;
  String contentbirthday;

  FirstCardContent(
      {Key key, @required this.contentname, @required this.contentbirthday})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(16.0),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: TextField(
              style: TextStyle(
                color: Colors.black,
              ),
              decoration: kNameInput,
              onChanged: (value1) {
                contentname = value1;
              },
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: TextField(
              style: TextStyle(
                color: Colors.black,
              ),
              decoration: kBirthdayInput,
              onChanged: (value2) {
                contentbirthday = value2;
              },
            ),
          ),
        ],
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
导入“package:flatter/rendering.dart”;
导入“constants.dart”;
类CardBasic扩展StatefulWidget{
@凌驾
_CardBasicState createState();
}
类_CardBasicState扩展状态{
@凌驾
小部件构建(构建上下文){
返回大小框(
高度:MediaQuery.of(上下文).size.height*

0.58,//我很抱歉,但也许你可以展示一些不起作用的代码。在我看来,解释并没有多大帮助。 我唯一注意到的是缺少变量

child:FinalCardCreation(/*此处为姓名和生日*/);

当您设置这些字段为必填字段时。

嘿,谢谢您的回答。我想在Finalcardcreation中获得变量contentname和contentbirthday的信息。但我不能说:finalname:contentname,finalbirthday:contentbirthday。
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'real_new_card.dart';
import 'real_new_algorithm_card.dart';

class CardFinish extends StatefulWidget {
  @override
  _CardFinishState createState() => _CardFinishState();
}

class _CardFinishState extends State<CardFinish> {
  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height:
          MediaQuery.of(context).size.height * 0.5, //<-- set height of the card
      child: FinalCardCreation(),
    );
  }
}

class FinalCardCreation extends StatelessWidget {
  final String finalname;
  final String finalbirthday;

  const FinalCardCreation({
    Key key,
    @required this.finalname,
    @required this.finalbirthday,
  }) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Card(
      color: Color(0xFFef9a9a),
      margin: EdgeInsets.all(8),
      elevation: 8,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(32)),
      child: Column(
        children: <Widget>[
          SizedBox(height: 8),
          Expanded(
            child: FinalCardContent(
              name: finalname,
              birthday: finalbirthday,
            ),
          )
        ],
      ),
    );
  }
}

class FinalCardContent extends StatelessWidget {
  String name;
  String birthday;
  FinalCardContent({Key key, @required this.name, @required this.birthday})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(16.0),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Text(
              '$name',
              textAlign: TextAlign.center,
              style: TextStyle(
                fontSize: 50.0,
                color: Colors.black,
              ),
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Text(
              '$birthday',
              textAlign: TextAlign.center,
              style: TextStyle(
                fontSize: 50.0,
                color: Colors.black,
              ),
            ),
          ),
        ],
      ),
    );
  }
}