mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Update Samples for 3.16 (#2085)
*Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.* *List which issues are fixed by this PR. For larger changes, raising an issue first helps reduce redundant work.* ## Pre-launch Checklist - [ ] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [ ] I signed the [CLA]. - [ ] I read the [Contributors Guide]. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-devrel channel on [Discord]. <!-- Links --> [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/wiki/Chat [Contributors Guide]: https://github.com/flutter/samples/blob/main/CONTRIBUTING.md
This commit is contained in:
@@ -26,6 +26,7 @@ class BasicTextField extends StatefulWidget {
|
||||
VoidCallback? onCut,
|
||||
VoidCallback? onPaste,
|
||||
VoidCallback? onSelectAll,
|
||||
VoidCallback? onLookUp,
|
||||
VoidCallback? onLiveTextInput,
|
||||
TextSelectionToolbarAnchors anchors,
|
||||
) {
|
||||
@@ -35,8 +36,12 @@ class BasicTextField extends StatefulWidget {
|
||||
onCut: onCut,
|
||||
onPaste: onPaste,
|
||||
onSelectAll: onSelectAll,
|
||||
onLookUp: onLookUp,
|
||||
onLiveTextInput: onLiveTextInput,
|
||||
anchors: anchors,
|
||||
// TODO(Renzo-Olivares): https://github.com/flutter/samples/issues/2088
|
||||
onSearchWeb: null,
|
||||
onShare: null,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ typedef BasicTextFieldContextMenuBuilder = Widget Function(
|
||||
VoidCallback? onCut,
|
||||
VoidCallback? onPaste,
|
||||
VoidCallback? onSelectAll,
|
||||
VoidCallback? onLookUp,
|
||||
VoidCallback? onLiveTextInput,
|
||||
TextSelectionToolbarAnchors anchors,
|
||||
);
|
||||
@@ -860,6 +861,9 @@ class BasicTextInputClientState extends State<BasicTextInputClient>
|
||||
selectAllEnabled
|
||||
? () => selectAll(SelectionChangedCause.toolbar)
|
||||
: null,
|
||||
lookUpEnabled
|
||||
? () => _lookUpSelection(SelectionChangedCause.toolbar)
|
||||
: null,
|
||||
liveTextInputEnabled
|
||||
? () => _startLiveTextInput(SelectionChangedCause.toolbar)
|
||||
: null,
|
||||
@@ -988,6 +992,30 @@ class BasicTextInputClientState extends State<BasicTextInputClient>
|
||||
}
|
||||
}
|
||||
|
||||
/// For lookup support.
|
||||
@override
|
||||
bool get lookUpEnabled {
|
||||
if (defaultTargetPlatform != TargetPlatform.iOS) {
|
||||
return false;
|
||||
}
|
||||
return !textEditingValue.selection.isCollapsed;
|
||||
}
|
||||
|
||||
/// Look up the current selection, as in the "Look Up" edit menu button on iOS.
|
||||
/// Currently this is only implemented for iOS.
|
||||
/// Throws an error if the selection is empty or collapsed.
|
||||
Future<void> _lookUpSelection(SelectionChangedCause cause) async {
|
||||
final String text =
|
||||
textEditingValue.selection.textInside(textEditingValue.text);
|
||||
if (text.isEmpty) {
|
||||
return;
|
||||
}
|
||||
await SystemChannels.platform.invokeMethod(
|
||||
'LookUp.invoke',
|
||||
text,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Actions(
|
||||
@@ -1016,7 +1044,7 @@ class BasicTextInputClientState extends State<BasicTextInputClient>
|
||||
expands: false, // expands to height of parent.
|
||||
strutStyle: null,
|
||||
selectionColor: Colors.blue.withOpacity(0.40),
|
||||
textScaleFactor: MediaQuery.textScaleFactorOf(context),
|
||||
textScaler: MediaQuery.textScalerOf(context),
|
||||
textAlign: TextAlign.left,
|
||||
textDirection: _textDirection,
|
||||
locale: Localizations.maybeLocaleOf(context),
|
||||
@@ -1068,7 +1096,7 @@ class _Editable extends MultiChildRenderObjectWidget {
|
||||
required this.expands,
|
||||
this.strutStyle,
|
||||
this.selectionColor,
|
||||
required this.textScaleFactor,
|
||||
required this.textScaler,
|
||||
required this.textAlign,
|
||||
required this.textDirection,
|
||||
this.locale,
|
||||
@@ -1117,7 +1145,7 @@ class _Editable extends MultiChildRenderObjectWidget {
|
||||
final bool expands;
|
||||
final StrutStyle? strutStyle;
|
||||
final Color? selectionColor;
|
||||
final double textScaleFactor;
|
||||
final TextScaler textScaler;
|
||||
final TextAlign textAlign;
|
||||
final TextDirection textDirection;
|
||||
final Locale? locale;
|
||||
@@ -1156,7 +1184,7 @@ class _Editable extends MultiChildRenderObjectWidget {
|
||||
expands: expands,
|
||||
strutStyle: strutStyle,
|
||||
selectionColor: selectionColor,
|
||||
textScaleFactor: textScaleFactor,
|
||||
textScaler: textScaler,
|
||||
textAlign: textAlign,
|
||||
textDirection: textDirection,
|
||||
locale: locale ?? Localizations.maybeLocaleOf(context),
|
||||
@@ -1197,7 +1225,7 @@ class _Editable extends MultiChildRenderObjectWidget {
|
||||
..expands = expands
|
||||
..strutStyle = strutStyle
|
||||
..selectionColor = selectionColor
|
||||
..textScaleFactor = textScaleFactor
|
||||
..textScaler = textScaler
|
||||
..textAlign = textAlign
|
||||
..textDirection = textDirection
|
||||
..locale = locale ?? Localizations.maybeLocaleOf(context)
|
||||
|
||||
Reference in New Issue
Block a user