YSTools.dart 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'dart:ffi';
  4. import 'dart:io';
  5. import 'package:flutter/cupertino.dart';
  6. import 'package:flutter/gestures.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter/services.dart';
  9. import 'package:flutter_webview_pro/webview_flutter.dart';
  10. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  11. import 'package:image_picker/image_picker.dart';
  12. import 'package:live_flutter_plugin/v2_tx_live_premier.dart';
  13. import 'package:package_info/package_info.dart';
  14. import 'package:permission_handler/permission_handler.dart';
  15. import 'package:pull_to_refresh/pull_to_refresh.dart';
  16. import 'package:qiniu_flutter_sdk/qiniu_flutter_sdk.dart';
  17. import 'package:shared_preferences/shared_preferences.dart';
  18. import 'package:sign_in_with_apple/sign_in_with_apple.dart';
  19. import '../../YSPage.dart';
  20. import '../YSMeans.dart';
  21. import '../version2/YSVersionView.dart';
  22. double ysHeight(BuildContext context) => MediaQuery.of(context).size.height;
  23. double ysWidth(BuildContext context) => MediaQuery.of(context).size.width;
  24. double ysTOP(BuildContext context) => MediaQuery.of(context).padding.top;
  25. double ysBottom(BuildContext context) => MediaQuery.of(context).padding.bottom;
  26. Color ysBgColor = const Color(0xFFF6F6F6);
  27. class YSDatePicker extends StatefulWidget {
  28. final ValueSetter<String> choose;
  29. final bool withTime;
  30. const YSDatePicker({Key key, this.choose, this.withTime = false}) : super(key: key);
  31. @override
  32. _YSDatePickerState createState() => _YSDatePickerState();
  33. }
  34. class _YSDatePickerState extends State<YSDatePicker> {
  35. String birthday = DateTime.now().year.toString()+'-'+DateTime.now().month.toString().padLeft(2,'0')+'-'+DateTime.now().day.toString().padLeft(2,'0');
  36. @override
  37. void initState() {
  38. if(widget.withTime){
  39. birthday = birthday+' '+'${DateTime.now().hour}'.padLeft(2,'0')+':'+'${DateTime.now().minute}'.padLeft(2,'0');
  40. }
  41. super.initState();
  42. }
  43. @override
  44. Widget build(BuildContext context) {
  45. return Container(
  46. color: Colors.transparent,
  47. height: 340,
  48. child: Column(
  49. crossAxisAlignment: CrossAxisAlignment.end,
  50. children: [
  51. CupertinoButton(
  52. padding: EdgeInsets.all(0),
  53. child: Container(
  54. height: 20,
  55. child: Image.asset('lib/images/off.png'),
  56. ),
  57. onPressed: (){
  58. Navigator.pop(context);
  59. },
  60. ),
  61. Container(
  62. height: 240,
  63. padding: EdgeInsets.all(10),
  64. decoration: BoxDecoration(
  65. color: Colors.white,
  66. borderRadius: BorderRadius.only(topLeft: Radius.circular(20),topRight: Radius.circular(20))
  67. ),
  68. child: CupertinoDatePicker(
  69. initialDateTime: DateTime.now(),
  70. onDateTimeChanged: (date) {
  71. birthday = date.year.toString()+'-'+date.month.toString().padLeft(2,'0')+'-'+date.day.toString().padLeft(2,'0');
  72. if(widget.withTime){
  73. birthday = birthday+' '+'${date.hour}'.padLeft(2,'0')+':'+'${date.minute}'.padLeft(2,'0');
  74. }
  75. },
  76. mode: widget.withTime?CupertinoDatePickerMode.dateAndTime:CupertinoDatePickerMode.date,
  77. ),
  78. ),
  79. Container(
  80. height: 56,
  81. width: MediaQuery.of(context).size.width,
  82. color: Colors.white,
  83. child: CupertinoButton(
  84. padding: EdgeInsets.all(0),
  85. child: Container(
  86. height: 30,
  87. width: 80,
  88. decoration: BoxDecoration(
  89. color: Colors.white,
  90. borderRadius: BorderRadius.all(Radius.circular(15)),
  91. boxShadow: [
  92. BoxShadow(color: Colors.grey,blurRadius: 3)
  93. ]
  94. ),
  95. child: Text('确定',style: TextStyle(fontSize: 14,color: Color(0xFF4CC17C),decoration: TextDecoration.none,fontWeight: FontWeight.normal)),
  96. alignment: Alignment.center,
  97. ),
  98. onPressed: (){
  99. Navigator.pop(context);
  100. widget.choose(birthday);
  101. },
  102. ),
  103. alignment: Alignment.center,
  104. )
  105. ],
  106. ),
  107. );
  108. }
  109. }
  110. ysDatePicker(BuildContext context,ValueSetter valueSetter,{DateTime firstDate,DateTime lastDate,DateTime initDate}) {
  111. showDatePicker(
  112. context: context,
  113. firstDate: firstDate!=null?firstDate:DateTime.parse('2000-01-01 00:00:00'),
  114. initialDate: initDate!=null?initDate:DateTime.now(),
  115. lastDate: lastDate!=null?lastDate:DateTime.parse('3000-01-01 00:00:00'),
  116. builder: (BuildContext context, Widget child) {
  117. return Theme(
  118. data: ThemeData.dark().copyWith(
  119. colorScheme: ColorScheme.light(
  120. primary: Colors.pinkAccent,
  121. ),
  122. dialogBackgroundColor:Colors.white,
  123. ),
  124. child: child,
  125. );
  126. },
  127. ).then((date) {
  128. if(date==null)return;
  129. String dateStr = date.year.toString()+'-'+date.month.toString().padLeft(2,'0')+'-'+date.day.toString().padLeft(2,'0');
  130. valueSetter(dateStr);
  131. });
  132. }
  133. ysUploadFile(BuildContext context,{String path,ValueSetter setter,String type}) async{
  134. var dict = await ysRequestHttpNoLoading(context, requestType.get, 'upQiniuToken', {'type':type});
  135. if(dict!=null){
  136. Storage _storage = Storage();
  137. _storage.putFile(
  138. File(path),
  139. dict['token'],
  140. options: PutOptions(
  141. key: dict['path'],
  142. ),
  143. ).then((PutResponse response) async{
  144. setter({'path':dict['path'],'url':dict['url']});
  145. });
  146. }
  147. }
  148. GlobalKey<_YSRefreshLoadState> refreshKey = GlobalKey();
  149. GlobalKey<_YSRefreshLoadState> refreshKey2 = GlobalKey();
  150. GlobalKey<_YSRefreshLoadState> refreshKey3 = GlobalKey();
  151. class YSRefreshLoad extends StatefulWidget {
  152. final dataWidget;
  153. final ValueSetter postData;
  154. final String url;
  155. final Map request;
  156. const YSRefreshLoad({Key key, @required this.url, @required this.request, @required this.dataWidget, @required this.postData,}) : super(key: key);
  157. @override
  158. _YSRefreshLoadState createState() => _YSRefreshLoadState();
  159. }
  160. class _YSRefreshLoadState extends State<YSRefreshLoad> {
  161. int _page = 1;
  162. RefreshController _refreshController = RefreshController(initialRefresh: false);
  163. List _dataArray = [];
  164. int _totalNum = 0;
  165. @override
  166. void initState() {
  167. Future.delayed(Duration(seconds: 0)).then((value){
  168. _refreshData();
  169. });
  170. super.initState();
  171. }
  172. refresh(){
  173. _refreshData();
  174. }
  175. @override
  176. void dispose() {
  177. if(_refreshController!=null){
  178. _refreshController.dispose();
  179. }
  180. super.dispose();
  181. }
  182. @override
  183. Widget build(BuildContext context) {
  184. return SmartRefresher(
  185. onRefresh: _refreshData,
  186. onLoading: _loadMore,
  187. enablePullUp: _dataArray.length<_totalNum,
  188. controller: _refreshController,
  189. header: ClassicHeader(
  190. height: 45.0,
  191. releaseText: '松开手刷新',
  192. refreshingText: '刷新中',
  193. completeText: '刷新完成',
  194. failedText: '刷新失败',
  195. idleText: '下拉刷新',
  196. ),
  197. footer: ClassicFooter(
  198. height: 45.0,
  199. canLoadingText: '没有更多数据了',
  200. noDataText: ' 无数据',
  201. loadingText: '加载中 ',
  202. failedText: '加载失败',
  203. idleText: '上拉加载',
  204. ),
  205. child: NotificationListener<CustomNotification>(
  206. onNotification: (value){
  207. _refreshData();
  208. return true;
  209. },
  210. child: _dataArray.isEmpty?Center(
  211. child: Image.asset('lib/images/none.png',height: 200,width: 200,),
  212. ):widget.dataWidget,
  213. )
  214. );
  215. }
  216. Future<void> _refreshData() async{
  217. _page = 1;
  218. Map request = {'page':_page};
  219. request.addAll(widget.request);
  220. requestType type = requestType.get;
  221. if(widget.url=='transfer/coupon/getCommunityVouchers'){
  222. type = requestType.post;
  223. request['pageSize'] = 10;
  224. }
  225. Map dict = await ysRequestHttpNoLoading(context,type,widget.url,request);
  226. if(dict!=null){
  227. List array = [];
  228. array = dict['data']['datas'];
  229. _totalNum = dict['data']['pages']['total'];
  230. _refreshController.refreshCompleted();
  231. _dataArray = array;
  232. widget.postData(_dataArray);
  233. }
  234. }
  235. Future<void> _loadMore() async{
  236. _page++;
  237. Map request = {'page':_page};
  238. request.addAll(widget.request);
  239. requestType type = requestType.get;
  240. if(widget.url=='transfer/coupon/getCommunityVouchers'){
  241. type = requestType.post;
  242. request['pageSize'] = 10;
  243. }
  244. Map dict = await ysRequestHttpNoLoading(context,type,widget.url,request);
  245. if(dict!=null){
  246. List array = [];
  247. array = dict['data']['datas'];
  248. _refreshController.loadComplete();
  249. _dataArray.addAll(array);
  250. widget.postData(_dataArray);
  251. }
  252. }
  253. }
  254. class YSRefreshLoad2 extends StatefulWidget {
  255. final dataWidget;
  256. final ValueSetter postData;
  257. final String url;
  258. final Map request;
  259. const YSRefreshLoad2({Key key, @required this.url, @required this.request, @required this.dataWidget, @required this.postData,}) : super(key: key);
  260. @override
  261. _YSRefreshLoad2State createState() => _YSRefreshLoad2State();
  262. }
  263. class _YSRefreshLoad2State extends State<YSRefreshLoad2> {
  264. int _page = 1;
  265. RefreshController _refreshController = RefreshController(initialRefresh: false);
  266. List _dataArray = [];
  267. int _totalNum = 0;
  268. @override
  269. void initState() {
  270. Future.delayed(Duration(seconds: 0)).then((value){
  271. _refreshData();
  272. });
  273. super.initState();
  274. }
  275. refresh(){
  276. _refreshData();
  277. }
  278. @override
  279. void dispose() {
  280. if(_refreshController!=null){
  281. _refreshController.dispose();
  282. }
  283. super.dispose();
  284. }
  285. @override
  286. Widget build(BuildContext context) {
  287. return SmartRefresher(
  288. onRefresh: _refreshData,
  289. onLoading: _loadMore,
  290. enablePullUp: _dataArray.length<_totalNum,
  291. controller: _refreshController,
  292. header: ClassicHeader(
  293. height: 45.0,
  294. releaseText: '松开手刷新',
  295. refreshingText: '刷新中',
  296. completeText: '刷新完成',
  297. failedText: '刷新失败',
  298. idleText: '下拉刷新',
  299. ),
  300. footer: ClassicFooter(
  301. height: 45.0,
  302. canLoadingText: '没有更多数据了',
  303. noDataText: ' 无数据',
  304. loadingText: '加载中 ',
  305. failedText: '加载失败',
  306. idleText: '上拉加载',
  307. ),
  308. child: NotificationListener<CustomNotification>(
  309. onNotification: (value){
  310. _refreshData();
  311. return true;
  312. },
  313. child: widget.dataWidget,
  314. )
  315. );
  316. }
  317. Future<void> _refreshData() async{
  318. _page = 1;
  319. Map request = {'page':_page};
  320. request.addAll(widget.request);
  321. Map dict = await ysRequestHttpNoLoading(context,requestType.post,widget.url,request);
  322. if(dict!=null){
  323. List array = [];
  324. array = dict['data']['records'];
  325. _totalNum = dict['data']['total'];
  326. _refreshController.refreshCompleted();
  327. _dataArray = array;
  328. widget.postData(_dataArray);
  329. }
  330. }
  331. Future<void> _loadMore() async{
  332. _page++;
  333. Map request = {'page':_page};
  334. request.addAll(widget.request);
  335. Map dict = await ysRequestHttpNoLoading(context,requestType.post,widget.url,request);
  336. if(dict!=null){
  337. List array = [];
  338. array = dict['data']['records'];
  339. _totalNum = dict['data']['total'];
  340. _refreshController.loadComplete();
  341. _dataArray.addAll(array);
  342. widget.postData(_dataArray);
  343. }
  344. }
  345. }
  346. class CustomNotification extends Notification {
  347. CustomNotification(this.value);
  348. final String value;
  349. }
  350. class LogUtil {
  351. static var _separator = "=";
  352. static var _split =
  353. "$_separator$_separator$_separator$_separator$_separator$_separator$_separator$_separator$_separator";
  354. static var _title = "Yl-Log";
  355. static var _isDebug = true;
  356. static int _limitLength = 800;
  357. static String _startLine = "$_split$_title$_split";
  358. static String _endLine = "$_split$_separator$_separator$_separator$_split";
  359. static void init({String title, @required bool isDebug,int limitLength}) {
  360. _title = title;
  361. _isDebug = isDebug;
  362. _limitLength = limitLength??=_limitLength;
  363. _startLine = "$_split$_title$_split";
  364. var endLineStr = StringBuffer();
  365. var cnCharReg = RegExp("[\u4e00-\u9fa5]");
  366. for (int i = 0; i < _startLine.length; i++) {
  367. if (cnCharReg.stringMatch(_startLine[i]) != null) {
  368. endLineStr.write(_separator);
  369. }
  370. endLineStr.write(_separator);
  371. }
  372. _endLine = endLineStr.toString();
  373. }
  374. //仅Debug模式可见
  375. static void d(dynamic obj) {
  376. if (_isDebug) {
  377. _log(obj.toString());
  378. }
  379. }
  380. static void v(dynamic obj) {
  381. _log(obj.toString());
  382. }
  383. static void _log(String msg) {
  384. print("$_startLine");
  385. _logEmpyLine();
  386. if(msg.length<_limitLength){
  387. print(msg);
  388. }else{
  389. segmentationLog(msg);
  390. }
  391. _logEmpyLine();
  392. print("$_endLine");
  393. }
  394. static void segmentationLog(String msg) {
  395. var outStr = StringBuffer();
  396. for (var index = 0; index < msg.length; index++) {
  397. outStr.write(msg[index]);
  398. if (index % _limitLength == 0 && index!=0) {
  399. print(outStr);
  400. outStr.clear();
  401. var lastIndex = index+1;
  402. if(msg.length-lastIndex<_limitLength){
  403. var remainderStr = msg.substring(lastIndex,msg.length);
  404. print(remainderStr);
  405. break;
  406. }
  407. }
  408. }
  409. }
  410. static void _logEmpyLine(){
  411. print("");
  412. }
  413. }
  414. ysShowBottomAlertView(BuildContext context,Widget widget,{bool isBarr = false}) {
  415. showModalBottomSheet(
  416. context: context,
  417. isScrollControlled: true,
  418. backgroundColor: Colors.transparent,
  419. barrierColor: !isBarr?Colors.transparent:Colors.black54,
  420. builder: (context){
  421. return widget;
  422. }
  423. );
  424. }
  425. ysShowBottomAlertView2(BuildContext context,Widget widget,{bool isBarr = false}) {
  426. showModalBottomSheet(
  427. context: context,
  428. isScrollControlled: true,
  429. backgroundColor: Colors.transparent,
  430. barrierColor: !isBarr?Colors.transparent:Colors.black54,
  431. builder: (context){
  432. return AnimatedPadding(
  433. padding: MediaQuery.of(context).viewInsets,
  434. duration: const Duration(milliseconds: 100),
  435. child: widget
  436. );
  437. }
  438. );
  439. }
  440. ysShowCenterAlertView(BuildContext context,Widget widget,{bool isTrans = false,bool isBarr = false}) {
  441. showGeneralDialog(
  442. context: context,
  443. barrierDismissible: isBarr,
  444. barrierLabel: '',
  445. barrierColor: isTrans==true?Colors.transparent:Colors.black54,
  446. pageBuilder: (context,animation,scAnimation){
  447. return widget;
  448. }
  449. );
  450. }
  451. class User {
  452. // 工厂模式 : 单例公开访问点
  453. factory User() => _getInstance();
  454. static User get instance => _getInstance();
  455. // 静态私有成员,没有初始化
  456. static User _instance;
  457. String userId = '0';
  458. String name = '';
  459. String avatar = '';
  460. String stream = '';
  461. String idCard;
  462. String content = '';
  463. bool isAnchor = false;
  464. String routeStr = '';
  465. int chapter = 0;
  466. String castAvatar;
  467. String castName;
  468. // 私有构造函数
  469. User._internal() {
  470. // 初始化
  471. }
  472. // 静态、同步、私有访问点
  473. static User _getInstance() {
  474. if (_instance == null) {
  475. _instance = new User._internal();
  476. }
  477. return _instance;
  478. }
  479. }
  480. class YSChooseFileView extends StatefulWidget {
  481. final bool isPhoto;
  482. final ValueSetter valueSetter;
  483. const YSChooseFileView({Key key, this.valueSetter, this.isPhoto = true}) : super(key: key);
  484. @override
  485. YSChooseFileViewState createState() => YSChooseFileViewState();
  486. }
  487. class YSChooseFileViewState extends State<YSChooseFileView> {
  488. final ImagePicker _picker = ImagePicker();
  489. final List _chooseArray = [];
  490. @override
  491. void initState() {
  492. _chooseArray.clear();
  493. if(widget.isPhoto){
  494. _chooseArray.addAll([
  495. {'title':'拍摄图片','type':1},
  496. {'title':'选择图片','type':2},
  497. {'title':'取消','type':0}
  498. ]);
  499. }else{
  500. _chooseArray.addAll([
  501. {'title':'拍摄图片','type':1},
  502. {'title':'选择图片','type':2},
  503. {'title':'拍摄视频','type':3},
  504. {'title':'选择视频','type':4},
  505. {'title':'取消','type':0}
  506. ]);
  507. }
  508. super.initState();
  509. }
  510. @override
  511. Widget build(BuildContext context) {
  512. return Container(
  513. height: 20+50*_chooseArray.length/1,
  514. decoration: const BoxDecoration(
  515. color: Colors.white,
  516. borderRadius: BorderRadius.only(topRight: Radius.circular(10),topLeft: Radius.circular(10))
  517. ),
  518. child: ListView.separated(
  519. physics: const NeverScrollableScrollPhysics(),
  520. itemCount: _chooseArray.length,
  521. padding: const EdgeInsets.all(0),
  522. itemBuilder: (context,index){
  523. Map item = _chooseArray[index];
  524. int type = item['type'];
  525. return GestureDetector(
  526. onTap: (){
  527. if(type==0){
  528. Navigator.pop(context);
  529. }else{
  530. if(type==1){
  531. _picker.pickImage(source: ImageSource.camera,imageQuality: 60).then((value){
  532. widget.valueSetter(value);
  533. Navigator.pop(context);
  534. });
  535. }else if(type==2){
  536. _picker.pickImage(imageQuality: 60,source: ImageSource.gallery).then((value){
  537. widget.valueSetter(value);
  538. Navigator.pop(context);
  539. });
  540. }else if(type==3||type==4){
  541. _picker.pickVideo(source: type==3?ImageSource.camera:ImageSource.gallery).then((value){
  542. widget.valueSetter(value);
  543. Navigator.pop(context);
  544. });
  545. }
  546. }
  547. },
  548. behavior: HitTestBehavior.opaque,
  549. child: Container(
  550. height: 50,
  551. width: MediaQuery.of(context).size.width,
  552. padding: EdgeInsets.only(left: 16,right: 16),
  553. alignment: Alignment.center,
  554. child: Text(item['title'],style: TextStyle(fontSize: 16,color: Colors.black),),
  555. ),
  556. );
  557. },
  558. separatorBuilder: (context,index){
  559. return Divider(height: index==_chooseArray.length-2?8:1,thickness: index==_chooseArray.length-2?8:1,color: const Color(0xFFF7F7F7),);
  560. },
  561. ),
  562. );
  563. }
  564. }
  565. setupLicense() {
  566. var LICENSEURL = "https://license.vod2.myqcloud.com/license/v2/1308439060_1/v_cube.license";
  567. var LICENSEURLKEY = "e194f81894e300965d1ae08a5e0bf404";
  568. V2TXLivePremier.setLicence(LICENSEURL, LICENSEURLKEY);
  569. }
  570. Future<bool> permissionHandler(String serviceStr) async{
  571. if(serviceStr=='location'){
  572. if (await Permission.location.request().isGranted||await Permission.locationWhenInUse.request().isGranted) {
  573. return true;
  574. }else if (await Permission.location.request().isPermanentlyDenied&&await Permission.locationWhenInUse.request().isPermanentlyDenied) {
  575. return false;
  576. }else{
  577. Map<Permission, PermissionStatus> statuses = await [Permission.location,Permission.locationWhenInUse].request();
  578. if(statuses[Permission.location].isGranted || statuses[Permission.locationWhenInUse].isGranted){
  579. return true;
  580. }
  581. }
  582. }else if(serviceStr=='camera'){
  583. if (await Permission.camera.request().isGranted) {
  584. return true;
  585. }else if (await Permission.camera.request().isPermanentlyDenied) {
  586. return false;
  587. }else{
  588. Map<Permission, PermissionStatus> statuses = await [Permission.camera].request();
  589. if(statuses[Permission.camera].isGranted){
  590. return true;
  591. }
  592. }
  593. }else if(serviceStr=='microphone'){
  594. if (await Permission.microphone.request().isGranted) {
  595. return true;
  596. }else if (await Permission.microphone.request().isPermanentlyDenied) {
  597. return false;
  598. }else{
  599. Map<Permission, PermissionStatus> statuses = await [Permission.microphone].request();
  600. if(statuses[Permission.microphone].isGranted){
  601. return true;
  602. }
  603. }
  604. }
  605. return false;
  606. }
  607. class CustomerNotification extends Notification {
  608. CustomerNotification();
  609. }
  610. class CustomerValueNotification extends Notification {
  611. final Map value;
  612. CustomerValueNotification(this.value);
  613. }
  614. // class SocketManage {
  615. // static WebSocket _socket;
  616. // static ValueSetter<Map> setter;
  617. // // 建立连接
  618. // static void connectSocket() async {
  619. // WebSocket.connect('ws://101.43.97.222:8686').then((socket) {
  620. // _socket = socket;
  621. // _socket.listen(onData,onError: onError, onDone: onDone, cancelOnError: false);
  622. // }).catchError((e){
  623. // LogUtil.d("Unable to connect: $e");
  624. // connectSocket(); // 连接超时,重新建立连接
  625. // });
  626. // }
  627. //
  628. // // 收到消息回调
  629. // static void onData(event) async{
  630. // Map dict = jsonDecode(event);
  631. // LogUtil.d("---onData---$dict");
  632. // Map data = dict['data'];
  633. // if(dict['msg']=='连接成功'){
  634. // setter({'type':0,'content':data['content']});
  635. // Map message = {};
  636. // message['type'] = 'bind';
  637. // message['live_stream'] = User().stream;
  638. // message['uid'] = data['uid'];
  639. // message['user'] = {'username':User().name,'avatar':User().avatar,'is_owner':User().isAnchor};
  640. // LogUtil.d('---onData---$message');
  641. // writeData(message);
  642. // }
  643. // }
  644. //
  645. // // 收到错误回调
  646. // static void onError(err) {
  647. // LogUtil.d("---onError---");
  648. // }
  649. //
  650. // // 断开回调
  651. // static void onDone() {
  652. // // Future.delayed(const Duration(milliseconds: 2000), () {
  653. // // connectSocket(); // 重新建立连接
  654. // // });
  655. // LogUtil.d("---onDone---");
  656. // }
  657. //
  658. // // 发数据
  659. // static void writeData(Object object){
  660. // _socket.add(jsonEncode(object));
  661. // }
  662. //
  663. // // 关闭流通道
  664. // static void socketClose(){
  665. // _socket.close();
  666. // }
  667. // }
  668. class YSTipsAlertView extends StatelessWidget {
  669. final ValueSetter<bool> valueSetter;
  670. final String tipsStr;
  671. const YSTipsAlertView({Key key, this.valueSetter, this.tipsStr}) : super(key: key);
  672. @override
  673. Widget build(BuildContext context) {
  674. return Center(
  675. child: Container(
  676. width: ysWidth(context)-60,
  677. height: 200,
  678. decoration: const BoxDecoration(
  679. color: Colors.white,
  680. borderRadius: BorderRadius.all(Radius.circular(10))
  681. ),
  682. child: LayoutBuilder(
  683. builder: (context,conSize){
  684. return Column(
  685. children: [
  686. Container(
  687. height: 50,
  688. decoration: const BoxDecoration(
  689. border: Border(bottom: BorderSide(color: Color(0xFFEBEDF0),width: 0.5))
  690. ),
  691. alignment: Alignment.center,
  692. child: Text('提醒',style: TextStyle(fontSize: 16,color: Colors.black,decoration: TextDecoration.none),),
  693. ),
  694. Container(
  695. height: 100,
  696. alignment: Alignment.center,
  697. padding: EdgeInsets.all(10),
  698. child: Text(tipsStr,style: TextStyle(fontSize: 14,color: const Color(0xFF4A4A4A),
  699. decoration: TextDecoration.none,fontWeight: FontWeight.normal),maxLines: 3,overflow: TextOverflow.ellipsis,),
  700. ),
  701. Container(
  702. height: 50,
  703. decoration: const BoxDecoration(
  704. border: Border(top: BorderSide(color: Color(0xFFEBEDF0),width: 0.5))
  705. ),
  706. child: ListView.separated(
  707. itemBuilder: (context,index){
  708. return GestureDetector(
  709. onTap: (){
  710. Navigator.pop(context);
  711. valueSetter(index==1);
  712. },
  713. behavior: HitTestBehavior.opaque,
  714. child: Container(
  715. width: conSize.maxWidth/2-0.25,
  716. alignment: Alignment.center,
  717. child: Text(
  718. index==0?'取消':'确定',
  719. style: TextStyle(
  720. fontSize: 16,
  721. color: index==0?const Color(0xFF323233):const Color(0xFFF05183),
  722. decoration: TextDecoration.none,
  723. fontWeight: FontWeight.normal
  724. ),
  725. ),
  726. ),
  727. );
  728. },
  729. separatorBuilder: (context,index){
  730. return Container(width: 0.5,color: const Color(0xFFEBEDF0),);
  731. },
  732. itemCount: 2,
  733. scrollDirection: Axis.horizontal,
  734. ),
  735. )
  736. ],
  737. );
  738. },
  739. ),
  740. ),
  741. );
  742. }
  743. }
  744. class YSTipsAlertView2 extends StatelessWidget {
  745. final ValueSetter<bool> valueSetter;
  746. final String tipsStr;
  747. const YSTipsAlertView2({Key key, this.valueSetter, this.tipsStr}) : super(key: key);
  748. @override
  749. Widget build(BuildContext context) {
  750. return Center(
  751. child: Container(
  752. width: ysWidth(context)-60,
  753. height: 200,
  754. decoration: const BoxDecoration(
  755. color: Colors.white,
  756. borderRadius: BorderRadius.all(Radius.circular(10))
  757. ),
  758. child: LayoutBuilder(
  759. builder: (context,conSize){
  760. return Column(
  761. children: [
  762. Container(
  763. height: 50,
  764. decoration: const BoxDecoration(
  765. border: Border(bottom: BorderSide(color: Color(0xFFEBEDF0),width: 0.5))
  766. ),
  767. alignment: Alignment.center,
  768. child: Text('提醒',style: TextStyle(fontSize: 16,color: Colors.black,decoration: TextDecoration.none),),
  769. ),
  770. Container(
  771. height: 100,
  772. alignment: Alignment.center,
  773. padding: EdgeInsets.all(10),
  774. child: Text(tipsStr,style: TextStyle(fontSize: 14,color: const Color(0xFF4A4A4A),
  775. decoration: TextDecoration.none,fontWeight: FontWeight.normal),maxLines: 3,overflow: TextOverflow.ellipsis,),
  776. ),
  777. GestureDetector(
  778. onTap: (){
  779. Navigator.pop(context);
  780. valueSetter(true);
  781. },
  782. behavior: HitTestBehavior.opaque,
  783. child: Container(
  784. height: 50,
  785. decoration: const BoxDecoration(
  786. border: Border(top: BorderSide(color: Color(0xFFEBEDF0),width: 0.5))
  787. ),
  788. alignment: Alignment.center,
  789. child: Text('确定',
  790. style: TextStyle(
  791. fontSize: 16,
  792. color: const Color(0xFFF05183),
  793. decoration: TextDecoration.none,
  794. fontWeight: FontWeight.normal
  795. ),
  796. ),
  797. ),
  798. )
  799. ],
  800. );
  801. },
  802. ),
  803. ),
  804. );
  805. }
  806. }
  807. showNegotiate1AlertDio(BuildContext context,{String content = '',String title = ''}) {
  808. showGeneralDialog(
  809. context: context,
  810. barrierDismissible:true,
  811. barrierColor: Colors.black.withOpacity(0.6),
  812. barrierLabel: '',
  813. transitionDuration: Duration(milliseconds: 200),
  814. pageBuilder: (BuildContext context, Animation<double> animation,
  815. Animation<double> secondaryAnimation) {
  816. return Center(
  817. child: Container(
  818. height: MediaQuery.of(context).size.height-(MediaQuery.of(context).padding.top+50*2),
  819. width: MediaQuery.of(context).size.width-50,
  820. decoration: BoxDecoration(
  821. color: Colors.white,
  822. borderRadius: BorderRadius.all(Radius.circular(5))
  823. ),
  824. child: Column(
  825. children: [
  826. Container(
  827. height: 50,
  828. padding: EdgeInsets.only(left: 15,right: 15),
  829. child: Row(
  830. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  831. children: [
  832. Container(),
  833. Text(title,style: TextStyle(fontSize: 17,color: Color(0xFF242329),decoration: TextDecoration.none),),
  834. GestureDetector(
  835. child: Icon(Icons.close,size: 25,color: Color(0xFF242329)),
  836. onTap: (){Navigator.pop(context);},
  837. )
  838. ],
  839. ),
  840. ),
  841. Divider(height: 0.5,thickness: 0.5,color: Color(0xFFEDEDED),),
  842. Container(
  843. height: MediaQuery.of(context).size.height-(MediaQuery.of(context).padding.top+50*2)-50-0.5,
  844. width: MediaQuery.of(context).size.width,
  845. padding: EdgeInsets.all(10),
  846. child: WebView(
  847. javascriptMode: JavascriptMode.unrestricted,
  848. onWebViewCreated: (WebViewController webViewController) {
  849. // webViewController.loadUrl(Uri.dataFromString(content, mimeType: 'text/html', encoding: Encoding.getByName('utf-8')).toString());
  850. webViewController.loadUrl(content);
  851. },
  852. ),
  853. ),
  854. ],
  855. ),
  856. ),
  857. );
  858. }
  859. );
  860. }
  861. showNegotiate2AlertDio(BuildContext context,{String content = '',String title = '',VoidCallback agree,VoidCallback disAgree}) {
  862. showGeneralDialog(
  863. context: context,
  864. barrierDismissible:true,
  865. barrierColor: Colors.black.withOpacity(0.6),
  866. barrierLabel: '',
  867. transitionDuration: Duration(milliseconds: 200),
  868. pageBuilder: (BuildContext context, Animation<double> animation,
  869. Animation<double> secondaryAnimation) {
  870. return WillPopScope(
  871. onWillPop: () async{
  872. return false;
  873. },
  874. child: Center(
  875. child: Container(
  876. height: MediaQuery.of(context).size.height-(MediaQuery.of(context).padding.top+50*2),
  877. width: MediaQuery.of(context).size.width-50,
  878. decoration: BoxDecoration(
  879. color: Colors.white,
  880. borderRadius: BorderRadius.all(Radius.circular(5))
  881. ),
  882. child: Column(
  883. children: [
  884. Container(
  885. height: 50,
  886. padding: EdgeInsets.only(left: 15,right: 15),
  887. child: Row(
  888. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  889. children: [
  890. Container(),
  891. Text(title,style: TextStyle(fontSize: 17,color: Color(0xFF242329),decoration: TextDecoration.none),),
  892. Container(),
  893. // GestureDetector(
  894. // child: Icon(Icons.close,size: 25,color: Color(0xFF242329)),
  895. // onTap: (){Navigator.pop(context);},
  896. // )
  897. ],
  898. ),
  899. ),
  900. Divider(height: 0.5,thickness: 0.5,color: Color(0xFFEDEDED),),
  901. Container(
  902. height: MediaQuery.of(context).size.height-(MediaQuery.of(context).padding.top+50*2)-100-0.5,
  903. width: MediaQuery.of(context).size.width-50,
  904. padding: EdgeInsets.all(10),
  905. child: WebView(
  906. javascriptMode: JavascriptMode.unrestricted,
  907. onWebViewCreated: (WebViewController webViewController) {
  908. // webViewController.loadUrl(Uri.dataFromString(content, mimeType: 'text/html', encoding: Encoding.getByName('utf-8')).toString());
  909. webViewController.loadUrl(content);
  910. },
  911. ),
  912. ),
  913. Container(
  914. height: 50,
  915. alignment: Alignment.center,
  916. child: Row(
  917. children: [
  918. GestureDetector(
  919. onTap: (){
  920. Navigator.pop(context);
  921. disAgree();
  922. },
  923. child: Container(
  924. width: (MediaQuery.of(context).size.width-50)/2-0.5,
  925. alignment: Alignment.center,
  926. child: Text('不同意',style: TextStyle(fontSize: 17,color: Color(0xFF999999),decoration: TextDecoration.none),),
  927. ),
  928. ),
  929. Container(
  930. height: 50,
  931. width: 0.5,
  932. color: Color(0xFFF9F9F9),
  933. ),
  934. GestureDetector(
  935. onTap: (){
  936. Navigator.pop(context);
  937. agree();
  938. },
  939. child: Container(
  940. width: (MediaQuery.of(context).size.width-50)/2-0.5,
  941. alignment: Alignment.center,
  942. child: Text('同意',style: TextStyle(fontSize: 17,color: Colors.pinkAccent,decoration: TextDecoration.none),),
  943. ),
  944. )
  945. ],
  946. )
  947. ),
  948. ],
  949. ),
  950. ),
  951. ),
  952. );
  953. }
  954. );
  955. }
  956. showNegotiate3AlertDio(BuildContext context,{String content = '',String title = '',VoidCallback agree,}) {
  957. showGeneralDialog(
  958. context: context,
  959. barrierDismissible:false,
  960. barrierColor: Colors.black.withOpacity(0.6),
  961. barrierLabel: '',
  962. transitionDuration: Duration(milliseconds: 200),
  963. pageBuilder: (BuildContext context, Animation<double> animation,
  964. Animation<double> secondaryAnimation) {
  965. return YSAlertView3(title: title,content: content,callback: agree,);
  966. }
  967. );
  968. }
  969. class YSAlertView3 extends StatefulWidget {
  970. final String title;
  971. final String content;
  972. final VoidCallback callback;
  973. const YSAlertView3({Key key, this.title, this.content, this.callback}) : super(key: key);
  974. @override
  975. _YSAlertView3State createState() => _YSAlertView3State();
  976. }
  977. class _YSAlertView3State extends State<YSAlertView3> {
  978. Timer _timer;
  979. int _count = 10;
  980. @override
  981. void dispose() {
  982. if(_timer.isActive)_timer.cancel();
  983. super.dispose();
  984. }
  985. _startTimer() {
  986. _timer =Timer.periodic(Duration(seconds: 1), (timer) {
  987. _count--;
  988. if(_count<=0){
  989. timer.cancel();
  990. }
  991. setState(() {});
  992. });
  993. }
  994. @override
  995. void initState() {
  996. _startTimer();
  997. super.initState();
  998. }
  999. @override
  1000. Widget build(BuildContext context) {
  1001. return WillPopScope(
  1002. onWillPop: () async{
  1003. return false;
  1004. },
  1005. child: Center(
  1006. child: Container(
  1007. height: MediaQuery.of(context).size.height-(MediaQuery.of(context).padding.top+50*2),
  1008. width: MediaQuery.of(context).size.width-50,
  1009. decoration: BoxDecoration(
  1010. color: Colors.white,
  1011. borderRadius: BorderRadius.all(Radius.circular(5))
  1012. ),
  1013. child: Column(
  1014. children: [
  1015. // Container(
  1016. // height: 50,
  1017. // padding: EdgeInsets.only(left: 15,right: 15),
  1018. // child: Row(
  1019. // mainAxisAlignment: MainAxisAlignment.spaceBetween,
  1020. // children: [
  1021. // Container(),
  1022. // Text(widget.title,style: TextStyle(fontSize: 17,color: Color(0xFF242329),decoration: TextDecoration.none),),
  1023. // Container(),
  1024. // // GestureDetector(
  1025. // // child: Icon(Icons.close,size: 25,color: Color(0xFF242329)),
  1026. // // onTap: (){Navigator.pop(context);},
  1027. // // )
  1028. // ],
  1029. // ),
  1030. // ),
  1031. // Divider(height: 0.5,thickness: 0.5,color: Color(0xFFEDEDED),),
  1032. Container(
  1033. height: MediaQuery.of(context).size.height-(MediaQuery.of(context).padding.top+50*2)-50,
  1034. width: MediaQuery.of(context).size.width-50,
  1035. padding: EdgeInsets.all(10),
  1036. child: WebView(
  1037. javascriptMode: JavascriptMode.unrestricted,
  1038. onWebViewCreated: (WebViewController webViewController) {
  1039. webViewController.loadUrl(Uri.dataFromString(widget.content, mimeType: 'text/html', encoding: Encoding.getByName('utf-8')).toString());
  1040. // webViewController.loadUrl(content);
  1041. },
  1042. ),
  1043. ),
  1044. GestureDetector(
  1045. onTap: (){
  1046. // LogUtil.d('obj');
  1047. if(_count==0){
  1048. Navigator.pop(context);
  1049. widget.callback();
  1050. }
  1051. },
  1052. behavior: HitTestBehavior.opaque,
  1053. child: Container(
  1054. width: ysWidth(context),
  1055. height: 50,
  1056. alignment: Alignment.center,
  1057. child: Text(_count==0?'我已阅读':'我已阅读($_count)',style: TextStyle(fontSize: 17,color: _count==0?Colors.blue:Colors.grey,decoration: TextDecoration.none),),
  1058. ),
  1059. ),
  1060. ],
  1061. ),
  1062. ),
  1063. ),
  1064. );
  1065. }
  1066. }
  1067. ///手机号验证
  1068. bool isChinaPhoneLegal(String str) {
  1069. return RegExp(r"^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[1589])\d{8}$").hasMatch(str);
  1070. }
  1071. getVersionData(BuildContext context) async{
  1072. Map dict = await ysRequestHttpNoLoading(context, requestType.get, 'app/version', {'device':Platform.isAndroid?'android':'ios'});
  1073. if(dict!=null){
  1074. Map data = dict['data'];
  1075. PackageInfo packageInfo = await PackageInfo.fromPlatform();
  1076. if(int.parse(packageInfo.buildNumber)<data['version']){
  1077. ysShowCenterAlertView(context, YSVersionView(
  1078. buildNumber: '${data['version']}',
  1079. content: data['up_log'],
  1080. url: data['down_url'],
  1081. isMust: data['is_force'],)
  1082. );
  1083. }
  1084. }
  1085. }
  1086. class YSAppleView extends StatelessWidget {
  1087. final ValueSetter valueSetter;
  1088. const YSAppleView({Key key, this.valueSetter}) : super(key: key);
  1089. @override
  1090. Widget build(BuildContext context) {
  1091. return Container(
  1092. height: 60,
  1093. width: 60,
  1094. margin: EdgeInsets.only(right: 30),
  1095. child: SignInWithAppleButton(
  1096. text: '',
  1097. style: SignInWithAppleButtonStyle.black,
  1098. onPressed: () async {
  1099. final credential = await SignInWithApple.getAppleIDCredential(
  1100. scopes: [
  1101. AppleIDAuthorizationScopes.email,
  1102. AppleIDAuthorizationScopes.fullName,
  1103. ],
  1104. );
  1105. if (credential != null) {
  1106. debugPrint("facebook userInfo : userId=${credential.userIdentifier} email=${credential.email} "
  1107. "giveName=${credential.givenName} familyName=${credential.familyName} identityToken=${credential.identityToken}");
  1108. valueSetter({'client_user':credential.userIdentifier,'identity_token':credential.identityToken});
  1109. }
  1110. },
  1111. )
  1112. );
  1113. }
  1114. }
  1115. class ColorUtil {
  1116. static Color fromHex(String hexString) {
  1117. final buffer = StringBuffer();
  1118. if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
  1119. buffer.write(hexString.replaceFirst('#', ''));
  1120. return Color(int.parse(buffer.toString(), radix: 16));
  1121. }
  1122. }
  1123. class DashLine extends StatelessWidget {
  1124. const DashLine({
  1125. Key key,
  1126. this.width = 2.0,
  1127. this.height = 1.0,
  1128. this.color,
  1129. this.direction = Axis.horizontal,
  1130. }) : super(key: key);
  1131. final double width; // 虚线宽度
  1132. final double height; // 虚线高度
  1133. final Color color; // 虚线颜色
  1134. final Axis direction; // 虚线方向
  1135. @override
  1136. Widget build(BuildContext context) {
  1137. return LayoutBuilder(
  1138. builder: (BuildContext context, BoxConstraints constraints) {
  1139. final boxWidth = direction == Axis.horizontal
  1140. ? constraints.constrainWidth()
  1141. : constraints.constrainHeight();
  1142. final dashCount = (boxWidth / (2 * width)).floor();
  1143. return Flex(
  1144. children: List.generate(dashCount, (_) {
  1145. return SizedBox(
  1146. width: direction == Axis.horizontal ? width : height,
  1147. height: direction == Axis.horizontal ? height : width,
  1148. child: DecoratedBox(
  1149. decoration: BoxDecoration(color: color ?? Colors.grey),
  1150. ),
  1151. );
  1152. }),
  1153. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  1154. direction: direction,
  1155. );
  1156. },
  1157. );
  1158. }
  1159. }
  1160. class YSScreenChange {
  1161. static YSScreenChange _instance;
  1162. var _channel;
  1163. YSScreenChange._internal() {
  1164. _instance = this;
  1165. _channel = MethodChannel('com.flutter.screen.MethodChannel');
  1166. }
  1167. factory YSScreenChange() => _instance ?? YSScreenChange._internal();
  1168. change(int number){
  1169. _channel.invokeMethod('setScreen',{'number': number});
  1170. }
  1171. }
  1172. toPage(BuildContext context) async{
  1173. SharedPreferences _perfer = await SharedPreferences.getInstance();
  1174. Map period = await ysRequestHttpNoLoading(context, requestType.get, 'chapter/list', {});
  1175. if(period!=null){
  1176. Map periodData = period['data'];
  1177. _perfer.setInt('chapters', periodData['category_id']-1);
  1178. int childId = periodData['child_id']??0;
  1179. if(childId!=0){
  1180. _perfer.setInt('childId', periodData['child_id']);
  1181. }
  1182. Map profile = await ysRequestHttpNoLoading(context, requestType.get, 'user/info/isComplete', {});
  1183. if(profile!=null){
  1184. Map profileData = profile['data'];
  1185. bool isComplete = profileData['is_complete']??false;
  1186. if(isComplete==true){
  1187. _perfer.setBool('isMeans', true);
  1188. Navigator.pushAndRemoveUntil(context, MaterialPageRoute(
  1189. builder: (context){
  1190. return YSPage();
  1191. }
  1192. ), (route) => false);
  1193. }else{
  1194. Navigator.pushAndRemoveUntil(context, MaterialPageRoute(
  1195. builder: (context){
  1196. return YSMeans(isFirst: true,);
  1197. }
  1198. ), (route) => false);
  1199. }
  1200. }
  1201. }
  1202. }
  1203. toPage2(BuildContext context) async{
  1204. Map profile = await ysRequestHttpNoLoading(context, requestType.get, 'user/info/isComplete', {});
  1205. if(profile!=null){
  1206. Map profileData = profile['data'];
  1207. bool isComplete = profileData['is_complete']??false;
  1208. if(isComplete==true){}else{
  1209. Navigator.of(context,rootNavigator:true ).pushAndRemoveUntil(MaterialPageRoute(
  1210. builder: (context){
  1211. return YSMeans(isFirst: true,);
  1212. }
  1213. ), (route) => false);
  1214. }
  1215. }
  1216. }
  1217. checkValue(BuildContext context,{String tips = '当前绑定卫生院存在未使用券信息,无法更改至其他卫生院'}) async{
  1218. Map info = await ysRequestHttpNoLoading(context, requestType.get, 'user/info', {});
  1219. if(info!=null){
  1220. String cardStr = info['id_card']??'';
  1221. if(cardStr.isNotEmpty){
  1222. Map dict1 = await ysRequestHttpNoLoading(context, requestType.post, 'transfer/coupon/getCommunityVouchers',
  1223. {'idcard':User().idCard,'pageSize':1,'pageNum':10});
  1224. if(dict1!=null){
  1225. Map dict2 = await ysRequestHttpNoLoading(context, requestType.post, 'transfer/coupon/getUserCouponList',
  1226. {'idcard':User().idCard,'pageSize':1,'pageNum':10});
  1227. if(dict2!=null){
  1228. // List array1 = dict1['data']['datas']??[];
  1229. //array1.isEmpty&&
  1230. var data = dict2['data'];
  1231. bool isArray = data is List;
  1232. // return;
  1233. if(isArray){
  1234. return true;
  1235. }else{
  1236. ysShowCenterAlertView(context, YSTipsAlertView2(
  1237. tipsStr: tips,
  1238. valueSetter: (value){
  1239. if(User().routeStr.isNotEmpty){
  1240. Navigator.popUntil(context, ModalRoute.withName(User().routeStr));
  1241. }
  1242. },
  1243. ));
  1244. }
  1245. }
  1246. }
  1247. }else{
  1248. return true;
  1249. }
  1250. }
  1251. }