【发布时间】:2018-09-16 14:05:51
【问题描述】:
我创建了以下客户小部件:
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,
),)
],
),
),
);
}
}
这是我如何创建 MainButtonWidget 类型的对象:
Widget mapMainBtn = new MainButtonWidget('Map', textTheme, Icons.location_on, ()=> debugPrint("mapMainBtn -> onPressed called"));
按下按钮时似乎 VoidCallback 的内容没有执行。
在日志中显示以下消息: I/flutter (21436):_onPressed 之前的 mainButtonWidget I/flutter (21436):_onPressed 后的 mainButtonWidget
我希望在上述消息之间看到“mapMainBtn -> onPressed called”。
【问题讨论】:
标签: flutter