mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-04-24 06:37:14 -04:00
feat: implement keyboard triggering on buttons and add focus state
This commit is contained in:
parent
351c891a5a
commit
1443f9d620
1 changed files with 59 additions and 16 deletions
|
@ -36,29 +36,72 @@ class AFBaseButton extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _AFBaseButtonState extends State<AFBaseButton> {
|
||||
final FocusNode focusNode = FocusNode();
|
||||
|
||||
bool isHovering = false;
|
||||
bool isFocused = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Color borderColor = _buildBorderColor(context);
|
||||
final Color backgroundColor = _buildBackgroundColor(context);
|
||||
|
||||
return MouseRegion(
|
||||
cursor:
|
||||
widget.disabled ? SystemMouseCursors.basic : SystemMouseCursors.click,
|
||||
onEnter: (_) => setState(() => isHovering = true),
|
||||
onExit: (_) => setState(() => isHovering = false),
|
||||
child: GestureDetector(
|
||||
onTap: widget.disabled ? null : widget.onTap,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: backgroundColor,
|
||||
border: Border.all(color: borderColor),
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
),
|
||||
child: Padding(
|
||||
padding: widget.padding,
|
||||
child: widget.builder(context, isHovering, widget.disabled),
|
||||
return Actions(
|
||||
actions: {
|
||||
ActivateIntent: CallbackAction<ActivateIntent>(
|
||||
onInvoke: (_) {
|
||||
if (!widget.disabled) {
|
||||
widget.onTap?.call();
|
||||
}
|
||||
return;
|
||||
},
|
||||
),
|
||||
},
|
||||
child: Focus(
|
||||
focusNode: focusNode,
|
||||
onFocusChange: (isFocused) {
|
||||
setState(() => this.isFocused = isFocused);
|
||||
},
|
||||
child: MouseRegion(
|
||||
cursor: widget.disabled
|
||||
? SystemMouseCursors.basic
|
||||
: SystemMouseCursors.click,
|
||||
onEnter: (_) => setState(() => isHovering = true),
|
||||
onExit: (_) => setState(() => isHovering = false),
|
||||
child: GestureDetector(
|
||||
onTap: widget.disabled ? null : widget.onTap,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
border: isFocused
|
||||
? Border.all(
|
||||
color: AppFlowyTheme.of(context)
|
||||
.borderColorScheme
|
||||
.themeThick
|
||||
.withAlpha(128),
|
||||
width: 2,
|
||||
strokeAlign: BorderSide.strokeAlignOutside,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: backgroundColor,
|
||||
border: Border.all(color: borderColor),
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
),
|
||||
child: Padding(
|
||||
padding: widget.padding,
|
||||
child: widget.builder(context, isHovering, widget.disabled),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue