- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题:如果用户在其可见边框之外单击,我希望用户无法点击该按钮。
我创建了两个FlatButton
,里面没有任何填充,问题是即使我在两个按钮之间点击,我的按钮仍然可以单击。
请向我解释为什么会这样?
如果需要,这是我的登录屏幕的代码:
class SignInPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final _googleSignIn = CustomFlatButton(text: 'Sign in with Google',);
final _facebookSignIn = CustomFlatButton(text: 'Sign in with Facebook', color: Colors.blue[900], textColor: Colors.white, onTapColor: Colors.white30,);
return Scaffold(
backgroundColor: Colors.grey[100],
appBar: AppBar(
title: Text('Time Tracker'),
centerTitle: true,
elevation: 0.0,
),
body: Container(
padding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 20),
color: Colors.grey[200],
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Sign In',
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 30,
),
),
_googleSignIn,
_facebookSignIn,
],
),
));
}
}
这是我的自定义
FlatButton
的代码:
class CustomFlatButton extends StatelessWidget {
final String text;
final Color color;
final Color textColor;
final Color onTapColor;
CustomFlatButton(
{this.text = 'Default sign in text', color, textColor, onTapColor})
: textColor = textColor ?? Colors.grey[900],
color = color ?? Colors.white70,
onTapColor = onTapColor ?? ThemeData.light().splashColor;
@override
Widget build(BuildContext context) {
return FlatButton(
splashColor: onTapColor,
onPressed: () {},
child: Text(
text,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w400,
color: textColor,
),
),
color: color, //Colors.white70
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(7)),
),
);
}
}
最佳答案
你需要做两件事
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap
添加到FlatButton SizedBox(height:10)
)关于flutter - Flutter Flat Button在其可见边框之外可以单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63014800/
我遇到过这个 html: 上面的html和这个有什么区别: 最佳答案 来自MDN page on the tag : 对于 type 的属性标签,可能的值是: 提交:按钮将表单数据提交给服务器
Button button= (Button) findViewbyID(R.id.button); 和 Button button = new Button(this); 有什么区别? 最佳答案 有
我是一名优秀的程序员,十分优秀!