I've been trying to get this to work, but with no success. I get this error: type '_HandleErrorStream<dynamic>' is not a subtype of type 'Stream<String>'
This seems to happen when i try to add the websocket to the streamController
. I dont know that is the right way to do it.
class FoodProvider {
List<String> comments;
IOWebSocketChannel webSocketChannel;
StreamController<String> streamController = StreamController<String>.broadcast();
Stream<String> get stream => streamController.stream;
FoodProvider() {
foodName = <String>[];
webSocketChannel = IOWebSocketChannel.connect("ws://myip:8080");
streamController = StreamController.broadcast();
streamController.addStream(webSocketChannel.stream);
}
void dispose() {
webSocketChannel.sink.close();
streamController.close();
}
}
StreamProvider<String>.value(
value: FoodProvider().stream,
initialData: null,
catchError: (_, __) => null,
child: const FoodWidget(),
),
class Test extends StatelessWidget {
const Test();
@override
Widget build(BuildContext context) {
return child: Center(
child: Consumer<String>(
builder: (context, String food, child) {
return Column(
children: <Widget>[
Text("Food Name: $food"),
],
);
},
),
);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…