Flutter展开的窗口小部件错误,即使有Flex父级也是如此

问题描述 投票:0回答:1

[大家好,我能帮上忙,我知道Expanded小部件需要Flex父级。但是由于某种原因,我的给出了一个错误:

enter image description here

我的代码是:

import 'package:flutter/material.dart';

class InputPage extends StatefulWidget {
  @override
  _InputPageState createState() => _InputPageState();
}

class _InputPageState extends State<InputPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Center(child: Text('BMI CALCULATOR')),
      ),
      body: Column(
        children: <Widget>[
          Expanded(
                      child: Container(
              child: ReusableCard(colour: Color(0xFF141A3C)),
            ),
          ),
        ],
      ),
    );
  }
}

class ReusableCard extends StatelessWidget {
  //CUSTOM CONSTRUCTOR
  //the color from the Stateful Widget from above is passed in to the INPUT of ReusableCard({PASSED IN HERE}),

  ReusableCard({this.colour});
  Color colour;

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Container(
        margin: EdgeInsets.all(15.0),
        // height: 200.0,
        // width: 170.0,
        decoration: BoxDecoration(
          color: colour,
          borderRadius: BorderRadius.circular(10.0),
        ),
      ),
    );
  }
}

[嗨,大家好,我可以帮助我,我知道Expanded小部件需要Flex父级。但是由于某种原因,我的错误:我的代码是:import'package:flutter / material.dart';类...

android flutter flutter-layout
1个回答
0
投票

您的ReusableCard小部件包装在Container类中。这就是给您错误的原因。要解决此问题,您只需将Container类更改为RowColumn

© www.soinside.com 2019 - 2024. All rights reserved.