路由工具
import 'package:test/main.dart';
import 'package:flutter/material.dart';
import 'circle_page_route.dart';
class NavigatorUtil {
static push(Widget page, {BuildContext context}) {
return Navigator.push(context ?? navigatorKey.currentContext,
MaterialPageRoute(builder: (context) => page));
}
/// 透明页面
static pushTransparentRoute(Widget page, {BuildContext context}) {
return Navigator.push(context ?? navigatorKey.currentContext,
TransparentRoute(builder: (context) => page));
}
/// 透明关闭页面
static pushTransparentReplacement(Widget page, {BuildContext context}) {
return Navigator.pushReplacement(context ?? navigatorKey.currentContext,
TransparentRoute(builder: (context) => page));
}
/// 关闭所有页面
static pushReplacement(
Widget page, {
BuildContext context,
}) {
Navigator.pushReplacement(context ?? navigatorKey.currentContext,
MaterialPageRoute(builder: (context) => page));
}
/// 跳转并且无法返回到上一页
static pushAndNoBack(Widget page, {BuildContext context}) {
return Navigator.pushAndRemoveUntil(
context ?? navigatorKey.currentContext,
MaterialPageRoute(builder: (context) => page),
(route) => route == null);
}
/// 返回上一页
static pop<T extends Object>({BuildContext context, T value}) {
Navigator.pop(
context == null ? navigatorKey.currentContext : context, value);
}
/// 删除指定路由
static removeRoute(Widget page, {BuildContext context}) {
return Navigator.removeRoute(context ?? navigatorKey.currentContext,
MaterialPageRoute(builder: (context) => page));
}
}
路由文章来源:https://www.toymoban.com/news/detail-561218.html
//透明路由
class TransparentRoute extends PageRoute<void> {
TransparentRoute({
this.builder,
});
final WidgetBuilder builder;
Duration get transitionDuration => Duration(milliseconds: 100);
bool get opaque => false;
bool get barrierDismissible => false;
Color get barrierColor => Colors.white.withOpacity(0.1);
String get barrierLabel => null;
bool get maintainState => true;
Widget buildPage(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
return Container(
child: builder(context),
);
}
}
// 孔雀开屏动画效果路由
class CirclePageRoute extends PageRoute {
CirclePageRoute({
this.builder,
});
final WidgetBuilder builder;
Duration get transitionDuration => Duration(milliseconds: 500);
bool get opaque => false;
bool get barrierDismissible => false;
Color get barrierColor => Colors.white.withOpacity(0.1);
String get barrierLabel => null;
bool get maintainState => true;
Widget buildPage(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
return Container(
child: builder(context),
);
}
Widget buildTransitions(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
return AnimatedBuilder(
animation: animation,
builder: (context, child) {
return ClipPath(
clipper: CirclePath(animation.value),
child: child,
);
},
child: builder(context),
);
}
}
透明遮罩页面显示文章来源地址https://www.toymoban.com/news/detail-561218.html
//在需要遮罩的页面的initState()函数中使用
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
NavigatorUtil.pushTransparentRoute(PushArticleGuidePage(
itemType: 1,
));
});
}
到了这里,关于flutter页面添加透明遮罩的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!