mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2026-01-06 12:21:48 +00:00
feat(flutter_desktop): clickable url links in row detail (#5916)
* feat: Url row detail openable via `ctrl | meta + click` * feat: Optimize `LinkTextField` state management --------- Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
This commit is contained in:
parent
813c8e6b86
commit
59f79be290
@ -5,6 +5,7 @@ import 'package:appflowy/plugins/database/widgets/row/cells/cell_container.dart'
|
||||
import 'package:appflowy/plugins/database/application/cell/bloc/url_cell_bloc.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../editable_cell_skeleton/url.dart';
|
||||
|
||||
@ -18,26 +19,9 @@ class DesktopRowDetailURLSkin extends IEditableURLCellSkin {
|
||||
TextEditingController textEditingController,
|
||||
URLCellDataNotifier cellDataNotifier,
|
||||
) {
|
||||
return TextField(
|
||||
return LinkTextField(
|
||||
controller: textEditingController,
|
||||
focusNode: focusNode,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 9),
|
||||
border: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
errorBorder: InputBorder.none,
|
||||
disabledBorder: InputBorder.none,
|
||||
hintText: LocaleKeys.grid_row_textPlaceholder.tr(),
|
||||
hintStyle: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(context).hintColor,
|
||||
),
|
||||
isDense: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -54,3 +38,76 @@ class DesktopRowDetailURLSkin extends IEditableURLCellSkin {
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class LinkTextField extends StatefulWidget {
|
||||
const LinkTextField({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.focusNode,
|
||||
});
|
||||
|
||||
final TextEditingController controller;
|
||||
final FocusNode focusNode;
|
||||
|
||||
@override
|
||||
State<LinkTextField> createState() => _LinkTextFieldState();
|
||||
}
|
||||
|
||||
class _LinkTextFieldState extends State<LinkTextField> {
|
||||
bool isLinkClickable = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
HardwareKeyboard.instance.addHandler(_handleGlobalKeyEvent);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
HardwareKeyboard.instance.removeHandler(_handleGlobalKeyEvent);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool _handleGlobalKeyEvent(KeyEvent event) {
|
||||
final keyboard = HardwareKeyboard.instance;
|
||||
final canOpenLink = event is KeyDownEvent &&
|
||||
(keyboard.isControlPressed || keyboard.isMetaPressed);
|
||||
if (canOpenLink != isLinkClickable) {
|
||||
setState(() => isLinkClickable = canOpenLink);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextField(
|
||||
mouseCursor:
|
||||
isLinkClickable ? SystemMouseCursors.click : SystemMouseCursors.text,
|
||||
controller: widget.controller,
|
||||
focusNode: widget.focusNode,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
onTap: () {
|
||||
if (isLinkClickable) {
|
||||
openUrlCellLink(widget.controller.text);
|
||||
}
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 9),
|
||||
border: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
errorBorder: InputBorder.none,
|
||||
disabledBorder: InputBorder.none,
|
||||
hintText: LocaleKeys.grid_row_textPlaceholder.tr(),
|
||||
hintStyle: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(context).hintColor,
|
||||
),
|
||||
isDense: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user