#
whycq
2025-03-03 6a90c5bde0facc8330ce4c7c7d89292717b7ac65
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
 
enum Type {
  primary,
  second,
  cancel,
  disable,
}
enum BtnSize {
  small,
  normal,
  large,
}
 
class CEBtn extends StatelessWidget {
  final String title;
  final Type? type;
  final BtnSize? btnSize;
  final VoidCallback onPressed;
 
  const CEBtn({
    super.key,
    required this.title,
    required this.onPressed,
    this.type,
    this.btnSize,
  });
 
 
  @override
  Widget build(BuildContext context) {
    Color? backColor = Colors.blue;
    var textColor = Colors.white;
    var size = WidgetStateProperty.all(Size(40, 20));
    double fontSize = 12;
    switch (type) {
      case Type.primary:
        backColor = Colors.blue;
        break;
      case Type.second:
        backColor = Colors.lightBlue;
        break;
      case Type.cancel:
        backColor = Colors.grey[100];
        textColor = Colors.black87;
        break;
      case Type.disable:
        backColor = Colors.grey;
        break;
      case null:
        backColor = Colors.blue;
        break;
    }
    switch (btnSize) {
      case BtnSize.small:
        size = WidgetStateProperty.all(Size(40, 20));
        fontSize = 12;
        break;
      case BtnSize.large:
        size = WidgetStateProperty.all(Size(80, 40));
        fontSize = 16;
        break;
      case null:
        size = WidgetStateProperty.all(Size(0, 0));
        fontSize = 14;
        break;
      case BtnSize.normal:
        size = WidgetStateProperty.all(Size(60, 30));
        fontSize = 14;
        break;
    }
 
    var backgroundColor = WidgetStateProperty.all(backColor); // 按扭背景颜色
    var foregroundColor = WidgetStateProperty.all(textColor); // 按钮文本颜色
    return ElevatedButton(
      onPressed: onPressed,
      child: Text(title,style: TextStyle(fontSize: fontSize,fontWeight: FontWeight.normal),),
      style: ButtonStyle(
        backgroundColor: backgroundColor,
        foregroundColor: foregroundColor,
        padding: WidgetStateProperty.all(EdgeInsets.symmetric(vertical: 4, horizontal: 8)),
        minimumSize: size, // 设置最小宽度和高度// 设置内边距
        shape: WidgetStateProperty.all(RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(5))), // 圆角
      ),
    );
  }
}