第三个目标:% 3不添加到目标% 1和% 2。目标1和目标2正确相加
请注意“TextEditingController num 3controller = new TextEditingController();“已添加由我尝试添加3字段添加我需要使用不同的类或语法添加多个字段谢谢大家
输出outputenter image description here的图片
测试结果
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final appTitle = 'Twin City Bowmen Score Sheet';
return MaterialApp(
title: appTitle,
home: Scaffold(
appBar: AppBar(
title: Text(appTitle),
),
body: AddTwoNumbers(),
),
);
}
}
class AddTwoNumbers extends StatefulWidget {
@override
_AddTwoNumbersState createState() => _AddTwoNumbersState();
}
class _AddTwoNumbersState extends State<AddTwoNumbers> {
TextEditingController num1controller = new TextEditingController();
TextEditingController num2controller = new TextEditingController();
TextEditingController num3controller = new TextEditingController();
String result = "0";
@override
Widget build(BuildContext context) {
return Container(
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Text("Target 1:"),
new Flexible(
child: new TextField(
keyboardType: TextInputType.number,
controller: num1controller,
),
),
],
),
Row(
children: <Widget>[
Text("Target 2:"),
new Flexible(
child: new TextField(
keyboardType: TextInputType.number,
controller: num2controller,
),
),
],
),
Row(
children: <Widget>[
Text("Target 3:"),
new Flexible(
child: new TextField(
keyboardType: TextInputType.number,
controller: num3controller,
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: Text("Add"),
onPressed: () {
setState(() {
int sum = int.parse(num1controller.text) +
int.parse(num2controller.text);
result = sum.toString();
});
},
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Result:",
style: TextStyle(
fontSize: 30,
),
),
Text(
result,
style: TextStyle(
fontSize: 30,
),
),
],
),
],
),
);
}
}
字符串
1条答案
按热度按时间p3rjfoxz1#
如果我正确理解你的问题,这应该是解决方案:
字符串