43 lines
1.2 KiB
Dart
43 lines
1.2 KiB
Dart
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 Container(
|
||
//不写默认撑开
|
||
height: height ?? double.infinity,
|
||
width: width ?? double.infinity,
|
||
//需要裁切,不然没有圆角
|
||
clipBehavior: Clip.antiAlias,
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(radius ?? 32),
|
||
),
|
||
child: ElevatedButton(
|
||
onPressed: onPressed,
|
||
style: ButtonStyle(
|
||
elevation: MaterialStateProperty.all(0),
|
||
//设置最小值为0,是的尺寸为children尺寸
|
||
minimumSize: MaterialStateProperty.all(Size.zero)),
|
||
child: Text(text ?? "",
|
||
style: const TextStyle(
|
||
fontSize: 16,
|
||
color: Colors.white,
|
||
fontWeight: FontWeight.w300,
|
||
)),
|
||
),
|
||
);
|
||
}
|
||
}
|