init property

  1. @override
dynamic Function() get init
override

Initialize your widget in init.

  • init is called in the initState method. You can use this method to perform any operations before the widget is rendered.

E.g.

get init => () async {
  await api<ApiService>((request) => request.fetchData());
  setState(() {});
};

Implementation

@override
get init => () {
  final dynamic navData = data();
  int? activeTab;
  if (navData is Map && navData.containsKey('tab-index')) {
    activeTab = navData['tab-index'];
  }
  currentIndex ??= activeTab ?? initialIndex;

  // Store current tab index and total pages count for navigation helpers
  Backpack.instance.save('${stateName}_current_tab', currentIndex);

  _loadPages();
};