Так что я пытаюсь сделать очень простую вещь (в теории). Я хочу общаться с моим Raspberry Pi и хочу превратить его в приложение. Я смотрел на флаттерные пакеты, и есть один, который позволяет вам ssh. Поэтому я подумал, что я просто запустил ssh в свой Pi и запустил скрипт, но я получил сообщение об ошибке, которое понятия не имею, что это значит. Спасибо за помощь в продвижении! Вот мой код и ошибка:
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:ssh/ssh.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Lights',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Center(
child: RaisedButton(
onPressed: lightsOff,
child: Text("Lights Off"),
),
),
],
),
);
}
Future<void> lightsOff() async {
final pi = new SSHClient(
host: "IP_ADDRESS",
port: 22,
username: "pi",
passwordOrKey: "raspberry",
);
String result;
try {
result = await pi.connect();
if (result == "session_connected")
result = await pi.execute("sudo python /home/pi/Desktop/scripts/lightOff.py");
} on PlatformException catch (e) {
print('Error: ${e.code}\nError Message: ${e.message}');
}
}
}
Ошибка:
flutter: ══╡ EXCEPTION CAUGHT BY SERVICES LIBRARY ╞══════════════════════════════════════════════════════════
flutter: The following MissingPluginException was thrown while activating platform stream on channel
flutter: shell_sftp:
flutter: MissingPluginException(No implementation found for method listen on channel shell_sftp)
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:291:7)
flutter: <asynchronous suspension>
flutter: #1 EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:437:29)
flutter: <asynchronous suspension>
flutter: #9 new SSHClient (package:ssh/ssh.dart:40:40)
flutter: #10 _MyHomePageState.lightsOff (package:lights/main.dart:48:20)
flutter: <asynchronous suspension>
flutter: #11 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
flutter: #12 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
flutter: #13 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
flutter: #14 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
flutter: #15 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7)
flutter: #16 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
flutter: #17 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
flutter: #18 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
flutter: #19 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:180:19)
flutter: #20 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:158:22)
flutter: #21 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:138:7)
flutter: #22 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
flutter: #23 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7)
flutter: #24 _invoke1 (dart:ui/hooks.dart:168:13)
flutter: #25 _dispatchPointerDataPacket (dart:ui/hooks.dart:122:5)
flutter: (elided 7 frames from package dart:async)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
[VERBOSE-2:shell.cc(184)] Dart Error: Unhandled exception:
MissingPluginException(No implementation found for method connectToHost on channel ssh)
#0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:291:7)
<asynchronous suspension>
#1 SSHClient.connect (package:ssh/ssh.dart:63:33)
<asynchronous suspension>
#2 _MyHomePageState.lightsOff (package:lights/main.dart:57:25)
#3 _AsyncAwaitCompleter.start (dart:async/runtime/libasync_patch.dart:49:6)
#4 _MyHomePageState.lightsOff (package:lights/main.dart:47:25)
#5 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
#6 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
#7 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
#8 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
#9 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gesture<…>