mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Flutter beta (#1952)
This commit is contained in:
@@ -26,6 +26,7 @@ class BasicTextField extends StatefulWidget {
|
||||
VoidCallback? onCut,
|
||||
VoidCallback? onPaste,
|
||||
VoidCallback? onSelectAll,
|
||||
VoidCallback? onLiveTextInput,
|
||||
TextSelectionToolbarAnchors anchors,
|
||||
) {
|
||||
return AdaptiveTextSelectionToolbar.editable(
|
||||
@@ -34,6 +35,7 @@ class BasicTextField extends StatefulWidget {
|
||||
onCut: onCut,
|
||||
onPaste: onPaste,
|
||||
onSelectAll: onSelectAll,
|
||||
onLiveTextInput: onLiveTextInput,
|
||||
anchors: anchors,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ typedef BasicTextFieldContextMenuBuilder = Widget Function(
|
||||
VoidCallback? onCut,
|
||||
VoidCallback? onPaste,
|
||||
VoidCallback? onSelectAll,
|
||||
VoidCallback? onLiveTextInput,
|
||||
TextSelectionToolbarAnchors anchors,
|
||||
);
|
||||
|
||||
@@ -65,6 +66,7 @@ class BasicTextInputClientState extends State<BasicTextInputClient>
|
||||
void initState() {
|
||||
super.initState();
|
||||
_clipboardStatus?.addListener(_onChangedClipboardStatus);
|
||||
_liveTextInputStatus?.addListener(_onChangedLiveTextInputStatus);
|
||||
widget.focusNode.addListener(_handleFocusChanged);
|
||||
widget.controller.addListener(_didChangeTextEditingValue);
|
||||
}
|
||||
@@ -78,6 +80,9 @@ class BasicTextInputClientState extends State<BasicTextInputClient>
|
||||
@override
|
||||
void dispose() {
|
||||
widget.controller.removeListener(_didChangeTextEditingValue);
|
||||
widget.focusNode.removeListener(_handleFocusChanged);
|
||||
_liveTextInputStatus?.removeListener(_onChangedLiveTextInputStatus);
|
||||
_liveTextInputStatus?.dispose();
|
||||
_clipboardStatus?.removeListener(_onChangedClipboardStatus);
|
||||
_clipboardStatus?.dispose();
|
||||
super.dispose();
|
||||
@@ -157,6 +162,7 @@ class BasicTextInputClientState extends State<BasicTextInputClient>
|
||||
return false;
|
||||
}
|
||||
|
||||
_liveTextInputStatus?.update();
|
||||
_selectionOverlay!.showToolbar();
|
||||
|
||||
return true;
|
||||
@@ -854,6 +860,9 @@ class BasicTextInputClientState extends State<BasicTextInputClient>
|
||||
selectAllEnabled
|
||||
? () => selectAll(SelectionChangedCause.toolbar)
|
||||
: null,
|
||||
liveTextInputEnabled
|
||||
? () => _startLiveTextInput(SelectionChangedCause.toolbar)
|
||||
: null,
|
||||
_contextMenuAnchors,
|
||||
);
|
||||
},
|
||||
@@ -950,6 +959,35 @@ class BasicTextInputClientState extends State<BasicTextInputClient>
|
||||
);
|
||||
}
|
||||
|
||||
/// For OCR Support.
|
||||
/// Detects whether the Live Text input is enabled.
|
||||
final LiveTextInputStatusNotifier? _liveTextInputStatus =
|
||||
kIsWeb ? null : LiveTextInputStatusNotifier();
|
||||
|
||||
@override
|
||||
bool get liveTextInputEnabled {
|
||||
return _liveTextInputStatus?.value == LiveTextInputStatus.enabled &&
|
||||
textEditingValue.selection.isCollapsed;
|
||||
}
|
||||
|
||||
void _onChangedLiveTextInputStatus() {
|
||||
setState(() {
|
||||
// Inform the widget that the value of liveTextInputStatus has changed.
|
||||
});
|
||||
}
|
||||
|
||||
void _startLiveTextInput(SelectionChangedCause cause) {
|
||||
if (!liveTextInputEnabled) {
|
||||
return;
|
||||
}
|
||||
if (_hasInputConnection) {
|
||||
LiveText.startLiveTextInput();
|
||||
}
|
||||
if (cause == SelectionChangedCause.toolbar) {
|
||||
hideToolbar();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Actions(
|
||||
|
||||
Reference in New Issue
Block a user