Flutter封装 Button

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,flutter,android,android,studio)