initialize method

void initialize({
  1. List<DebugProfile>? initialProfiles,
  2. int profileIndex = 0,
  3. bool clearExisting = false,
})

Optional one-time initialization. Call this early (e.g. in main) if you want to seed profiles. Calling initialize more than once will append profiles unless you pass clearExisting:true.

Implementation

void initialize({
  List<DebugProfile>? initialProfiles,
  int profileIndex = 0,
  bool clearExisting = false,
}) {
  if (clearExisting) {
    _profiles.clear();
    _currentProfileIndex = 0;
  }

  if (initialProfiles != null && initialProfiles.isNotEmpty) {
    if (profileIndex < 0 || profileIndex > initialProfiles.length - 1) {
      throw MissMatchProfileIndex(profileIndex, initialProfiles.length - 1);
    }
    _profiles.addAll(initialProfiles);
    _currentProfileIndex = profileIndex;
  }

  _initialized = true;
}