YSTools.dart 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718
  1. import 'dart:convert';
  2. import 'dart:ffi';
  3. import 'dart:math';
  4. import 'dart:ui';
  5. import 'package:flutter/cupertino.dart';
  6. import 'package:flutter/foundation.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter/services.dart';
  9. import 'package:package_info/package_info.dart';
  10. import 'package:url_launcher/url_launcher.dart';
  11. import 'package:webview_flutter/webview_flutter.dart';
  12. import 'package:ysairplane2/code/YSLogin.dart';
  13. import 'package:flutter_screenutil/screenutil.dart';
  14. import 'package:shared_preferences/shared_preferences.dart';
  15. import 'dart:math' as math;
  16. class YSDatePicker extends StatefulWidget {
  17. final ValueSetter<String> choose;
  18. final bool isBefore;
  19. final bool isDate;
  20. const YSDatePicker({Key key, this.choose, this.isBefore, this.isDate = false}) : super(key: key);
  21. @override
  22. _YSDatePickerState createState() => _YSDatePickerState();
  23. }
  24. class _YSDatePickerState extends State<YSDatePicker> {
  25. String birthday = DateTime.now().year.toString()+'-'+DateTime.now().month.toString().padLeft(2,'0')+'-'+DateTime.now().day.toString().padLeft(2,'0')+' '+
  26. DateTime.now().hour.toString().padLeft(2,'0')+':'+DateTime.now().minute.toString().padLeft(2,'0');
  27. @override
  28. void initState() {
  29. if(widget.isDate==true){
  30. birthday = DateTime.now().year.toString()+'-'+DateTime.now().month.toString().padLeft(2,'0')+'-'+DateTime.now().day.toString().padLeft(2,'0');
  31. }
  32. super.initState();
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. return Container(
  37. color: Colors.transparent,
  38. height: 280,
  39. child: Column(
  40. crossAxisAlignment: CrossAxisAlignment.end,
  41. children: [
  42. Container(
  43. height: 40,
  44. padding: EdgeInsets.only(left: wsp(40),right: wsp(40)),
  45. decoration: BoxDecoration(
  46. color: Colors.white,
  47. border: Border(bottom: BorderSide(width: 0.5,color: Color(0xFFEEEEEE)))
  48. ),
  49. child: Row(
  50. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  51. children: [
  52. GestureDetector(
  53. child: Text('取消',style: TextStyle(fontSize: zsp(30),color: Color(0xFF999999)),),
  54. onTap: (){
  55. Navigator.pop(context);
  56. },
  57. ),
  58. GestureDetector(
  59. child: Text('确定',style: TextStyle(fontSize: zsp(30),color: Color(0xFF108DE9)),),
  60. onTap: (){
  61. widget.choose(birthday);
  62. Navigator.pop(context);
  63. },
  64. )
  65. ],
  66. ),
  67. ),
  68. Container(
  69. height: 240,
  70. padding: EdgeInsets.all(10),
  71. decoration: BoxDecoration(
  72. color: Colors.white,
  73. borderRadius: BorderRadius.only(topLeft: Radius.circular(20),topRight: Radius.circular(20))
  74. ),
  75. child: CupertinoDatePicker(
  76. initialDateTime: DateTime.now(),
  77. use24hFormat: true,
  78. minimumDate: widget.isBefore==true?null:DateTime.parse(DateTime.now().year.toString()+'-'+DateTime.now().month.toString().padLeft(2,'0')+'-'+
  79. DateTime.now().day.toString().padLeft(2,'0')+' '+
  80. DateTime.now().hour.toString().padLeft(2,'0')+':'+DateTime.now().minute.toString().padLeft(2,'0')),
  81. onDateTimeChanged: (date) {
  82. if(widget.isDate==true){
  83. birthday = date.year.toString()+'-'+date.month.toString().padLeft(2,'0')+'-'+date.day.toString().padLeft(2,'0');
  84. }else{
  85. birthday = date.year.toString()+'-'+date.month.toString().padLeft(2,'0')+'-'+date.day.toString().padLeft(2,'0')+' '+
  86. date.hour.toString().padLeft(2,'0')+':'+date.minute.toString().padLeft(2,'0');
  87. }
  88. },
  89. mode: widget.isDate==true?CupertinoDatePickerMode.date:CupertinoDatePickerMode.dateAndTime,
  90. ),
  91. ),
  92. ],
  93. ),
  94. );
  95. }
  96. }
  97. class BottomInputDialog extends StatefulWidget {
  98. final Widget inputView;
  99. final double height;
  100. final Color color;
  101. const BottomInputDialog({Key key, this.inputView,this.height,this.color}) : super(key: key);
  102. @override
  103. _State createState() => _State();
  104. }
  105. class _State extends State<BottomInputDialog> with WidgetsBindingObserver{
  106. @override
  107. void initState() {
  108. WidgetsBinding.instance.addObserver(this);
  109. super.initState();
  110. }
  111. @override
  112. void didChangeMetrics() {
  113. WidgetsBinding.instance.addPostFrameCallback((_) {
  114. if(MediaQuery.of(context).viewInsets.bottom <= 0){
  115. Navigator.pop(context);
  116. if (!mounted) {
  117. return;
  118. }
  119. WidgetsBinding.instance.removeObserver(this);
  120. }
  121. });
  122. super.didChangeMetrics();
  123. }
  124. @override
  125. void dispose() {
  126. super.dispose();
  127. if (!mounted) {
  128. return;
  129. }
  130. WidgetsBinding.instance.removeObserver(this);
  131. }
  132. @override
  133. Widget build(BuildContext context) {
  134. return CupertinoPageScaffold(
  135. backgroundColor: Colors.transparent,
  136. child: Stack(
  137. children: <Widget>[
  138. GestureDetector(
  139. child: BackdropFilter(
  140. filter: ImageFilter.blur(sigmaX: 3, sigmaY: 3),
  141. child: Container(
  142. height: MediaQuery.of(context).size.height,
  143. color: widget.color!=null?widget.color:Colors.black12.withOpacity(0.8),
  144. ),
  145. ),
  146. onTap: () {
  147. Navigator.pop(context);
  148. if (!mounted) {
  149. return;
  150. }
  151. WidgetsBinding.instance.removeObserver(this);
  152. },
  153. ),
  154. Container(
  155. margin: EdgeInsets.only(top: MediaQuery.of(context).size.height-widget.height-MediaQuery.of(context).viewInsets.bottom),
  156. height: widget.height,
  157. decoration: BoxDecoration(
  158. color: Colors.white,
  159. borderRadius: BorderRadius.only(topLeft: Radius.circular(10),topRight: Radius.circular(10)),
  160. boxShadow: [
  161. BoxShadow(
  162. color: Colors.black12,
  163. offset: Offset(-1, -3),
  164. blurRadius: 5
  165. )
  166. ]
  167. ),
  168. padding: EdgeInsets.all(10),
  169. child: widget.inputView,
  170. )
  171. ],
  172. ),
  173. );
  174. }
  175. }
  176. class PopRoute extends PopupRoute{
  177. final Duration _duration = Duration(milliseconds: 300);
  178. Widget child;
  179. PopRoute({@required this.child});
  180. @override
  181. Color get barrierColor => null;
  182. @override
  183. bool get barrierDismissible => true;
  184. @override
  185. String get barrierLabel => null;
  186. @override
  187. Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
  188. return child;
  189. }
  190. @override
  191. Duration get transitionDuration => _duration;
  192. }
  193. wsp(int number){
  194. return ScreenUtil().setWidth(number);
  195. }
  196. hsp(int number){
  197. return ScreenUtil().setHeight(number);
  198. }
  199. zsp(int number){
  200. return ScreenUtil().setSp(number,allowFontScalingSelf: false);
  201. }
  202. isLogin(BuildContext context,{VoidCallback login}) async{
  203. SharedPreferences prefs = await SharedPreferences.getInstance();
  204. String token = prefs.getString('token');
  205. if(token==null){
  206. Navigator.of(context,rootNavigator: true).push(
  207. CupertinoPageRoute(
  208. fullscreenDialog: true,
  209. builder: (context){
  210. return YSLogin();
  211. }
  212. )
  213. ).then((value){
  214. if(value!=null){
  215. login();
  216. }
  217. });
  218. }else{
  219. login();
  220. }
  221. }
  222. ///手机号验证
  223. bool isChinaPhoneLegal(String str) {
  224. return RegExp(r"^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$").hasMatch(str);
  225. }
  226. ///邮箱验证
  227. bool isEmail(String str) {
  228. return RegExp(r"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$").hasMatch(str);
  229. }
  230. ///验证URL
  231. bool isUrl(String value) {
  232. return RegExp(r"^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+").hasMatch(value);
  233. }
  234. ///验证身份证
  235. bool isIdCard(String value) {
  236. return RegExp(r"\d{17}[\d|x]|\d{15}").hasMatch(value);
  237. }
  238. ///验证中文
  239. bool isChinese(String value) {
  240. return RegExp(r"[\u4e00-\u9fa5]").hasMatch(value);
  241. }
  242. class LogUtil {
  243. static var _separator = "=";
  244. static var _split =
  245. "$_separator$_separator$_separator$_separator$_separator$_separator$_separator$_separator$_separator";
  246. static var _title = "Yl-Log";
  247. static var _isDebug = true;
  248. static int _limitLength = 800;
  249. static String _startLine = "$_split$_title$_split";
  250. static String _endLine = "$_split$_separator$_separator$_separator$_split";
  251. static void init({String title, @required bool isDebug,int limitLength}) {
  252. _title = title;
  253. _isDebug = isDebug;
  254. _limitLength = limitLength??=_limitLength;
  255. _startLine = "$_split$_title$_split";
  256. var endLineStr = StringBuffer();
  257. var cnCharReg = RegExp("[\u4e00-\u9fa5]");
  258. for (int i = 0; i < _startLine.length; i++) {
  259. if (cnCharReg.stringMatch(_startLine[i]) != null) {
  260. endLineStr.write(_separator);
  261. }
  262. endLineStr.write(_separator);
  263. }
  264. _endLine = endLineStr.toString();
  265. }
  266. //仅Debug模式可见
  267. static void d(dynamic obj) {
  268. if (_isDebug) {
  269. _log(obj.toString());
  270. }
  271. }
  272. static void v(dynamic obj) {
  273. _log(obj.toString());
  274. }
  275. static void _log(String msg) {
  276. print("$_startLine");
  277. _logEmpyLine();
  278. if(msg.length<_limitLength){
  279. print(msg);
  280. }else{
  281. segmentationLog(msg);
  282. }
  283. _logEmpyLine();
  284. print("$_endLine");
  285. }
  286. static void segmentationLog(String msg) {
  287. var outStr = StringBuffer();
  288. for (var index = 0; index < msg.length; index++) {
  289. outStr.write(msg[index]);
  290. if (index % _limitLength == 0 && index!=0) {
  291. print(outStr);
  292. outStr.clear();
  293. var lastIndex = index+1;
  294. if(msg.length-lastIndex<_limitLength){
  295. var remainderStr = msg.substring(lastIndex,msg.length);
  296. print(remainderStr);
  297. break;
  298. }
  299. }
  300. }
  301. }
  302. static void _logEmpyLine(){
  303. print("");
  304. }
  305. }
  306. //indicate
  307. Widget indicateString(String longStr,String str,String otherStr){
  308. List strings = longStr.split(str);
  309. print(strings);
  310. return Container(
  311. child: RichText(
  312. text: longStr!=str?TextSpan(
  313. children:
  314. [
  315. for(int i = 0;i<strings.length;i++)TextSpan(
  316. children: [
  317. TextSpan(
  318. text: strings[i]==''?str:strings[i],
  319. style: TextStyle(fontSize: zsp(32),color: strings[i]==''?Color(0xFF007AFF):Color(0xFF444444)),
  320. ),
  321. ]
  322. ),
  323. TextSpan(
  324. text: ' $otherStr',
  325. style: TextStyle(fontSize: zsp(26),color: Color(0xFF999999)),
  326. )
  327. ]
  328. ):TextSpan(
  329. children:[
  330. TextSpan(
  331. text: longStr,
  332. style: TextStyle(fontSize: zsp(32),color: Color(0xFF007AFF)),
  333. ),
  334. TextSpan(
  335. text: ' $otherStr',
  336. style: TextStyle(fontSize: zsp(26),color: Color(0xFF999999)),
  337. )
  338. ]
  339. ),
  340. ),
  341. );
  342. }
  343. class ExpandableText extends StatefulWidget {
  344. final String text;
  345. final int maxLines;
  346. final TextStyle style;
  347. final bool expand;
  348. const ExpandableText({Key key, this.text, this.maxLines, this.style, this.expand}) : super(key: key);
  349. @override
  350. State<StatefulWidget> createState() {
  351. return _ExpandableTextState(text, maxLines, style, expand);
  352. }
  353. }
  354. class _ExpandableTextState extends State<ExpandableText> {
  355. final String text;
  356. final int maxLines;
  357. final TextStyle style;
  358. bool expand;
  359. _ExpandableTextState(this.text, this.maxLines, this.style, this.expand) {
  360. if (expand == null) {
  361. expand = false;
  362. }
  363. }
  364. @override
  365. Widget build(BuildContext context) {
  366. return LayoutBuilder(builder: (context, size) {
  367. final span = TextSpan(text: text ?? '', style: style);
  368. final tp = TextPainter(
  369. text: span, maxLines: maxLines, textDirection: TextDirection.ltr);
  370. tp.layout(maxWidth: size.maxWidth);
  371. if (tp.didExceedMaxLines) {
  372. return Column(
  373. crossAxisAlignment: CrossAxisAlignment.start,
  374. children: <Widget>[
  375. expand ?
  376. Text(text ?? '', style: style) :
  377. Text(text ?? '', maxLines: maxLines,overflow: TextOverflow.ellipsis,style: style),
  378. GestureDetector(
  379. behavior: HitTestBehavior.translucent,
  380. onTap: () {
  381. setState(() {
  382. expand = !expand;
  383. });
  384. },
  385. child: Container(
  386. padding: EdgeInsets.only(top: 2),
  387. child: Text(expand ? '收起' : '全文', style: TextStyle(
  388. fontSize: style != null ? style.fontSize : null,
  389. color: Colors.blue)),
  390. ),
  391. ),
  392. ],
  393. );
  394. } else {
  395. return Text(text ?? '', style: style);
  396. }
  397. });
  398. }
  399. }
  400. Widget ysTextExpend({String text,int maxLines,TextStyle style,bool expand = false}) {
  401. return StatefulBuilder(
  402. builder: (context,ysState){
  403. return LayoutBuilder(builder: (context, size) {
  404. final span = TextSpan(text: text ?? '', style: style);
  405. final tp = TextPainter(
  406. text: span, maxLines: maxLines, textDirection: TextDirection.ltr);
  407. tp.layout(maxWidth: size.maxWidth);
  408. if (tp.didExceedMaxLines) {
  409. return Column(
  410. crossAxisAlignment: CrossAxisAlignment.start,
  411. children: <Widget>[
  412. expand ?
  413. Text(text ?? '', style: style) :
  414. Text(text ?? '', maxLines: maxLines,
  415. overflow: TextOverflow.ellipsis,
  416. style: style),
  417. GestureDetector(
  418. behavior: HitTestBehavior.translucent,
  419. onTap: () {
  420. ysState(() {
  421. expand = !expand;
  422. });
  423. },
  424. child: Container(
  425. padding: EdgeInsets.only(top: 2),
  426. child: Text(expand ? '收起' : '全文', style: TextStyle(
  427. fontSize: style != null ? style.fontSize : null,
  428. color: Colors.blue)),
  429. ),
  430. ),
  431. ],
  432. );
  433. } else {
  434. return Text(text ?? '', style: style);
  435. }
  436. });
  437. },
  438. );
  439. }
  440. class YSPicker extends StatefulWidget {
  441. final ValueSetter choose;
  442. final List dataArray;
  443. final String title;
  444. const YSPicker({Key key, this.choose, this.dataArray, this.title}) : super(key: key);
  445. @override
  446. _YSPickerState createState() => _YSPickerState();
  447. }
  448. class _YSPickerState extends State<YSPicker> {
  449. var _value;
  450. @override
  451. Widget build(BuildContext context) {
  452. _value = widget.dataArray[0];
  453. return Container(
  454. color: Colors.transparent,
  455. height: hsp(600),
  456. child: Column(
  457. crossAxisAlignment: CrossAxisAlignment.end,
  458. children: [
  459. Container(
  460. height: hsp(100),
  461. padding: EdgeInsets.only(left: wsp(40),right: wsp(40)),
  462. decoration: BoxDecoration(
  463. color: Colors.white,
  464. border: Border(bottom: BorderSide(width: 0.5,color: Color(0xFFEEEEEE)))
  465. ),
  466. child: Row(
  467. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  468. children: [
  469. GestureDetector(
  470. child: Text('取消',style: TextStyle(fontSize: zsp(30),color: Color(0xFF999999)),),
  471. onTap: (){
  472. Navigator.pop(context);
  473. },
  474. ),
  475. GestureDetector(
  476. child: Text('确定',style: TextStyle(fontSize: zsp(30),color: Color(0xFF108DE9)),),
  477. onTap: (){
  478. widget.choose(_value);
  479. Navigator.pop(context);
  480. },
  481. )
  482. ],
  483. ),
  484. ),
  485. Container(
  486. height: hsp(500),
  487. padding: EdgeInsets.all(10),
  488. decoration: BoxDecoration(
  489. color: Colors.white,
  490. borderRadius: BorderRadius.only(topLeft: Radius.circular(20),topRight: Radius.circular(20))
  491. ),
  492. child: CupertinoPicker(
  493. children: [
  494. for(int i=0;i<widget.dataArray.length;i++)Container(
  495. alignment: Alignment.center,
  496. child: Text('${widget.dataArray[i][widget.title]}'),
  497. )
  498. ],
  499. itemExtent: hsp(100),
  500. onSelectedItemChanged: (value){
  501. _value = widget.dataArray[value];
  502. },
  503. ),
  504. ),
  505. ],
  506. ),
  507. );
  508. }
  509. }
  510. timeTag(String time) {
  511. DateTime date = DateTime(DateTime.parse('$time').year,DateTime.parse('$time').month,DateTime.parse('$time').day);
  512. DateTime now = DateTime(DateTime.now().year,DateTime.now().month,DateTime.now().day);
  513. String tagStr = '';
  514. if(now.difference(date).inHours<=0 && now.difference(date).inHours>-24){
  515. tagStr = '今天';
  516. }else if(now.difference(date).inHours<=-24 && now.difference(date).inHours>-48){
  517. tagStr = '明天';
  518. }else if(now.difference(date).inHours<=-48 && now.difference(date).inHours>-72){
  519. tagStr = '后天';
  520. }else{
  521. switch(date.weekday){
  522. case 1: tagStr = '周一';break;
  523. case 2: tagStr = '周二';break;
  524. case 3: tagStr = '周三';break;
  525. case 4: tagStr = '周四';break;
  526. case 5: tagStr = '周五';break;
  527. case 6: tagStr = '周六';break;
  528. case 7: tagStr = '周日';break;
  529. }
  530. }
  531. return tagStr;
  532. }
  533. class DashedRect extends StatelessWidget {
  534. final Color color;
  535. final double strokeWidth;
  536. final double gap;
  537. DashedRect(
  538. {this.color = Colors.black, this.strokeWidth = 1.0, this.gap = 5.0});
  539. @override
  540. Widget build(BuildContext context) {
  541. return Container(
  542. child: Padding(
  543. padding: EdgeInsets.all(strokeWidth / 2),
  544. child: CustomPaint(
  545. painter:
  546. DashRectPainter(color: color, strokeWidth: strokeWidth, gap: gap),
  547. ),
  548. ),
  549. );
  550. }
  551. }
  552. class DashRectPainter extends CustomPainter {
  553. double strokeWidth;
  554. Color color;
  555. double gap;
  556. DashRectPainter(
  557. {this.strokeWidth = 5.0, this.color = Colors.red, this.gap = 5.0});
  558. @override
  559. void paint(Canvas canvas, Size size) {
  560. Paint dashedPaint = Paint()
  561. ..color = color
  562. ..strokeWidth = strokeWidth
  563. ..style = PaintingStyle.stroke;
  564. double x = size.width;
  565. double y = size.height;
  566. Path _topPath = getDashedPath(
  567. a: math.Point(0, 0),
  568. b: math.Point(x, 0),
  569. gap: gap,
  570. );
  571. Path _rightPath = getDashedPath(
  572. a: math.Point(x, 0),
  573. b: math.Point(x, y),
  574. gap: gap,
  575. );
  576. Path _bottomPath = getDashedPath(
  577. a: math.Point(0, y),
  578. b: math.Point(x, y),
  579. gap: gap,
  580. );
  581. Path _leftPath = getDashedPath(
  582. a: math.Point(0, 0),
  583. b: math.Point(0.001, y),
  584. gap: gap,
  585. );
  586. canvas.drawPath(_topPath, dashedPaint);
  587. canvas.drawPath(_rightPath, dashedPaint);
  588. canvas.drawPath(_bottomPath, dashedPaint);
  589. canvas.drawPath(_leftPath, dashedPaint);
  590. }
  591. Path getDashedPath({
  592. @required math.Point<double> a,
  593. @required math.Point<double> b,
  594. @required gap,
  595. }) {
  596. Size size = Size(b.x - a.x, b.y - a.y);
  597. Path path = Path();
  598. path.moveTo(a.x, a.y);
  599. bool shouldDraw = true;
  600. math.Point currentPoint = math.Point(a.x, a.y);
  601. num radians = math.atan(size.height / size.width);
  602. num dx = math.cos(radians) * gap < 0
  603. ? math.cos(radians) * gap * -1
  604. : math.cos(radians) * gap;
  605. num dy = math.sin(radians) * gap < 0
  606. ? math.sin(radians) * gap * -1
  607. : math.sin(radians) * gap;
  608. while (currentPoint.x <= b.x && currentPoint.y <= b.y) {
  609. shouldDraw
  610. ? path.lineTo(currentPoint.x, currentPoint.y)
  611. : path.moveTo(currentPoint.x, currentPoint.y);
  612. shouldDraw = !shouldDraw;
  613. currentPoint = math.Point(
  614. currentPoint.x + dx,
  615. currentPoint.y + dy,
  616. );
  617. }
  618. return path;
  619. }
  620. @override
  621. bool shouldRepaint(CustomPainter oldDelegate) {
  622. return true;
  623. }
  624. }
  625. getSecretStr(String str) {
  626. String secret = str.length==11?'****':'***********';
  627. return str.substring(0,3)+secret+str.substring(str.length-4,str.length);
  628. }
  629. class CirclePageRoute extends PageRoute {
  630. CirclePageRoute({
  631. @required this.builder,
  632. this.transitionDuration = const Duration(milliseconds: 500),
  633. this.opaque = true,
  634. this.barrierDismissible = false,
  635. this.barrierColor,
  636. this.barrierLabel,
  637. this.maintainState = true,
  638. });
  639. final WidgetBuilder builder;
  640. @override
  641. final Duration transitionDuration;
  642. @override
  643. final bool opaque;
  644. @override
  645. final bool barrierDismissible;
  646. @override
  647. final Color barrierColor;
  648. @override
  649. final String barrierLabel;
  650. @override
  651. final bool maintainState;
  652. @override
  653. Widget buildPage(BuildContext context, Animation<double> animation,
  654. Animation<double> secondaryAnimation) {
  655. return AnimatedBuilder(
  656. animation: animation,
  657. builder: (context, child) {
  658. return ClipPath(
  659. clipper: CirclePath(animation.value),
  660. child: child,
  661. );
  662. },
  663. child: builder(context),
  664. );
  665. }
  666. }
  667. class CirclePath extends CustomClipper<Path> {
  668. CirclePath(this.value);
  669. final double value;
  670. @override
  671. Path getClip(Size size) {
  672. var path = Path();
  673. double radius =
  674. value * sqrt(size.height * size.height + size.width * size.width);
  675. path.addOval(Rect.fromLTRB(
  676. size.width - radius, -radius, size.width + radius, radius));
  677. return path;
  678. }
  679. @override
  680. bool shouldReclip(CustomClipper<Path> oldClipper) {
  681. return true;
  682. }
  683. }
  684. loadingView() {
  685. return Center(
  686. //child: CircularProgressIndicator(),
  687. );
  688. }
  689. Widget platformView({ValueSetter platforms,Map message}){
  690. if(message==null)message = {'type':2};
  691. if(defaultTargetPlatform == TargetPlatform.android){
  692. return AndroidView(
  693. viewType: 'plugins.flutter.io/custom_platform_view',
  694. onPlatformViewCreated: (viewId) {
  695. platforms(MethodChannel('com.flutter.guide.MyFlutterView_$viewId'));
  696. },
  697. creationParams: message,
  698. creationParamsCodec: StandardMessageCodec(),
  699. );
  700. }else{
  701. return UiKitView(
  702. viewType: 'plugins.flutter.io/custom_platform_view',
  703. onPlatformViewCreated: (viewId) {
  704. platforms(MethodChannel('com.flutter.guide.MyFlutterView_$viewId'));
  705. },
  706. creationParams: message,
  707. creationParamsCodec: StandardMessageCodec(),
  708. );
  709. }
  710. }
  711. Future<bool> checkVersion() async{
  712. PackageInfo packageInfo = await PackageInfo.fromPlatform();
  713. SharedPreferences prefer = await SharedPreferences.getInstance();
  714. String locVer = prefer.getString('version')??'';
  715. String version = packageInfo.version;
  716. prefer.setString('version', version);
  717. return locVer==version;
  718. }
  719. Widget ysHtml(String content) {
  720. double htmlHeight = 1;
  721. WebViewController _controller;
  722. return StatefulBuilder(
  723. builder: (context,heightSet){
  724. return Container(
  725. height: htmlHeight,
  726. width: MediaQuery.of(context).size.width,
  727. color: Colors.white,
  728. child: WebView(
  729. javascriptMode: JavascriptMode.unrestricted,
  730. onWebViewCreated: (WebViewController controller) {
  731. controller.loadUrl(Uri.dataFromString(content, mimeType: 'text/html', encoding: Encoding.getByName('utf-8')).toString());
  732. _controller = controller;
  733. },
  734. onPageFinished: (url){
  735. _controller.evaluateJavascript("document.body.scrollHeight").then((result){
  736. heightSet(() {
  737. htmlHeight = double.parse(result);
  738. });
  739. });
  740. },
  741. )
  742. );
  743. },
  744. );
  745. }
  746. showNegotiateAlertDio(BuildContext context,{String content,VoidCallback sure}){
  747. showGeneralDialog(
  748. context: context,
  749. barrierDismissible:true,
  750. barrierColor: Colors.black.withOpacity(0.6),
  751. barrierLabel: '',
  752. transitionDuration: Duration(milliseconds: 200),
  753. pageBuilder: (BuildContext context, Animation<double> animation,
  754. Animation<double> secondaryAnimation) {
  755. return Center(
  756. child: Container(
  757. height: MediaQuery.of(context).size.height-(MediaQuery.of(context).padding.top+hsp(100)*2),
  758. width: MediaQuery.of(context).size.width-wsp(100),
  759. decoration: BoxDecoration(
  760. color: Colors.white,
  761. borderRadius: BorderRadius.all(Radius.circular(5))
  762. ),
  763. child: Column(
  764. children: [
  765. Container(
  766. height: hsp(100),
  767. padding: EdgeInsets.only(left: wsp(30),right: wsp(30)),
  768. child: Row(
  769. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  770. children: [
  771. Container(width: hsp(50),),
  772. Text('预定须知',style: TextStyle(fontSize: zsp(34),color: Color(0xFF242329),decoration: TextDecoration.none),),
  773. GestureDetector(
  774. child: Icon(Icons.close,size: hsp(50),color: Color(0xFF242329)),
  775. onTap: (){Navigator.pop(context);},
  776. )
  777. ],
  778. ),
  779. ),
  780. Container(
  781. height: MediaQuery.of(context).size.height-(MediaQuery.of(context).padding.top+hsp(100)*2)-hsp(200),
  782. width: MediaQuery.of(context).size.width-wsp(100),
  783. padding: EdgeInsets.all(wsp(20)),
  784. color: Colors.white,
  785. child: SingleChildScrollView(
  786. child: ysHtml(content),
  787. )
  788. ),
  789. GestureDetector(
  790. onTap: (){Navigator.pop(context);sure();},
  791. child: Container(
  792. height: hsp(100),
  793. alignment: Alignment.center,
  794. child: Text('我知道了',style: TextStyle(fontSize: zsp(34),color: Color(0xFF007EFF),decoration: TextDecoration.none),),
  795. ),
  796. ),
  797. ],
  798. ),
  799. ),
  800. );
  801. }
  802. );
  803. }
  804. showAgreeAlert(BuildContext context,{String title = '',String content = '',ValueSetter agree,bool isWelcome = false}) async{
  805. showGeneralDialog(
  806. context: context,
  807. barrierDismissible:true,
  808. barrierColor: Colors.black.withOpacity(0.6),
  809. barrierLabel: '',
  810. transitionDuration: Duration(milliseconds: 200),
  811. pageBuilder: (BuildContext context, Animation<double> animation,
  812. Animation<double> secondaryAnimation) {
  813. return Center(
  814. child: Container(
  815. height: MediaQuery.of(context).size.height-(MediaQuery.of(context).padding.top+hsp(100)*2),
  816. width: MediaQuery.of(context).size.width-wsp(100),
  817. decoration: BoxDecoration(
  818. color: Colors.white,
  819. borderRadius: BorderRadius.all(Radius.circular(5))
  820. ),
  821. child: Column(
  822. children: [
  823. Container(
  824. height: hsp(100),
  825. padding: EdgeInsets.only(left: wsp(30),right: wsp(30)),
  826. child: Row(
  827. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  828. children: [
  829. Container(width: hsp(34),),
  830. Text(title,style: TextStyle(fontSize: zsp(34),color: Color(0xFF242329),decoration: TextDecoration.none),),
  831. GestureDetector(
  832. onTap: (){Navigator.pop(context);},
  833. child: Icon(Icons.close,size: hsp(50),color: Color(0xFF242329)),
  834. )
  835. ],
  836. ),
  837. ),
  838. Container(
  839. height: MediaQuery.of(context).size.height-(MediaQuery.of(context).padding.top+hsp(100)*2)-hsp(200),
  840. width: MediaQuery.of(context).size.width-wsp(100),
  841. padding: EdgeInsets.all(wsp(20)),
  842. color: Color(0xFFF9F9F9),
  843. child: WebView(
  844. javascriptMode: JavascriptMode.unrestricted,
  845. onWebViewCreated: (WebViewController webViewController) {
  846. webViewController.loadUrl(Uri.dataFromString(content, mimeType: 'text/html', encoding: Encoding.getByName('utf-8')).toString());
  847. },
  848. )
  849. ),
  850. Container(
  851. height: hsp(100),
  852. alignment: Alignment.center,
  853. child: Row(
  854. children: [
  855. GestureDetector(
  856. onTap: (){
  857. agree(false);
  858. },
  859. child: Container(
  860. width: (MediaQuery.of(context).size.width-wsp(100))/2-wsp(1),
  861. alignment: Alignment.center,
  862. child: Text(isWelcome?'不同意并退出':'不同意',style: TextStyle(fontSize: zsp(34),color: Color(0xFF999999),decoration: TextDecoration.none),),
  863. ),
  864. ),
  865. Container(
  866. height: hsp(100),
  867. width: wsp(2),
  868. color: Color(0xFFF9F9F9),
  869. ),
  870. GestureDetector(
  871. onTap: (){
  872. agree(true);
  873. },
  874. child: Container(
  875. width: (MediaQuery.of(context).size.width-wsp(100))/2-wsp(1),
  876. alignment: Alignment.center,
  877. child: Text('同意',style: TextStyle(fontSize: zsp(34),color: Color(0xFF0079FF),decoration: TextDecoration.none),),
  878. ),
  879. )
  880. ],
  881. )
  882. ),
  883. ],
  884. ),
  885. ),
  886. );
  887. }
  888. );
  889. }
  890. showKnowAlert(BuildContext context,{String title = '',String content = '',VoidCallback know}) async{
  891. showGeneralDialog(
  892. context: context,
  893. barrierDismissible:true,
  894. barrierColor: Colors.black.withOpacity(0.6),
  895. barrierLabel: '',
  896. transitionDuration: Duration(milliseconds: 200),
  897. pageBuilder: (BuildContext context, Animation<double> animation,
  898. Animation<double> secondaryAnimation) {
  899. return Center(
  900. child: Container(
  901. height: MediaQuery.of(context).size.height-(MediaQuery.of(context).padding.top+hsp(100)*2),
  902. width: MediaQuery.of(context).size.width-wsp(100),
  903. decoration: BoxDecoration(
  904. color: Colors.white,
  905. borderRadius: BorderRadius.all(Radius.circular(5))
  906. ),
  907. child: Column(
  908. children: [
  909. Container(
  910. height: hsp(100),
  911. padding: EdgeInsets.only(left: wsp(30),right: wsp(30)),
  912. child: Row(
  913. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  914. children: [
  915. Container(),
  916. Text(title,style: TextStyle(fontSize: zsp(34),color: Color(0xFF242329),decoration: TextDecoration.none),),
  917. GestureDetector(
  918. onTap: (){Navigator.pop(context);},
  919. child: Icon(Icons.close,size: hsp(50),color: Color(0xFF242329)),
  920. )
  921. ],
  922. ),
  923. ),
  924. Container(
  925. height: MediaQuery.of(context).size.height-(MediaQuery.of(context).padding.top+hsp(100)*2)-hsp(200),
  926. width: MediaQuery.of(context).size.width-wsp(100),
  927. padding: EdgeInsets.all(wsp(20)),
  928. color: Color(0xFFF9F9F9),
  929. child: WebView(
  930. // initialUrl: 'data:text/html;base64,${base64Encode(const Utf8Encoder().convert(content))}',
  931. javascriptMode: JavascriptMode.unrestricted,
  932. onWebViewCreated: (WebViewController webViewController) {
  933. webViewController.loadUrl(Uri.dataFromString(content, mimeType: 'text/html', encoding: Encoding.getByName('utf-8')).toString());
  934. },
  935. )
  936. ),
  937. GestureDetector(
  938. child: Container(
  939. height: hsp(100),
  940. alignment: Alignment.center,
  941. child: Text('我知道了',style: TextStyle(fontSize: zsp(34),color: Color(0xFF0079FF),decoration: TextDecoration.none),),
  942. ),
  943. onTap: (){
  944. Navigator.pop(context);
  945. know();
  946. },
  947. behavior: HitTestBehavior.opaque,
  948. ),
  949. ],
  950. ),
  951. ),
  952. );
  953. }
  954. );
  955. }
  956. showInformAlert(BuildContext context,{String title = '',String content = '',VoidCallback sure}){
  957. double htmlHeight = MediaQuery.of(context).size.height*0.85-0.5-hsp(100);
  958. WebViewController _controller;
  959. showModalBottomSheet(
  960. isScrollControlled: true,
  961. context: context,
  962. backgroundColor: Colors.transparent,
  963. builder: (context){
  964. return Container(
  965. height: MediaQuery.of(context).size.height*0.85,
  966. decoration: BoxDecoration(
  967. color: Colors.white,
  968. borderRadius: BorderRadius.only(topRight: Radius.circular(10),topLeft: Radius.circular(10))
  969. ),
  970. child: Column(
  971. children: [
  972. Container(
  973. height: hsp(100),
  974. padding: EdgeInsets.only(left: hsp(30),right: hsp(30)),
  975. child: Row(
  976. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  977. children: [
  978. Container(width: wsp(50),),
  979. Text(title,style: TextStyle(fontSize: 15,color: Color(0xFF000000),decoration: TextDecoration.none,fontWeight: FontWeight.bold),),
  980. GestureDetector(
  981. child: Text('关闭',style: TextStyle(fontSize: 15,color: Color(0xFF007EFF),decoration: TextDecoration.none,fontWeight: FontWeight.bold),),
  982. onTap: (){
  983. Navigator.pop(context);
  984. },
  985. ),
  986. ],
  987. ),
  988. ),
  989. Divider(height: 0.5,thickness: 0.5,color: Color(0xFFE5E5E5),),
  990. Container(
  991. height: MediaQuery.of(context).size.height*0.85-0.5-hsp(100),
  992. child: WebView(
  993. // initialUrl: 'data:text/html;base64,${base64Encode(const Utf8Encoder().convert(content))}',
  994. javascriptMode: JavascriptMode.unrestricted,
  995. onWebViewCreated: (WebViewController webViewController) {
  996. webViewController.loadUrl(Uri.dataFromString(content, mimeType: 'text/html', encoding: Encoding.getByName('utf-8')).toString());
  997. },
  998. ),
  999. ),
  1000. ],
  1001. ),
  1002. );
  1003. }
  1004. );
  1005. }
  1006. alertPhone(BuildContext context, String phoneStr) async{
  1007. showCupertinoDialog(
  1008. context: context,
  1009. builder: (context) {
  1010. return CupertinoAlertDialog(
  1011. title: Text('提示'),
  1012. content: Text('拨打 $phoneStr ?'),
  1013. actions: <Widget>[
  1014. CupertinoDialogAction(child: Text('取消'),onPressed: (){Navigator.pop(context);},),
  1015. CupertinoDialogAction(child: Text('确认'),onPressed: (){Navigator.pop(context);launch('tel:$phoneStr');},),
  1016. ],
  1017. );
  1018. });
  1019. }
  1020. _getMonthDay() async{
  1021. }
  1022. getDateArray({ValueSetter dates,int count = 90,String startStr}) {
  1023. List zhongQius = ['2021-9-21','2022-9-10','2023-9-29','2024-9-17','2025-10-6','2026-9-25','2027-9-15','2028-10-3','2029-9-22','2030-9-12'];
  1024. List chuXis = ['2021-2-11','2022-1-31','2023-1-21','2024-2-9','2025-1-28','2026-2-16','2027-2-5','2028-1-25','2029-2-12','2030-2-2'];
  1025. List chunJies = ['2021-2-12','2022-2-1','2023-1-22','2024-2-10','2025-1-29','2026-2-17','2027-2-6','2028-1-26','2029-2-13','2030-2-3'];
  1026. List duanWus = ['2021-6-14','2022-6-3','2023-6-22','2024-6-10','2025-5-31','2026-6-19','2027-6-9','2028-6-27','2029-6-16','2030-6-5'];
  1027. DateTime _time = startStr!=null?DateTime.parse(startStr):DateTime.now();
  1028. int year = _time.year;
  1029. List dateArray = [];
  1030. int month = _time.month;
  1031. int days = DateTime(year, month + 1, 0).day;
  1032. int days2 = DateTime(year, month + 2, 0).day;
  1033. int months = count>days-_time.day+days2+1?3:2;
  1034. int number = 1;
  1035. for(int i = 0;i<months;i++){
  1036. if(month>12){
  1037. year++;
  1038. month = 1;
  1039. }
  1040. int days3 = DateTime(year, month + 1, 0).day;
  1041. dateArray.add({'year':year,'month':month,'days':[]});
  1042. int firstNum = 0;
  1043. int week = DateTime.parse('$year-${'$month'.padLeft(2,'0')}-01 00:00:00').weekday;
  1044. if(week==7){
  1045. firstNum = 0;
  1046. }else{
  1047. firstNum = week;
  1048. }
  1049. for(int j=1;j<days3+1+firstNum;j++){
  1050. if(j<=firstNum){
  1051. dateArray[i]['days'].add(0);
  1052. }else if(number>count||(year==_time.year&&month==_time.month&&j-firstNum<_time.day)){
  1053. //print('$i=============$days================${count+_time.day}');
  1054. dateArray[i]['days'].add((j-firstNum)*0.01);
  1055. }else{
  1056. number++;
  1057. String yStr = '$year-$month-${j-firstNum}';
  1058. String str = '$month-${j-firstNum}';
  1059. if(zhongQius.contains(yStr)==true){
  1060. dateArray[i]['days'].add({'day':j-firstNum,'fes':'中秋'});
  1061. }else if(chuXis.contains(yStr)==true){
  1062. dateArray[i]['days'].add({'day':j-firstNum,'fes':'除夕'});
  1063. }else if(chunJies.contains(yStr)==true){
  1064. dateArray[i]['days'].add({'day':j-firstNum,'fes':'春节'});
  1065. }else if(chunJies.contains(yStr)==true){
  1066. dateArray[i]['days'].add({'day':j-firstNum,'fes':'端午'});
  1067. }else if(str=='1-1'){
  1068. dateArray[i]['days'].add({'day':j-firstNum,'fes':'元旦'});
  1069. }else if(str=='4-4'){
  1070. dateArray[i]['days'].add({'day':j-firstNum,'fes':'清明'});
  1071. }else if(str=='10-1'){
  1072. dateArray[i]['days'].add({'day':j-firstNum,'fes':'国庆'});
  1073. }else if(str=='5-1'){
  1074. dateArray[i]['days'].add({'day':j-firstNum,'fes':'劳动节'});
  1075. }else if(str=='6-1'){
  1076. dateArray[i]['days'].add({'day':j-firstNum,'fes':'儿童节'});
  1077. }else if(str=='12-25'){
  1078. dateArray[i]['days'].add({'day':j-firstNum,'fes':'圣诞节'});
  1079. }else{
  1080. dateArray[i]['days'].add(j-firstNum);
  1081. }
  1082. }
  1083. }
  1084. month++;
  1085. }
  1086. print(dateArray);
  1087. dates(dateArray);
  1088. }
  1089. dateChooseAlert(BuildContext context,{ValueSetter dateValue,int count = 90,String startStr}) {
  1090. List dates = [];
  1091. getDateArray( dates: (value){dates = value;},count: count,startStr: startStr);
  1092. List weeks = ['日','一','二','三','四','五','六'];
  1093. int today = DateTime.now().day;
  1094. int thisMonth = DateTime.now().month;
  1095. int thisYear = DateTime.now().year;
  1096. int year = DateTime.now().year;
  1097. int month = DateTime.now().month;
  1098. int day = DateTime.now().day;
  1099. showModalBottomSheet(
  1100. context: context,
  1101. backgroundColor: Colors.transparent,
  1102. isScrollControlled: true,
  1103. builder: (context){
  1104. return StatefulBuilder(
  1105. builder: (context,dateSet){
  1106. return Container(
  1107. height: MediaQuery.of(context).size.height*0.7,
  1108. width: MediaQuery.of(context).size.width,
  1109. color: Colors.white,
  1110. child: SingleChildScrollView(
  1111. child: Column(
  1112. children: [
  1113. Container(
  1114. height: hsp(80),
  1115. padding: EdgeInsets.only(left: hsp(30),right: hsp(40),top: hsp(10)),
  1116. child: Row(
  1117. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  1118. children: [
  1119. GestureDetector(
  1120. onTap: (){Navigator.pop(context);},
  1121. child: Icon(Icons.close,size: hsp(40),color: Color(0xFF4B4B4B),),
  1122. ),
  1123. Text('选择日期',style: TextStyle(fontSize: zsp(30),color: Colors.black,fontWeight: FontWeight.bold),),
  1124. Container(width: hsp(40),)
  1125. ],
  1126. ),
  1127. ),
  1128. Container(
  1129. height: hsp(80),
  1130. width: MediaQuery.of(context).size.width,
  1131. child: ListView.builder(
  1132. itemCount: weeks.length,
  1133. scrollDirection: Axis.horizontal,
  1134. padding: EdgeInsets.all(0),
  1135. itemBuilder: (context,index){
  1136. return Container(
  1137. height: hsp(80),
  1138. width: MediaQuery.of(context).size.width/weeks.length,
  1139. alignment: Alignment.center,
  1140. child: Text('${weeks[index]}',style: TextStyle(fontSize: zsp(32),color: index==0||index==6?Color(0xFFE85D54):Color(0xFF666666)),),
  1141. );
  1142. },
  1143. ),
  1144. ),
  1145. Container(
  1146. height: MediaQuery.of(context).size.height*0.7-hsp(300),
  1147. width: MediaQuery.of(context).size.width,
  1148. child: SingleChildScrollView(
  1149. child: ListView.separated(
  1150. padding: EdgeInsets.all(0),
  1151. itemCount: dates.length,
  1152. shrinkWrap: true,
  1153. physics: NeverScrollableScrollPhysics(),
  1154. itemBuilder: (context,index){
  1155. Map dateMonth = dates[index];
  1156. return Column(
  1157. children: [
  1158. Container(
  1159. width: MediaQuery.of(context).size.width,
  1160. padding: EdgeInsets.only(left: hsp(30),right: hsp(30)),
  1161. alignment: Alignment.center,
  1162. child: Text('${dateMonth['year']}年 '+'${dateMonth['month']}'.padLeft(2,'0')+'月'),
  1163. height: hsp(70),
  1164. ),
  1165. Divider(height: 1,thickness: 1,color: Color(0xFFF4F4F7),),
  1166. GridView.builder(
  1167. itemCount: dateMonth['days'].length,
  1168. padding: EdgeInsets.all(0),
  1169. shrinkWrap: true,
  1170. physics: NeverScrollableScrollPhysics(),
  1171. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  1172. crossAxisCount: 7,
  1173. ),
  1174. itemBuilder: (context,indexSub){
  1175. var dateDay = dateMonth['days'][indexSub];
  1176. return dateDay==0?Container():GestureDetector(
  1177. onTap: (){
  1178. if((dateDay is Map?dateDay['day']:dateDay)<1)return;
  1179. dateSet(() {
  1180. month = dateMonth['month'];
  1181. day = dateDay is Map?dateDay['day']:dateDay;
  1182. year = dateMonth['year'];
  1183. });
  1184. },
  1185. child: Container(
  1186. alignment: Alignment.center,
  1187. child: dates[index]['days'][indexSub] is Map?Column(
  1188. children: [
  1189. Text(
  1190. dateDay['day']-today==0&&dateMonth['month']==thisMonth&&dateMonth['year']==thisYear?'今天':
  1191. dateDay['day']-today==1&&dateMonth['month']==thisMonth&&dateMonth['year']==thisYear?'明天':
  1192. dateDay['day']-today==2&&dateMonth['month']==thisMonth&&dateMonth['year']==thisYear?'后天':
  1193. '${dateDay['day']~/(dateDay['day']<1?0.01:1)}',style: TextStyle(fontSize: zsp(28),
  1194. color: dateDay['day']==day&&dateMonth['month']==month&&dateMonth['year']==year?Colors.white:
  1195. dateDay['day']<1?Color(0xFFCBCBCB):Color(0xFF333333)),),
  1196. Text('${dateDay['fes']}',style: TextStyle(fontSize: zsp(20),
  1197. color: dateDay['day']==day&&dateMonth['month']==month&&dateMonth['year']==year?Colors.white:
  1198. dateDay['day']<1?Color(0xFFCBCBCB):Color(0xFFE85D54)),)
  1199. ],
  1200. mainAxisSize: MainAxisSize.min,
  1201. ):Text(
  1202. dateDay-today==0&&dateMonth['month']==thisMonth&&dateMonth['year']==thisYear?'今天':
  1203. dateDay-today==1&&dateMonth['month']==thisMonth&&dateMonth['year']==thisYear?'明天':
  1204. dateDay-today==2&&dateMonth['month']==thisMonth&&dateMonth['year']==thisYear?'后天':
  1205. '${dateDay~/(dateDay<1?0.01:1)}',style: TextStyle(fontSize: zsp(28),
  1206. color: dateDay==day&&dateMonth['month']==month&&dateMonth['year']==year?Colors.white:
  1207. dateDay<1?Color(0xFFCBCBCB):Color(0xFF333333)),),
  1208. margin: EdgeInsets.all(hsp(15)),
  1209. decoration: BoxDecoration(
  1210. color: (dateDay is Map?dateDay['day']:dateDay)==day
  1211. &&dateMonth['month']==month&&dateMonth['year']==year?Color(0xFF007AFF):Colors.transparent,
  1212. borderRadius: BorderRadius.all(Radius.circular(5))
  1213. ),
  1214. ),
  1215. );
  1216. },
  1217. )
  1218. ],
  1219. );
  1220. },
  1221. separatorBuilder: (context,index){
  1222. return Divider(height: hsp(20),thickness: hsp(20),color: Color(0xFFF4F4F7),);
  1223. },
  1224. ),
  1225. ),
  1226. ),
  1227. GestureDetector(
  1228. onTap: (){
  1229. Navigator.pop(context);
  1230. String date = '$year-${'$month'.padLeft(2,'0')}-${'$day'.padLeft(2,'0')}';
  1231. dateValue(date);
  1232. },
  1233. child: Container(
  1234. margin: EdgeInsets.only(top: hsp(26)),
  1235. height: hsp(88),
  1236. width: MediaQuery.of(context).size.width-hsp(80),
  1237. decoration: BoxDecoration(
  1238. color: Color(0xFF007EFF),
  1239. borderRadius: BorderRadius.all(Radius.circular(5))
  1240. ),
  1241. alignment: Alignment.center,
  1242. child: Text('完成',style: TextStyle(fontSize: zsp(36),color: Colors.white),),
  1243. ),
  1244. )
  1245. ],
  1246. ),
  1247. ),
  1248. );
  1249. },
  1250. );
  1251. }
  1252. );
  1253. }
  1254. dateChooseAlert1(BuildContext context,{ValueSetter dateValue}) {
  1255. List dates = [];
  1256. getDateArray( dates: (value){dates = value;});
  1257. List weeks = ['日','一','二','三','四','五','六'];
  1258. int today = DateTime.now().day;
  1259. int thisMonth = DateTime.now().month;
  1260. int thisYear = DateTime.now().year;
  1261. int year = DateTime.now().year;
  1262. int month = DateTime.now().month;
  1263. int day = DateTime.now().day;
  1264. showModalBottomSheet(
  1265. context: context,
  1266. backgroundColor: Colors.transparent,
  1267. isScrollControlled: true,
  1268. builder: (context){
  1269. return StatefulBuilder(
  1270. builder: (context,dateSet){
  1271. return Container(
  1272. height: MediaQuery.of(context).size.height*0.7,
  1273. width: MediaQuery.of(context).size.width,
  1274. color: Colors.white,
  1275. child: SingleChildScrollView(
  1276. child: Column(
  1277. children: [
  1278. Container(
  1279. height: hsp(80),
  1280. padding: EdgeInsets.only(left: hsp(30),right: hsp(40),top: hsp(10)),
  1281. child: Row(
  1282. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  1283. children: [
  1284. GestureDetector(
  1285. onTap: (){Navigator.pop(context);},
  1286. child: Icon(Icons.close,size: hsp(40),color: Color(0xFF4B4B4B),),
  1287. ),
  1288. Text('选择日期',style: TextStyle(fontSize: zsp(30),color: Colors.black,fontWeight: FontWeight.bold),),
  1289. Container(width: hsp(40),)
  1290. ],
  1291. ),
  1292. ),
  1293. Container(
  1294. height: hsp(80),
  1295. width: MediaQuery.of(context).size.width,
  1296. child: ListView.builder(
  1297. itemCount: weeks.length,
  1298. scrollDirection: Axis.horizontal,
  1299. padding: EdgeInsets.all(0),
  1300. itemBuilder: (context,index){
  1301. return Container(
  1302. height: hsp(80),
  1303. width: MediaQuery.of(context).size.width/weeks.length,
  1304. alignment: Alignment.center,
  1305. child: Text('${weeks[index]}',style: TextStyle(fontSize: zsp(32),color: index==0||index==6?Color(0xFFE85D54):Color(0xFF666666)),),
  1306. );
  1307. },
  1308. ),
  1309. ),
  1310. Container(
  1311. height: MediaQuery.of(context).size.height*0.7-hsp(300),
  1312. width: MediaQuery.of(context).size.width,
  1313. child: SingleChildScrollView(
  1314. child: ListView.separated(
  1315. padding: EdgeInsets.all(0),
  1316. itemCount: dates.length,
  1317. shrinkWrap: true,
  1318. physics: NeverScrollableScrollPhysics(),
  1319. itemBuilder: (context,index){
  1320. return Column(
  1321. children: [
  1322. Container(
  1323. width: MediaQuery.of(context).size.width,
  1324. padding: EdgeInsets.only(left: hsp(30),right: hsp(30)),
  1325. alignment: Alignment.center,
  1326. child: Text('${dates[index]['year']}年 '+'${dates[index]['month']}'.padLeft(2,'0')+'月'),
  1327. height: hsp(70),
  1328. ),
  1329. Divider(height: 1,thickness: 1,color: Color(0xFFF4F4F7),),
  1330. GridView.builder(
  1331. itemCount: dates[index]['days'].length,
  1332. padding: EdgeInsets.all(0),
  1333. shrinkWrap: true,
  1334. physics: NeverScrollableScrollPhysics(),
  1335. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  1336. crossAxisCount: 7,
  1337. ),
  1338. itemBuilder: (context,indexSub){
  1339. return dates[index]['days'][indexSub]==0?Container():GestureDetector(
  1340. onTap: (){
  1341. if((dates[index]['days'][indexSub] is Map?dates[index]['days'][indexSub]['day']:dates[index]['days'][indexSub])<
  1342. today&&dates[index]['month']==thisMonth&&dates[index]['year']==thisYear)return;
  1343. dateSet(() {
  1344. month = dates[index]['month'];
  1345. day = dates[index]['days'][indexSub] is Map?dates[index]['days'][indexSub]['day']:dates[index]['days'][indexSub];
  1346. year = dates[index]['year'];
  1347. });
  1348. },
  1349. child: Container(
  1350. alignment: Alignment.center,
  1351. child: dates[index]['days'][indexSub] is Map?Column(
  1352. children: [
  1353. Text(
  1354. dates[index]['days'][indexSub]['day']-today==0&&dates[index]['month']==thisMonth&&dates[index]['year']==thisYear?'今天':
  1355. dates[index]['days'][indexSub]['day']-today==1&&dates[index]['month']==thisMonth&&dates[index]['year']==thisYear?'明天':
  1356. dates[index]['days'][indexSub]['day']-today==2&&dates[index]['month']==thisMonth&&dates[index]['year']==thisYear?'后天':
  1357. '${dates[index]['days'][indexSub]['day']}',style: TextStyle(fontSize: zsp(28),
  1358. color: dates[index]['days'][indexSub]['day']==day&&dates[index]['month']==month&&dates[index]['year']==year?Colors.white:
  1359. dates[index]['days'][indexSub]['day']<today&&dates[index]['month']==thisMonth&&dates[index]['year']==thisYear?
  1360. Color(0xFFCBCBCB):Color(0xFF333333)),),
  1361. Text('${dates[index]['days'][indexSub]['fes']}',style: TextStyle(fontSize: zsp(20),
  1362. color: dates[index]['days'][indexSub]['day']==day&&dates[index]['month']==month&&dates[index]['year']==year?Colors.white:
  1363. dates[index]['days'][indexSub]['day']<today&&dates[index]['month']==thisMonth&&dates[index]['year']==thisYear?
  1364. Color(0xFFCBCBCB):Color(0xFFE85D54)),)
  1365. ],
  1366. mainAxisSize: MainAxisSize.min,
  1367. ):Text(dates[index]['days'][indexSub]-today==0&&dates[index]['month']==thisMonth&&dates[index]['year']==thisYear?'今天':
  1368. dates[index]['days'][indexSub]-today==1&&dates[index]['month']==thisMonth&&dates[index]['year']==thisYear?'明天':
  1369. dates[index]['days'][indexSub]-today==2&&dates[index]['month']==thisMonth&&dates[index]['year']==thisYear?'后天':
  1370. '${dates[index]['days'][indexSub]}',style: TextStyle(fontSize: zsp(28),
  1371. color: dates[index]['days'][indexSub]==day&&dates[index]['month']==month&&dates[index]['year']==year?Colors.white:
  1372. dates[index]['days'][indexSub]<today&&dates[index]['month']==thisMonth&&dates[index]['year']==thisYear?
  1373. Color(0xFFCBCBCB):Color(0xFF333333)),),
  1374. margin: EdgeInsets.all(hsp(15)),
  1375. decoration: BoxDecoration(
  1376. color: (dates[index]['days'][indexSub] is Map?dates[index]['days'][indexSub]['day']:dates[index]['days'][indexSub])==day
  1377. &&dates[index]['month']==month&&dates[index]['year']==year?Color(0xFF007AFF):Colors.transparent,
  1378. borderRadius: BorderRadius.all(Radius.circular(5))
  1379. ),
  1380. ),
  1381. );
  1382. },
  1383. )
  1384. ],
  1385. );
  1386. },
  1387. separatorBuilder: (context,index){
  1388. return Divider(height: hsp(20),thickness: hsp(20),color: Color(0xFFF4F4F7),);
  1389. },
  1390. ),
  1391. ),
  1392. ),
  1393. GestureDetector(
  1394. onTap: (){
  1395. String date = '$year-${'$month'.padLeft(2,'0')}-${'$day'.padLeft(2,'0')}';
  1396. Navigator.pop(context);
  1397. dateValue(date);
  1398. },
  1399. child: Container(
  1400. margin: EdgeInsets.only(top: hsp(26)),
  1401. height: hsp(88),
  1402. width: MediaQuery.of(context).size.width-hsp(80),
  1403. decoration: BoxDecoration(
  1404. color: Color(0xFF007EFF),
  1405. borderRadius: BorderRadius.all(Radius.circular(5))
  1406. ),
  1407. alignment: Alignment.center,
  1408. child: Text('完成',style: TextStyle(fontSize: zsp(36),color: Colors.white),),
  1409. ),
  1410. )
  1411. ],
  1412. ),
  1413. ),
  1414. );
  1415. },
  1416. );
  1417. }
  1418. );
  1419. }
  1420. timeChooseAlert(BuildContext context,{ValueSetter timeValue}) {
  1421. int hour = DateTime.now().hour;
  1422. int min = DateTime.now().minute;
  1423. showModalBottomSheet(
  1424. context: context,
  1425. backgroundColor: Colors.transparent,
  1426. builder: (context){
  1427. return Container(
  1428. color: Colors.transparent,
  1429. height: 280,
  1430. child: Column(
  1431. crossAxisAlignment: CrossAxisAlignment.end,
  1432. children: [
  1433. Container(
  1434. height: 40,
  1435. padding: EdgeInsets.only(left: wsp(40),right: wsp(40)),
  1436. decoration: BoxDecoration(
  1437. color: Colors.white,
  1438. border: Border(bottom: BorderSide(width: 0.5,color: Color(0xFFEEEEEE)))
  1439. ),
  1440. child: Row(
  1441. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  1442. children: [
  1443. GestureDetector(
  1444. child: Text('取消',style: TextStyle(fontSize: zsp(30),color: Color(0xFF999999)),),
  1445. onTap: (){
  1446. Navigator.pop(context);
  1447. },
  1448. ),
  1449. GestureDetector(
  1450. child: Text('确定',style: TextStyle(fontSize: zsp(30),color: Color(0xFF108DE9)),),
  1451. onTap: (){
  1452. Navigator.pop(context);
  1453. timeValue(hour.toString().padLeft(2,'0')+':'+min.toString().padLeft(2,'0'));
  1454. },
  1455. )
  1456. ],
  1457. ),
  1458. ),
  1459. Row(
  1460. children: [
  1461. for(int i=0;i<2;i++)Container(
  1462. height: 240,
  1463. width: MediaQuery.of(context).size.width/2,
  1464. color: Colors.white,
  1465. child: CupertinoPicker(
  1466. itemExtent: hsp(100),
  1467. children: [
  1468. for(int j=0;j<(i==0?24:60);j++)Container(
  1469. child: Text(i==0?'$j时':'$j分',style: TextStyle(fontSize: zsp(32),color: Colors.black),),
  1470. alignment: Alignment.center,
  1471. )
  1472. ],
  1473. onSelectedItemChanged: (value){
  1474. if(i==0){
  1475. hour = value;
  1476. }else{
  1477. min = value;
  1478. }
  1479. },
  1480. scrollController: FixedExtentScrollController(
  1481. initialItem: i==0?hour:min
  1482. ),
  1483. ),
  1484. ),
  1485. ],
  1486. ),
  1487. ],
  1488. ),
  1489. );
  1490. }
  1491. );
  1492. }
  1493. showVersionAlert(BuildContext context){
  1494. showGeneralDialog(
  1495. context: context,
  1496. barrierDismissible:true,
  1497. barrierColor: Colors.black.withOpacity(0.6),
  1498. barrierLabel: '',
  1499. transitionDuration: Duration(milliseconds: 200),
  1500. pageBuilder: (BuildContext context, Animation<double> animation,
  1501. Animation<double> secondaryAnimation) {
  1502. return Center(
  1503. child: Container(
  1504. height: MediaQuery.of(context).size.height*0.5,
  1505. width: MediaQuery.of(context).size.width-hsp(100),
  1506. decoration: BoxDecoration(
  1507. color: Colors.white,
  1508. borderRadius: BorderRadius.all(Radius.circular(5))
  1509. ),
  1510. child: Column(
  1511. children: [
  1512. Container(
  1513. padding: EdgeInsets.all(hsp(30)),
  1514. child: Text('版本更新',style: TextStyle(fontSize: zsp(32),color: Colors.black,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  1515. alignment: Alignment.center,
  1516. ),
  1517. Divider(height: 1,thickness: 1,color: Color(0xFFF4F4F7),),
  1518. Container(
  1519. height: MediaQuery.of(context).size.height*0.5-hsp(215),
  1520. width: MediaQuery.of(context).size.width-hsp(100),
  1521. child: ListView.separated(
  1522. itemCount: 5,
  1523. padding: EdgeInsets.only(left: hsp(50),right: hsp(50),top: hsp(30),bottom: hsp(30)),
  1524. itemBuilder: (context,index){
  1525. return Container(
  1526. child: Text('${index+1}、更新更新更新更新更新更新更新更新更新更新更新更新',
  1527. style: TextStyle(fontSize: zsp(30),color: Colors.black,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  1528. width: MediaQuery.of(context).size.width-hsp(160),
  1529. );
  1530. },
  1531. separatorBuilder: (context,index){
  1532. return Divider(height: hsp(20),thickness: hsp(20),color: Colors.transparent,);
  1533. },
  1534. ),
  1535. ),
  1536. Divider(height: 1,thickness: 1,color: Color(0xFFF4F4F7),),
  1537. Container(
  1538. height: hsp(100),
  1539. child: Row(
  1540. children: [
  1541. GestureDetector(
  1542. onTap: (){
  1543. Navigator.pop(context);
  1544. },
  1545. child: Container(
  1546. width: (MediaQuery.of(context).size.width-hsp(100))/2-hsp(1),
  1547. height: hsp(100),
  1548. alignment: Alignment.center,
  1549. child: Text('忽略此版',style: TextStyle(fontSize: zsp(32),color: Colors.black,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  1550. ),
  1551. ),
  1552. Container(height: hsp(100),color: Color(0xFFF4F4F7),width: hsp(2),),
  1553. GestureDetector(
  1554. onTap: (){
  1555. Navigator.pop(context);
  1556. },
  1557. child: Container(
  1558. width: (MediaQuery.of(context).size.width-hsp(100))/2-hsp(1),
  1559. height: hsp(100),
  1560. alignment: Alignment.center,
  1561. child: Text('立即更新',style: TextStyle(fontSize: zsp(32),color: Color(0xFF007AFF),decoration: TextDecoration.none),),
  1562. ),
  1563. )
  1564. ],
  1565. ),
  1566. )
  1567. ],
  1568. ),
  1569. ),
  1570. );
  1571. }
  1572. );
  1573. }
  1574. class NumberFormat extends TextInputFormatter {
  1575. NumberFormat({this.decimalRange = 3})
  1576. : assert(decimalRange == null || decimalRange > 0);
  1577. final int decimalRange;
  1578. @override
  1579. TextEditingValue formatEditUpdate(TextEditingValue oldValue,
  1580. TextEditingValue newValue) {
  1581. // 拿到录入后的字符
  1582. String nValue = newValue.text;
  1583. //当前所选择的文字区域
  1584. TextSelection nSelection = newValue.selection;
  1585. // 先来一波过滤,过滤出数字及小数点
  1586. // 匹配包含数字和小数点的字符
  1587. Pattern p = RegExp(r'(\d+\.?)|(\.?\d+)|(\.?)');
  1588. nValue = p.allMatches(nValue)
  1589. .map<String>((Match match) => match.group(0))
  1590. .join();
  1591. // 用匹配完的字符判断
  1592. if (nValue.startsWith('.')) { //如果小数点开头,我们给他补个0
  1593. nValue = '0.';
  1594. } else if (nValue.contains('.')) {
  1595. //来验证小数点位置
  1596. if (nValue.substring(nValue.indexOf('.') + 1).length > decimalRange) {
  1597. nValue = oldValue.text;
  1598. } else {
  1599. if (nValue.split('.').length > 2) { //多个小数点,去掉后面的
  1600. List<String> split = nValue.split('.');
  1601. nValue = split[0] + '.' + split[1];
  1602. }
  1603. }
  1604. }
  1605. //使光标定位到最后一个字符后面
  1606. nSelection = newValue.selection.copyWith(
  1607. baseOffset: math.min(nValue.length, nValue.length + 1),
  1608. extentOffset: math.min(nValue.length, nValue.length + 1),
  1609. );
  1610. return TextEditingValue(
  1611. text: nValue,
  1612. selection: nSelection,
  1613. composing: TextRange.empty
  1614. );
  1615. }
  1616. }