Skip to content

Commit e76a33e

Browse files
committed
StreamSync : Added backspace
Signed-off-by: Aviral Jain <aviraljainltr@gmail.com>
1 parent ecfc1a9 commit e76a33e

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

lib/RemoteConnectionPage.dart

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class _RemoteConnectionPageState extends State<RemoteConnectionPage> {
3434

3535
List<_Message> messages = [];
3636
String _messageBuffer = '';
37-
37+
String _previousText = '';
3838
final TextEditingController textEditingController =
3939
new TextEditingController();
4040
final ScrollController listScrollController = new ScrollController();
@@ -56,6 +56,7 @@ class _RemoteConnectionPageState extends State<RemoteConnectionPage> {
5656
@override
5757
void initState() {
5858
super.initState();
59+
textEditingController.addListener(_onTextChanged);
5960
prevFocalPoint = Offset.zero;
6061
prevScale = 0.0;
6162

@@ -692,7 +693,7 @@ class _RemoteConnectionPageState extends State<RemoteConnectionPage> {
692693
child: TextField(
693694
style: const TextStyle(fontSize: 15.0),
694695
controller: textEditingController,
695-
onChanged: _sendStringToType,
696+
//onChanged: _sendStringToType,
696697
decoration: InputDecoration.collapsed(
697698
hintText: (isConnecting
698699
? 'Wait until connected...'
@@ -822,7 +823,7 @@ class _RemoteConnectionPageState extends State<RemoteConnectionPage> {
822823
if (text != null && text.isNotEmpty) {
823824
text = text.trim();
824825
if (text.length > 0) {
825-
textEditingController.clear();
826+
//textEditingController.clear();
826827
_bluetoothConnection.output.add(ascii.encode(text + "\r\n"));
827828
}
828829
}
@@ -963,14 +964,32 @@ class _RemoteConnectionPageState extends State<RemoteConnectionPage> {
963964
late double prevScale;
964965

965966
_sendStringToType(String text) {
966-
_sendMessage("*#*TYPE$text*@*");
967+
String _finalText = text[text.length -1];
968+
_sendMessage("*#*TYPE$_finalText*@*");
967969
}
968970

969971
void accelerometerControl(bool isOn) {
970972
setState(() {
971973
this.isGyroOn = isOn;
972974
});
973975
}
976+
977+
void _onTextChanged() {
978+
String currentText = textEditingController.text;
979+
print(currentText);
980+
if (_previousText.length > currentText.length) {
981+
print("Backspace pressed!");
982+
_onBackspacePressed();
983+
}
984+
else{
985+
_sendStringToType(currentText);
986+
}
987+
_previousText = currentText;
988+
}
989+
990+
void _onBackspacePressed() {
991+
presentCurrent();
992+
}
974993
}
975994

976995

pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,10 @@ packages:
417417
dependency: transitive
418418
description:
419419
name: vm_service
420-
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
420+
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
421421
url: "https://pub.dev"
422422
source: hosted
423-
version: "14.2.4"
423+
version: "14.2.5"
424424
web:
425425
dependency: transitive
426426
description:

0 commit comments

Comments
 (0)