FlatButton;
FlatButton(
//长按时颜色
highlightColor:Colors.red,
//点击的水波纹颜色
splashColor: Colors.blue,
onPressed: onPressed,
child: Text(text,
style: TextStyle(
fontSize:20,
fontWeight: FontWeight.w400)),
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.black, style: BorderStyle.solid, width: 1),
),
))
InkWell:
这里有个问题,InkWell子布局添加颜色后点击就无法展示水波纹了,子布局将父布局覆盖了。
InkWell(
onTap: () {},
highlightColor: Colors.blue,
splashColor: Colors.red,
child: Container(
color: Colors.white,
height: 100,
width: 100,
child: Text('点我'),
),
)
GestureDetector包裹子控件,点击空白区域点击无效解决方案:
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: callback,
child: Container(
padding: EdgeInsets.only(right: ScreenUtil().setHeight(30)),
alignment: Alignment.centerRight,
child: Image.asset(
LocalIcons.start_right,
width: ScreenUtil().setWidth(18),
height: ScreenUtil().setHeight(36),
),
),
),
GestureDetector(
onTap: callback,
child: Container(
color: Colours.transparent,
padding: EdgeInsets.only(right: ScreenUtil().setHeight(30)),
alignment: Alignment.centerRight,
child: Image.asset(
LocalIcons.start_right,
width: ScreenUtil().setWidth(18),
height: ScreenUtil().setHeight(36),
),
),
),
RaisedButton(onPressed: _onclick()),
...
_onclick(){}
error:
When the exception was thrown, this was the stack:
flutter: #0 Element.markNeedsBuild. (package:flutter/src/widgets/framework.dart:3670:11)
flutter: #1 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:3685:6)
flutter: #2 State.setState (package:flutter/src/widgets/framework.dart:1161:14)
flutter: #3 __ValueListenableDelegate&SingleValueDelegate&_ListenableDelegateMixin.startListening. (package:provider/src/listenable_provider.dart:134:36)
flutter: #4 _CountProvider&Object&ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier
解决方式1:需要在(){}
RaisedButton(
onPressed: (){
_onclick();
}),
...
_onclick(){}
解决方式2:
RaisedButton(
onPressed: _onclick ,
...