diff --git a/lib/config/themes/tb_theme.dart b/lib/config/themes/tb_theme.dart index bc01db1..a666652 100644 --- a/lib/config/themes/tb_theme.dart +++ b/lib/config/themes/tb_theme.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:thingsboard_app/utils/transition/page_transitions.dart'; const int _tbPrimaryColorValue = 0xFF305680; const Color _tbPrimaryColor = Color(_tbPrimaryColorValue); @@ -67,7 +68,11 @@ ThemeData tbTheme = ThemeData( unselectedItemColor: _tbPrimaryColor.withAlpha((255 * 0.38).ceil()), showSelectedLabels: true, showUnselectedLabels: true - ) + ), + pageTransitionsTheme: PageTransitionsTheme(builders: { + TargetPlatform.iOS: FadeOpenPageTransitionsBuilder(), + TargetPlatform.android: FadeOpenPageTransitionsBuilder(), + }) ); ThemeData tbDarkTheme = ThemeData( diff --git a/lib/core/context/tb_context.dart b/lib/core/context/tb_context.dart index 8891ef6..13817ef 100644 --- a/lib/core/context/tb_context.dart +++ b/lib/core/context/tb_context.dart @@ -349,7 +349,7 @@ class TbContext { if (replace) { transition = TransitionType.fadeIn; } else { - transition = TransitionType.inFromRight; + transition = TransitionType.native; } } var res = await router.navigateTo(currentState!.context, path, transition: transition, transitionDuration: transitionDuration, replace: replace, clearStack: clearStack); @@ -364,9 +364,10 @@ class TbContext { await _mainDashboardHolder?.navigateToDashboard(dashboardId, dashboardTitle: dashboardTitle, state: state, hideToolbar: hideToolbar, animate: animate); } - void pop([T? result]) { - if (currentState != null) { - router.pop(currentState!.context, result); + void pop([T? result, BuildContext? context]) { + var targetContext = context ?? currentState?.context; + if (targetContext != null) { + router.pop(targetContext, result); } } @@ -391,9 +392,9 @@ class TbContext { title: Text(title), content: Text(message), actions: [ - TextButton(onPressed: () => pop(false), + TextButton(onPressed: () => pop(false, context), child: Text(cancel)), - TextButton(onPressed: () => pop(true), + TextButton(onPressed: () => pop(true, context), child: Text(ok)) ], )); diff --git a/lib/modules/dashboard/dashboard.dart b/lib/modules/dashboard/dashboard.dart index 9ea824b..3bb85ac 100644 --- a/lib/modules/dashboard/dashboard.dart +++ b/lib/modules/dashboard/dashboard.dart @@ -152,6 +152,10 @@ class _DashboardState extends TbContextState { } Future _goBack() async { + if (_dashboardController.rightLayoutOpened.value) { + await _toggleRightLayout(); + return false; + } var controller = await _controller.future; if (await controller.canGoBack()) { await controller.goBack(); @@ -220,12 +224,7 @@ class _DashboardState extends TbContextState { if (widget._home == true && !tbContext.isHomePage()) { return true; } - var controller = await _controller.future; - if (await controller.canGoBack()) { - await controller.goBack(); - return false; - } - return true; + return await _goBack(); }, child: ValueListenableBuilder( diff --git a/lib/utils/transition/page_transitions.dart b/lib/utils/transition/page_transitions.dart new file mode 100644 index 0000000..6f501cd --- /dev/null +++ b/lib/utils/transition/page_transitions.dart @@ -0,0 +1,51 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; + +class FadeOpenPageTransitionsBuilder extends PageTransitionsBuilder { + /// Constructs a page transition animation that slides the page up. + const FadeOpenPageTransitionsBuilder(); + + @override + Widget buildTransitions( + PageRoute? route, + BuildContext? context, + Animation animation, + Animation? secondaryAnimation, + Widget child, + ) { + return FadeOpenPageTransition(routeAnimation: animation, child: child); + } +} + +class FadeOpenPageTransition extends StatelessWidget { + FadeOpenPageTransition({ + Key? key, + required Animation routeAnimation, // The route's linear 0.0 - 1.0 animation. + required this.child, + }) : _positionAnimation = routeAnimation.drive(_leftRightTween.chain(_fastOutSlowInTween)), + _opacityAnimation = routeAnimation.drive(_easeInTween), + super(key: key); + + // Fractional offset from 1/4 screen below the top to fully on screen. + static final Tween _leftRightTween = Tween( + begin: const Offset(0.5, 0.0), + end: Offset.zero, + ); + static final Animatable _fastOutSlowInTween = CurveTween(curve: Curves.fastOutSlowIn); + static final Animatable _easeInTween = CurveTween(curve: Curves.easeIn); + + final Animation _positionAnimation; + final Animation _opacityAnimation; + final Widget child; + + @override + Widget build(BuildContext context) { + return SlideTransition( + position: _positionAnimation, + child: FadeTransition( + opacity: _opacityAnimation, + child: child, + ), + ); + } +} diff --git a/lib/widgets/transition_indexed_stack.dart b/lib/widgets/transition_indexed_stack.dart index 409c71d..59120a5 100644 --- a/lib/widgets/transition_indexed_stack.dart +++ b/lib/widgets/transition_indexed_stack.dart @@ -1,4 +1,5 @@ import 'package:flutter/widgets.dart'; +import 'package:thingsboard_app/utils/transition/page_transitions.dart'; class TransitionIndexedStackController { @@ -124,7 +125,7 @@ class _TransitionIndexedStackState extends State with Ti position: Tween( begin: Offset.zero, end: const Offset(1, 0), - ).animate(animation), + ).chain(CurveTween(curve: Curves.fastOutSlowIn)).animate(animation), child: widget ); }