# Syrius: Fix realtime statistics refresh

**URL:** http://forum.zenon.org/t/syrius-fix-realtime-statistics-refresh/1347
**Category:** Archived
**Created:** [April 5, 2023, 2:48pm UTC](http://forum.zenon.org/t/syrius-fix-realtime-statistics-refresh/1347 "2023-04-05T14:48:35Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![CryptoFish](http://forum.zenon.org/user_avatar/forum.zenon.org/cryptofish/32/171_2.png) [@CryptoFish](http://forum.zenon.org/u/CryptoFish)
#### Post date: [April 5, 2023, 2:48pm UTC](http://forum.zenon.org/t/syrius-fix-realtime-statistics-refresh/1347/1 "2023-04-05T14:48:35Z")

</div>

# What?

The `RealtimeStatistics` widget periodically fetches data on each new momentum, but does not update the `RealtimeTxsChart` widget with the newly retrived data. The new data is only loaded when navigating from another tab.

# Why?

The `RealtimeTxsChart` widget generates the Znn and Qsr spots data when the widget is initialized in the `initState` method.

```dart
@override
  void initState() {
    super.initState();
    _znnSpots = _generateZnnSpots();
    _qsrSpots = _generateQsrSpots();
  }

```

This method is only called once when the widget is created. When the stream is updated, the widget gets rebuild but does not generate new spots.

# How?

The `RealtimeTxsChart` widget must generate the Znn and Qsr spots data whenever the widget configuration changes by overriding the `didUpdateWidget` method.

```dart
@override
  void didUpdateWidget(RealtimeTxsChart oldWidget) {
    _znnSpots = _generateZnnSpots();
    _qsrSpots = _generateQsrSpots();
    super.didUpdateWidget(oldWidget);
  }

```

# Anything else?

This PR depends on PR [Fix realtime graph by KingGorrin · Pull Request #7 · zenon-network/syrius · GitHub](https://github.com/zenon-network/syrius/pull/7); otherwise no chart will be displayed.

# Implementation

> <https://github.com/zenon-network/syrius/pull/15>
>
> \# What?
> 
> The \`RealtimeStatistics\` widget periodically fetches data on each new… momentum, but does not update the \`RealtimeTxsChart\` widget with the newly retrived data. The new data is only loaded when navigating from another tab.
> 
> \# Why?
> 
> The \`RealtimeTxsChart\` widget generates the Znn and Qsr spots data when the widget is initialized in the \`initState\` method. 
> 
> \`\`\` dart
> @override
> void initState() {
> super.initState();
> \_znnSpots = \_generateZnnSpots();
> \_qsrSpots = \_generateQsrSpots();
> }
> \`\`\`
> 
> This method is only called once when the widget is created. When the stream is updated, the widget gets rebuild but does not generate new spots. 
> 
> \# How?
> 
> The \`RealtimeTxsChart\` widget must generate the Znn and Qsr spots data whenever the widget configuration changes by overriding the \`didUpdateWidget\` method.
> 
> \`\`\` dart
> @override
> void didUpdateWidget(RealtimeTxsChart oldWidget) {
> \_znnSpots = \_generateZnnSpots();
> \_qsrSpots = \_generateQsrSpots();
> super.didUpdateWidget(oldWidget);
> }
> \`\`\`
> 
> \# Anything else?
> 
> This PR depends on PR https://github.com/zenon-network/syrius/pull/7; otherwise no chart will be displayed.

---

<div class="post-metadata">

### Author: ![mehowbrainz](http://forum.zenon.org/user_avatar/forum.zenon.org/mehowbrainz/32/1532_2.png) [@mehowbrainz](http://forum.zenon.org/u/mehowbrainz)
#### Post date: [September 12, 2023, 7:00pm UTC](http://forum.zenon.org/t/syrius-fix-realtime-statistics-refresh/1347/2 "2023-09-12T19:00:26Z")

</div>



---

<div class="post-metadata">

### Author: ![mehowbrainz](http://forum.zenon.org/user_avatar/forum.zenon.org/mehowbrainz/32/1532_2.png) [@mehowbrainz](http://forum.zenon.org/u/mehowbrainz)
#### Post date: [September 12, 2023, 7:00pm UTC](http://forum.zenon.org/t/syrius-fix-realtime-statistics-refresh/1347/3 "2023-09-12T19:00:41Z")

</div>



---

<div class="post-metadata">

### Author: ![mehowbrainz](http://forum.zenon.org/user_avatar/forum.zenon.org/mehowbrainz/32/1532_2.png) [@mehowbrainz](http://forum.zenon.org/u/mehowbrainz)
#### Post date: [September 12, 2023, 7:01pm UTC](http://forum.zenon.org/t/syrius-fix-realtime-statistics-refresh/1347/4 "2023-09-12T19:01:20Z")

</div>


