我创建了以下的custome小部件:
df1.union(df2).groupBy("key").pivot("date").agg(max("val")).show
+---+----------+----------+----------+
|key|2016-04-16|2017-04-16|2018-04-16|
+---+----------+----------+----------+
| 1| 20| 10| 100|
| 2| null| null| 200|
+---+----------+----------+----------+
}
以下是我创建MainButtonWidget类型的对象的方法:
class MainButtonWidget extends StatelessWidget{
String _text = "";
TextTheme _textTheme = new TextTheme();
IconData _icon = null;
VoidCallback _onPressed;
MainButtonWidget(String text, TextTheme textTheme, IconData icon, VoidCallback onPressed){
_text = text;
_textTheme = textTheme;
_icon = icon;
_onPressed = onPressed;
}
void setText(String text){
_text = text;
}
@override
Widget build(BuildContext context) {
return new Container(
child: new RaisedButton(
padding: const EdgeInsets.fromLTRB(
Dimens.edgeMainButtonLRB, Dimens.edgeMainButtonT,
Dimens.edgeMainButtonLRB, Dimens.edgeMainButtonLRB),
shape: new CircleBorder(side: new BorderSide(
color: ColorRes.whiteTranslucent2,
width: Dimens.widthSmallButtonHome)),
onPressed: (){
debugPrint("mainButtonWidget before _onPressed");
_onPressed;
debugPrint("mainButtonWidget after _onPressed");
},
color: Colors.transparent,
child: new Column(
children: <Widget>[
new Icon(
_icon,
color: Colors.white,
),
new Text(_text,
style: _textTheme.button.copyWith(
color: Colors.white,
),)
],
),
),
);
}
按下按钮时,似乎没有执行VoidCallback的内容。
在日志中显示以下消息: I / flutter(21436):_onPressed之前的mainButtonWidget I / flutter(21436):_onPressed之后的mainButtonWidget
我希望看到'mapMainBtn - &gt; onPressed称为'在上述消息之间。
答案 0 :(得分:1)
要求将其称为()
_onPressed();
答案 1 :(得分:0)
_onPressed()。
请参阅下面的代码:
`onPressed: (){
debugPrint("mainButtonWidget before _onPressed");
_onPressed;
debugPrint("mainButtonWidget after _onPressed");
}`