lerp static method

ThemeData lerp(
  1. ThemeData a,
  2. ThemeData b,
  3. double t
)

Linearly interpolate between two themes.

The t argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning a (or something equivalent to a), 1.0 meaning that the interpolation has finished, returning b (or something equivalent to b), and values in between meaning that the interpolation is at the relevant point on the timeline between a and b. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid (and can easily be generated by curves such as Curves.elasticInOut).

Values for t are usually obtained from an Animation<double>, such as an AnimationController.

Implementation

static ThemeData lerp(ThemeData a, ThemeData b, double t) {
  if (identical(a, b)) {
    return a;
  }
  return ThemeData.raw(
    // For the sanity of the reader, make sure these properties are in the same
    // order in every place that they are separated by section comments (e.g.
    // GENERAL CONFIGURATION). Each section except for deprecations should be
    // alphabetical by symbol name.

    // GENERAL CONFIGURATION
    adaptationMap: t < 0.5 ? a.adaptationMap : b.adaptationMap,
    applyElevationOverlayColor:t < 0.5 ? a.applyElevationOverlayColor : b.applyElevationOverlayColor,
    cupertinoOverrideTheme:t < 0.5 ? a.cupertinoOverrideTheme : b.cupertinoOverrideTheme,
    extensions: _lerpThemeExtensions(a, b, t),
    inputDecorationTheme:t < 0.5 ? a.inputDecorationTheme : b.inputDecorationTheme,
    materialTapTargetSize:t < 0.5 ? a.materialTapTargetSize : b.materialTapTargetSize,
    pageTransitionsTheme:t < 0.5 ? a.pageTransitionsTheme : b.pageTransitionsTheme,
    platform: t < 0.5 ? a.platform : b.platform,
    scrollbarTheme: ScrollbarThemeData.lerp(a.scrollbarTheme, b.scrollbarTheme, t),
    splashFactory: t < 0.5 ? a.splashFactory : b.splashFactory,
    useMaterial3: t < 0.5 ? a.useMaterial3 : b.useMaterial3,
    visualDensity: VisualDensity.lerp(a.visualDensity, b.visualDensity, t),
    // COLOR
    canvasColor: Color.lerp(a.canvasColor, b.canvasColor, t)!,
    cardColor: Color.lerp(a.cardColor, b.cardColor, t)!,
    colorScheme: ColorScheme.lerp(a.colorScheme, b.colorScheme, t),
    dialogBackgroundColor: Color.lerp(a.dialogBackgroundColor, b.dialogBackgroundColor, t)!,
    disabledColor: Color.lerp(a.disabledColor, b.disabledColor, t)!,
    dividerColor: Color.lerp(a.dividerColor, b.dividerColor, t)!,
    focusColor: Color.lerp(a.focusColor, b.focusColor, t)!,
    highlightColor: Color.lerp(a.highlightColor, b.highlightColor, t)!,
    hintColor: Color.lerp(a.hintColor, b.hintColor, t)!,
    hoverColor: Color.lerp(a.hoverColor, b.hoverColor, t)!,
    indicatorColor: Color.lerp(a.indicatorColor, b.indicatorColor, t)!,
    primaryColor: Color.lerp(a.primaryColor, b.primaryColor, t)!,
    primaryColorDark: Color.lerp(a.primaryColorDark, b.primaryColorDark, t)!,
    primaryColorLight: Color.lerp(a.primaryColorLight, b.primaryColorLight, t)!,
    scaffoldBackgroundColor: Color.lerp(a.scaffoldBackgroundColor, b.scaffoldBackgroundColor, t)!,
    secondaryHeaderColor: Color.lerp(a.secondaryHeaderColor, b.secondaryHeaderColor, t)!,
    shadowColor: Color.lerp(a.shadowColor, b.shadowColor, t)!,
    splashColor: Color.lerp(a.splashColor, b.splashColor, t)!,
    unselectedWidgetColor: Color.lerp(a.unselectedWidgetColor, b.unselectedWidgetColor, t)!,
    // TYPOGRAPHY & ICONOGRAPHY
    iconTheme: IconThemeData.lerp(a.iconTheme, b.iconTheme, t),
    primaryIconTheme: IconThemeData.lerp(a.primaryIconTheme, b.primaryIconTheme, t),
    primaryTextTheme: TextTheme.lerp(a.primaryTextTheme, b.primaryTextTheme, t),
    textTheme: TextTheme.lerp(a.textTheme, b.textTheme, t),
    typography: Typography.lerp(a.typography, b.typography, t),
    // COMPONENT THEMES
    actionIconTheme: ActionIconThemeData.lerp(a.actionIconTheme, b.actionIconTheme, t),
    appBarTheme: AppBarTheme.lerp(a.appBarTheme, b.appBarTheme, t),
    badgeTheme: BadgeThemeData.lerp(a.badgeTheme, b.badgeTheme, t),
    bannerTheme: MaterialBannerThemeData.lerp(a.bannerTheme, b.bannerTheme, t),
    bottomAppBarTheme: BottomAppBarTheme.lerp(a.bottomAppBarTheme, b.bottomAppBarTheme, t),
    bottomNavigationBarTheme: BottomNavigationBarThemeData.lerp(a.bottomNavigationBarTheme, b.bottomNavigationBarTheme, t),
    bottomSheetTheme: BottomSheetThemeData.lerp(a.bottomSheetTheme, b.bottomSheetTheme, t)!,
    buttonTheme: t < 0.5 ? a.buttonTheme : b.buttonTheme,
    cardTheme: CardThemeData.lerp(a.cardTheme, b.cardTheme, t),
    checkboxTheme: CheckboxThemeData.lerp(a.checkboxTheme, b.checkboxTheme, t),
    chipTheme: ChipThemeData.lerp(a.chipTheme, b.chipTheme, t)!,
    dataTableTheme: DataTableThemeData.lerp(a.dataTableTheme, b.dataTableTheme, t),
    datePickerTheme: DatePickerThemeData.lerp(a.datePickerTheme, b.datePickerTheme, t),
    dialogTheme: DialogThemeData.lerp(a.dialogTheme, b.dialogTheme, t),
    dividerTheme: DividerThemeData.lerp(a.dividerTheme, b.dividerTheme, t),
    drawerTheme: DrawerThemeData.lerp(a.drawerTheme, b.drawerTheme, t)!,
    dropdownMenuTheme: DropdownMenuThemeData.lerp(a.dropdownMenuTheme, b.dropdownMenuTheme, t),
    elevatedButtonTheme: ElevatedButtonThemeData.lerp(a.elevatedButtonTheme, b.elevatedButtonTheme, t)!,
    expansionTileTheme: ExpansionTileThemeData.lerp(a.expansionTileTheme, b.expansionTileTheme, t)!,
    filledButtonTheme: FilledButtonThemeData.lerp(a.filledButtonTheme, b.filledButtonTheme, t)!,
    floatingActionButtonTheme: FloatingActionButtonThemeData.lerp(a.floatingActionButtonTheme, b.floatingActionButtonTheme, t)!,
    iconButtonTheme: IconButtonThemeData.lerp(a.iconButtonTheme, b.iconButtonTheme, t)!,
    listTileTheme: ListTileThemeData.lerp(a.listTileTheme, b.listTileTheme, t)!,
    menuBarTheme: MenuBarThemeData.lerp(a.menuBarTheme, b.menuBarTheme, t)!,
    menuButtonTheme: MenuButtonThemeData.lerp(a.menuButtonTheme, b.menuButtonTheme, t)!,
    menuTheme: MenuThemeData.lerp(a.menuTheme, b.menuTheme, t)!,
    navigationBarTheme: NavigationBarThemeData.lerp(a.navigationBarTheme, b.navigationBarTheme, t)!,
    navigationDrawerTheme: NavigationDrawerThemeData.lerp(a.navigationDrawerTheme, b.navigationDrawerTheme, t)!,
    navigationRailTheme: NavigationRailThemeData.lerp(a.navigationRailTheme, b.navigationRailTheme, t)!,
    outlinedButtonTheme: OutlinedButtonThemeData.lerp(a.outlinedButtonTheme, b.outlinedButtonTheme, t)!,
    popupMenuTheme: PopupMenuThemeData.lerp(a.popupMenuTheme, b.popupMenuTheme, t)!,
    progressIndicatorTheme: ProgressIndicatorThemeData.lerp(a.progressIndicatorTheme, b.progressIndicatorTheme, t)!,
    radioTheme: RadioThemeData.lerp(a.radioTheme, b.radioTheme, t),
    searchBarTheme: SearchBarThemeData.lerp(a.searchBarTheme, b.searchBarTheme, t)!,
    searchViewTheme: SearchViewThemeData.lerp(a.searchViewTheme, b.searchViewTheme, t)!,
    segmentedButtonTheme: SegmentedButtonThemeData.lerp(a.segmentedButtonTheme, b.segmentedButtonTheme, t),
    sliderTheme: SliderThemeData.lerp(a.sliderTheme, b.sliderTheme, t),
    snackBarTheme: SnackBarThemeData.lerp(a.snackBarTheme, b.snackBarTheme, t),
    switchTheme: SwitchThemeData.lerp(a.switchTheme, b.switchTheme, t),
    tabBarTheme: TabBarThemeData.lerp(a.tabBarTheme, b.tabBarTheme, t),
    textButtonTheme: TextButtonThemeData.lerp(a.textButtonTheme, b.textButtonTheme, t)!,
    textSelectionTheme: TextSelectionThemeData.lerp(a.textSelectionTheme, b.textSelectionTheme, t)!,
    timePickerTheme: TimePickerThemeData.lerp(a.timePickerTheme, b.timePickerTheme, t),
    toggleButtonsTheme: ToggleButtonsThemeData.lerp(a.toggleButtonsTheme, b.toggleButtonsTheme, t)!,
    tooltipTheme: TooltipThemeData.lerp(a.tooltipTheme, b.tooltipTheme, t)!,
    buttonBarTheme: ButtonBarThemeData.lerp(a.buttonBarTheme, b.buttonBarTheme, t),
  );
}