Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate flutter 3.19 #188

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions example/lib/ssh.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';

import 'package:dartssh2/dartssh2.dart';
import 'package:example/src/virtual_keyboard.dart';
Expand Down Expand Up @@ -77,7 +76,7 @@ class _MyHomePageState extends State<MyHomePage> {
};

terminal.onOutput = (data) {
session.write(utf8.encode(data) as Uint8List);
session.write(utf8.encode(data));
};

session.stdout
Expand Down
2 changes: 1 addition & 1 deletion example/lib/suggestion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class _HomeState extends State<Home> {
autofocus: true,
backgroundOpacity: 0.7,
onKey: (node, event) {
if (event is! RawKeyDownEvent) {
if (event is! KeyDownEvent) {
return KeyEventResult.ignored;
}

Expand Down
70 changes: 51 additions & 19 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.18.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -264,6 +264,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.8.1"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "2.0.1"
lints:
dependency: "direct dev"
description:
Expand All @@ -276,26 +300,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.15"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.11.0"
package_config:
dependency: transitive
description:
Expand All @@ -308,10 +332,10 @@ packages:
dependency: "direct main"
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.9.0"
petitparser:
dependency: transitive
description:
Expand Down Expand Up @@ -393,26 +417,26 @@ 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:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
Expand All @@ -433,10 +457,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.6.1"
typed_data:
dependency: transitive
description:
Expand All @@ -453,6 +477,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "13.0.0"
watcher:
dependency: transitive
description:
Expand Down Expand Up @@ -501,5 +533,5 @@ packages:
source: hosted
version: "0.0.6"
sdks:
dart: ">=3.0.0 <4.0.0"
dart: ">=3.2.0-0 <4.0.0"
flutter: ">=3.10.0"
32 changes: 17 additions & 15 deletions lib/src/terminal_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TerminalView extends StatefulWidget {
this.controller,
this.theme = TerminalThemes.defaultTheme,
this.textStyle = const TerminalStyle(),
this.textScaleFactor,
this.textScaler,
this.padding,
this.scrollController,
this.autoResize = true,
Expand Down Expand Up @@ -63,9 +63,9 @@ class TerminalView extends StatefulWidget {
final TerminalStyle textStyle;

/// The number of font pixels for each logical pixel. If null, will use the
/// [MediaQueryData.textScaleFactor] obtained from [MediaQuery], or 1.0 if
/// [MediaQueryData.textScaler] obtained from [MediaQuery], or 1.0 if
/// there is no [MediaQuery] in scope.
final double? textScaleFactor;
final TextScaler? textScaler;

/// Padding around the inner [Scrollable] widget.
final EdgeInsets? padding;
Expand Down Expand Up @@ -129,7 +129,7 @@ class TerminalView extends StatefulWidget {

/// Keyboard event handler of the terminal. This has higher priority than
/// [shortcuts] and input handler of the terminal.
final FocusOnKeyCallback? onKey;
final FocusOnKeyEventCallback? onKey;

/// True if no input should send to the terminal.
final bool readOnly;
Expand Down Expand Up @@ -233,8 +233,7 @@ class TerminalViewState extends State<TerminalView> {
padding: MediaQuery.of(context).padding,
autoResize: widget.autoResize,
textStyle: widget.textStyle,
textScaleFactor:
widget.textScaleFactor ?? MediaQuery.textScaleFactorOf(context),
textScaler: widget.textScaler ?? MediaQuery.textScalerOf(context),
theme: widget.theme,
focusNode: _focusNode,
cursorType: widget.cursorType,
Expand Down Expand Up @@ -394,7 +393,7 @@ class TerminalViewState extends State<TerminalView> {
setState(() => _composingText = text);
}

KeyEventResult _handleKeyEvent(FocusNode focusNode, RawKeyEvent event) {
KeyEventResult _handleKeyEvent(FocusNode focusNode, KeyEvent event) {
final resultOverride = widget.onKey?.call(focusNode, event);
if (resultOverride != null && resultOverride != KeyEventResult.ignored) {
return resultOverride;
Expand All @@ -410,7 +409,7 @@ class TerminalViewState extends State<TerminalView> {
return shortcutResult;
}

if (event is! RawKeyDownEvent) {
if (event is! KeyDownEvent) {
return KeyEventResult.ignored;
}

Expand All @@ -422,9 +421,12 @@ class TerminalViewState extends State<TerminalView> {

final handled = widget.terminal.keyInput(
key,
ctrl: event.isControlPressed,
alt: event.isAltPressed,
shift: event.isShiftPressed,
ctrl: event.physicalKey == PhysicalKeyboardKey.controlLeft ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll find that the shift and control keys don't work as expected in your terminal editor. According to the RawKeyEvent docs the correct replacement for isShiftPressed is HardwareKeyboard.isShiftPressed.

See https://github.com/TerminalStudio/xterm.dart/pull/190/files#diff-d62cc3ae7257875f8ff5223bcb0ba25023d5e12166597467e693d3f10378b87eR423 for my implementation.

Hth!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I will modify it later. Thanks.

event.physicalKey == PhysicalKeyboardKey.controlRight,
alt: event.physicalKey == PhysicalKeyboardKey.altLeft ||
event.physicalKey == PhysicalKeyboardKey.altRight,
shift: event.physicalKey == PhysicalKeyboardKey.shiftLeft ||
event.physicalKey == PhysicalKeyboardKey.shiftRight,
);

if (handled) {
Expand Down Expand Up @@ -463,7 +465,7 @@ class _TerminalView extends LeafRenderObjectWidget {
required this.padding,
required this.autoResize,
required this.textStyle,
required this.textScaleFactor,
required this.textScaler,
required this.theme,
required this.focusNode,
required this.cursorType,
Expand All @@ -484,7 +486,7 @@ class _TerminalView extends LeafRenderObjectWidget {

final TerminalStyle textStyle;

final double textScaleFactor;
final TextScaler textScaler;

final TerminalTheme theme;

Expand All @@ -507,7 +509,7 @@ class _TerminalView extends LeafRenderObjectWidget {
padding: padding,
autoResize: autoResize,
textStyle: textStyle,
textScaleFactor: textScaleFactor,
textScaler: textScaler,
theme: theme,
focusNode: focusNode,
cursorType: cursorType,
Expand All @@ -526,7 +528,7 @@ class _TerminalView extends LeafRenderObjectWidget {
..padding = padding
..autoResize = autoResize
..textStyle = textStyle
..textScaleFactor = textScaleFactor
..textScaler = textScaler
..theme = theme
..focusNode = focusNode
..cursorType = cursorType
Expand Down
5 changes: 3 additions & 2 deletions lib/src/ui/char_metrics.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import 'dart:ui';

import 'package:flutter/painting.dart';
import 'package:xterm/src/ui/terminal_text_style.dart';

Size calcCharSize(TerminalStyle style, double textScaleFactor) {
Size calcCharSize(TerminalStyle style, TextScaler textScaler) {
const test = 'mmmmmmmmmm';

final textStyle = style.toTextStyle();
final builder = ParagraphBuilder(textStyle.getParagraphStyle());
builder.pushStyle(textStyle.getTextStyle(textScaleFactor: textScaleFactor));
builder.pushStyle(textStyle.getTextStyle(textScaler: textScaler));
builder.addText(test);

final paragraph = builder.build();
Expand Down
6 changes: 3 additions & 3 deletions lib/src/ui/custom_text_edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CustomTextEdit extends StatefulWidget {

final void Function(TextInputAction) onAction;

final KeyEventResult Function(FocusNode, RawKeyEvent) onKey;
final KeyEventResult Function(FocusNode, KeyEvent) onKey;

final FocusNode focusNode;

Expand Down Expand Up @@ -90,7 +90,7 @@ class CustomTextEditState extends State<CustomTextEdit> with TextInputClient {
return Focus(
focusNode: widget.focusNode,
autofocus: widget.autofocus,
onKey: _onKey,
onKeyEvent: _onKey,
child: widget.child,
);
}
Expand Down Expand Up @@ -133,7 +133,7 @@ class CustomTextEditState extends State<CustomTextEdit> with TextInputClient {
_openOrCloseInputConnectionIfNeeded();
}

KeyEventResult _onKey(FocusNode focusNode, RawKeyEvent event) {
KeyEventResult _onKey(FocusNode focusNode, KeyEvent event) {
if (_currentEditingState.composing.isCollapsed) {
return widget.onKey(focusNode, event);
}
Expand Down
27 changes: 13 additions & 14 deletions lib/src/ui/keyboard_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CustomKeyboardListener extends StatelessWidget {

final void Function(String?) onComposing;

final KeyEventResult Function(FocusNode, RawKeyEvent) onKey;
final KeyEventResult Function(FocusNode, KeyEvent) onKey;

const CustomKeyboardListener({
Key? key,
Expand All @@ -24,7 +24,7 @@ class CustomKeyboardListener extends StatelessWidget {
required this.onKey,
}) : super(key: key);

KeyEventResult _onKey(FocusNode focusNode, RawKeyEvent keyEvent) {
KeyEventResult _onKey(FocusNode focusNode, KeyEvent keyEvent) {
// First try to handle the key event directly.
final handled = onKey(focusNode, keyEvent);
if (handled == KeyEventResult.ignored) {
Expand All @@ -33,20 +33,19 @@ class CustomKeyboardListener extends StatelessWidget {
if (keyEvent.character != null && keyEvent.character != "") {
onInsert(keyEvent.character!);
return KeyEventResult.handled;
} else if (keyEvent.data is RawKeyEventDataIos &&
keyEvent is RawKeyDownEvent) {
} else if (keyEvent is KeyDownEvent) {
// On iOS keyEvent.character is always null. But data.characters
// contains the the character(s) corresponding to the input.
final data = keyEvent.data as RawKeyEventDataIos;
if (data.characters != "") {
final data = keyEvent.logicalKey.keyLabel;
if (data != "") {
onComposing(null);
onInsert(data.characters);
} else if (data.charactersIgnoringModifiers != "") {
// If characters is an empty string but charactersIgnoringModifiers is
// not an empty string, this indicates that the current characters is
// being composed. The current composing state is
// charactersIgnoringModifiers.
onComposing(data.charactersIgnoringModifiers);
onInsert(data);
// } else if (data.charactersIgnoringModifiers != "") {
// // If characters is an empty string but charactersIgnoringModifiers is
// // not an empty string, this indicates that the current characters is
// // being composed. The current composing state is
// // charactersIgnoringModifiers.
// onComposing(data.charactersIgnoringModifiers);
}
}
}
Expand All @@ -58,7 +57,7 @@ class CustomKeyboardListener extends StatelessWidget {
return Focus(
focusNode: focusNode,
autofocus: autofocus,
onKey: _onKey,
onKeyEvent: _onKey,
child: child,
);
}
Expand Down
Loading