|
| 1 | +import 'dart:ui'; |
| 2 | + |
| 3 | +import 'package:flutter/cupertino.dart'; |
| 4 | +import 'package:flutter/material.dart'; |
| 5 | + |
| 6 | +class LoadingModalPopupRoute<T> extends PopupRoute<T> { |
| 7 | + LoadingModalPopupRoute({ |
| 8 | + this.barrierColor, |
| 9 | + this.barrierLabel, |
| 10 | + this.builder, |
| 11 | + bool semanticsDismissible, |
| 12 | + ImageFilter filter, |
| 13 | + RouteSettings settings, |
| 14 | + }) : super( |
| 15 | + filter: filter, |
| 16 | + settings: settings, |
| 17 | + ) { |
| 18 | + _semanticsDismissible = semanticsDismissible; |
| 19 | + } |
| 20 | + |
| 21 | + final WidgetBuilder builder; |
| 22 | + bool _semanticsDismissible; |
| 23 | + |
| 24 | + @override |
| 25 | + final String barrierLabel; |
| 26 | + |
| 27 | + @override |
| 28 | + final Color barrierColor; |
| 29 | + |
| 30 | + @override |
| 31 | + bool get barrierDismissible => true; |
| 32 | + |
| 33 | + @override |
| 34 | + bool get semanticsDismissible => _semanticsDismissible ?? false; |
| 35 | + |
| 36 | + @override |
| 37 | + Duration get transitionDuration => Duration(milliseconds: 300); |
| 38 | + |
| 39 | + Animation<double> _animation; |
| 40 | + |
| 41 | + Tween<Offset> _offsetTween; |
| 42 | + |
| 43 | + @override |
| 44 | + Animation<double> createAnimation() { |
| 45 | + assert(_animation == null); |
| 46 | + _animation = CurvedAnimation( |
| 47 | + parent: super.createAnimation(), |
| 48 | + |
| 49 | + // These curves were initially measured from native iOS horizontal page |
| 50 | + // route animations and seemed to be a good match here as well. |
| 51 | + curve: Curves.linearToEaseOut, |
| 52 | + reverseCurve: Curves.linearToEaseOut.flipped, |
| 53 | + ); |
| 54 | + _offsetTween = Tween<Offset>( |
| 55 | + begin: const Offset(0.0, 1.0), |
| 56 | + end: const Offset(0.0, 0.0), |
| 57 | + ); |
| 58 | + return _animation; |
| 59 | + } |
| 60 | + |
| 61 | + @override |
| 62 | + Widget buildPage(BuildContext context, Animation<double> animation, |
| 63 | + Animation<double> secondaryAnimation) { |
| 64 | + return CupertinoUserInterfaceLevel( |
| 65 | + data: CupertinoUserInterfaceLevelData.elevated, |
| 66 | + child: Builder(builder: builder), |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + @override |
| 71 | + Widget buildTransitions(BuildContext context, Animation<double> animation, |
| 72 | + Animation<double> secondaryAnimation, Widget child) { |
| 73 | + return Align( |
| 74 | + alignment: Alignment.center, |
| 75 | + child: FractionalTranslation( |
| 76 | + translation: _offsetTween.evaluate(_animation), |
| 77 | + child: child, |
| 78 | + ), |
| 79 | + ); |
| 80 | + } |
| 81 | +} |
0 commit comments