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() {
xDataType = K;
if (widget.xCells_EditType == null) {
widget.xCells_EditType = XEnums.editType.form;
}
widget.liCols_EditData = List<XCol>.empty(growable: true);
//Starto il loading dell'Elenco
_isLoaded = ValueNotifier(true);
//Preparo le Liste vuote a livello di State di XElenco
xActionLi_LEFT = List<XAction>.empty(growable: true);
xActionLi_RIGHT = List<XAction>.empty(growable: true);
xActionLi_FAST = List<XAction>.empty(growable: true);
xAppBar_Widgets_LEFT = List<Widget>.empty(growable: true);
xAppBar_Widgets_RIGHT = List<Widget>.empty(growable: true);
//Riempio le Actions Fast cone le Azioni Base
xActionLi_FAST!.addAll([XActionsBase.showXMedia, XActionsBase.addXMedia, XActionsBase.addDett, XActionsBase.popUpActions]);
if (widget.xTab_List == null) widget.xTab_List = List<XTabItem>.empty(growable: true);
if (widget.edited == null) widget.edited = ValueNotifier(false);
if (widget.xCells_Item_TextStyle == null) widget.xCells_Item_TextStyle = (xCol, item, color) => XStyles.xStyTextForLabel(textColor: color == Colors.black ? XColors.foregroundLight : color);
if (searchBar_StyleText == null) searchBar_StyleText = XStyles.xStyTextForSubLabel(textColor: widget.searchBar_ColorHint ?? XColors.foregroundLight);
//Carico i Dati
xLoadDataOnly();
if (widget.xApp!.enterpriseMode) {
//add a cell with a button to "open the scheda" (await xOnTapItem_INTERNAL(xDSource!.rows[details.rowColumnIndex.rowIndex - 1].item as K);)
if (widget.xOpenScheda_Enabled && widget.view!.cols.any((element) => element.colKey == "btn").not()) widget.view!.cols.insert(0, XCol("btn", "", 50, XProp("btn", "", XColors.enterpriseMode_Foreground)));
dataGridController = DataGridController();
xgds = xLoadData_getXGDS;
xDSource = xgds();
// widget.xgds_Origin != null ? xgds = () => widget.xgds_Origin!() : null;
}
//Riempio le liste con gli oggetti che mi aggiungono nelle Actions
xActions_LoadLists();
//Inizializzo i Filtri
initXFilters();
//Ciclo per tutte le colonne della view che mmi passano e vado a ordinare la lista con le propietà passate
widget.view!.cols.forEach((element) {
if (xFilter_OrderBy_XProps.any((xProp) => xProp.col_Name == element.colKey)) element.sorted = true;
});
if (widget.liDetts != null) {
for (var xProp in xFilter_OrderBy_XProps) {
widget.liDetts!.orderBy([xProp.col_Name], desc: (widget.view!.cols.firstWhere((element) => element.colKey == (xProp.col_Name.endsWith("ID") ? xProp.col_Name + "_resolved" : xProp.col_Name)).sorted ?? false).not());
}
} else {
for (var xProp in xFilter_OrderBy_XProps) {
list.orderBy([xProp.col_Name], desc: (widget.view!.cols.firstWhere((element) => element.colKey == (xProp.col_Name.endsWith("ID") ? xProp.col_Name + "_resolved" : xProp.col_Name)).sorted ?? false).not());
}
}
//metto in ascolto il searchController
searchController.addListener(
() => setState(() {
xFilterValue = searchController.text;
if (timerSearch != null) timerSearch!.cancel();
timerSearch = Timer(Duration(milliseconds: 300), timerSearchHandlerList);
}),
);
//Aggiungo la lista che mi passano se me la passano in ascolto per eventuali cambi di UI per delle Changes fatte su di essa
if (xListObservable_Hook != null) xListObservable_Hook!.changes.listen((event) => neededRealoadData = true);
//Riempio la Lista a livello di State dell'elenco degli XMedia partendo dall'originale che mi passano
if (widget.liXMediaToUse != null) liMediaRAW = widget.liXMediaToUse!;
//Se Flag dell'elenco xActions_AddNota_isActive è attivo aggiungo l'azione all'itemComplex dell'AddNota
if (xActions_AddNota_isActive) {
xActionLi_RIGHT!.add(XAction(
"addNotaVuota",
0,
"",
icon: Icons.note_add_outlined,
label_Color: Colors.white,
toolTip: "Aggiungi una nota vuota",
fastAction: false,
cmd: (itemActive, parentSetState, context) async => await xCMD_AddNewNota(itemActive, parentSetState),
));
}
super.initState();
//BL post initState
if (kIsWeb.not()) {
//Preparo il playerController per il VideoRecorder e l'AudioPlayer
playerController = PlayerController();
playerStateSubscription = playerController.onPlayerStateChanged.listen((_) => setState(() {}));
}
//Preparo il TabContreoller per le Tab ipotetiche nell'Elenco
tabController = TabController(length: widget.xTab_List!.length, vsync: this, initialIndex: xCurrentTabIdx, animationDuration: Duration.zero);
var _controllerIsValid = tabController.animation != null;
if (_controllerIsValid) {
tabController.addListener(() => setState(() => xCurrentTabIdx = tabController.index));
tabController.animation!.addListener(() => setState(() => xCurrentTabIdx = tabController.index));
}
// calcRow(null);
Future.delayed(
Duration(milliseconds: 500),
() async {
KeyboardVisibilityController().onChange.listen((bool visible) {
isKeyboardVisible = visible;
if (isKeyboardVisible.not() && itemSelectedInEdit != null) {
widget.rootItemEdited!(itemSelectedInEdit as K);
}
});
},
);
if (widget.xApp!.enterpriseMode) {
widget.item_Widget = null;
}
}