image - 位置参数过多导致堆栈错误
问题描述
我有一个将文本放在图像上的堆栈,但是当我这样做时,我得到一个错误,上面写着:位置参数太多:预期为 0,但找到了 3。它是一个计算器,用户的输出是 claculator.view.toString()。它背后的图像位于一个名为 assets 的文件中,名为 please.png。随时问我任何问题。请注意,错误在第 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
不接受任何位置参数。它需要一个带有列表的命名 children
参数:
Stack(children: [
Spacer(),
ImageBanner("assets/please.png"),
...
]),