import 'dart:ui';
|
|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
|
import 'global.dart';
|
|
typedef PageDataLisener = void Function(dynamic data);
|
|
//滑动效果
|
class CustomRouteSlide extends PageRouteBuilder {
|
final Widget widget;
|
|
CustomRouteSlide(this.widget)
|
: super(
|
transitionDuration: const Duration(milliseconds: 500),
|
pageBuilder: (BuildContext context, Animation<double> animation1,
|
Animation<double> animation2) {
|
return widget;
|
},
|
transitionsBuilder: (BuildContext context,
|
Animation<double> animation1,
|
Animation<double> animation2,
|
Widget child) {
|
return SlideTransition(
|
position: Tween<Offset>(
|
begin: Offset(1.0, 0.0), end: Offset(0.0, 0.0))
|
.animate(CurvedAnimation(
|
parent: animation1, curve: Curves.fastOutSlowIn)),
|
child: child,
|
);
|
});
|
}
|
|
class NavigatorUtil {
|
// static void navigateToNextPage(BuildContext context, PageRoute route,
|
// PageDataLisener? dataLisener) async {
|
// final result = await Navigator.of(context).push(route);
|
// dataLisener!(result);
|
// }
|
|
static void navigateToNextPage(
|
BuildContext context, Widget page, PageDataLisener? dataLisener) async {
|
final result =
|
await Navigator.of(context).push(CupertinoPageRoute(builder: (context) {
|
return page;
|
}));
|
dataLisener!(result);
|
}
|
|
static void navigateToNextPagePush(Widget page) {
|
|
navigatorKey.currentState!.push(
|
CupertinoPageRoute (builder: (BuildContext context) => page));
|
}
|
|
static void navigateToNextPageWithFinish(
|
BuildContext context, PageRoute route) {
|
Navigator.of(context).pushReplacement(route);
|
}
|
}
|
|
class KeepAliveWrapper extends StatefulWidget {
|
const KeepAliveWrapper({
|
Key? key,
|
this.keepAlive = true,
|
required this.child,
|
}) : super(key: key);
|
final bool keepAlive;
|
final Widget child;
|
|
@override
|
_KeepAliveWrapperState createState() => _KeepAliveWrapperState();
|
}
|
|
class _KeepAliveWrapperState extends State<KeepAliveWrapper>
|
with AutomaticKeepAliveClientMixin {
|
@override
|
Widget build(BuildContext context) {
|
super.build(context);
|
return widget.child;
|
}
|
|
@override
|
void didUpdateWidget(covariant KeepAliveWrapper oldWidget) {
|
if (oldWidget.keepAlive != widget.keepAlive) {
|
// keepAlive 状态需要更新,实现在 AutomaticKeepAliveClientMixin 中
|
updateKeepAlive();
|
}
|
super.didUpdateWidget(oldWidget);
|
}
|
|
@override
|
bool get wantKeepAlive => widget.keepAlive;
|
}
|