在行FLUTTER中添加列表磁贴后,列表视图消失

时间:2020-09-26 16:11:55

标签: flutter flutter-layout

我正在“编辑用户”个人资料屏幕上,我需要创建一个行,该行应使用两个RadioListTile小部件进行性别设置。但是在将行添加到列表视图后,所有内容立即消失,并且出现此错误

2: 'child.hasSize': is not true.
I/flutter (31410): Another exception was thrown: NoSuchMethodError: The
getter 'scrollOffsetCorrection' was called on null.
I/flutter (31410): Another exception was thrown: NoSuchMethodError: The
method 'debugAssertIsValid' was called on null.
I/flutter (31410): Another exception was thrown: NoSuchMethodError: The
getter 'visible' was called on null.

我真的不明白,如果我将它们作为列小部件的直接子代,它会很好用,但是我需要将性别放在一行中,尝试寻找解决方案,但找不到任何解决方案,请大家好,这是我的下面的代码

class EditUserProfile extends StatefulWidget {
  static String id = 'edit-profile';
  @override
  _EditUserProfileState createState() => _EditUserProfileState();
}

enum Gender { male, female }

class _EditUserProfileState extends State<EditUserProfile> {
  Gender _gender = Gender.male;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        iconTheme: IconThemeData(color: Colors.black),
        title: Text(
          "Edit Profile",
          style: TextStyle(color: Colors.black),
        ),
        actions: [
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: RaisedButton(
              onPressed: null,
              child: Text('Done'),
            ),
          )
        ],
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: ListView(
          children: [
            InputField(
              icon: Icon(
                Icons.person,
                color: Colors.white,
              ),
              showText: true,
              labelText: 'Nickname',
              hintText: 'What do they call you?',
            ),
            SizedBox(
              height: 10,
            ),
            InputField(
              icon: Icon(
                Icons.phone_in_talk,
                color: Colors.white,
              ),
              showText: true,
              labelText: 'Mobile Number',
              hintText: 'How can people reach your cell?',
            ),
            SizedBox(
              height: 10,
            ),
            InputField(
              icon: Icon(
                FontAwesomeIcons.child,
                color: Colors.white,
              ),
              showText: true,
              labelText: 'Age',
              hintText: 'How old are you?',
            ),
            SizedBox(
              height: 10,
            ),
            InputField(
              icon: Icon(
                Icons.person,
                color: Colors.white,
              ),
              showText: true,
              labelText: 'Gender',
              hintText: 'Are you single or married?',
            ),
            SizedBox(
              height: 10,
            ),
            Expanded(
              child: Row(
                children: [
                  RadioListTile<Gender>(
                    title: Text('Male'),
                    value: Gender.male,
                    groupValue: _gender,
                    onChanged: (Gender value) {
                      setState(() {
                        _gender = value;
                      });
                    },
                  ),
                  RadioListTile<Gender>(
                    title: Text('Female'),
                    value: Gender.female,
                    groupValue: _gender,
                    onChanged: (Gender value) {
                      setState(() {
                        _gender = value;
                      });
                    },
                  ),
                ],
              ),
            ),
            InputField(
              icon: Icon(
                FontAwesomeIcons.locationArrow,
                color: Colors.white,
              ),
              showText: true,
              labelText: 'Lives In',
              hintText: 'Where do you reside',
            ),
            SizedBox(
              height: 10,
            ),
            InputField(
              icon: Icon(
                Icons.person,
                color: Colors.white,
              ),
              showText: true,
              labelText: 'Relationship Status',
              hintText: 'Are you single or married?',
            ),
            SizedBox(
              height: 10,
            ),
            Expanded(
              child: Row(
                children: [
                  RadioListTile<Gender>(
                    title: Text('Male'),
                    value: Gender.male,
                    groupValue: _gender,
                    onChanged: (Gender value) {
                      setState(() {
                        _gender = value;
                      });
                    },
                  ),
                  RadioListTile<Gender>(
                    title: Text('Female'),
                    value: Gender.female,
                    groupValue: _gender,
                    onChanged: (Gender value) {
                      setState(() {
                        _gender = value;
                      });
                    },
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

我尝试为“专栏”设置固定的高度和宽度,但仍然没有运气。

child: Expanded(
          child: Container(
            width: double.infinity,
            height: 200,
            child: ListView(
              children: [
                InputField(
                  icon: Icon(
                    Icons.person,
                    color: Colors.white,
                  ),

2 个答案:

答案 0 :(得分:0)

在列表视图中添加rinklewrap = true。

答案 1 :(得分:0)

以防万一其他人陷入困境,我能够通过用IntrinsicHeight包装我的Row小部件,并用Flexible包装每一个RadioListTile小部件来完成这项工作。我可以在这里找到帮助。 BoxConstraints forces an infinite width

0.7471190781