button.dart 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import 'package:flowy_infra/size.dart';
  2. import 'package:flowy_infra_ui/style_widget/hover.dart';
  3. import 'package:flowy_infra_ui/style_widget/text.dart';
  4. import 'package:flowy_infra_ui/widget/spacing.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter/widgets.dart';
  7. class FlowyButton extends StatelessWidget {
  8. final Widget text;
  9. final VoidCallback? onTap;
  10. final EdgeInsets padding;
  11. final Widget? icon;
  12. final Color hoverColor;
  13. const FlowyButton({
  14. Key? key,
  15. required this.text,
  16. this.onTap,
  17. this.padding = const EdgeInsets.symmetric(horizontal: 3, vertical: 2),
  18. this.icon,
  19. this.hoverColor = Colors.transparent,
  20. }) : super(key: key);
  21. @override
  22. Widget build(BuildContext context) {
  23. return InkWell(
  24. onTap: onTap,
  25. child: FlowyHover(
  26. config: HoverDisplayConfig(borderRadius: Corners.s6Border, hoverColor: hoverColor),
  27. builder: (context, onHover) => _render(),
  28. ),
  29. );
  30. }
  31. Widget _render() {
  32. List<Widget> children = List.empty(growable: true);
  33. if (icon != null) {
  34. children.add(SizedBox.fromSize(size: const Size.square(16), child: icon!));
  35. children.add(const HSpace(6));
  36. }
  37. children.add(Align(child: text));
  38. return Padding(
  39. padding: padding,
  40. child: Row(
  41. children: children,
  42. ),
  43. );
  44. }
  45. }
  46. class FlowyTextButton extends StatelessWidget {
  47. final String text;
  48. final double fontSize;
  49. final TextOverflow overflow;
  50. final FontWeight fontWeight;
  51. final VoidCallback? onPressed;
  52. final EdgeInsets padding;
  53. final Widget? heading;
  54. final Color? hoverColor;
  55. final Color? fillColor;
  56. final BorderRadius? radius;
  57. final MainAxisAlignment mainAxisAlignment;
  58. final String? tooltip;
  59. // final HoverDisplayConfig? hoverDisplay;
  60. const FlowyTextButton(
  61. this.text, {
  62. Key? key,
  63. this.onPressed,
  64. this.fontSize = 16,
  65. this.overflow = TextOverflow.ellipsis,
  66. this.fontWeight = FontWeight.w400,
  67. this.padding = const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
  68. this.hoverColor,
  69. this.fillColor,
  70. this.heading,
  71. this.radius,
  72. this.mainAxisAlignment = MainAxisAlignment.start,
  73. this.tooltip,
  74. }) : super(key: key);
  75. @override
  76. Widget build(BuildContext context) {
  77. List<Widget> children = [];
  78. if (heading != null) {
  79. children.add(heading!);
  80. children.add(const HSpace(6));
  81. }
  82. children.add(
  83. FlowyText(
  84. text,
  85. overflow: overflow,
  86. fontWeight: fontWeight,
  87. fontSize: fontSize,
  88. textAlign: TextAlign.center,
  89. ),
  90. );
  91. Widget child = Padding(
  92. padding: padding,
  93. child: Row(
  94. crossAxisAlignment: CrossAxisAlignment.center,
  95. mainAxisAlignment: mainAxisAlignment,
  96. children: children,
  97. ),
  98. );
  99. child = RawMaterialButton(
  100. visualDensity: VisualDensity.compact,
  101. hoverElevation: 0,
  102. highlightElevation: 0,
  103. shape: RoundedRectangleBorder(borderRadius: radius ?? BorderRadius.circular(2)),
  104. fillColor: fillColor,
  105. hoverColor: hoverColor ?? Colors.transparent,
  106. focusColor: Colors.transparent,
  107. splashColor: Colors.transparent,
  108. highlightColor: Colors.transparent,
  109. elevation: 0,
  110. onPressed: onPressed,
  111. child: child,
  112. );
  113. if (tooltip != null) {
  114. child = Tooltip(
  115. message: tooltip!,
  116. child: child,
  117. );
  118. }
  119. return child;
  120. }
  121. }
  122. // return TextButton(
  123. // style: ButtonStyle(
  124. // textStyle: MaterialStateProperty.all(TextStyle(fontSize: fontSize)),
  125. // alignment: Alignment.centerLeft,
  126. // foregroundColor: MaterialStateProperty.all(Colors.black),
  127. // padding: MaterialStateProperty.all<EdgeInsets>(
  128. // const EdgeInsets.symmetric(horizontal: 2)),
  129. // ),
  130. // onPressed: onPressed,
  131. // child: Text(
  132. // text,
  133. // overflow: TextOverflow.ellipsis,
  134. // softWrap: false,
  135. // ),
  136. // );