Skip to content

Commit e98e277

Browse files
authored
Support Flutter 3.44 text input changes (#583)
1 parent ebd507e commit e98e277

9 files changed

Lines changed: 72 additions & 11 deletions

File tree

.github/workflows/fleather.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
- uses: actions/checkout@v3
1111
- uses: subosito/flutter-action@v2
1212
with:
13-
flutter-version: "3.38.0"
13+
flutter-version: "3.44.0"
1414
cache: true
1515
# Manually Update this `key`
16-
cache-key: "3.38.0"
16+
cache-key: "3.44.0"
1717
- run: dart pub global activate coverage
1818

1919
#

packages/fleather/example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class _HomePageState extends State<HomePage> {
148148
final data = node.value.data;
149149
// Icons.rocket_launch_outlined
150150
return Icon(
151+
// ignore: non_const_argument_for_const_parameter
151152
IconData(int.parse(data['codePoint']), fontFamily: data['fontFamily']),
152153
color: Color(int.parse(data['color'])),
153154
size: 18,

packages/fleather/lib/l10n/fleather_localizations.g.dart

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

packages/fleather/lib/src/widgets/editor_input_client_mixin.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ mixin RawEditorStateTextInputClientMixin on EditorState
146146
return;
147147
}
148148

149-
_textInputConnection?.setStyle(
149+
_textInputConnection?.updateStyle(TextInputStyle(
150150
fontFamily: style.textStyle.fontFamily,
151151
fontSize: style.textStyle.fontSize,
152152
fontWeight: style.textStyle.fontWeight,
153153
textDirection: style.textDirection,
154-
textAlign: style.textAlign);
154+
textAlign: style.textAlign));
155155
});
156156
}
157157

@@ -200,6 +200,17 @@ mixin RawEditorStateTextInputClientMixin on EditorState
200200
// no-op
201201
}
202202

203+
@override
204+
bool onFocusReceived() {
205+
if (mounted &&
206+
!effectiveFocusNode.hasFocus &&
207+
effectiveFocusNode.canRequestFocus) {
208+
effectiveFocusNode.requestFocus();
209+
return true;
210+
}
211+
return false;
212+
}
213+
203214
@override
204215
void performAction(TextInputAction action) {
205216
// no-op

packages/fleather/test/rendering/rendering_tools.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ class FakeTickerProvider implements TickerProvider {
352352
}
353353

354354
class FakeTicker implements Ticker {
355+
@override
356+
bool forceFrames = false;
357+
355358
@override
356359
bool muted = false;
357360

packages/fleather/test/widgets/editor_input_client_mixin_test.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,46 @@ import 'package:flutter_test/flutter_test.dart';
77
import '../testing.dart';
88

99
void main() {
10+
group('onFocusReceived', () {
11+
testWidgets('requests focus when the editor can receive focus',
12+
(tester) async {
13+
final editor = EditorSandBox(tester: tester);
14+
await editor.pump();
15+
16+
final inputClient = getInputClient();
17+
expect(editor.focusNode.hasFocus, isFalse);
18+
19+
expect(inputClient.onFocusReceived(), isTrue);
20+
await tester.pump();
21+
22+
expect(editor.focusNode.hasFocus, isTrue);
23+
});
24+
25+
testWidgets('returns false when the editor already has focus',
26+
(tester) async {
27+
final editor = EditorSandBox(tester: tester);
28+
await editor.pumpAndTap();
29+
30+
final inputClient = getInputClient();
31+
32+
expect(inputClient.onFocusReceived(), isFalse);
33+
expect(editor.focusNode.hasFocus, isTrue);
34+
});
35+
36+
testWidgets('returns false when focus cannot be requested', (tester) async {
37+
final focusNode = FocusNode(canRequestFocus: false);
38+
final editor = EditorSandBox(tester: tester, focusNode: focusNode);
39+
await editor.pump();
40+
41+
final inputClient = getInputClient();
42+
43+
expect(inputClient.onFocusReceived(), isFalse);
44+
await tester.pump();
45+
46+
expect(focusNode.hasFocus, isFalse);
47+
});
48+
});
49+
1050
group('send text editing state to TextInputConnection', () {
1151
final composingRanges = <TextRange>[];
1252

packages/fleather/test/widgets/editor_intents_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ void main() {
237237
baseOffset: 13, extentOffset: 0, affinity: TextAffinity.upstream));
238238
});
239239

240-
testWidgets('$ExtendSelectionByPageIntent selection to end', (tester) async {
240+
testWidgets('$ExtendSelectionVerticallyToAdjacentPageIntent selection to end',
241+
(tester) async {
241242
final editor = EditorSandBox(
242243
tester: tester,
243244
document: ParchmentDocument.fromJson([
@@ -253,7 +254,8 @@ void main() {
253254
baseOffset: 3, extentOffset: 19, affinity: TextAffinity.upstream));
254255
});
255256

256-
testWidgets('$ExtendSelectionByPageIntent selection to end', (tester) async {
257+
testWidgets('$ExtendSelectionVerticallyToAdjacentPageIntent selection to end',
258+
(tester) async {
257259
final editor = EditorSandBox(
258260
tester: tester,
259261
document: ParchmentDocument.fromJson([

packages/fleather/test/widgets/editor_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,9 @@ void main() {
13231323
if (node.value.type == 'icon') {
13241324
final data = node.value.data;
13251325
return Icon(
1326+
// ignore: non_const_argument_for_const_parameter
13261327
IconData(int.parse(data['codePoint']),
1328+
// ignore: non_const_argument_for_const_parameter
13271329
fontFamily: data['fontFamily']),
13281330
color: Color(int.parse(data['color'])),
13291331
size: 100,
@@ -1420,7 +1422,9 @@ void main() {
14201422
if (node.value.type == 'icon') {
14211423
final data = node.value.data;
14221424
return Icon(
1425+
// ignore: non_const_argument_for_const_parameter
14231426
IconData(int.parse(data['codePoint']),
1427+
// ignore: non_const_argument_for_const_parameter
14241428
fontFamily: data['fontFamily']),
14251429
color: Color(int.parse(data['color'])),
14261430
size: 100,

0 commit comments

Comments
 (0)