setInitialTimeline method

Future<void> setInitialTimeline()

Implementation

Future<void> setInitialTimeline() async {
  if(_currentIndex.value == 0 && !startingHome) {
    // OPTIMIZATION: Only reload if data is stale (older than 5 minutes)
    final now = DateTime.now();
    if (_lastTimelineLoad != null &&
        now.difference(_lastTimelineLoad!) < _timelineRefreshThreshold) {
      AppConfig.logger.d("Timeline data still fresh, skipping reload");
      // Just scroll to top without reloading
      if(timelineServiceImpl?.getScrollController().hasClients ?? false) {
        await timelineServiceImpl?.getScrollController().animateTo(
            0.0, curve: Curves.easeOut,
            duration: const Duration(milliseconds: 500));
      }
      return;
    }

    // Skip if timeline was already loaded by TimelineController.onReady
    if (_timelineReady.value) {
      _lastTimelineLoad = now;
      if(timelineServiceImpl?.getScrollController().hasClients ?? false) {
        await timelineServiceImpl?.getScrollController().animateTo(
            0.0, curve: Curves.easeOut,
            duration: const Duration(milliseconds: 500));
      }
      return;
    }

    if(timelineServiceImpl?.getScrollController().hasClients ?? false) {
      await timelineServiceImpl?.getScrollController().animateTo(
          0.0, curve: Curves.easeOut,
          duration: const Duration(milliseconds: 1000));
    }
    await timelineServiceImpl?.getTimeline();
    _lastTimelineLoad = now;
  }
}