class LoginButton extends StatelessWidget {
final String title;
final bool enable;
final VoidCallback onPressed; // 点击回调
const LoginButton({Key key, this.title, this.enable = true, this.onPressed})
: super(key: key);
@override
Widget build(BuildContext context) {
return FractionallySizedBox(
// FractionallySizedBox 使在 ListView 中的Button撑满屏幕宽度
widthFactor: 1,
child: MaterialButton(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6)),
height: 45,
onPressed: enable ? onPressed : null,
disabledColor: primary[50],
color: primary,
child: Text(title, style: TextStyle(color: Colors.white, fontSize: 16)),
),
);
}
}
Flutter封装 Button
最新推荐文章于 2024-05-07 20:26:21 发布