admin
2022-01-20 d8ef9a783b9e0b2a495f02fdf3daaf27ef49e99d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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;
}