This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:math'; | |
import 'package:http/http.dart' as http; | |
/// A utility class for generating a list of waiting times (delays) for HTTP request retries. | |
/// This class uses an exponential backoff strategy with jitter for calculating delay times. | |
class HttpRetryDurationListGenerator { | |
/// Generates a list of waiting times (durations) to be used between retry attempts. | |
/// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ScrollableBottomSheetTopBar extends StatelessWidget { | |
final String topBarTitle; | |
final double topBarHeight; | |
final double? heroImageHeight; | |
final Color backgroundColor; | |
final ValueListenable<double> currentScrollPositionListenable; | |
final GlobalKey titleKey; | |
final double pageTitleTopPadding; | |
final double topBarTranslationYAmountInPx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ScrollableBottomSheetHeroImage extends StatelessWidget { | |
final Widget heroImage; | |
final double topBarHeight; | |
final double heroImageHeight; | |
const ScrollableBottomSheetHeroImage({ | |
required this.heroImage, | |
required this.topBarHeight, | |
required this.heroImageHeight, | |
Key? key, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _emptyContainerLayoutId = 'empty_container'; | |
const _bottomSheetLayoutId = 'bottomSheet'; | |
Future<T?> showScrollableBottomSheet<T>( | |
{required BuildContext context, | |
required List<ScrollableBottomSheetPage> Function(BuildContext) pages, | |
ValueNotifier<int>? pageIndexListenable, | |
EdgeInsetsDirectional? edgeInsetsDirectional, | |
ScrollController? scrollController, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final _scaleStart = 1.1; | |
final _scaleEnd = 1.0; | |
double _calculateScale(double currentScrollPosition) { | |
final startPointInPx = 0.0; | |
final endPointInPx = heroImageHeight - topBarHeight; | |
final distanceInPx = endPointInPx - startPointInPx; | |
final progressInPx = currentScrollPosition - startPointInPx; | |
final progress = progressInPx / distanceInPx; | |
final rawScale = _scaleStart - (progress * (_scaleStart - _scaleEnd)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flowPaintingContext.paintChild( | |
0, | |
transform: Matrix4.diagonal3Values(scale, scale, 1.0), | |
opacity: opacity, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@override | |
void paintChildren(FlowPaintingContext flowPaintingContext) { | |
final currentScrollPosition = scrollPosition.pixels; | |
/// Calculate scale | |
double scale = calculateTransformationValue( | |
startValue: 1.1, | |
endValue: 1.0, | |
rangeInPx: heroImageHeight - topBarHeight, | |
progressInRangeInPx: currentScrollPosition, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Calculate opacity | |
final _opacityStart = 1.0; | |
final _opacityEnd = 0.0; | |
double opacity = _calculatePropertyValue( | |
currentScrollPosition: currentScrollPosition, | |
startPointInPx: (heroImageHeight / 2) - topBarHeight, | |
endPointInPx: heroImageHeight - topBarHeight, | |
lowerLimit: _opacityEnd, | |
upperLimit: _opacityStart, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final _opacityStart = 1.0; | |
final _opacityEnd = 0.0; | |
double _calculateOpacity(double currentScrollPosition) { | |
final double distance = heroImageHeight / 2; | |
final double startPoint = heroImageHeight - topBarHeight; | |
final rawOpacity = ((startPoint - currentScrollPosition) / distance); | |
return rawOpacity.clamp(_opacityEnd, _opacityStart); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double calculateTransformationValue({ | |
required double rangeInPx, | |
required double progressInRangeInPx, | |
required double startValue, | |
required double endValue, | |
}) { | |
final progress = progressInRangeInPx / rangeInPx; | |
final rawValue = startValue + (progress * (endValue - startValue)); | |
return rawValue.clamp(min(startValue, endValue), max(startValue, endValue)); | |
} |
NewerOlder