other_utils.dart
3.24 KB
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
import 'dart:ui';
import 'package:common_utils/common_utils.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:Parlando/res/constant.dart';
import 'package:keyboard_actions/keyboard_actions_config.dart';
import 'package:keyboard_actions/keyboard_actions_item.dart';
import 'package:url_launcher/url_launcher.dart';
import 'theme_utils.dart';
import 'toast_utils.dart';
class Utils {
/// 打开链接
static Future<void> launchWebURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
Toast.show('打开链接失败!');
}
}
/// 调起拨号页
static Future<void> launchTelURL(String phone) async {
final String url = 'tel:$phone';
if (await canLaunch(url)) {
await launch(url);
} else {
Toast.show('拨号失败!');
}
}
static String formatPrice(String price, {MoneyFormat format = MoneyFormat.END_INTEGER}){
return MoneyUtil.changeYWithUnit(NumUtil.getDoubleByValueStr(price) ?? 0, MoneyUnit.YUAN, format: format);
}
static KeyboardActionsConfig getKeyboardActionsConfig(BuildContext context, List<FocusNode> list) {
return KeyboardActionsConfig(
keyboardBarColor: ThemeUtils.getKeyboardActionsColor(context),
actions: List.generate(list.length, (i) => KeyboardActionsItem(
focusNode: list[i],
toolbarButtons: [
(node) {
return GestureDetector(
onTap: () => node.unfocus(),
child: Padding(
padding: const EdgeInsets.only(right: 16.0),
child: Text(getCurrLocale() == 'zh' ? '关闭' : 'Close'),
),
);
},
],
)),
);
}
static String? getCurrLocale() {
final String locale = SpUtil.getString(Constant.locale)!;
if (locale == '') {
return window.locale.languageCode;
}
return locale;
}
}
Future<T?> showElasticDialog<T>({
required BuildContext context,
bool barrierDismissible = true,
required WidgetBuilder builder,
}) {
return showGeneralDialog(
context: context,
pageBuilder: (BuildContext buildContext, Animation<double> animation, Animation<double> secondaryAnimation) {
final Widget pageChild = Builder(builder: builder);
return SafeArea(
child: pageChild,
);
},
barrierDismissible: barrierDismissible,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
barrierColor: Colors.black54,
transitionDuration: const Duration(milliseconds: 550),
transitionBuilder: _buildDialogTransitions,
);
}
Widget _buildDialogTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
return FadeTransition(
opacity: CurvedAnimation(
parent: animation,
curve: Curves.easeOut,
),
child: SlideTransition(
position: Tween<Offset>(
begin: const Offset(0.0, 0.3),
end: Offset.zero
).animate(CurvedAnimation(
parent: animation,
curve: const ElasticOutCurve(0.85),
reverseCurve: Curves.easeOutBack,
)),
child: child,
),
);
}
/// String 空安全处理
extension StringExtension on String? {
String get nullSafe => this ?? '';
}