Android 如何在一个屏幕上安装所有这些颤振小部件?
我正在构建这个颤振应用程序。我的问题是我不能在一个屏幕上安装所有的小部件。所有的字体大小和图标看起来都不一样,尽管它们本来是一样的。在ReusableCard中,当容器高度和宽度属性分别设置为200和250时,整个应用程序会调整大小,但它们并不统一,如图所示。有人有什么建议吗Android 如何在一个屏幕上安装所有这些颤振小部件?,android,flutter,dart,Android,Flutter,Dart,我正在构建这个颤振应用程序。我的问题是我不能在一个屏幕上安装所有的小部件。所有的字体大小和图标看起来都不一样,尽管它们本来是一样的。在ReusableCard中,当容器高度和宽度属性分别设置为200和250时,整个应用程序会调整大小,但它们并不统一,如图所示。有人有什么建议吗 import 'results_page.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_a
import 'results_page.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'icon_content_widget.dart';
import 'reusable_card.dart';
import 'bottom_button.dart';
import 'calculator_brain.dart';
import 'constants.dart';
enum GenderType {
male,
female,
}
class InputPage extends StatefulWidget {
@override
_InputPageState createState() => _InputPageState();
}
class _InputPageState extends State<InputPage> {
GenderType selectedGender;
int height = 180;
int weight = 60;
int age = 20;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('CALCULATE BMI'), centerTitle: true),
body: ListView(
scrollDirection: Axis.vertical,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
child: FittedBox(
child: Material(
color: Color(0xFF00053C),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
child: ReusableCard(
onPress: () {
setState(() {
selectedGender = GenderType.male;
});
},
colour: selectedGender == GenderType.male
? kActiveCardColor
: kInactiveCardColor,
cardChild:
IconContentWidget('MALE', FontAwesomeIcons.mars),
),
),
Container(
child: ReusableCard(
onPress: () {
setState(() {
selectedGender = GenderType.female;
});
},
colour: selectedGender == GenderType.female
? kActiveCardColor
: kInactiveCardColor,
cardChild: IconContentWidget(
'FEMALE', FontAwesomeIcons.venus),
),
),
],
),
),
),
),
),
Padding(
padding: const EdgeInsets.all(1.0),
child: Container(
child: FittedBox(
child: Material(
color: Color(0xFF00053C),
child: Row(
children: <Widget>[
Container(
child: ReusableCard(
colour: kActiveCardColor,
cardChild: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('HEIGHT', style: kLabelTextStyle),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: <Widget>[
Text(height.toString(),
style: kNumberTextStyle),
Text('cm', style: kLabelTextStyle),
],
),
SliderTheme(
data: SliderTheme.of(context).copyWith(
activeTrackColor: Colors.white,
inactiveTrackColor: Color(0xFF8D8E98),
thumbColor: Color(0xFFEB1555),
overlayColor: Color(0x29EB1555),
thumbShape: RoundSliderThumbShape(
enabledThumbRadius: 15.0),
overlayShape: RoundSliderOverlayShape(
overlayRadius: 30.0),
),
child: Slider(
value: height.toDouble(),
min: 120.0,
max: 220.0,
onChanged: (double newValue) {
setState(() {
height = newValue.round();
});
},
),
),
],
),
),
),
],
),
),
),
),
),
Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
child: FittedBox(
child: Material(
color: Color(0xFF00053C),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
child: ReusableCard(
colour: kActiveCardColor,
cardChild: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'WEIGHT(Kg)',
style: kLabelTextStyle,
),
Text(
weight.toString(),
style: kNumberTextStyle,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RoundIconButton(
iconName: FontAwesomeIcons.minus,
onPressed: () {
setState(() {
weight--;
});
},
),
SizedBox(
width: 15.0,
),
RoundIconButton(
iconName: FontAwesomeIcons.plus,
onPressed: () {
setState(() {
weight++;
});
},
),
],
),
],
),
),
),
Container(
child: ReusableCard(
colour: kActiveCardColor,
cardChild: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'AGE',
style: kLabelTextStyle,
),
Text(age.toString(), style: kNumberTextStyle),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RoundIconButton(
iconName: FontAwesomeIcons.minus,
onPressed: () {
setState(() {
age--;
});
},
),
SizedBox(
width: 15.0,
),
RoundIconButton(
iconName: FontAwesomeIcons.plus,
onPressed: () {
setState(() {
age++;
});
},
)
],
),
],
),
),
),
],
),
),
),
),
),
BottomButton(
buttonTitle: 'CALCULATE',
onTap: () {
CalculatorBrain calc =
CalculatorBrain(height: height, weight: weight);
print(calc);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return ResultsPage(
bmiResult: calc.calculateBMI(),
interpretation: calc.getInterpretation(),
resultText: calc.getResult());
},
),
);
},
),
],
),
);
}
}
class RoundIconButton extends StatelessWidget {
final Function onPressed;
final IconData iconName;
RoundIconButton({@required this.iconName, this.onPressed});
@override
Widget build(BuildContext context) {
return RawMaterialButton(
shape: CircleBorder(),
fillColor: Color(0xFF4C4F5E),
constraints: BoxConstraints.tightFor(width: 56.0, height: 56.0),
elevation: 0.0,
onPressed: onPressed,
child: Icon(iconName),
);
}
}
class ReusableCard extends StatelessWidget {
ReusableCard({@required this.colour, this.cardChild, this.onPress});
final Color colour;
final Widget cardChild;
final Function onPress;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onPress,
child: Container(
height: 200,
width: 250,
child: cardChild,
margin: EdgeInsets.all(5.0),
decoration: BoxDecoration(
color: colour,
borderRadius: BorderRadius.circular(10.0),
),
),
);
}
}[![enter image description here][1]][1]
import'results_page.dart';
进口“包装:颤振/材料.省道”;
导入“package:font_awesome_flatter/font_awesome_flatter.dart”;
导入“icon\u content\u widget.dart”;
导入“可重复使用的卡.省道”;
导入“底部按钮.省道”;
导入“计算器_brain.dart”;
导入“constants.dart”;
枚举性别类型{
男,,
女,,
}
类InputPage扩展StatefulWidget{
@凌驾
_InputPageState createState()=>\u InputPageState();
}
类_InputPageState扩展状态{
性别类型选择基因;
内部高度=180;
整数重量=60;
年龄=20岁;
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(标题:文本('CALCULATE BMI'),中心标题:true),
正文:ListView(
滚动方向:轴垂直,
儿童:[
填充物(
填充:常数边集全部(5.0),
子:容器(
孩子:FittedBox(
儿童:材料(
颜色:颜色(0xFF00053C),
孩子:排(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
容器(
儿童:可重用卡(
新闻界:(){
设置状态(){
selectedGender=GenderType.male;
});
},
颜色:selectedGender==GenderType.male
?kActiveCardColor
:kInactiveCardColor,
卡片儿童:
IconContentWidget('MALE',FontAwesomeIcons.mars),
),
),
容器(
儿童:可重用卡(
新闻界:(){
设置状态(){
selectedGender=GenderType.female;
});
},
颜色:selectedGender==GenderType.female
?kActiveCardColor
:kInactiveCardColor,
cardChild:IconContentWidget(
“女性”,FontAwesomeIcons.维纳斯),
),
),
],
),
),
),
),
),
填充物(
填充:常数边集全部(1.0),
子:容器(
孩子:FittedBox(
儿童:材料(
颜色:颜色(0xFF00053C),
孩子:排(
儿童:[
容器(
儿童:可重用卡(
颜色:kActiveCardColor,
卡片儿童:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
文本(“高度”,样式:kLabelTextStyle),
划船(
mainAxisAlignment:mainAxisAlignment.center,
crossAxisAlignment:crossAxisAlignment.baseline,
textb基线:textb基线。字母,
儿童:[
文本(height.toString(),
样式:kNumberTextStyle),
文本('cm',样式:kLabelTextStyle),
],
),
幻灯片主题(
数据:SliderTheme.of(context).copyWith(
activeTrackColor:Colors.white,
不活动跟踪颜色:颜色(0xFF8D8E98),
拇指颜色:颜色(0xFFEB1555),
覆盖颜色:颜色(0x29EB1555),
拇指形状:圆形滑块拇指形状(
启用的半径:15.0),
覆盖形状:圆形滑块覆盖形状(
覆盖率:30.0),
),
子:滑块(
值:height.toDouble(),
最低:120.0,
最高:220.0,
一旦更改:(双新值){
设置状态(){
高度=newValue.round();
});
},
),
),
],
),
),
),
],
),
),
),
),
),
填充物(
填充:常数边集全部(5.0),
子:容器(
孩子:FittedBox(
儿童:材料(
颜色:颜色(0xFF00053C),
孩子:排(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
容器(
儿童:可重用卡(
有限公司