Last active
February 8, 2023 13:21
-
-
Save RahmiTufanoglu/c7f786b2fa0b47a8d3e8106192701f36 to your computer and use it in GitHub Desktop.
Custom AppDialog
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 'package:flutter/material.dart'; | |
class CustomDialogTransition extends PageRouteBuilder { | |
CustomDialogTransition({ | |
required super.pageBuilder, | |
super.fullscreenDialog = true, | |
bool opaque = true, | |
bool barrierDismissible = true, | |
Color? barrierColor, | |
Duration transitionDuration = const Duration(milliseconds: 600), | |
Duration reverseTransitionDuration = Duration.zero, | |
Curve curve = Curves.ease, | |
}) : _opaque = opaque, | |
_barrierDismissible = barrierDismissible, | |
_barrierColor = barrierColor ?? Colors.black54, | |
_transitionDuration = transitionDuration, | |
_reverseTransitionDuration = reverseTransitionDuration; | |
final bool _opaque; | |
final bool _barrierDismissible; | |
final Color _barrierColor; | |
final Duration _transitionDuration; | |
final Duration _reverseTransitionDuration; | |
final Curve _curve; | |
@override | |
bool get opaque => _opaque; | |
@override | |
bool get barrierDismissible => _barrierDismissible; | |
@override | |
Color get barrierColor => _barrierColor; | |
@override | |
Duration get transitionDuration => _transitionDuration; | |
@override | |
Duration get reverseTransitionDuration => _reverseTransitionDuration; | |
@override | |
Widget buildTransitions( | |
BuildContext context, | |
Animation<double> animation, | |
Animation<double> secondaryAnimation, | |
Widget child, | |
) { | |
return ScaleTransition( | |
scale: CurvedAnimation(parent: animation, curve: _curve), | |
child: child, | |
); | |
} | |
} | |
class SpringCurve extends Curve { | |
const SpringCurve([this.period = 0.4]); | |
final double period; | |
@override | |
double transformInternal(double t) { | |
final double s = period / 2.0; | |
const bounceDistance = -18.0; | |
const bounciness = 2.0; | |
const stiffness = 1.4; | |
return pow(bounciness, bounceDistance * t) * sin((t - s) * (pi * stiffness) / period) + 1.0; | |
} | |
@override | |
String toString() { | |
return '${objectRuntimeType(this, 'ElasticOutCurve')}($period)'; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment