[大家好,我能帮上忙,我知道Expanded
小部件需要Flex父级。但是由于某种原因,我的给出了一个错误:
我的代码是:
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';类...
您的ReusableCard
小部件包装在Container
类中。这就是给您错误的原因。要解决此问题,您只需将Container
类更改为Row
或Column
: