initState method

  1. @override
void initState()
override

Called when this object is inserted into the tree.

The framework will call this method exactly once for each State object it creates.

Override this method to perform initialization that depends on the location at which this object was inserted into the tree (i.e., context) or on the widget used to configure this object (i.e., widget).

If a State's build method depends on an object that can itself change state, for example a ChangeNotifier or Stream, or some other object to which one can subscribe to receive notifications, then be sure to subscribe and unsubscribe properly in initState, didUpdateWidget, and dispose:

  • In initState, subscribe to the object.
  • In didUpdateWidget unsubscribe from the old object and subscribe to the new one if the updated widget configuration requires replacing the object.
  • In dispose, unsubscribe from the object.

You should not use BuildContext.dependOnInheritedWidgetOfExactType from this method. However, didChangeDependencies will be called immediately following this method, and BuildContext.dependOnInheritedWidgetOfExactType can be used there.

Implementations of this method should start with a call to the inherited method, as in super.initState().

Implementation

@override
void initState() {
  //Settare quali Dashboard andranno visualizzate all'interno della liDashboard
  liDashBoardIndexesDecodedFromURL = List<int>.empty(growable: true);
  liDashBoardIndexesDecodedFromURL_timeOfView = List<int>.empty(growable: true);

  ///Stabilisco quante Dash deve far vedere l'XPlayer e in che sequenza
  var res = initMainDash();
  XPlayer.liXDashBoard.addAll(widget.liDash);
  if (res) {
    //decodifico liDashBoardIndexesByURL
    // 1,3.30,0 >= la 1 per timeOut std, la 3 con timeOut 30sec, la 0
    var parts = widget.urlParams.split(',');
    print(parts);
    for (var dashCode in parts) {
      var timeOutDash = defaultTimeOutForDash;
      var idxDash = -1;
      var dashCodeParts = dashCode.split('.');
      print(dashCodeParts);

      if (dashCodeParts.length >= 1) {
        idxDash = int.parse(dashCodeParts[0]);
        if (dashCodeParts.length >= 2) timeOutDash = int.parse(dashCodeParts[1]);
      }
      if (idxDash >= 0) {
        liDashBoardIndexesDecodedFromURL.add(idxDash);
        liDashBoardIndexesDecodedFromURL_timeOfView.add(timeOutDash);
      }
    }
  } else {}
  //definisce elenco definitivo delle dash da visualizzare e apllica i timeOfView
  for (var i = 0; i < liDashBoardIndexesDecodedFromURL.length; i++) {
    XPlayer.liXDashBoard[liDashBoardIndexesDecodedFromURL[i]].timeOfView = liDashBoardIndexesDecodedFromURL_timeOfView[i];
  }

  ///Chiamo il Refresh
  init();

  ///inserisco nella lista di Dash dell'XPlayer tutte le Dash che dovrò visualizzare
  super.initState();
}