我正在將 Inkwell() 用于某些容器以獲取按鈕互動性。在帶有一列的小部件 1 中,我想將其中一些容器放入其中。因此,我創建了小部件 2 作為容器的定義類。
問題:當我在小部件 1 中使用 Inkwell() 時,我可以呼叫某個函式,但是當我使用小部件 2 中的容器之一時,它不起作用。甚至沒有呼叫 print() 函式。
這是代碼(ContainerButton() 下的 Inkwell() 只是為了顯示作業解決方案):
void ShowAnswerBox(String headline, String answer) {
answerBoxHeadline = headline;
answerBoxText = answer;
setState(() {
answerBoxVisible = !answerBoxVisible;});
}
return Material(
child: Center(
child: Container(
color: Colors.blueGrey,
height: double.infinity,
child: SingleChildScrollView(
child: Column(
//mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: SizedBox(height: size.height*0.9,
child: Stack(
children:[
Padding(
padding: const EdgeInsets.only(top: 75),
child: SingleChildScrollView(
child: Column(//mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(color: Colors.blueGrey[200], child: Center(child: Text("Funktionsterm: f(x) = $factorA(x${factorB >= 0 ? " " : ""}$factorB)2${factorC >= 0 ? " " : ""} $factorC", style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold))),width: double.infinity,height: 100),
SizedBox(height: 15),
ContainerButton(onTap: (){print("tapped");}, containerColor: Colors.redAccent, containerText: "Scheitelpunkt: S(${factorB*-1}/$factorC)"),
InkWell(onTap:(){ShowAnswerBox("überschrift Scheitelpunkt","L?sungsweg Scheitelpunkt");},child: Container(width: 350,height: 100,decoration: BoxDecoration(color: Colors.redAccent,borderRadius: BorderRadius.circular(20), border: Border.all(color: Colors.black38, width: 5),
boxShadow: [BoxShadow(
color: Colors.black54,
blurRadius: 2.0,
spreadRadius: 0.0,
offset: Offset(2.0, 2.0), // shadow direction: bottom right
)
],),
child: Center(child: Text("Scheitelpunkt: S(${factorB*-1}/$factorC)", style: TextStyle(fontSize: 25))))),
這是小部件2:
class ContainerButton extends StatefulWidget {
final Function onTap;
final Color containerColor;
final String containerText;
const ContainerButton({Key? key, required this.onTap, required this.containerColor, required this.containerText}) : super(key: key);
@override
State<ContainerButton> createState() => _ContainerButtonState();
}
class _ContainerButtonState extends State<ContainerButton> {
@override
Widget build(BuildContext context) {
return Material(
child: InkWell(onTap: (){widget.onTap;},child: IgnorePointer(
child: Container(width: 350,height: 100,decoration: BoxDecoration(color: widget.containerColor,borderRadius: BorderRadius.circular(20), border: Border.all(color: Colors.black38, width: 5),
boxShadow: [BoxShadow(
color: Colors.black54,
blurRadius: 2.0,
spreadRadius: 0.0,
offset: Offset(2.0, 2.0), // shadow direction: bottom right
)
],), child: Center(child: Text(widget.containerText, style: TextStyle(fontSize: 25)))),
)),
);
}
}
uj5u.com熱心網友回復:
您在小部件 2 中以錯誤的方式呼叫函式,您忘記呼叫(),將其更改為:
child: InkWell(
onTap: widget.onTap,
child: IgnorePointer(
...
)
或這個:
child: InkWell(
onTap: (){
widget.onTap();
},
child: IgnorePointer(
...
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/515995.html
標籤:扑镖颤振布局
