Home > Enterprise >  flutter stream shows error type '_TypeError' is not a subtype of type 'String'
flutter stream shows error type '_TypeError' is not a subtype of type 'String'

Time:10-19

I'm new to flutter, I need to read data from api and store in a list, but I get the error type '_TypeError' is not a subtype of type 'String', please help me

class HomeController extends ControllerMVC {
List<Slide> slides = <Slide>[];
HomeController() {
  listenForSlides();
}
Future<void> listenForSlides() async {
  final Stream<Slide> stream = await getSlides();
  stream.listen((Slide _slide) {
    setState(() => slides.add(_slide));
  }, one rror: (a) {
    print(a);
  }, onDone: () {});
}


Future<void> refreshHome() async {
  setState(() {
    slides = <Slide>[];
  });
  await listenForSlides();
}

}

CodePudding user response:

the onError is an object not a string, if you want to print out the whole error stack object add a .toString():

 one rror: (a, stackTrace) {
    print(a.toString());
  }, onDone: () {});
  • Related