Skip to content

Commit

Permalink
Fixes for Flutter 3.13 breaking changes (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
suragch committed Aug 22, 2023
1 parent cadcb23 commit 7296b39
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 274 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [6.0.0] - 2023.08.22

- Fixes for breaking changes in Flutter 2.13, mostly related to the text selection API.

## [5.0.0] - 2023.05.15

- Update APIs to match the Flutter 3.10 and Dart 3.0 release. (#45) (@Satsrag)
Expand Down
3 changes: 1 addition & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
include: package:flutter_lints/flutter.yaml
include: package:lints/recommended.yaml

analyzer:
exclude: [build/**]
language:
strict-casts: true
strict-raw-types: true
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'demos/resizable_text_demo.dart';
import 'demos/text_demo.dart';
import 'demos/text_span_demo.dart';

const versionTitle = 'Flutter mongol package 5.0.0';
const versionTitle = 'Flutter mongol package 6.0.0';

void main() {
runApp(const DemoApp());
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "The Flutter Authors";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
48 changes: 24 additions & 24 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.17.2"
fake_async:
dependency: transitive
description:
Expand All @@ -58,47 +58,39 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c
sha256: "2118df84ef0c3ca93f96123a616ae8540879991b8b57af2f81b76a7ada49b2a4"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "2.0.2"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
lints:
dependency: transitive
description:
name: lints
sha256: "6b0206b0bf4f04961fc5438198ccb3a885685cd67d4d4a32cc20ad7f8adbe015"
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
version: "2.1.1"
matcher:
dependency: transitive
description:
name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.15"
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.5.0"
meta:
dependency: transitive
description:
Expand All @@ -113,7 +105,7 @@ packages:
path: ".."
relative: true
source: path
version: "5.0.0"
version: "6.0.0"
path:
dependency: transitive
description:
Expand All @@ -131,10 +123,10 @@ packages:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -171,10 +163,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.6.0"
vector_math:
dependency: transitive
description:
Expand All @@ -183,5 +175,13 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
sdks:
dart: ">=3.0.0 <4.0.0"
dart: ">=3.1.0-185.0.dev <4.0.0"
37 changes: 16 additions & 21 deletions lib/src/editing/mongol_editable_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import 'package:flutter/material.dart'
ScrollToDocumentBoundaryIntent,
Size,
kMinInteractiveDimension;
import 'package:flutter/rendering.dart'
show CaretChangedHandler, RevealedOffset, ViewportOffset;
import 'package:flutter/rendering.dart' show RevealedOffset, ViewportOffset;
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'
Expand Down Expand Up @@ -133,7 +132,6 @@ import 'package:mongol/src/base/mongol_text_align.dart';
import 'package:mongol/src/editing/mongol_render_editable.dart';
import 'package:mongol/src/editing/text_selection/mongol_text_selection.dart';

import 'mongol_text_editing_action.dart';
import 'mongol_text_editing_intents.dart';

export 'package:flutter/services.dart'
Expand Down Expand Up @@ -381,7 +379,7 @@ class MongolEditableText extends StatefulWidget {
'Use `contextMenuBuilder` instead. '
'This feature was deprecated after v3.3.0-0.5.pre.',
)
ToolbarOptions? toolbarOptions,
ToolbarOptions? toolbarOptions,
this.autofillHints,
this.autofillClient,
this.clipBehavior = Clip.hardEdge,
Expand Down Expand Up @@ -1373,8 +1371,9 @@ class MongolEditableTextState extends State<MongolEditableText>
AutomaticKeepAliveClientMixin<MongolEditableText>,
WidgetsBindingObserver,
TickerProviderStateMixin<MongolEditableText>,
TextSelectionDelegate
implements TextInputClient, AutofillClient, MongolTextEditingActionTarget {
TextSelectionDelegate,
TextInputClient
implements AutofillClient {
Timer? _cursorTimer;
AnimationController get _cursorBlinkOpacityController {
return _backingCursorBlinkOpacityController ??= AnimationController(
Expand Down Expand Up @@ -2543,12 +2542,6 @@ class MongolEditableTextState extends State<MongolEditableText>
}
}

Rect? _currentCaretRect;

void _handleCaretChanged(Rect caretRect) {
_currentCaretRect = caretRect;
}

// Animation configuration for scrolling the caret back on screen.
static const Duration _caretAnimationDuration = Duration(milliseconds: 100);
static const Curve _caretAnimationCurve = Curves.fastOutSlowIn;
Expand All @@ -2562,7 +2555,13 @@ class MongolEditableTextState extends State<MongolEditableText>
_showCaretOnScreenScheduled = true;
SchedulerBinding.instance.addPostFrameCallback((Duration _) {
_showCaretOnScreenScheduled = false;
if (_currentCaretRect == null || !_scrollController.hasClients) {
// Since we are in a post frame callback, check currentContext in case
// RenderEditable has been disposed (in which case it will be null).
final renderEditable = _editableKey.currentContext?.findRenderObject()
as MongolRenderEditable?;
if (renderEditable == null ||
!(renderEditable.selection?.isValid ?? false) ||
!_scrollController.hasClients) {
return;
}

Expand Down Expand Up @@ -2592,7 +2591,9 @@ class MongolEditableTextState extends State<MongolEditableText>

final caretPadding = widget.scrollPadding.copyWith(right: rightSpacing);

final targetOffset = _getOffsetToRevealCaret(_currentCaretRect!);
final caretRect =
renderEditable.getLocalRectForCaret(renderEditable.selection!.extent);
final targetOffset = _getOffsetToRevealCaret(caretRect);

final Rect rectToReveal;
final TextSelection selection = textEditingValue.selection;
Expand Down Expand Up @@ -2891,8 +2892,7 @@ class MongolEditableTextState extends State<MongolEditableText>
///
/// This property is typically used to notify the renderer of input gestures
/// when [MongolRenderEditable.ignorePointer] is true.
@override
MongolRenderEditable get renderEditable =>
late final MongolRenderEditable renderEditable =
_editableKey.currentContext!.findRenderObject()! as MongolRenderEditable;

@override
Expand Down Expand Up @@ -3590,7 +3590,6 @@ class MongolEditableTextState extends State<MongolEditableText>
autocorrect: widget.autocorrect,
enableSuggestions: widget.enableSuggestions,
offset: offset,
onCaretChanged: _handleCaretChanged,
rendererIgnoresPointer: widget.rendererIgnoresPointer,
cursorWidth: widget.cursorWidth,
cursorHeight: widget.cursorHeight,
Expand Down Expand Up @@ -3665,7 +3664,6 @@ class _MongolEditable extends LeafRenderObjectWidget {
required this.autocorrect,
required this.enableSuggestions,
required this.offset,
this.onCaretChanged,
this.rendererIgnoresPointer = false,
this.cursorWidth,
required this.cursorHeight,
Expand Down Expand Up @@ -3697,7 +3695,6 @@ class _MongolEditable extends LeafRenderObjectWidget {
final bool autocorrect;
final bool enableSuggestions;
final ViewportOffset offset;
final CaretChangedHandler? onCaretChanged;
final bool rendererIgnoresPointer;
final double? cursorWidth;
final double cursorHeight;
Expand Down Expand Up @@ -3727,7 +3724,6 @@ class _MongolEditable extends LeafRenderObjectWidget {
textAlign: textAlign,
selection: value.selection,
offset: offset,
onCaretChanged: onCaretChanged,
ignorePointer: rendererIgnoresPointer,
obscuringCharacter: obscuringCharacter,
obscureText: obscureText,
Expand Down Expand Up @@ -3762,7 +3758,6 @@ class _MongolEditable extends LeafRenderObjectWidget {
..textAlign = textAlign
..selection = value.selection
..offset = offset
..onCaretChanged = onCaretChanged
..ignorePointer = rendererIgnoresPointer
..obscuringCharacter = obscuringCharacter
..obscureText = obscureText
Expand Down
6 changes: 3 additions & 3 deletions lib/src/editing/mongol_input_decorator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ class _RenderDecorationLayout {

// The workhorse: layout and paint a _Decorator widget's _Decoration.
class _RenderDecoration extends RenderBox
with SlottedContainerRenderObjectMixin<_DecorationSlot> {
with SlottedContainerRenderObjectMixin<_DecorationSlot, RenderBox> {
_RenderDecoration({
required _Decoration decoration,
required TextBaseline textBaseline,
Expand Down Expand Up @@ -1455,8 +1455,8 @@ class _RenderDecoration extends RenderBox
}
}

class _Decorator extends RenderObjectWidget
with SlottedMultiChildRenderObjectWidgetMixin<_DecorationSlot> {
class _Decorator
extends SlottedMultiChildRenderObjectWidget<_DecorationSlot, RenderBox> {
const _Decorator({
required this.textAlignHorizontal,
required this.decoration,
Expand Down
Loading

0 comments on commit 7296b39

Please sign in to comment.