Dashboard navigation and page transitions improvements

This commit is contained in:
Igor Kulikov
2021-06-07 16:23:02 +03:00
parent a6d89f1d0c
commit 8c519540ba
5 changed files with 71 additions and 14 deletions

View File

@@ -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(

View File

@@ -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>([T? result]) {
if (currentState != null) {
router.pop<T>(currentState!.context, result);
void pop<T>([T? result, BuildContext? context]) {
var targetContext = context ?? currentState?.context;
if (targetContext != null) {
router.pop<T>(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))
],
));

View File

@@ -152,6 +152,10 @@ class _DashboardState extends TbContextState<Dashboard, _DashboardState> {
}
Future<bool> _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<Dashboard, _DashboardState> {
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(

View File

@@ -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<T>(
PageRoute<T>? route,
BuildContext? context,
Animation<double> animation,
Animation<double>? secondaryAnimation,
Widget child,
) {
return FadeOpenPageTransition(routeAnimation: animation, child: child);
}
}
class FadeOpenPageTransition extends StatelessWidget {
FadeOpenPageTransition({
Key? key,
required Animation<double> 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<Offset> _leftRightTween = Tween<Offset>(
begin: const Offset(0.5, 0.0),
end: Offset.zero,
);
static final Animatable<double> _fastOutSlowInTween = CurveTween(curve: Curves.fastOutSlowIn);
static final Animatable<double> _easeInTween = CurveTween(curve: Curves.easeIn);
final Animation<Offset> _positionAnimation;
final Animation<double> _opacityAnimation;
final Widget child;
@override
Widget build(BuildContext context) {
return SlideTransition(
position: _positionAnimation,
child: FadeTransition(
opacity: _opacityAnimation,
child: child,
),
);
}
}

View File

@@ -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<TransitionIndexedStack> with Ti
position: Tween<Offset>(
begin: Offset.zero,
end: const Offset(1, 0),
).animate(animation),
).chain(CurveTween(curve: Curves.fastOutSlowIn)).animate(animation),
child: widget
);
}