Неправильное использование ParentDataWidget при использовании TextField - PullRequest
0 голосов
/ 01 августа 2020

Я получаю Incorrect use of ParentDataWidget каждый раз, когда я пытаюсь ввести текстовое поле или когда я перехожу со страницы регистрации на страницу входа, нажав «У вас уже есть учетная запись?» кнопка. Это код, который я использовал для пользовательского интерфейса


    import 'package:flutter/material.dart';
    import 'package:tariffo/HomePage.dart';
    import 'auth.dart';
    import 'LoginPage.dart';
    import 'LoginScreen.dart';
    import 'package:firebase_auth/firebase_auth.dart';

    class SignupPage extends StatefulWidget {
      @override
      _SignupPageState createState() => _SignupPageState();
    }

    class _SignupPageState extends State<SignupPage> {
      final _formKey = GlobalKey<FormState>();
      String email = '';
      String password = '';
      String error = '';
      bool loading = false;
      final Authentication authentication = Authentication();
      @override
      Widget build(BuildContext context) {
        Widget _backButton() {
          return InkWell(
            onTap: () {
              Navigator.pop(context);
            },
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 10),
              child: Row(
                children: <Widget>[
                  Container(
                    padding: EdgeInsets.only(left: 0, top: 10, bottom: 10),
                    child: Icon(Icons.keyboard_arrow_left, color: Colors.black),
                  ),
                  Text('Back',
                      style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500))
                ],
              ),
            ),
          );
        }

        return loading
            ? Homepage()
            : Scaffold(
                resizeToAvoidBottomInset: false,
                resizeToAvoidBottomPadding: false,
                body: Container(
                  height: 900.0,
                  width: 500.0,
                  child: Column(
                    children: <Widget>[
                      Padding(
                        padding: const EdgeInsets.only(top: 50.0),
                        child: Row(
                          children: <Widget>[
                            IconButton(
                              icon: Icon(Icons.arrow_back_ios, color: Colors.white),
                              onPressed: () {
                                Navigator.pushReplacement(
                                    context,
                                    MaterialPageRoute(
                                        builder: (context) => LoginScreen()));
                              },
                            )
                          ],
                        ),
                      ),
                      Positioned(top: 40, left: 0, child: _backButton()),
                      Padding(
                        padding: const EdgeInsets.only(top: 40.0),
                        child: RichText(
                          text: TextSpan(
                            text: 'Tariffo',
                            style: TextStyle(
                                color: Colors.blue,
                                fontFamily: 'SignPainter',
                                fontSize: 60),
                          ),
                        ),
                      ),
                      SizedBox(
                          height: 400.0,
                          child: Form(
                            key: _formKey,
                            child: Column(
                              children: <Widget>[
                                Padding(
                                  padding: const EdgeInsets.only(
                                      left: 80.0, right: 80.0, top: 40.0),
                                  child: TextFormField(
                                    validator: (val) =>
                                        val.isEmpty ? 'enter email' : null,
                                    onChanged: (val) {
                                      setState(() => email = val);
                                    },
                                    style: TextStyle(color: Colors.black),
                                    decoration: InputDecoration(
                                        hintText: 'enter email',
                                        hintStyle: TextStyle(
                                            fontFamily: 'Antra',
                                            fontSize: 12.0,
                                            color: Colors.black)),
                                  ),
                                ),
                                Padding(
                                  padding: const EdgeInsets.only(
                                      left: 80.0, right: 80.0, top: 40.0),
                                  child: TextFormField(
                                    validator: (val) => val.length < 8
                                        ? 'enter password > 8 digits'
                                        : null,
                                    onChanged: (val) {
                                      setState(() => password = val);
                                    },
                                    style: TextStyle(color: Colors.black),
                                    decoration: InputDecoration(
                                        hintText: 'enter password',
                                        hintStyle: TextStyle(
                                            fontFamily: 'Antra',
                                            fontSize: 12.0,
                                            color: Colors.black)),
                                    obscureText: true,
                                  ),
                                ),
                                SizedBox(height: 50),
                                Padding(
                                  padding: const EdgeInsets.only(top: 40.0),
                                  child: MaterialButton(
                                    color: Colors.blue,
                                    onPressed: () async {
                                      if (_formKey.currentState.validate()) {
                                        setState(() => loading = true);
                                        dynamic result = await authentication
                                            .registerwithEmailAndPassword(
                                                email, password);
                                        if (result == null) {
                                          setState(() => error =
                                              'Sorry,These credentials will not work out');
                                          loading = false;
                                        }
                                      }
                                    },
                                    child: Text(
                                      'Sign up',
                                      style: TextStyle(
                                          fontFamily: 'Antra', color: Colors.white),
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          )),
                      _createAccountLabel(),
                    ],
                  ),
                ),
              );
      }

      Widget _createAccountLabel() {
        return InkWell(
          onTap: () {
            Navigator.push(
                context, MaterialPageRoute(builder: (context) => LoginPage()));
          },
          child: Container(
            margin: EdgeInsets.symmetric(vertical: 20),
            padding: EdgeInsets.all(15),
            alignment: Alignment.bottomCenter,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  'Do you have an account ?',
                  style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600),
                ),
                SizedBox(
                  width: 10,
                ),
                Text(
                  'Login',
                  style: TextStyle(
                      color: Colors.blue,
                      fontSize: 13,
                      fontWeight: FontWeight.w600),
                ),
              ],
            ),
          ),
        );
      }
    }


    import 'package:flutter/material.dart';
    import 'SignUp.dart';
    import 'brazierContainer.dart';
    import 'package:google_fonts/google_fonts.dart';
    import 'LoginScreen.dart';
    import 'HomePage.dart';
    import 'auth.dart';

    class LoginPage extends StatefulWidget {
      LoginPage({Key key, this.title}) : super(key: key);

      final String title;

      @override
      _LoginPageState createState() => _LoginPageState();
    }

    class _LoginPageState extends State<LoginPage> {
      final _formKey = GlobalKey<FormState>();
      String email = '';
      String password = '';
      String error = '';
      bool loading = false;
      final Authentication authentication = Authentication();
      @override
      Widget build(BuildContext context) {
        Widget _backButton() {
          return InkWell(
            onTap: () {
              Navigator.pop(context);
            },
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 10),
              child: Row(
                children: <Widget>[
                  Container(
                    padding: EdgeInsets.only(left: 0, top: 10, bottom: 10),
                    child: Icon(Icons.keyboard_arrow_left, color: Colors.black),
                  ),
                  Text('Back',
                      style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500))
                ],
              ),
            ),
          );
        }

        return loading
            ? Homepage()
            : Scaffold(
                resizeToAvoidBottomInset: false,
                resizeToAvoidBottomPadding: false,
                body: Container(
                  height: 900.0,
                  width: 500.0,
                  child: Column(
                    children: <Widget>[
                      Padding(
                        padding: const EdgeInsets.only(top: 50.0),
                        child: Row(
                          children: <Widget>[
                            IconButton(
                              icon: Icon(Icons.arrow_back_ios, color: Colors.white),
                              onPressed: () {
                                Navigator.pushReplacement(
                                    context,
                                    MaterialPageRoute(
                                        builder: (context) => LoginScreen()));
                              },
                            )
                          ],
                        ),
                      ),
                      Positioned(top: 40, left: 0, child: _backButton()),
                      Padding(
                        padding: const EdgeInsets.only(top: 40.0),
                        child: RichText(
                          text: TextSpan(
                            text: 'Tariffo',
                            style: TextStyle(
                                color: Colors.blue,
                                fontFamily: 'SignPainter',
                                fontSize: 60),
                          ),
                        ),
                      ),
                      SizedBox(
                          height: 400.0,
                          child: Form(
                            key: _formKey,
                            child: Column(
                              children: <Widget>[
                                Padding(
                                  padding: const EdgeInsets.only(
                                      left: 80.0, right: 80.0, top: 40.0),
                                  child: TextFormField(
                                    validator: (val) =>
                                        val.isEmpty ? 'enter email' : null,
                                    onChanged: (val) {
                                      setState(() => email = val);
                                    },
                                    style: TextStyle(color: Colors.black),
                                    decoration: InputDecoration(
                                        hintText: 'enter email',
                                        hintStyle: TextStyle(
                                            fontFamily: 'Antra',
                                            fontSize: 12.0,
                                            color: Colors.black)),
                                  ),
                                ),
                                Padding(
                                  padding: const EdgeInsets.only(
                                      left: 80.0, right: 80.0, top: 40.0),
                                  child: TextFormField(
                                    validator: (val) => val.length < 8
                                        ? 'enter password > 8 digits'
                                        : null,
                                    onChanged: (val) {
                                      setState(() => password = val);
                                    },
                                    style: TextStyle(color: Colors.black),
                                    decoration: InputDecoration(
                                        hintText: 'enter password',
                                        hintStyle: TextStyle(
                                            fontFamily: 'Antra',
                                            fontSize: 12.0,
                                            color: Colors.black)),
                                    obscureText: true,
                                  ),
                                ),
                                SizedBox(height: 50),
                                Padding(
                                  padding: const EdgeInsets.only(top: 40.0),
                                  child: MaterialButton(
                                    color: Colors.blue,
                                    onPressed: () async {
                                      if (_formKey.currentState.validate()) {
                                        setState(() => loading = true);
                                        dynamic result = await authentication
                                            .signUpWithEmailAndPassword(
                                                email, password);
                                        if (result == null) {
                                          setState(() => error =
                                              'Sorry,These credentials will not work out');
                                          loading = false;
                                        }
                                      }
                                    },
                                    child: Text(
                                      'Sign in',
                                      style: TextStyle(
                                          fontFamily: 'Antra', color: Colors.white),
                                    ),
                                  ),
                                ),
                                Container(
                                  padding: EdgeInsets.symmetric(vertical: 10),
                                  alignment: Alignment.centerRight,
                                  child: Text('Forgot Password ?',
                                      style: TextStyle(
                                          fontSize: 14,
                                          fontWeight: FontWeight.w500)),
                                ),
                              ],
                            ),
                          )),
                      _createAccountLabel(),
                    ],
                  ),
                ),
              );
      }

      Widget _createAccountLabel() {
        return InkWell(
          onTap: () {
            Navigator.push(
                context, MaterialPageRoute(builder: (context) => SignupPage()));
          },
          child: Container(
            margin: EdgeInsets.symmetric(vertical: 20),
            padding: EdgeInsets.all(15),
            alignment: Alignment.bottomCenter,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  'Don/t you have an account ?',
                  style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600),
                ),
                SizedBox(
                  width: 10,
                ),
                Text(
                  'Register',
                  style: TextStyle(
                      color: Colors.blue,
                      fontSize: 13,
                      fontWeight: FontWeight.w600),
                ),
              ],
            ),
          ),
        );
      }
    }

И это ошибка:

════════ Exception caught by widgets library ═══════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.

The ParentDataWidget Positioned(left: 0.0, top: 40.0) wants to apply ParentData of type StackParentData to a RenderObject, which has been set up to accept ParentData of incompatible type FlexParentData.

Usually, this means that the Positioned widget has the wrong ancestor RenderObjectWidget. Typically, Positioned widgets are placed directly inside Stack widgets.
The offending Positioned is currently placed inside a Column widget.

1 Ответ

0 голосов
/ 01 августа 2020

Вы используете Positioned в Column. Positioned можно использовать только в Stack. Поэтому подумайте о замене Column на Stack или используйте Alignment(x,y), чтобы выровнять его

...