ParentDataWidget 用于定位颤动的错误使用

时间:2021-03-26 11:39:15

标签: flutter stack

我的代码是

 Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: Helper.of(context).onWillPop,
      child: Scaffold(
        key: _con.scaffoldKey,
        resizeToAvoidBottomInset: true,
        body: SingleChildScrollView(
          child: Column(
              children: <Widget>[
                SizedBox(height: 60),
                Center(
                  child: Image.asset(
                    'assets/img/villa_logo-transparent.png',
                    width: 230.0,
                    height: 230.0,
                  ),
                ),
                Stack(
                  children: [
createTextForm()
],
                ),
              ]),
        ),
      ),
    );
  }

这就是我创建文本表单的方式

Widget createTextForm() {
    return  Positioned(
      // top: config.App(context).appHeight(29.5) - 50,
      child: Container(
        // decoration: BoxDecoration(
        //     color: Theme.of(context).primaryColor,
        //     borderRadius: BorderRadius.all(Radius.circular(10)),
        //     boxShadow: [
        //       BoxShadow(
        //         blurRadius: 50,
        //         color: Theme.of(context).hintColor.withOpacity(0.2),
        //       )
        //     ]),
        margin: EdgeInsets.symmetric(
          horizontal: 20,
        ),
        padding: EdgeInsets.symmetric(vertical: 2, horizontal: 27),
        width: config.App(context).appWidth(88),
        // height: config.App(context).appHeight(70),

        // height: config.App(context).appHeight(80),
        child: Form(
          key: _con.loginFormKey,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              TextFormField(
                keyboardType: TextInputType.text,
                onSaved: (input) => _con.user.name = input,
                validator: (input) => input.length < 3
                    ? S.of(context).should_be_more_than_3_letters
                    : null,
                decoration: InputDecoration(
                  labelText: S.of(context).full_name,
                  labelStyle: TextStyle(color: Theme.of(context).accentColor),
                  contentPadding: EdgeInsets.all(12),
                  hintText: S.of(context).john_doe,
                  hintStyle: TextStyle(
                      color: Theme.of(context).focusColor.withOpacity(0.7)),
                  prefixIcon: Icon(Icons.person_outline,
                      color: Theme.of(context).accentColor),
                  border: OutlineInputBorder(
                      borderSide: BorderSide(
                          color:
                              Theme.of(context).focusColor.withOpacity(0.2))),
                  focusedBorder: OutlineInputBorder(
                      borderSide: BorderSide(
                          color:
                              Theme.of(context).focusColor.withOpacity(0.5))),
                  enabledBorder: OutlineInputBorder(
                      borderRadius: BorderRadius.all(Radius.circular(20)),
                      borderSide: BorderSide(
                          color:
                              Theme.of(context).focusColor.withOpacity(0.2))),
                ),
              ),
              SizedBox(height: 30),
              TextFormField(
                keyboardType: TextInputType.phone,
                onSaved: (input) => _con.user.phone = input,
                validator: (input) => input.length < 3
                    ? S.of(context).should_be_more_than_3_letters
                    : null,
                decoration: InputDecoration(
                  labelText: "Phone Number",
                  labelStyle: TextStyle(color: Theme.of(context).accentColor),
                  contentPadding: EdgeInsets.all(12),
                  hintText: "+1 234 56789",
                  hintStyle: TextStyle(
                      color: Theme.of(context).focusColor.withOpacity(0.7)),
                  prefixIcon: Icon(Icons.person_outline,
                      color: Theme.of(context).accentColor),
                  border: OutlineInputBorder(
                      borderSide: BorderSide(
                          color:
                              Theme.of(context).focusColor.withOpacity(0.2))),
                  focusedBorder: OutlineInputBorder(
                      borderSide: BorderSide(
                          color:
                              Theme.of(context).focusColor.withOpacity(0.5))),
                  enabledBorder: OutlineInputBorder(
                      borderRadius: BorderRadius.all(Radius.circular(20)),
                      borderSide: BorderSide(
                          color:
                              Theme.of(context).focusColor.withOpacity(0.2))),
                ),
              ),
              SizedBox(height: 30),
              TextFormField(
                keyboardType: TextInputType.emailAddress,
                onSaved: (input) => _con.user.email = input,
                validator: (input) => !input.contains('@')
                    ? S.of(context).should_be_a_valid_email
                    : null,
                decoration: InputDecoration(
                  labelText: S.of(context).email,
                  labelStyle: TextStyle(color: Theme.of(context).accentColor),
                  contentPadding: EdgeInsets.all(12),
                  hintText: '',
                  hintStyle: TextStyle(
                      color: Theme.of(context).focusColor.withOpacity(0.7)),
                  prefixIcon: Icon(Icons.alternate_email,
                      color: Theme.of(context).accentColor),
                  border: OutlineInputBorder(
                      borderSide: BorderSide(
                          color:
                              Theme.of(context).focusColor.withOpacity(0.2))),
                  focusedBorder: OutlineInputBorder(
                      borderSide: BorderSide(
                          color:
                              Theme.of(context).focusColor.withOpacity(0.5))),
                  enabledBorder: OutlineInputBorder(
                      borderRadius: BorderRadius.all(Radius.circular(20)),
                      borderSide: BorderSide(
                          color:
                              Theme.of(context).focusColor.withOpacity(0.2))),
                ),
              ),
              SizedBox(height: 30),
              TextFormField(
                obscureText: _con.hidePassword,
                onSaved: (input) => _con.user.password = input,
                validator: (input) => input.length < 6
                    ? S.of(context).should_be_more_than_6_letters
                    : null,
                decoration: InputDecoration(
                  labelText: S.of(context).password,
                  labelStyle: TextStyle(color: Theme.of(context).accentColor),
                  contentPadding: EdgeInsets.all(12),
                  hintText: '••••••••••••',
                  hintStyle: TextStyle(
                      color: Theme.of(context).focusColor.withOpacity(0.7)),
                  prefixIcon: Icon(Icons.lock_outline,
                      color: Theme.of(context).accentColor),
                  suffixIcon: IconButton(
                    onPressed: () {
                      setState(() {
                        _con.hidePassword = !_con.hidePassword;
                      });
                    },
                    color: Theme.of(context).focusColor,
                    icon: Icon(_con.hidePassword
                        ? Icons.visibility
                        : Icons.visibility_off),
                  ),
                  border: OutlineInputBorder(
                      borderSide: BorderSide(
                          color:
                              Theme.of(context).focusColor.withOpacity(0.2))),
                  focusedBorder: OutlineInputBorder(
                      borderSide: BorderSide(
                          color:
                              Theme.of(context).focusColor.withOpacity(0.5))),
                  enabledBorder: OutlineInputBorder(
                      borderRadius: BorderRadius.all(Radius.circular(20)),
                      borderSide: BorderSide(
                          color:
                              Theme.of(context).focusColor.withOpacity(0.2))),
                ),
              ),
              SizedBox(height: 30),
              registerButtonCall(),
              bottomLoginText(),
              
            ],
          ),
        ),
      ),
    );
    //
    // ]);
  }

错误 应用父数据时抛出以下断言。: I/flutter (21259):ParentDataWidget 的错误使用。 I/flutter (21259): The ParentDataWidget Positioned(bottom: 10.0) 想要将 StackParentData 类型的 ParentData 应用到一个 I/flutter (21259):RenderObject,已设置为接受不兼容类型 FlexParentData 的 ParentData。 I/flutter (21259):通常,这意味着 Positioned 小部件具有错误的祖先 RenderObjectWidget。通常, I/flutter (21259):定位的小部件直接放置在 Stack 小部件内。 I/flutter (21259):有问题的 Positioned 当前放置在 Column 小部件内。 I/flutter (21259):接收到不兼容父数据的 RenderObject 的所有权链是: I/flutter (21259):语义← RawMaterialButton ← FlatButton ← Positioned ← Column ← _FormScope ← WillPopScope ← I/flutter (21259): Form-[LabeledGlobalKey#ea070] ← Padding ← ConstrainedBox ← ⋯ 我/扑(21259): I/flutter (21259):当抛出异常时,这是堆栈: I/flutter (21259):#0 RenderObjectElement._updateParentData。 (包:flutter/src/widgets/framework.dart:5770:11) I/flutter (21259): #1 RenderObjectElement._updateParentData (package:flutter/src/widgets/framework.dart:5786:6) I/flutter (21259): #2 RenderObjectElement.attachRenderObject (package:flutter/src/widgets/framework.dart:5808:7) I/flutter (21259): #3 RenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5501:5) I/flutter (21259): #4 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6117:11) I/flutter (21259):... 普通元件安装(21 帧) I/flutter (21259): #25 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) I/flutter (21259): #26 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6236:32) I/flutter (21259):... 普通元件安装(44 帧) I/flutter (21259): #70 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) I/flutter (21259): #71 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6236:32) I/flutter (21259): #72 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) I/flutter (21259): #73 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6236:32) I/flutter (21259):... 普通元件安装(109 帧) I/flutter (21259): #182 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) I/flutter (21259): #183 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6236:32) I/flutter (21259):... 普通元件安装(218 帧) I/flutter (21259): #401 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) I/flutter (21259): #402 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18) I/flutter (21259): #403 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5705:32) I/flutter (21259): #404 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6246:17) I/flutter (21259): #405 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15) I/flutter (21259): #406 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) I/flutter (21259): #407 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11) I/flutter (21259): #408 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) I/flutter (21259): #409 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5) I/flutter (21259): #410 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15) I/flutter (21259): #411 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) I/flutter (21259): #412 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) I/flutter (21259): #413 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5) I/flutter (21259): #414 _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:183:11) I/flutter (21259): #415 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15) I/flutter (21259): #416 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14) I/flutter (21259): #417 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15) I/flutter (21259): #418 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) I/flutter (21259): #419 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11) I/flutter (21259): #420 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) I/flutter (21259): #421 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5) I/flutter (21259): #422 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15) I/flutter (21259): #423 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14) I/flutter (21259): #424 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15) I/flutter (21259): #425 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14) I/flutter (21259): #426 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15) I/flutter (21259): #427 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) I/flutter (21259): #428 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) I/flutter (21259): #429 StatelessElement.update (package:flutter/src/widgets/framework.dart:4708:5) I/flutter (21259): #430 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15) I/flutter (21259): #431 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) I/flutter (21259): #432 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) I/flutter (21259): #433 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5) I/flutter (21259): #434 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15) I/flutter (21259): #435 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) I/flutter (21259): #436 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11) I/flutter (21259): #437 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) I/flutter (21259): #438 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2730:33) I/flutter (21259): #439 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:913:20) I/flutter (21259): #440 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:302:5) I/flutter (21259): #441 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15) I/flutter (21259): #442 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1055:9) I/flutter (21259): #443 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:971:5) I/flutter (21259): #447 _invoke (dart:ui/hooks.dart:251:10) I/flutter (21259): #448 _drawFrame (dart:ui/hooks.dart:209:3) I/flutter (21259):(从 dart:async 中删除了 3 帧) I/flutter(21259):======================================= ================================================= ======== I/flutter (21259):抛出另一个异常:异常:图像数据无效

1 个答案:

答案 0 :(得分:0)

您的 Positioned 小部件必须直接Stack 内,而不是在另一个返回 Positioned 的小部件内。

Stack(
  children: [
    Positioned(
      child: TextForm()
    )
  ],
),

这只是 Flutter 进行错误检查的方式,以确保 Positioned 仅在 Stack 内使用。

ExpandedFlexible 小部件只能直接在 RowColumn 内使用,不能被任何其他小部件包装的方式相同。