Im trying to stream data from a JSON file I have into my app using StreamController
in my case I want to constantly update the balance. I think its failing on reloading the file, it might be loading only the first time and that could why it is not updating the number, also because when i press hot reload it gets the correct value
Stream<double> initBalance() async* {
final response = await rootBundle
.loadString('lib/assets/data.json')
.then((jsonStr) => jsonDecode(jsonStr));
yield double.parse(response['balance']);
}
MainController mainController;
StreamController<double> streamController;
@override
void initState() {
super.initState();
this.mainController = new MainController();
this.streamController = new StreamController();
getData();
}
getData() {
Timer.periodic(Duration(seconds: 1), (timer) async {
var test = this.mainController.initBalance();
this.streamController.sink.addStream(test);
});
}