123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- import 'package:fis_theme/theme.dart';
- import 'package:fis_ui/index.dart';
- import 'package:fis_ui/interface/active_widget.dart';
- import 'package:fis_ui/interface/interactive_container.dart';
- import 'package:flutter/material.dart';
- class FHoverTextButton extends FStatefulWidget implements FActiveWidget {
- ///按钮文字
- final String label;
- ///鼠标悬浮时颜色
- final Color? hoverColor;
- ///非鼠标悬浮颜色
- final Color? color;
- ///点击事件
- final GestureTapCallback onTap;
- /// 图标数值
- final IconData? iconData;
- /// 字号
- final double fontSize;
- /// 字体粗细
- final FontWeight fontWeight;
- /// 字体高度
- final double? fontHeight;
- @override
- final FInteractiveContainer businessParent;
- @override
- final String? name;
- FHoverTextButton({
- required this.label,
- required this.onTap,
- required this.businessParent,
- this.name,
- this.hoverColor,
- this.color,
- this.iconData,
- this.fontSize = 18,
- this.fontWeight = FontWeight.normal,
- this.fontHeight,
- });
- @override
- FState<FStatefulWidget> createState() {
- return _FHoverTextButtonState();
- }
- }
- class _FHoverTextButtonState extends FState<FHoverTextButton> {
- bool _isHover = false;
- @override
- FWidget build(BuildContext context) {
- Color _color;
- if (_isHover) {
- _color = widget.hoverColor ?? FTheme.ins.colorScheme.secondary;
- } else {
- _color = widget.color ?? FTheme.ins.colorScheme.primary;
- }
- return FMouseRegion(
- cursor: SystemMouseCursors.click,
- onHover: (_) {
- setState(() {
- _isHover = true;
- });
- },
- onExit: (_) {
- setState(() {
- _isHover = false;
- });
- },
- child: FGestureDetector(
- name: widget.name ?? widget.label,
- businessParent: widget.businessParent,
- child: _buildBody(_color),
- onTap: widget.onTap,
- ),
- );
- }
- FWidget _buildBody(Color color) {
- final textWidget = FText(
- widget.label,
- style: TextStyle(
- height: widget.fontHeight,
- fontWeight: widget.fontWeight,
- fontSize: widget.fontSize,
- color: color,
- ),
- );
- if (widget.iconData == null) {
- return textWidget;
- } else {
- final iconWidget = FIcon(
- widget.iconData!,
- size: widget.fontSize,
- color: color,
- );
- return FRow(
- mainAxisSize: MainAxisSize.min,
- children: [
- iconWidget,
- textWidget,
- ],
- );
- }
- }
- }
|