102 lines
3.0 KiB
Dart
102 lines
3.0 KiB
Dart
import 'dart:ui';
|
|
|
|
import 'package:flustars_flutter3/flustars_flutter3.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:keyboard_actions/keyboard_actions_config.dart';
|
|
import 'package:keyboard_actions/keyboard_actions_item.dart';
|
|
|
|
import '../constants/constants.dart';
|
|
import 'theme_utils.dart';
|
|
|
|
class Utils {
|
|
static String getDayString(int day) {
|
|
var upperString = '一二三四五六七八九';
|
|
return upperString[day - 1];
|
|
}
|
|
|
|
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: REdgeInsets.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 ?? '';
|
|
}
|