Skip to content

Commit

Permalink
upgrade SDK 2.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lucky1213 committed Jun 3, 2021
1 parent 53ce0b1 commit 971d5ad
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 316 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
.vscode/
.fvm/

# Flutter/Dart/Pub related
**/doc/api/
Expand Down
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"dart.flutterSdkPath": "/Users/imac/fvm/versions/2.0.6"
}
"dart.flutterSdkPaths": [
".fvm/flutter_sdk"
],
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
## [0.0.2] - Improvement score

## [1.0.0] - Upgrade SDK 2.0.6 & support null-safety

## [1.0.1] - Upgrade SDK 2.2.1
403 changes: 116 additions & 287 deletions lib/editable_text.dart

Large diffs are not rendered by default.

23 changes: 10 additions & 13 deletions lib/extended_selectable_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ const int iOSHorizontalOffset = -2;
class _TextSpanEditingController extends TextEditingController {
_TextSpanEditingController({required TextSpan textSpan}):
_textSpan = textSpan,
super(text: textSpan.toPlainText());
super(text: textSpan.toPlainText(includeSemanticsLabels: false));

final TextSpan _textSpan;

@override
TextSpan buildTextSpan({TextStyle? style ,bool? withComposing}) {
TextSpan buildTextSpan({required BuildContext context, TextStyle? style, required bool withComposing}) {
// This does not care about composing.
return TextSpan(
style: style,
Expand Down Expand Up @@ -80,8 +80,7 @@ class _SelectableTextSelectionGestureDetectorBuilder extends ExtendedTextSelecti
break;
}
}
if (_state.widget.onTap != null)
_state.widget.onTap!();
_state.widget.onTap?.call();
}

@override
Expand Down Expand Up @@ -452,7 +451,6 @@ class ExtendedSelectableTextState extends State<ExtendedSelectableText>
@override
void initState() {
super.initState();
textSelectionControls = widget.selectionControls;
_selectionGestureDetectorBuilder = _SelectableTextSelectionGestureDetectorBuilder(state: this);
_controller = _TextSpanEditingController(
textSpan: widget.textSpan ?? TextSpan(text: widget.data)
Expand Down Expand Up @@ -513,17 +511,21 @@ class ExtendedSelectableTextState extends State<ExtendedSelectableText>
});
}

TextSelection? _lastSeenTextSelection;

void _handleSelectionChanged(TextSelection selection, SelectionChangedCause? cause) {
final bool willShowSelectionHandles = _shouldShowSelectionHandles(cause);
if (willShowSelectionHandles != _showSelectionHandles) {
setState(() {
_showSelectionHandles = willShowSelectionHandles;
});
}

if (widget.onSelectionChanged != null) {
// TODO(chunhtai): The selection may be the same. We should remove this
// check once this is fixed https://github.com/flutter/flutter/issues/76349.
if (widget.onSelectionChanged != null && _lastSeenTextSelection != selection) {
widget.onSelectionChanged!(selection, cause);
}
_lastSeenTextSelection = selection;

switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
Expand Down Expand Up @@ -597,6 +599,7 @@ class ExtendedSelectableTextState extends State<ExtendedSelectableText>
final TextSelectionThemeData selectionTheme = TextSelectionTheme.of(context);
final FocusNode focusNode = _effectiveFocusNode;

textSelectionControls = widget.selectionControls;
final bool paintCursorAboveText;
final bool cursorOpacityAnimates;
Offset? cursorOffset;
Expand Down Expand Up @@ -698,12 +701,6 @@ class ExtendedSelectableTextState extends State<ExtendedSelectableText>
);

return Semantics(
onTap: () {
if (!_controller.selection.isValid)
_controller.selection = TextSelection.collapsed(offset: _controller.text.length);
if (allowFocus)
_effectiveFocusNode.requestFocus();
},
onLongPress: () {
if (allowFocus)
_effectiveFocusNode.requestFocus();
Expand Down
21 changes: 11 additions & 10 deletions lib/extended_textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ class ExtendedTextField extends StatefulWidget {
@Deprecated(
'Use maxLengthEnforcement parameter which provides more specific '
'behavior related to the maxLength limit. '
'This feature was deprecated after v1.25.0-5.0.pre.'
'This feature was deprecated after v1.25.0-5.0.pre.',
)
final bool maxLengthEnforced;

Expand Down Expand Up @@ -997,6 +997,7 @@ class _ExtendedTextFieldState extends State<ExtendedTextField> with RestorationM
final Color selectionColor;
Color? autocorrectionTextRectColor;
Radius? cursorRadius = widget.cursorRadius;
VoidCallback? handleDidGainAccessibilityFocus;

switch (theme.platform) {
case TargetPlatform.iOS:
Expand All @@ -1022,6 +1023,13 @@ class _ExtendedTextFieldState extends State<ExtendedTextField> with RestorationM
selectionColor = selectionTheme.selectionColor ?? cupertinoTheme.primaryColor.withOpacity(0.40);
cursorRadius ??= const Radius.circular(2.0);
cursorOffset = Offset(iOSHorizontalOffset / MediaQuery.of(context).devicePixelRatio, 0);
handleDidGainAccessibilityFocus = () {
// macOS automatically activated the TextField when it receives
// accessibility focus.
if (!_effectiveFocusNode.hasFocus && _effectiveFocusNode.canRequestFocus) {
_effectiveFocusNode.requestFocus();
}
};
break;

case TargetPlatform.android:
Expand Down Expand Up @@ -1146,7 +1154,7 @@ class _ExtendedTextFieldState extends State<ExtendedTextField> with RestorationM
semanticsMaxValueLength = null;
}

child = MouseRegion(
return MouseRegion(
cursor: effectiveMouseCursor,
onEnter: (PointerEnterEvent event) => _handleHover(true),
onExit: (PointerExitEvent event) => _handleHover(false),
Expand All @@ -1163,6 +1171,7 @@ class _ExtendedTextFieldState extends State<ExtendedTextField> with RestorationM
_effectiveController.selection = TextSelection.collapsed(offset: _effectiveController.text.length);
_requestKeyboard();
},
onDidGainAccessibilityFocus: handleDidGainAccessibilityFocus,
child: child,
);
},
Expand All @@ -1173,13 +1182,5 @@ class _ExtendedTextFieldState extends State<ExtendedTextField> with RestorationM
),
),
);

if (kIsWeb) {
return Shortcuts(
shortcuts: scrollShortcutOverrides,
child: child,
);
}
return child;
}
}
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ packages:
version: "2.1.0"
sdks:
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.12.13+hotfix.5"
flutter: ">=2.2.1"
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: flutter_extended_text_field
description: Extend official TextField widget, support focus without pop-up keyboard.
version: 1.0.0
version: 1.0.1
homepage: https://github.com/lucky1213/extended_textfield

environment:
sdk: ">=2.12.0 <3.0.0"
flutter: ">=1.12.13+hotfix.5"
flutter: ">=2.2.1"

dependencies:
flutter:
Expand Down

0 comments on commit 971d5ad

Please sign in to comment.