initState method
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() {
widget.xCell_borderColor = XSchedaState.color_Border;
widget.xCell_borderColor_Disabled = XSchedaState.color_BorderDisabled;
widget.xCell_labelColor_Disabled = XSchedaState.color_LabelText; //color_TextDisabled;
if (widget.itemInEdit.id == "") widget.itemInEdit.isNew = true;
//Inizializzo la Scheda
init_Sch();
//Riempio le liste delle Actions se si è aggiunto qualcosa
//DD lo fa già xBottomBarAction_Fill xActions_LoadLists();
//Riempio i Tabs
_xfillxTabs();
//Inizializzo la BottomBar
xBottomBarAction_Fill();
//Inizializzo le TABS con le liste dei Detts della Scheda
if (xTabs.value.isNotEmpty) xTab_Active = xTabs.value.first;
//controllo se ci sono bottoni per l'aggiunta di items dett
//Inizializzo l'Audio player per la gestione degli Audio
audioPlayers = [AudioPlayer(playerId: "1")];
super.initState();
if (xInitList_AddDetts().isNotEmpty) widget.allowAddDetts = true;
if (kIsWeb.not()) {
//Preparo il playerController per il VideoRecorder e l'AudioPlayer
playerController = PlayerController();
// playerStateSubscription = playerController.onPlayerStateChanged.listen((_) => setState(() {}));
}
color_Text = ThemeData.estimateBrightnessForColor(widget.backGroundColor!) == Brightness.light ? Colors.black : Color.fromARGB(255, 255, 255, 255);
color_LabelText = ThemeData.estimateBrightnessForColor(widget.backGroundColor!) == Brightness.light ? Colors.black : Color.fromARGB(255, 255, 255, 255);
if (kIsWeb) {
// html.window.onBeforeUnload.listen((event) async {
// await xCMD_Back();
// // event.returnValue = 'Sei sicuro di voler uscire?';
// });
// Aggiungi un listener per intercettare il tasto "back" del browser
html.window.onPopState.listen((html.PopStateEvent event) async {
// print("Back premuto nel browser!");
await xCMD_Back();
});
}
}