import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:wakelock_plus/wakelock_plus.dart'; double ysHeight(BuildContext context) => MediaQuery.of(context).size.height; double ysWidth(BuildContext context) => MediaQuery.of(context).size.width; double ysTOP(BuildContext context) => MediaQuery.of(context).padding.top; double ysBottom(BuildContext context) => MediaQuery.of(context).padding.bottom; Color appColor = Colors.blueGrey; toDateFlex(DateTime date){ 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')}'; return dateStr; } class LogUtil { static const _separator = "="; static const _split = "$_separator$_separator$_separator$_separator$_separator$_separator$_separator$_separator$_separator"; static const _title = "Yl-Log"; static const _isDebug = true; static const int _limitLength = 800; static const String _startLine = "$_split$_title$_split"; static const String _endLine = "$_split$_separator$_separator$_separator$_split"; //仅Debug模式可见 static void d(dynamic obj) { if (_isDebug) { _log(obj.toString()); } } static void v(dynamic obj) { _log(obj.toString()); } static void _log(String msg) { if (kDebugMode) { print(_startLine); } _logEmpyLine(); if(msg.length<_limitLength){ if (kDebugMode) { print(msg); } }else{ segmentationLog(msg); } _logEmpyLine(); if (kDebugMode) { print(_endLine); } } static void segmentationLog(String msg) { var outStr = StringBuffer(); for (var index = 0; index < msg.length; index++) { outStr.write(msg[index]); if (index % _limitLength == 0 && index!=0) { if (kDebugMode) { print(outStr); } outStr.clear(); var lastIndex = index+1; if(msg.length-lastIndex<_limitLength){ var remainderStr = msg.substring(lastIndex,msg.length); if (kDebugMode) { print(remainderStr); } break; } } } } static void _logEmpyLine(){ if (kDebugMode) { print(""); } } } ysShowBottomAlertView(BuildContext context,Widget widget,{bool isBarr = false,bool isCancel = true}) { showModalBottomSheet( context: context, isScrollControlled: isCancel, isDismissible: isCancel, backgroundColor: Colors.transparent, barrierColor: !isBarr?Colors.transparent:Colors.black54, builder: (context){ return widget; } ); } ysShowCenterAlertView(BuildContext context,Widget widget,{bool isTrans = false,bool isBarr = false}) { showGeneralDialog( context: context, barrierDismissible: isBarr, barrierLabel: '', barrierColor: isTrans==true?Colors.transparent:Colors.black54, pageBuilder: (context,animation,scAnimation){ return widget; } ); } class AppUtil{ static H() { SystemChrome.setPreferredOrientations([ DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight ]); SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); WakelockPlus.enable(); } static V() { SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, DeviceOrientation.portraitDown ]); SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge, overlays: []); WakelockPlus.disable(); } }