[英]Too many positional arguments flutter stack error
I have a stack which puts text over an image, however when I do so I get an error which reads: Too many positional arguments: 0 expected, but 3 found.我有一个将文本放在图像上的堆栈,但是当我这样做时,我得到一个错误,上面写着:太多位置 arguments:预期为 0,但找到了 3。 It is a calculator, where the users output is claculator.view.toString().它是一个计算器,其中用户 output 是 claculator.view.toString()。 The image behind it is in a file called assets and is called please.png.它背后的图像位于一个名为 assets 的文件中,名为 please.png。 Feel free to ask me any question.随时问我任何问题。 Note the error is in line 19.请注意,错误在第 19 行。
import 'package:google_fonts/google_fonts.dart';
import 'package:neumorphism_web/calculator/calculator_logic.dart';
import 'package:neumorphism_web/calculator/neu_calculator_button.dart';
import 'package:neumorphism_web/calculator/neumorphic_theme.dart';
import 'package:provider/provider.dart';
import 'image_banner.dart';
class CalculatorView extends StatelessWidget {
@override
Widget build(BuildContext context) {
final calculator = Provider.of<Calculator>(context);
return Material(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Stack(
Spacer(),
ImageBanner("assets/please.png"),
Text(
calculator.value.toString(),
style: GoogleFonts.montserrat(
fontSize: 75,
fontWeight: FontWeight.w700,
color: Colors.white,
),
),
),
SizedBox(height: 50),
ButtonRow(children: [
NeuCalculatorButton(
text: 'AC',
onPressed: calculator.reset,
),
NeuCalculatorButton(
text: '+/-',
onPressed: () {},
),
NeuCalculatorButton(
text: '%',
onPressed: () {},
),
NeuCalculatorButton(
text: '÷',
textColor: kOrange,
textSize: 35,
onPressed: calculator.divide,
isChosen: calculator.currentVariable is CalculatorDivide,
),
]),
ButtonRow(
children: [
NeuCalculatorButton(
text: '7',
onPressed: () => calculator.setValue(7),
),
NeuCalculatorButton(
text: '8',
onPressed: () => calculator.setValue(8),
),
NeuCalculatorButton(
text: '9',
onPressed: () => calculator.setValue(9),
),
NeuCalculatorButton(
text: 'x',
textColor: kOrange,
onPressed: calculator.multiply,
isChosen: calculator.currentVariable is CalculatorMultiply,
),
],
),
ButtonRow(
children: [
NeuCalculatorButton(
text: '4',
onPressed: () => calculator.setValue(4),
),
NeuCalculatorButton(
text: '5',
onPressed: () => calculator.setValue(5),
),
NeuCalculatorButton(
text: '6',
onPressed: () => calculator.setValue(6),
),
NeuCalculatorButton(
text: '-',
textColor: kOrange,
textSize: 35,
onPressed: calculator.deduct,
isChosen: calculator.currentVariable is CalculatorDeduct,
),
],
),
ButtonRow(
children: [
NeuCalculatorButton(
text: '1',
onPressed: () => calculator.setValue(1),
),
NeuCalculatorButton(
text: '2',
onPressed: () => calculator.setValue(2),
),
NeuCalculatorButton(
text: '3',
onPressed: () => calculator.setValue(3),
),
NeuCalculatorButton(
text: '+',
textColor: kOrange,
textSize: 35,
onPressed: calculator.add,
isChosen: calculator.currentVariable is CalculatorAdd,
),
],
),
ButtonRow(
children: [
NeuCalculatorButton(
text: '0',
onPressed: () => calculator.setValue(0),
isPill: true,
),
NeuCalculatorButton(
text: '.',
onPressed: () {},
),
NeuCalculatorButton(
text: '=',
textColor: kOrange,
textSize: 35,
onPressed: calculator.showResult,
),
],
),
SizedBox(height: 15)
],
),
),
);
}
}
class ButtonRow extends StatelessWidget {
const ButtonRow({
Key key,
@required this.children,
}) : super(key: key);
final List<NeuCalculatorButton> children;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: children,
),
);
}
}
Stack
does not take any positional arguments. Stack
不占用任何位置 arguments。 It takes a named children
argument that takes a list :它需要一个命名的children
参数,该参数需要一个list :
Stack(children: [
Spacer(),
ImageBanner("assets/please.png"),
...
]),
You are directly passing Widgets as arguments to a Stack
, that means you are trying to provide it positional arguments while stack does not accept any positional arguments !您直接将 Widgets 作为 arguments 传递给Stack
,这意味着您正在尝试为其提供位置 arguments 而堆栈不接受任何位置 arguments !
However Stack
takes a named argument children
which takes a List
that you can use to put your widgets into !然而Stack
接受一个命名参数children
,它接受一个List
,您可以使用它来将您的小部件放入 !
Stack(
children: <Widget>[
MyWidget(),
Positioned(
bottom: 20,
left: 20,
child: MyWidget2(color: Colors.blue),
),
Positioned(
top: 50,
right: 50,
child: MyWidget3(color: Colors.red)
)
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.