util.dart 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import 'package:flutter/material.dart';
  2. import 'package:dio/dio.dart';
  3. import '../showAlert.dart';
  4. import 'package:intl/intl.dart';
  5. bool isNotError(BuildContext context,json){
  6. //print('-----------'+json+'----------');
  7. if(json is DioError){
  8. alertError(context, json.toString());
  9. return false;
  10. }else if( json.data['success']&& json.data['code']==1){
  11. return true;
  12. }else{
  13. alertError(context, json.data['msg']);
  14. return false;
  15. }
  16. }
  17. alertError(BuildContext context,String str){
  18. showDialog < Null > (
  19. context: context, //BuildContext对象
  20. barrierDismissible: false,
  21. builder: (BuildContext context) {
  22. return MyAlertDialog( //调用对话框
  23. text: str, childCallback: (val) {
  24. },
  25. );
  26. });
  27. }
  28. bool isChinaPhoneLegal(String str) {
  29. return new RegExp('^((13[0-9])|(15[^4])|(166)|(17[0-8])|(18[0-9])|(19[8-9])|(147,145))\\d{8}\$').hasMatch(str);
  30. }
  31. String fromatDate(int myDate){
  32. var now = DateTime.fromMicrosecondsSinceEpoch(myDate*1000);
  33. var formatter = new DateFormat('yyyy-MM-dd HH:mm:ss');
  34. String date = formatter.format(now);
  35. return date;
  36. }