admin
2022-05-12 fa705507ba574c857b1667553737d23b1b7ff495
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/physics.dart';
import 'package:flutter/services.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
 
class UIMethodChannel extends MethodChannel {
  UIMethodChannel(String name) : super(name) {
    setMethodCallHandler((call) {
      switch (call.method) {
        case "resumePage":
          {}
      }
      return Future.value();
    });
  }
}
 
MethodChannel uiMethodChannel = UIMethodChannel('com.yeshi.video/ui');
 
setStatusBarLight() {
  uiMethodChannel.invokeMethod("setStatusBarLight");
}
 
setStatusBarDark() {
  uiMethodChannel.invokeMethod("setStatusBarDark");
}
 
//跳转页面
jumpAppPage(String type, Map<String, dynamic>? params) {
  Map<String, dynamic> ps = {"type": type};
  if (params != null) {
    ps["params"] = params;
  }
  //跳转应用界面
  uiMethodChannel.invokeMethod("jumpAppPage", ps);
}
 
///包裹整个页面,下拉刷新,,上拉加载的默认配置
Widget getBasePage(Widget widget) {
  return RefreshConfiguration(
      headerBuilder: () => const WaterDropHeader(),
      // 配置默认头部指示器,假如你每个页面的头部指示器都一样的话,你需要设置这个
      footerBuilder: () => const ClassicFooter(),
      // 配置默认底部指示器
      headerTriggerDistance: 80.0,
      // 头部触发刷新的越界距离
      springDescription:
          const SpringDescription(stiffness: 170, damping: 16, mass: 1.9),
      // 自定义回弹动画,三个属性值意义请查询flutter api
      maxOverScrollExtent: 100,
      //头部最大可以拖动的范围,如果发生冲出视图范围区域,请设置这个属性
      maxUnderScrollExtent: 0,
      // 底部最大可以拖动的范围
      enableScrollWhenRefreshCompleted: true,
      //这个属性不兼容PageView和TabBarView,如果你特别需要TabBarView左右滑动,你需要把它设置为true
      enableLoadingWhenFailed: true,
      //在加载失败的状态下,用户仍然可以通过手势上拉来触发加载更多
      hideFooterWhenNotFull: false,
      // Viewport不满一屏时,禁用上拉加载更多功能
      enableBallisticLoad: true,
      // 可以通过惯性滑动触发加载更多
      child: MaterialApp(
          //国际化处理
          // localizationsDelegates: const [
          //   // 这行是关键
          //   RefreshLocalizations.delegate,
          // ],
          // supportedLocales: const [
          //   Locale('en'),
          //   Locale('zh'),
          // ],
          // localeResolutionCallback:
          //     (Locale? locale, Iterable<Locale> supportedLocales) {
          //   //print("change language");
          //   return locale;
          // },
          home: widget));
}
 
class ToastUtil {
  static toast(String text, BuildContext context) {
    // Toast.show(text, context);
    // showToast(text,position: ToastPosition.bottom);
    print("toast:$text");
    uiMethodChannel.invokeMethod("toast", text);
  }
}
 
class DialogUtil {
  static Future<dynamic> showDialog(BuildContext context, Dialog dialog) async {
    return await showGeneralDialog(
        context: context,
        pageBuilder: (BuildContext buildContext, Animation<double> animation,
            Animation<double> secondaryAnimation) {
          return dialog;
        });
  }
 
  static Future<dynamic> showDialogBottom(BuildContext context, Widget widget,
      {BorderRadius? borderRadius, Color? backgroundColor}) async {
    return await showModalBottomSheet<void>(
        backgroundColor: backgroundColor ?? Colors.transparent,
        shape: RoundedRectangleBorder(
          borderRadius: borderRadius ?? BorderRadius.zero,
        ),
        context: context,
        builder: (BuildContext context) {
          return widget;
        });
  }
}
 
class DimenUtil {
  //获取像素比
  static double getPixelRatio(BuildContext context) {
    MediaQueryData mediaQuery = MediaQuery.of(context);
    return mediaQuery.devicePixelRatio;
  }
 
  //获取1像素的取值
  static double getOnePixel(BuildContext context) {
    return 1 / MediaQuery.of(context).devicePixelRatio;
  }
}