YSTools.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import 'package:flutter/foundation.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:wakelock_plus/wakelock_plus.dart';
  5. double ysHeight(BuildContext context) => MediaQuery.of(context).size.height;
  6. double ysWidth(BuildContext context) => MediaQuery.of(context).size.width;
  7. double ysTOP(BuildContext context) => MediaQuery.of(context).padding.top;
  8. double ysBottom(BuildContext context) => MediaQuery.of(context).padding.bottom;
  9. Color appColor = Colors.blueGrey;
  10. toDateFlex(DateTime date){
  11. String dateStr = '${date.year}-${'${date.month}'.padLeft(2,'0')}-${'${date.day}'.padLeft(2,'0')} ${'${date.hour}'.padLeft(2,'0')}:${'${date.minute}'.padLeft(2,'0')}:${'${date.second}'.padLeft(2,'0')}';
  12. return dateStr;
  13. }
  14. class LogUtil {
  15. static const _separator = "=";
  16. static const _split =
  17. "$_separator$_separator$_separator$_separator$_separator$_separator$_separator$_separator$_separator";
  18. static const _title = "Yl-Log";
  19. static const _isDebug = true;
  20. static const int _limitLength = 800;
  21. static const String _startLine = "$_split$_title$_split";
  22. static const String _endLine = "$_split$_separator$_separator$_separator$_split";
  23. //仅Debug模式可见
  24. static void d(dynamic obj) {
  25. if (_isDebug) {
  26. _log(obj.toString());
  27. }
  28. }
  29. static void v(dynamic obj) {
  30. _log(obj.toString());
  31. }
  32. static void _log(String msg) {
  33. if (kDebugMode) {
  34. print(_startLine);
  35. }
  36. _logEmpyLine();
  37. if(msg.length<_limitLength){
  38. if (kDebugMode) {
  39. print(msg);
  40. }
  41. }else{
  42. segmentationLog(msg);
  43. }
  44. _logEmpyLine();
  45. if (kDebugMode) {
  46. print(_endLine);
  47. }
  48. }
  49. static void segmentationLog(String msg) {
  50. var outStr = StringBuffer();
  51. for (var index = 0; index < msg.length; index++) {
  52. outStr.write(msg[index]);
  53. if (index % _limitLength == 0 && index!=0) {
  54. if (kDebugMode) {
  55. print(outStr);
  56. }
  57. outStr.clear();
  58. var lastIndex = index+1;
  59. if(msg.length-lastIndex<_limitLength){
  60. var remainderStr = msg.substring(lastIndex,msg.length);
  61. if (kDebugMode) {
  62. print(remainderStr);
  63. }
  64. break;
  65. }
  66. }
  67. }
  68. }
  69. static void _logEmpyLine(){
  70. if (kDebugMode) {
  71. print("");
  72. }
  73. }
  74. }
  75. ysShowBottomAlertView(BuildContext context,Widget widget,{bool isBarr = false,bool isCancel = true}) {
  76. showModalBottomSheet(
  77. context: context,
  78. isScrollControlled: isCancel,
  79. isDismissible: isCancel,
  80. backgroundColor: Colors.transparent,
  81. barrierColor: !isBarr?Colors.transparent:Colors.black54,
  82. builder: (context){
  83. return widget;
  84. }
  85. );
  86. }
  87. ysShowCenterAlertView(BuildContext context,Widget widget,{bool isTrans = false,bool isBarr = false}) {
  88. showGeneralDialog(
  89. context: context,
  90. barrierDismissible: isBarr,
  91. barrierLabel: '',
  92. barrierColor: isTrans==true?Colors.transparent:Colors.black54,
  93. pageBuilder: (context,animation,scAnimation){
  94. return widget;
  95. }
  96. );
  97. }
  98. class AppUtil{
  99. static H() {
  100. SystemChrome.setPreferredOrientations([
  101. DeviceOrientation.landscapeLeft,
  102. DeviceOrientation.landscapeRight
  103. ]);
  104. SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
  105. WakelockPlus.enable();
  106. }
  107. static V() {
  108. SystemChrome.setPreferredOrientations([
  109. DeviceOrientation.portraitUp,
  110. DeviceOrientation.portraitDown
  111. ]);
  112. SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge, overlays: []);
  113. WakelockPlus.disable();
  114. }
  115. }