import 'package:flutter/material.dart'; class ButtonWidget extends StatelessWidget { const ButtonWidget({ Key? key, this.text, this.width, this.height, this.radius, this.onPressed, }) : super(key: key); final String? text; final double? width; final double? height; final double? radius; final void Function()? onPressed; @override Widget build(BuildContext context) { //套一层Container,可以做很多事,比如设置尺寸 return ElevatedButton( onPressed: onPressed, style: ButtonStyle( elevation: MaterialStateProperty.all(0), //设置最小值为0,是的尺寸为children尺寸 minimumSize: MaterialStateProperty.all(Size( width ?? double.infinity, height ?? double.infinity, )), shape: MaterialStateProperty.all( RoundedRectangleBorder( borderRadius: BorderRadius.circular(radius?? 32), ), ), ), child: Text(text ?? "", style: const TextStyle( fontSize: 16, color: Colors.white, fontWeight: FontWeight.w300, )), ); } }