117 lines
3.3 KiB
Dart
117 lines
3.3 KiB
Dart
|
import 'dart:io';
|
||
|
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 'package:pdf/widgets.dart' as pw;
|
||
|
|
||
|
import '../constants/constants.dart';
|
||
|
import 'theme_utils.dart';
|
||
|
|
||
|
class SavePdf {
|
||
|
pw.Document document;
|
||
|
String name;
|
||
|
String path;
|
||
|
|
||
|
SavePdf(this.document, this.name, this.path);
|
||
|
}
|
||
|
|
||
|
class Utils {
|
||
|
static Future<String> savePdf(SavePdf pdf) async {
|
||
|
var filePath = "${pdf.path}/${pdf.name}.pdf";
|
||
|
final file = File(filePath);
|
||
|
await file.writeAsBytes(await pdf.document.save());
|
||
|
return filePath;
|
||
|
}
|
||
|
|
||
|
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 ?? '';
|
||
|
}
|