Repository: flutter/flutter
File: packages/flutter/lib/src/material/bottom_sheet.dart (Dart)

Code before:

  @override
  Color get barrierColor => modalBarrierColor ?? Colors.black54;

  AnimationController? _animationController;

  @override
  AnimationController createAnimationController() {
    assert(_animationController == null);
    if (transitionAnimationController != null) {
      _animationController = transitionAnimationController;
      willDisposeAnimationController = false;
    } else {
      _animationController = BottomSheet.createAnimationController(
        navigator!,
        sheetAnimationStyle: sheetAnimationStyle,
      );
    }
    return _animationController!;
  }

  @override
  Animation<double> createAnimation() {
    final Animation<double> parent = super.createAnimation();

    return CurvedAnimation(
      parent: parent,
      curve: sheetAnimationStyle?.curve ?? _modalBottomSheetCurve,
      reverseCurve: sheetAnimationStyle?.reverseCurve ?? _modalBottomSheetCurve,
    );
  }

  @override
  Widget buildPage(
    BuildContext context,
    Animation<double> animation,
    Animation<double> secondaryAnimation,
  ) {
    final Widget content = DisplayFeatureSubScreen(
      anchorPoint: anchorPoint,
      child: Builder(
        builder: (BuildContext context) {
          final BottomSheetThemeData sheetTheme = Theme.of(context).bottomSheetTheme;
          final BottomSheetThemeData defaults = Theme.of(context).useMaterial3
              ? _BottomSheetDefaultsM3(context)
              : const BottomSheetThemeData();
          return _ModalBottomSheet<T>(
            route: this,
            backgroundColor:
                backgroundColor ??
                sheetTheme.modalBackgroundColor ??

Review comment (performance):
This is causing memory leaks, instead create a state instance variable to store and eventually dispose this `CurvedAnimation`. See [CupertinoContextMenu](https://github.com/flutter/flutter/blob/72321c82f99852685c5f9a25a44adbadb7d020ff/packages/flutter/lib/src/cupertino/context_menu.dart#L959) and [showMenu](https://github.com/flutter/flutter/blob/72321c82f99852685c5f9a25a44adbadb7d020ff/packages/flutter/lib/src/material/popup_menu.dart#L982) for inspiration.

Code after:
  }

  /// Updates the details regarding how the [SemanticsNode.rect] (focus) of
  /// the barrier for this [ModalBottomSheetRoute] should be clipped.
  ///
  /// Returns true if the clipDetails did change and false otherwise.
  bool _didChangeBarrierSemanticsClip(EdgeInsets newClipDetails) {
    if (_clipDetailsNotifier.value == newClipDetails) {
      return false;
    }
    _clipDetailsNotifier.value = newClipDetails;
    return true;
  }

  @override
  Duration get transitionDuration =>
      transitionAnimationController?.duration ??
      sheetAnimationStyle?.duration ??
      _kBottomSheetEnterDuration;

  @override
  Duration get reverseTransitionDuration =>
      transitionAnimationController?.reverseDuration ??
      transitionAnimationController?.duration ??
      sheetAnimationStyle?.reverseDuration ??
      _kBottomSheetExitDuration;

  @override
  bool get barrierDismissible => isDismissible;

  @override
  final String? barrierLabel;

  @override
  Color get barrierColor => modalBarrierColor ?? Colors.black54;

  AnimationController? _animationController;

  @override
  AnimationController createAnimationController() {
    assert(_animationController == null);
    if (transitionAnimationController != null) {
      _animationController = transitionAnimationController;
      willDisposeAnimationController = false;
    } else {
      _animationController = BottomSheet.createAnimationController(
        navigator!,
        sheetAnimationStyle: sheetAnimationStyle,
      );
    }
    return _animationController!;