@@ -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
0 commit comments