【问题标题】:How to get text Input details from other page如何从其他页面获取文本输入详细信息
【发布时间】:2020-12-22 22:15:49
【问题描述】:

我需要从其他页面调用文本输入详细信息,因为我在一个页面中有文本输入,而在其他页面中是用于收集 firebase 详细信息的代码,所以现在我想在用户输入输入后点击下一步以保存在其他页面

我在这里收集数据

  // Check if user is new or old
// If user is new then add new user to firebase firestore katabase
if (diff < Duration(seconds: 15)) {
  UserModel model = UserModel(
    bio: '',
    bio2: "",
    status: '',
     userName: _gUserNameController,    // now here is error, need get function
    dob: DateTime(2002, DateTime.now().month, DateTime.now().day + 3)
        .toString(),
    location: 'Location',
    profilePic: user.photoURL,
    displayName: user.displayName,
    email: user.email,

这是其他页面输入的代码

TextEditingController _gUserNameController;

Texxh 输入

 Container(
            decoration: BoxDecoration(
                border: Border.all(width: 1.0, color: Colors.black26),
                borderRadius: BorderRadius.circular(7.0)),
            child: TextField(
              controller: _gUserNameController,
              decoration: InputDecoration(
                  border: InputBorder.none,
                  contentPadding: const EdgeInsets.all(10.0),
                  labelText: "Username",
                  labelStyle: TextStyle(fontSize: 15.0)),
            ),
          ),

点击

  GestureDetector(
              onTap: () {
                if (_gUserNameController.text == null ||
                    _gUserNameController.text.length == 0) {
                  return;
                }
                Navigator.pop(context, _gUserNameController.text);
              },
              child: Container(
                width: 350.0,
                height: 50.0,
                child: Center(
                    child: Text(
                  "Next",
                  style: TextStyle(
                      color: Colors.white,
                      fontSize: 15.0,
                      fontWeight: FontWeight.bold),
                )),
                decoration: BoxDecoration(
                    color: Colors.black,
                    borderRadius: BorderRadius.circular(7.0)),
              ))

【问题讨论】:

    标签: android ios firebase flutter dart


    【解决方案1】:

    要在您的页面 A 中处理从页面 B(使用 TextField 或其他任何内容)返回的数据,您的页面 A 必须 await 页面 B

    在页面 A

    final value = await Navigator.of(context).push(MaterialPageRoute(builder: (context) => B(),));
    if (null != value) {
      // run your desired code with returned data
    }
    

    在你的页面 B

    Navigator.of(context).pop(_gUserNameController.text);
    

    【讨论】:

      【解决方案2】:

      我真的不明白你的问题,而且你的代码 sn-ps 很难说。所以让我笼统地回答这个问题。在页面 A 上,您将获得存储在 _gUserNameController 中的文本字段的输入。并使用页面 B 将数据保存到 FireStore。因此,在页面 A 上,您使用 B(_gUserNameController.text) 调用页面 B。然后。 B 页面如下所示:

      class B extends StatelessWidget {
        B(this.gUserName);
        String gUserName;
        ...
      }
      

      基本上我想从页面 B 中的文本输入中获取数据

      并在此数据库中收集它们

      这是其他页面中的文本输入

            Container(
                  decoration: BoxDecoration(
                      border: Border.all(width: 1.0, color: Colors.black26),
                      borderRadius: BorderRadius.circular(7.0)),
                  child: TextField(
                    controller: _gUserNameController,
                    decoration: InputDecoration(
                        border: InputBorder.none,
                        contentPadding: const EdgeInsets.all(10.0),
                        labelText: "Username",
                        labelStyle: TextStyle(fontSize: 15.0)),
                  ),
                ),
      

      在我注册用户后,我需要这个 bc,它将被导航到其他页面以添加用户名,并且 bc 在用户从图像中点击此设置状态旁边的此数据库集合后,此 bc

      【讨论】:

        猜你喜欢
        • 2016-10-20
        • 1970-01-01
        • 1970-01-01
        • 2014-10-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-25
        相关资源
        最近更新 更多