LazyFeatureDescriptor class final

Describes a feature that should be loaded lazily — only when one of its route prefixes is first navigated to.

This enables:

  • Web code splitting via Dart's deferred as imports
  • Faster app startup by deferring init/extension registration
  • Smaller initial bundle on web

On native platforms (iOS, Android), loadLibrary() is a no-op so the same code works everywhere — it simply defers initialization.

Example:

import 'package:feature_food/feature_food.dart' deferred as food;

LazyFeatureDescriptor(
  name: 'food',
  title: 'Food',
  routePrefixes: ['/food'],
  loader: () async {
    await food.loadLibrary();
    return food.feature;
  },
)

Constructors

LazyFeatureDescriptor({required String name, required String title, required List<String> routePrefixes, required DeferredFeatureLoader loader, String? description, IconData? icon, List<String> dependencies = const [], String? featureFlag})

Properties

dependencies → List<String>
Optional list of feature names this feature depends on. If a dependency is also lazy, it will be loaded first. If a dependency is already loaded (eager or previously loaded lazy), it is skipped.
final
description → String?
Optional description of what this feature does.
final
featureFlag → String?
Optional feature flag name. If provided and a FeatureFlagPlugin is registered, the feature is only loaded when the flag evaluates to true.
final
hashCode → int
The hash code for this object.
no setterinherited
icon → IconData?
Optional icon for the loading indicator.
final
loader → DeferredFeatureLoader
The function that loads the actual FeatureDescriptor. This is where deferred as loading happens.
final
name → String
Unique name for this feature. Must match the inner FeatureDescriptor.name returned by loader.
final
routePrefixes → List<String>
Route path prefixes that belong to this feature. When any URL matching these prefixes is navigated to, the feature is loaded.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
title → String
Human-readable title shown in the loading UI while the feature is being downloaded and initialized.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited