Wie man Echtzeitdaten zum Flattern bekommt
Stream<Object> objectStream() async* {
while (true) {
await Future.delayed(Duration(milliseconds: 500));
Object object = getObjectFromAPI();
yield object; //yield is like return
}
}
// add this widget
StreamBuilder(
stream: objectStream(),
builder: (context, snapshot) {
if(snapShot.connectionState == ConnectionState.waiting){
// do something
}else if (snapShot.data != null) {
// do something
}
}
)
// to prevent restarting with every set state you can create
late Stream<Object?> objectStream;
@override
void initState() {
// add data to it from here
objectStream = objectStream();
super.initState();
}
FunnyPointerException :|)