setNewIndex method
Called when switching to new tab Consider using a SynchronousFuture if the result can be computed synchronously.
Implementation
Future<int?> setNewIndex(int index) async {
if (index < 0 || index >= _descriptors.length || curRouteIndex == index) {
return SynchronousFuture(null);
}
int preIndex = curRouteIndex;
setState(() {
curRouteIndex = index;
_routes = _buildTabRoutes(_descriptors);
});
_routes[index].controller?.onFocused(true);
_routes[preIndex].controller?.onFocused(false);
return index;
}