flutter - 将 onPressed 函数放在 Container 上
问题描述
我需要取下 FlatButton 并将此功能放在所有容器中,使用按钮功能的 onPressed。我不知道是否有可能......我怎么能做到这一点?
Widget _buildFrontWidget() {
return Container(
color: Colors.white,
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("CARD",
style: TextStyle(
color: Color(0xFF2e282a),
fontSize: 20.0,
fontWeight: FontWeight.w800)
),
FlatButton(
onPressed: () => _foldingCellKey?.currentState?.toggleFold(),
child: Text(
"Open",
),
textColor: Colors.white,
color: Colors.indigoAccent,
splashColor: Colors.white.withOpacity(0.5),
)
],
));
}
Widget _buildInnerTopWidget() {
return Container(
color: Color(0xFFff9234),
alignment: Alignment.center,
child: Text("TITLE",
style: TextStyle(
color: Color(0xFF2e282a),
fontFamily: 'OpenSans',
fontSize: 20.0,
fontWeight: FontWeight.w800)));
}
Widget _buildInnerBottomWidget() {
return Container(
color: Color(0xFFecf2f9),
alignment: Alignment.bottomCenter,
child: Padding(
padding: EdgeInsets.only(bottom: 10),
child: FlatButton(
onPressed: () => _foldingCellKey?.currentState?.toggleFold(),
child: Text(
"Close",
),
textColor: Colors.white,
color: Colors.indigoAccent,
splashColor: Colors.white.withOpacity(0.5),
),
),
);
}
解决方案
像这样包装成 InkWell
Widget _buildFrontWidget() {
return InkWell(
onTap: _foldingCellKey?.currentState?.toggleFold(),
child: Container(
color: Colors.white,
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("CARD",
style: TextStyle(
color: Color(0xFF2e282a),
fontSize: 20.0,
fontWeight: FontWeight.w800)),
],
)),
);
}
推荐阅读
- r - 对 order() 函数的怀疑
- automation - 具有 aeonbits 库的每个文件中具有不同属性的多个属性文件
- azure - 无法链接 Azure 日志分析中的现有工作区
- php - 如何使用输入文本数组输入 Laravel Dusk?
- kubernetes - 在 GKE 中的现有节点池上添加或编辑标签
- xamarin - 即使从 Xamarin 的 android 版本 8.1 中的缓存中清除,如何在后台启动服务?
- wso2 - 通过 API 门户开发 WSO2 API
- sapui5 - SAPUI5 使用正斜杠绑定属性名称
- reactjs - .offsetWidth 的 ref 没有在 React 中更新
- ios - Objective-C,NSTask 缓冲区限制