utils.dart 129 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712
import 'dart:async';
import 'dart:convert' as Convert;
import 'dart:io';
import 'dart:math';
import 'dart:typed_data';
import 'dart:ui';

import 'package:call_log/call_log.dart';
import 'package:common_utils/common_utils.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
// import 'package:contacts_service/contacts_service.dart';
// import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:device_info/device_info.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
// import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
import 'package:flutter_statusbarcolor_ns/flutter_statusbarcolor_ns.dart';
// import 'package:flutter_wxwork/flutter_wxwork.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter/services.dart';
import 'package:fluwx/fluwx.dart';
import 'package:one_key/provider/my_model.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/dialog_util.dart';
import 'package:one_key/utils/lunar_calendar.dart';
import 'package:one_key/utils/misc.dart';
import 'package:one_key/route/navigator_util.dart';
import 'package:one_key/utils/screen_util.dart';
import 'package:one_key/utils/wx_sdk.dart';
import 'package:one_key/widgets/loading.dart';
import 'package:package_info/package_info.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:crypto/crypto.dart';
import 'package:flutter_image_compress/flutter_image_compress.dart';

import 'package:image/image.dart' as IMG;
import 'dart:ui' as ui;
import 'package:permission_handler/permission_handler.dart';
import 'package:path_provider/path_provider.dart';
import 'package:image_cropper/image_cropper.dart';
import 'dart:math';

import '../app.dart';
import '../constant/constant.dart';
import '../models/cookbook_model.dart';
import '../models/coupon_model.dart';
import '../models/recharge_list_model.dart';
// import 'dart:typed_data';
import 'dart:typed_data';
// import 'package:image/image.dart' as Img;

typedef BookTimeSetCallback = void Function(bool needChange);

class Utils {
  static Future<bool> isImageLargerThan120KB(Uint8List? imageBytes) async {
    if (imageBytes == null) {
      return false;
    }
    var fileSize = imageBytes.lengthInBytes;
    return fileSize > 120 * 1024; // 64KB = 120 * 1024 bytes
  }

  static List<CallLogEntry> removeDuplicates(List<CallLogEntry> items) {
    List<CallLogEntry> uniqueItems = []; // uniqueList
    var uniqueIDs = items
        .map((e) => e.number)
        .toSet(); //list if UniqueID to remove duplicates
    uniqueIDs.forEach((e) {
      uniqueItems.add(items.firstWhere((i) => i.number == e));
    }); // populate uniqueItems with equivalent original Batch items
    return uniqueItems; //send back the unique items list
  }

  /// 十六进制颜色
  /// colorString,字符串,例如:'0x000000'  '0xff000000' '#000000' '#000000',
  /// alpha,透明度[0.0, 1.0]
  static Color hexStringColor(String colorString, {double alpha = 1}) {
    colorString = '0x' + colorString;
    if (alpha < 0) {
      alpha = 0;
    } else if (alpha > 1) {
      alpha = 1;
    }
    String colorStr = colorString;
    // colorString未带0xff前缀并且长度为6
    if (!colorStr.startsWith('0xff') && colorStr.length == 6) {
      colorStr = '0xff' + colorStr;
    }
    // colorString为8位,如0x000000
    if (colorStr.startsWith('0x') && colorStr.length == 8) {
      colorStr = colorStr.replaceRange(0, 2, '0xff');
    }
    // colorString为7位,如#000000
    if (colorStr.startsWith('#') && colorStr.length == 7) {
      colorStr = colorStr.replaceRange(0, 1, '0xff');
    }
    // 先分别获取色值的RGB通道
    Color color = Color(int.parse(colorStr));
    int red = color.red;
    int green = color.green;
    int blue = color.blue;
    // 通过fromRGBO返回带透明度和RGB值的颜色
    return Color.fromRGBO(red, green, blue, alpha);
  }

  ///店铺是否过期
  static isStoreEdate() {
    if (App.sp!.containsKey('sellerEdate')) {
      List<String> data = App.sp!.getStringList('sellerEdate')!;
      if (data.contains('-1')) {
        //已经弹过过期弹窗
        return true;
      }
    }
    return false;
  }

  ///权限获取
  static getAuthority(BuildContext context, String? key) {
    bool hasAuthority = Constant.authorityConfig[key]!.contains(
        Provider.of<UserModel>(context, listen: false).user!.role_name);
    return hasAuthority;
  }

  //得到当月最后一天
  static getCurrentMonthLast(int month) {
    var date = new DateTime(2013, month + 1, 0);
    // print(date.day); // 28 for February
    return date.day;
  }

  static randomGet(int min, int max) {
    //实例化 Random类 并赋值给 私有变量 _random
    final _random = new Random();
//定义 指定返回值为 int 的函数方法,传入参数为 min 和 max

//变量c等于 (0+4)+随机数(9-4);实现了最小值不小于4,最大值不大于8的结果
    var c = min + _random.nextInt(max - min);
//打印变量 c
    print(c); //4~8
  }

  static bool cnIsNumber(String str) {
    final reg = RegExp(r'^-?[0-9.]+$');
    return reg.hasMatch(str);
  }

  static String intToWeek(int? week) {
    String str = '';
    switch (week) {
      case 0 || 7:
        str = '周日';
        break;
      case 1:
        str = '周一';
        break;
      case 2:
        str = '周二';
        break;
      case 3:
        str = '周三';
        break;
      case 4:
        str = '周四';
        break;
      case 5:
        str = '周五';
        break;
      case 6:
        str = '周六';
        break;
    }
    return str;
  }

  ///2023-03-11 二月二十
  static String returnYMDandLunarCalendar(DateTime day, BuildContext context) {
    String date =
        "${day.year}-${Utils.addZeroNumber(day.month)}-${Utils.addZeroNumber(day.day)}  ";
    date += Utils.lunarCalendarHolidays(day)!;
    return date;
  }

  //判定是否为数字
  static bool isNumeric(String? s) {
    if (s == null) {
      return false;
    }
    return double.tryParse(s) != null;
  }

  static bool isNumericReq(String str) {
    final reg = RegExp(r'^[0-9]+$');
    print('$str 是否数字:${reg.hasMatch(str)}');
    return reg.hasMatch(str);
  }

  static bool isNumeric1Req(String str) {
    final reg = RegExp(
        r'((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)');
    print('$str 是否数字:${reg.hasMatch(str)}');
    return reg.hasMatch(str);
  }

  // ^(([^0][0-9]+|0)$)|^(([1-9]+)$)

  // 验证是否为数字
  static bool isInteger(String str) {
    final reg = RegExp(r'^[1-9]\d*$');
    print('$str 是否数字:${reg.hasMatch(str)}');
    return reg.hasMatch(str);
  }

  // 验证是否为数字
  static bool isIntegerS(String str) {
    final reg = RegExp(r'^[0-9]\d*$');
    print('$str 是否数字:${reg.hasMatch(str)}');
    return reg.hasMatch(str);
  }

  // 验证是否为11位电话号码
  static bool is11PhoneS(String str) {
    final reg = RegExp(r'^1[3-9]\d{9}$');
    print('$str 是否11位电话号码:${reg.hasMatch(str)}');
    return reg.hasMatch(str);
  }

  //请求参数按key按ASCII排序key1=value1&key2=value2&...&keyN=valueN
  static String keySort(Map<String, String?> oldParamsMap) {
    List attrKeys = oldParamsMap.keys.toList();
    attrKeys.sort(); //排序 ASCII 字符顺序进行排序
    var str = '';
    for (var i = 0; i < oldParamsMap.length; i++) {
      if (i == oldParamsMap.length - 1) {
        str += "${attrKeys[i]}=${oldParamsMap[attrKeys[i]]}";
      } else {
        str += "${attrKeys[i]}=${oldParamsMap[attrKeys[i]]}&";
      }
    }
    print(str);
    String stringSignTemp =
        str + "&key=3F59D13EB7681868B96A50902296BCE6"; //注:key为商户平台设置的密钥key

    var key = Convert.utf8.encode('3F59D13EB7681868B96A50902296BCE6');
    var hmacSha256 = Hmac(sha256, key); // HMAC-SHA256
    var bytes = Convert.utf8.encode(stringSignTemp);
    var digest = hmacSha256.convert(bytes);

    print("HMAC digest as bytes: ${digest.bytes}");
    print("HMAC digest as hex string: $digest");

    return '$digest'.toUpperCase();
    //注:HMAC-SHA256签名方式,部分语言的hmac方法生成结果二进制结果,需要调对应函数转化为十六进制字符串
  }

  // 验证是否为数字
  static bool isNumber(String str) {
    final reg = RegExp(r'^-?[0-9]+');
    print('$str 是否数字:${reg.hasMatch(str)}');
    return reg.hasMatch(str);
  }
  //

  //时间转换
  static String formatCallLogFromMill(String datestr) {
    String date = '';
    DateTime _strtimes = DateTime.fromMillisecondsSinceEpoch(int.parse(
        datestr)); //首先先将字符串格式的时间转为DateTime类型,因为millisecondsSinceEpoch方法转换要求为该格式

    DateTime dateNow = DateTime.now();

    if (Utils.isOneDay(_strtimes, dateNow)) {
      //今天
      date = DateUtil.formatDate(_strtimes, format: DateFormats.h_m);
    } else if (Utils.isOneDay(_strtimes, dateNow.add(Duration(days: -1)))) {
      date = "昨天";
    } else if (Utils.isOneDay(_strtimes, dateNow.add(Duration(days: 2)))) {
      date = "后天 ";
    } else {
      if (_strtimes.year == dateNow.year) {
        date = Utils.addZeroNumber(_strtimes.month) +
            "月" +
            Utils.addZeroNumber(_strtimes.day) +
            "日";
      } else {
        date = _strtimes.year.toString() +
            "年" +
            Utils.addZeroNumber(_strtimes.month) +
            "月" +
            Utils.addZeroNumber(_strtimes.day) +
            "日";
      }
    }
    return date;
  }

  //时间转换
  static String formatFromMill(String datestr) {
    String date = '';
    DateTime _strtimes = DateTime.fromMillisecondsSinceEpoch(
        int.parse(datestr) *
            1000); //首先先将字符串格式的时间转为DateTime类型,因为millisecondsSinceEpoch方法转换要求为该格式
    // int _intendtime = _strtimes.millisecondsSinceEpoch; //方法一
    //   var _intendtime =  DateTime.fromMillisecondsSinceEpoch(_strtimes );//方法二
    //   //_intendtime 为以及转换好的时间戳
    DateTime dateNow = DateTime.now();
    // String ymd = "${day.year}-" +
    //     Utils.addZeroNumber(day.month) +
    //     "-" +
    //     Utils.addZeroNumber(day.day);

    if (Utils.isOneDay(_strtimes, dateNow)) {
      date = "今天 ";
    } else if (Utils.isOneDay(_strtimes, dateNow.add(Duration(days: 1)))) {
      date = "明天 ";
    } else if (Utils.isOneDay(_strtimes, dateNow.add(Duration(days: 2)))) {
      date = "后天 ";
    } else {
      final num ONE_HOUR = 3600000;
      final num ONE_DAY = 86400000;
      final String ONE_DAY_AGO = "天前";
      num delta = DateTime.now().millisecondsSinceEpoch -
          _strtimes.millisecondsSinceEpoch;
      // if (delta < 1 * ONE_MINUTE) {
      //   num seconds = toSeconds(delta);
      //   return (seconds <= 0 ? 1 : seconds).toInt().toString() + ONE_SECOND_AGO;
      // }
      // if (delta < 45 * ONE_MINUTE) {
      //   num minutes = toMinutes(delta);
      //   return (minutes <= 0 ? 1 : minutes).toInt().toString() + ONE_MINUTE_AGO;
      // }
      // if (delta < 24 * ONE_HOUR) {
      //   num hours = toHours(delta);
      //   return (hours <= 0 ? 1 : hours).toInt().toString() + ONE_HOUR_AGO;
      // }
      // if (delta < 48 * ONE_HOUR) {
      //   return "昨天";
      // }
      if (delta > 0) {
        // if (delta < 30 * ONE_DAY) {
        num days = toDays(delta);
        date = (days <= 0 ? 1 : days).toInt().toString() + ONE_DAY_AGO;
        // }
      } else {
        date = DateUtil.formatDate(_strtimes, format: DateFormats.y_mo_d);
        // date = datestr;
        // num delta = _strtimes.millisecondsSinceEpoch -
        //     DateTime.now().millisecondsSinceEpoch;
        // num days = toDays(delta);
        // date = (days <= 0 ? 1 : days).toInt().toString() +  "天后";
      }

      // if (delta < 12 * 4 * ONE_WEEK) {
      //   num months = toMonths(delta);
      //   return (months <= 0 ? 1 : months).toInt().toString() + ONE_MONTH_AGO;
      // } else {
      //   num years = toYears(delta);
      //   return (years <= 0 ? 1 : years).toInt().toString() + ONE_YEAR_AGO;
      // }
    }
    return date;
  }

  static String formatFromYmd(String datestr) {
    String date = '';
    String _str =
        datestr.replaceAll('年', '-').replaceAll('月', '-').replaceAll('日', '');
    String _time = "${_str} 16:00:00"; //注意格式否则在DateTime.parse()时会报错
    DateTime _strtimes = DateTime.parse(
        _time); //首先先将字符串格式的时间转为DateTime类型,因为millisecondsSinceEpoch方法转换要求为该格式
    int _intendtime = _strtimes.millisecondsSinceEpoch; //方法一
    //   var _intendtime =  DateTime.fromMillisecondsSinceEpoch(_strtimes );//方法二
    //   //_intendtime 为以及转换好的时间戳
    DateTime dateNow = DateTime.now();
    // String ymd = "${day.year}-" +
    //     Utils.addZeroNumber(day.month) +
    //     "-" +
    //     Utils.addZeroNumber(day.day);

    if (Utils.isOneDay(_strtimes, dateNow)) {
      date = "今天 ";
    } else if (Utils.isOneDay(_strtimes, dateNow.add(Duration(days: 1)))) {
      date = "明天 ";
    } else if (Utils.isOneDay(_strtimes, dateNow.add(Duration(days: 2)))) {
      date = "后天 ";
    } else {
      final num ONE_HOUR = 3600000;
      final num ONE_DAY = 86400000;
      final String ONE_DAY_AGO = "天前";
      num delta = DateTime.now().millisecondsSinceEpoch -
          _strtimes.millisecondsSinceEpoch;
      // if (delta < 1 * ONE_MINUTE) {
      //   num seconds = toSeconds(delta);
      //   return (seconds <= 0 ? 1 : seconds).toInt().toString() + ONE_SECOND_AGO;
      // }
      // if (delta < 45 * ONE_MINUTE) {
      //   num minutes = toMinutes(delta);
      //   return (minutes <= 0 ? 1 : minutes).toInt().toString() + ONE_MINUTE_AGO;
      // }
      // if (delta < 24 * ONE_HOUR) {
      //   num hours = toHours(delta);
      //   return (hours <= 0 ? 1 : hours).toInt().toString() + ONE_HOUR_AGO;
      // }
      // if (delta < 48 * ONE_HOUR) {
      //   return "昨天";
      // }
      if (delta > 0) {
        // if (delta < 30 * ONE_DAY) {
        num days = toDays(delta);
        date = (days <= 0 ? 1 : days).toInt().toString() + ONE_DAY_AGO;
        // }
      } else {
        date = datestr;
      }

      // if (delta < 12 * 4 * ONE_WEEK) {
      //   num months = toMonths(delta);
      //   return (months <= 0 ? 1 : months).toInt().toString() + ONE_MONTH_AGO;
      // } else {
      //   num years = toYears(delta);
      //   return (years <= 0 ? 1 : years).toInt().toString() + ONE_YEAR_AGO;
      // }
    }
    return date;
  }

  static num toSeconds(num date) {
    return date / 1000;
  }

  static num toMinutes(num date) {
    return toSeconds(date) / 60;
  }

  static num toHours(num date) {
    return toMinutes(date) / 60;
  }

  static num toDays(num date) {
    return toHours(date) / 24;
  }

  //人数
  static List<String> getPersonNumList() {
    List<String> personNumList = [];
    for (int i = 1; i < 31; i++) {
      personNumList.add(i.toString());
    }
    personNumList.add('30以上');
    return personNumList;
  }

  static String getLunarSpecialDate(DateTime dateTime) {
    String _day = '';
    int iYear = dateTime.year;
    int iMonth = dateTime.month;
    int iDay = dateTime.day;
    const List gLunarHolDay = [
      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78,
      0X77, //1901

      0X96, 0XA4, 0X96, 0X96, 0X97, 0X87, 0X79, 0X79, 0X79, 0X69, 0X78,
      0X78, //1902

      0X96, 0XA5, 0X87, 0X96, 0X87, 0X87, 0X79, 0X69, 0X69, 0X69, 0X78,
      0X78, //1903

      0X86, 0XA5, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X78,
      0X87, //1904

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78,
      0X77, //1905

      0X96, 0XA4, 0X96, 0X96, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78,
      0X78, //1906

      0X96, 0XA5, 0X87, 0X96, 0X87, 0X87, 0X79, 0X69, 0X69, 0X69, 0X78,
      0X78, //1907

      0X86, 0XA5, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78,
      0X87, //1908

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78,
      0X77, //1909

      0X96, 0XA4, 0X96, 0X96, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78,
      0X78, //1910

      0X96, 0XA5, 0X87, 0X96, 0X87, 0X87, 0X79, 0X69, 0X69, 0X69, 0X78,
      0X78, //1911

      0X86, 0XA5, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78,
      0X87, //1912

      0X95, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78,
      0X77, //1913

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78,
      0X78, //1914

      0X96, 0XA5, 0X97, 0X96, 0X97, 0X87, 0X79, 0X79, 0X69, 0X69, 0X78,
      0X78, //1915

      0X96, 0XA5, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77,
      0X87, //1916

      0X95, 0XB4, 0X96, 0XA6, 0X96, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78,
      0X87, //1917

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78,
      0X77, //1918

      0X96, 0XA5, 0X97, 0X96, 0X97, 0X87, 0X79, 0X79, 0X69, 0X69, 0X78,
      0X78, //1919

      0X96, 0XA5, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77,
      0X87, //1920

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78,
      0X87, //1921

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78,
      0X77, //1922

      0X96, 0XA4, 0X96, 0X96, 0X97, 0X87, 0X79, 0X79, 0X69, 0X69, 0X78,
      0X78, //1923

      0X96, 0XA5, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77,
      0X87, //1924

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78,
      0X87, //1925

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78,
      0X77, //1926

      0X96, 0XA4, 0X96, 0X96, 0X97, 0X87, 0X79, 0X79, 0X79, 0X69, 0X78,
      0X78, //1927

      0X96, 0XA5, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87,
      0X87, //1928

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77,
      0X87, //1929

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78,
      0X77, //1930

      0X96, 0XA4, 0X96, 0X96, 0X97, 0X87, 0X79, 0X79, 0X79, 0X69, 0X78,
      0X78, //1931

      0X96, 0XA5, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87,
      0X87, //1932

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78,
      0X87, //1933

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78,
      0X77, //1934

      0X96, 0XA4, 0X96, 0X96, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78,
      0X78, //1935

      0X96, 0XA5, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87,
      0X87, //1936

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78,
      0X87, //1937

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78,
      0X77, //1938

      0X96, 0XA4, 0X96, 0X96, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78,
      0X78, //1939

      0X96, 0XA5, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87,
      0X87, //1940

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78,
      0X87, //1941

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78,
      0X77, //1942

      0X96, 0XA4, 0X96, 0X96, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78,
      0X78, //1943

      0X96, 0XA5, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87,
      0X87, //1944

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77,
      0X87, //1945

      0X95, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78,
      0X77, //1946

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78,
      0X78, //1947

      0X96, 0XA5, 0XA6, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87,
      0X87, //1948

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X79, 0X78, 0X79, 0X77,
      0X87, //1949

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78,
      0X77, //1950

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X79, 0X79, 0X79, 0X69, 0X78,
      0X78, //1951

      0X96, 0XA5, 0XA6, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87,
      0X87, //1952

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77,
      0X87, //1953

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X78, 0X79, 0X78, 0X68, 0X78,
      0X87, //1954

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78,
      0X77, //1955

      0X96, 0XA5, 0XA5, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87,
      0X87, //1956

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77,
      0X87, //1957

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78,
      0X87, //1958

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78,
      0X77, //1959

      0X96, 0XA4, 0XA5, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //1960

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87,
      0X87, //1961

      0X96, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78,
      0X87, //1962

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78,
      0X77, //1963

      0X96, 0XA4, 0XA5, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //1964

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87,
      0X87, //1965

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78,
      0X87, //1966

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78,
      0X77, //1967

      0X96, 0XA4, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //1968

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87,
      0X87, //1969

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78,
      0X87, //1970

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X79, 0X69, 0X78,
      0X77, //1971

      0X96, 0XA4, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //1972

      0XA5, 0XB5, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87,
      0X87, //1973

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78,
      0X87, //1974

      0X96, 0XB4, 0X96, 0XA6, 0X97, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78,
      0X77, //1975

      0X96, 0XA4, 0XA5, 0XB5, 0XA6, 0XA6, 0X88, 0X89, 0X88, 0X78, 0X87,
      0X87, //1976

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87,
      0X87, //1977

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X78,
      0X87, //1978

      0X96, 0XB4, 0X96, 0XA6, 0X96, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78,
      0X77, //1979

      0X96, 0XA4, 0XA5, 0XB5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //1980

      0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X77,
      0X87, //1981

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77,
      0X87, //1982

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X78, 0X79, 0X78, 0X69, 0X78,
      0X77, //1983

      0X96, 0XB4, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87,
      0X87, //1984

      0XA5, 0XB4, 0XA6, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87,
      0X87, //1985

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77,
      0X87, //1986

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X79, 0X78, 0X69, 0X78,
      0X87, //1987

      0X96, 0XB4, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87,
      0X86, //1988

      0XA5, 0XB4, 0XA5, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //1989

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X79, 0X77,
      0X87, //1990

      0X95, 0XB4, 0X96, 0XA5, 0X86, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78,
      0X87, //1991

      0X96, 0XB4, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87,
      0X86, //1992

      0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //1993

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87,
      0X87, //1994

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X76, 0X78, 0X69, 0X78,
      0X87, //1995

      0X96, 0XB4, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87,
      0X86, //1996

      0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //1997

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87,
      0X87, //1998

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78,
      0X87, //1999

      0X96, 0XB4, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87,
      0X86, //2000

      0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //2001

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87,
      0X87, //2002

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78,
      0X87, //2003

      0X96, 0XB4, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87,
      0X86, //2004

      0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //2005

      0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87,
      0X87, //2006

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X69, 0X78,
      0X87, //2007

      0X96, 0XB4, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X87, 0X78, 0X87,
      0X86, //2008

      0XA5, 0XB3, 0XA5, 0XB5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //2009

      0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87,
      0X87, //2010

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X78,
      0X87, //2011

      0X96, 0XB4, 0XA5, 0XB5, 0XA5, 0XA6, 0X87, 0X88, 0X87, 0X78, 0X87,
      0X86, //2012

      0XA5, 0XB3, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87,
      0X87, //2013

      0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87,
      0X87, //2014

      0X95, 0XB4, 0X96, 0XA5, 0X96, 0X97, 0X88, 0X78, 0X78, 0X79, 0X77,
      0X87, //2015

      0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X87, 0X88, 0X87, 0X78, 0X87,
      0X86, //2016

      0XA5, 0XC3, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87,
      0X87, //2017

      0XA5, 0XB4, 0XA6, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87,
      0X87, //2018

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X79, 0X77,
      0X87, //2019

      0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X78, 0X87,
      0X86, //2020

      0XA5, 0XC3, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87,
      0X86, //2021

      0XA5, 0XB4, 0XA5, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //2022

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X79, 0X77,
      0X87, //2023

      0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X78, 0X87,
      0X96, //2024

      0XA5, 0XC3, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87,
      0X86, //2025

      0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //2026

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87,
      0X87, //2027

      0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X78, 0X87,
      0X96, //2028

      0XA5, 0XC3, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87,
      0X86, //2029

      0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //2030

      0XA5, 0XB4, 0X96, 0XA5, 0X96, 0X96, 0X88, 0X78, 0X78, 0X78, 0X87,
      0X87, //2031

      0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X78, 0X87,
      0X96, //2032

      0XA5, 0XC3, 0XA5, 0XB5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X86, //2033

      0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X78, 0X88, 0X78, 0X87,
      0X87, //2034

      0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87,
      0X87, //2035

      0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X78, 0X87,
      0X96, //2036

      0XA5, 0XC3, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87,
      0X86, //2037

      0XA5, 0XB3, 0XA5, 0XA5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //2038

      0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87,
      0X87, //2039

      0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X78, 0X87,
      0X96, //2040

      0XA5, 0XC3, 0XA5, 0XB5, 0XA5, 0XA6, 0X87, 0X88, 0X87, 0X78, 0X87,
      0X86, //2041

      0XA5, 0XB3, 0XA5, 0XB5, 0XA6, 0XA6, 0X88, 0X88, 0X88, 0X78, 0X87,
      0X87, //2042

      0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87,
      0X87, //2043

      0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X88, 0X87,
      0X96, //2044

      0XA5, 0XC3, 0XA5, 0XB4, 0XA5, 0XA6, 0X87, 0X88, 0X87, 0X78, 0X87,
      0X86, //2045

      0XA5, 0XB3, 0XA5, 0XB5, 0XA6, 0XA6, 0X87, 0X88, 0X88, 0X78, 0X87,
      0X87, //2046

      0XA5, 0XB4, 0X96, 0XA5, 0XA6, 0X96, 0X88, 0X88, 0X78, 0X78, 0X87,
      0X87, //2047

      0X95, 0XB4, 0XA5, 0XB4, 0XA5, 0XA5, 0X97, 0X87, 0X87, 0X88, 0X86,
      0X96, //2048

      0XA4, 0XC3, 0XA5, 0XA5, 0XA5, 0XA6, 0X97, 0X87, 0X87, 0X78, 0X87,
      0X86, //2049
    ];
    List chineseDays = [
      "小寒",
      "大寒",
      "立春",
      "雨水",
      "惊蛰",
      "春分",
      "清明",
      "谷雨",
      "立夏",
      "小满",
      "芒种",
      "夏至",
      "小暑",
      "大暑",
      "立秋",
      "处暑",
      "白露",
      "秋分",
      "寒露",
      "霜降",
      "立冬",
      "小雪",
      "大雪",
      "冬至"
    ];
    const int START_YEAR = 1901;
    const int END_YEAR = 2050;

    int array_index = (iYear - START_YEAR) * 12 + iMonth - 1;

    int flag = gLunarHolDay[array_index];

    int day;

    if (iDay < 15)
      day = 15 - ((flag >> 4) & 0x0f);
    else
      day = ((flag) & 0x0f) + 15;

    int index = -1;

    if (iDay == day) {
      index = (iMonth - 1) * 2 + (iDay > 15 ? 1 : 0);
    }

    if (index >= 0 && index < chineseDays.length) {
      _day = chineseDays[index];

      return _day;
    } else {
      return '';
    }
  }

  static String lunarCalendarUtils(DateTime day) {
    LunarCalendar lunarCalendar = LunarCalendar(day);
    String time =
        '${lunarCalendar.getChinaMonthStringShow()}${LunarCalendar.getChinaDayString(lunarCalendar.day!)}';
    return time;
  }

  static String lunarCalendarUtilsShow(DateTime day) {
    LunarCalendar lunarCalendar = LunarCalendar(day);
    if (lunarCalendar.day == 1) {
      return lunarCalendar.getChinaMonthStringShow();
    }
    // String time =
    //     '${lunarCalendar.getChinaMonthString()}月${LunarCalendar.getChinaDayString(lunarCalendar.day)}';
    return LunarCalendar.getChinaDayString(lunarCalendar.day!);
  }

  //农历节日  *表示放假日  日历上面使用
  static String? lunarCalendarHolidaysShow(DateTime day) {
    LunarCalendar lunarCalendar = LunarCalendar(day);
    //阴历月-日
    String keyLunar =
        addZeroNumber(lunarCalendar.month) + addZeroNumber(lunarCalendar.day!);
    //阳历月-日
    String keySolar =
        Utils.addZeroNumber(day.month) + Utils.addZeroNumber(day.day);
    Map<String, String> holiday1 = {
      "0101": "春节",
      "0102": "大年初二",
      "0103": "大年初三",
      "0104": "大年初四",
      "0105": "大年初五",
      "0106": "大年初六",
      "0107": "大年初七",
      "0115": "元宵节",
      "0505": "端午节",
      "0707": "七夕情人节",
      "0815": "中秋节",
      "0909": "重阳节",
      "1208": "腊八节",
      "1223": "过小年",
      "0100": "除夕"
    };
    // Map<String, String> holiday2 = {
    //   "0101": '元旦',
    //   "0214": "情人节",
    //   "0308": "妇女节",
    //   "0501": "劳动节",
    //   "0504": "青年节",
    //   "0601": "国际儿童节",
    //   "0801": "八一建军节",
    //   "0910": "教师节",
    //   "1001": "国庆节",
    //   "1224": "平安夜",
    //   "1225": "圣诞节",
    // };
    if (holiday1.containsKey(keyLunar)) {
      return holiday1[keyLunar];
    }
    String jieqi = getLunarSpecialDate(day);
    if (jieqi != '') {
      return jieqi;
    }
    // if (holiday2.containsKey(keySolar)) {
    //   return holiday2[keySolar];
    // }
    return lunarCalendarUtilsShow(day);
  }

  //农历节日  *表示放假日
  static String? lunarCalendarHolidays(DateTime day) {
    LunarCalendar lunarCalendar = LunarCalendar(day);
    //阴历月-日
    String keyLunar =
        addZeroNumber(lunarCalendar.month) + addZeroNumber(lunarCalendar.day!);
    //阳历月-日
    String keySolar =
        Utils.addZeroNumber(day.month) + Utils.addZeroNumber(day.day);
    Map<String, String> holiday1 = {
      "0101": "春节",
      "0102": "大年初二",
      "0103": "大年初三",
      "0104": "大年初四",
      "0105": "大年初五",
      "0106": "大年初六",
      "0107": "大年初七",
      "0115": "元宵节",
      "0505": "端午节",
      "0707": "七夕情人节",
      "0815": "中秋节",
      "0909": "重阳节",
      "1208": "腊八节",
      "1223": "过小年",
      "0100": "除夕"
    };
    // Map<String, String> holiday2 = {
    //   "0101": '元旦',
    //   "0214": "情人节",
    //   "0308": "妇女节",
    //   "0501": "劳动节",
    //   "0504": "青年节",
    //   "0601": "国际儿童节",
    //   "0801": "八一建军节",
    //   "0910": "教师节",
    //   "1001": "国庆节",
    //   "1224": "平安夜",
    //   "1225": "圣诞节",
    // };
    if (holiday1.containsKey(keyLunar)) {
      return holiday1[keyLunar];
    }
    // if (holiday2.containsKey(keySolar)) {
    //   return holiday2[keySolar];
    // }
    return lunarCalendarUtils(day);
  }

  //国历节日  *表示放假日
  static solarCalendarHolidays(DateTime day) {
    Map<String, String> holiday1 = {
      "0101": '元旦',
      "0214": "情人节",
      "0308": "妇女节",
      "0501": "劳动节",
      "0504": "青年节",
      "0601": "国际儿童节",
      "0801": "八一建军节",
      "0910": "教师节",
      "1001": "国庆节",
      "1224": "平安夜",
      "1225": "圣诞节",
    };
  }

  static String starPhone(String phone) {
    if (phone.length < 5) {
      return phone;
    }
    return phone.replaceFirst(new RegExp(r'\d{4}'), '****', 3);
  }

  static String showEndPhone(String phone) {
    if (phone.length > 4) {
      return '*' + phone.substring(phone.length - 4);
    }
    return phone;
  }

  static List<String>? stringToList(String str) {
    List<String>? list = <String>[];
    // for (var value in JsonDecoder().convert(str)) {
    //   list.add(value);
    // }
    list = Convert.jsonDecode(str);
    return list;
  }

  // 正则验证
  static bool isChinese(String value) {
    return RegExp(r"[\u4e00-\u9fa5]").hasMatch(value);
  }

  static bool isNum(String value) {
    return RegExp(r'^[0-9]*$').hasMatch(value);
  }

  static bool isPinyin(String value) {
    return RegExp(r'^[A-Za-z]+$').hasMatch(value);
  }

  /**
     * 获取图片后缀
     *
     * @param img_path 图片或者视频路径
     * @return
     */
  static String getPicSuffix(String img_path) {
    if (img_path == null || img_path.indexOf(".") == -1) {
      return ""; //如果图片地址为null或者地址中没有"."就返回""
    }
    return img_path
        .substring(img_path.lastIndexOf(".") + 1)
        .trim()
        .toLowerCase();
  }

  ///手机号码格式验证
  static bool phoneRegExp(String phone) {
    RegExp exp = RegExp(
        r'^((13[0-9])|(14[0-9])|(15[0-9])|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\d{8}$');
    return exp.hasMatch(phone);
  }

  ///密码格式验证
  static bool passwordRegExp(String password) {
    RegExp exp = RegExp(r'^[a-z0-9]{6,18}$');
    return exp.hasMatch(password);
  }

  ///生成随机验证码
  static randomBit(int len) {
    String scopeF = '123456789'; //首位
    String scopeC = '0123456789'; //中间
    String result = '';
    for (int i = 0; i < len; i++) {
      if (i == 0) {
        result = scopeF[Random().nextInt(scopeF.length)];
      } else {
        result = result + scopeC[Random().nextInt(scopeC.length)];
      }
    }
    return result;
  }

  //时间转换 将秒转换为小时分钟
  static String durationTransform(int seconds) {
    Duration d = Duration(seconds: seconds);
    List<String> parts = d.toString().split(':');
    return '${parts[1]}:${parts[2].substring(0, 2)}';
    // int minute = seconds % 3600 ~/ 60;
    // // 如果用到秒的话计算
    // int second = seconds % 60;
    // return '${minute}:${second}';
  }

  static getDeviceInfoSystem() async {
    DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
    if (Platform.isIOS) {
      IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
      print('Running on ${iosInfo.utsname.machine}');
      return iosInfo.systemVersion;
    } else if (Platform.isAndroid) {
      AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
      print('Running on ${androidInfo.model}');
      return androidInfo;
    }
  }

  ///检测是否有相机或者相册权限
  static getPickPermission(BuildContext context, VoidCallback callback,
      Permission permissionGroup) async {
    if (!(await checkPermission(permissionGroup))) {
      String title = Platform.isAndroid ? '存储' : '相册';
      if (permissionGroup == Permission.camera) {
        title = '相机';
      } else if (permissionGroup == Permission.location) {
        title = '位置';
      } else if (permissionGroup == Permission.microphone) {
        title = '麦克风';
      }
      PermissionStatus status = await permissionStatus(permissionGroup);
      if (status == PermissionStatus.permanentlyDenied) {
        //用户选择不在弹出权限提示框
        print('never');
        // Navigator.pop(context);
        DialogUtil.openAlertDialog(
            context, '未获得${title}权限', "请在手机的权限管理里,将${title}权限开启", '去设置', 340.0,
            onTap: () {
          openSetting();
          if (Navigator.canPop(context)) {
            Navigator.pop(context, '');
          }
        });
      } else {
        // 申请权限
        bool canContacts = await requestPermission(permissionGroup);
        if (canContacts) {
          callback();
        } else {
          // Navigator.pop(context);
          //拒绝通讯录权限 , 苹果拒绝权限后,不再提示权限框,进入此处
          DialogUtil.openAlertDialog(context, '未获得${title}权限',
              "请在手机的权限管理里,将${title}权限开启。", '去设置', 340.0, onTap: () {
            openSetting();
            if (Navigator.canPop(context)) {
              Navigator.pop(context, '');
            }
          });
        }
      }
    } else {
      callback();
    }
  }

  ///value: 文本内容;fontSize : 文字的大小;fontWeight:文字权重;maxWidth:文本框的最大宽度;maxLines:文本支持最大多少行
  static double calculateTextHeight(
      String value,
      fontSize,
      FontWeight fontWeight,
      double maxWidth,
      int maxLines,
      BuildContext context) {
    // value = filterText(value);
    TextPainter painter = TextPainter(

        ///AUTO:华为手机如果不指定locale的时候,该方法算出来的文字高度是比系统计算偏小的。
        locale: Localizations.localeOf(context),
        maxLines: maxLines,
        textDirection: TextDirection.ltr,
        text: TextSpan(
            text: value,
            style: TextStyle(
              fontWeight: fontWeight,
              fontSize: fontSize,
            )));
    painter.layout(maxWidth: maxWidth);

    ///文字的宽度:painter.width
    return painter.height;
  }

  static getDateStrFromJiekou(String? ms) {
    if (ms == null || ms == '') {
      return '';
    }
    return DateUtil.formatDate(
        DateTime.fromMillisecondsSinceEpoch(int.parse(ms) * 1000),
        format: DateFormats.y_mo_d);
  }

  static setBarStatus(bool isDarkIcon,
      {Color color = Colors.transparent}) async {
    if (Platform.isAndroid) {
      if (isDarkIcon) {
        SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
            statusBarColor: color,
            statusBarIconBrightness: Brightness.dark,
            statusBarBrightness: Brightness.dark);
        SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
      } else {
        SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
            statusBarColor: color,
            statusBarIconBrightness: Brightness.light,
            statusBarBrightness: Brightness.light);
        SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
      }
    }
  }

  static void showToast(String msg) {
    Fluttertoast.showToast(
        msg: msg, toastLength: Toast.LENGTH_LONG, gravity: ToastGravity.CENTER);
    // FToast().showToast(
    //   positionedToastBuilder: (context,child){

    //   },
    //     child: Center(
    //   child: Container(
    //     height: w(48),
    //     padding: EdgeInsets.symmetric(horizontal: w(10), vertical: w(15)),
    //     decoration: BoxDecoration(
    //         borderRadius: BorderRadius.circular(r(10)),
    //         color: MyColours.color_2e000000),
    //     child: Text(
    //       msg,
    //       style: TextStyle(color: MyColours.color_F8F9FD, fontSize: font(12)),
    //     ),
    //   ),
    // ));
  }

  static void removeToast() {
    Fluttertoast.cancel();
  }

  //本地图片资源路径
  static String getImgPath(String? name, {String format = 'png'}) {
    return 'assets/$name.$format';
  }

  //给数字前面加0
  static String addZeroNumberWithDouble(int numValue) {
    if (numValue < 10) {
      return "00" + numValue.toString();
    } else if (numValue < 100) {
      return "0" + numValue.toString();
    } else
      return numValue.toString();
  }

  //给数字前面加0
  static String addZeroNumber(int numValue) {
    return numValue < 10 ? "0" + numValue.toString() : numValue.toString();
  }

  //给数字前面加0
  // static String addZeroNumberSeller(String numValue) {
  //   return numValue.length < 7 ? "0" + numValue : numValue;
  // }

  //转换日期数字
  static String formatWeekDayNum(int numValue) {
    switch (numValue) {
      case 1:
        return "一";
      case 2:
        return "二";
      case 3:
        return "三";
      case 4:
        return "四";
      case 5:
        return "五";
      case 6:
        return "六";
      case 7:
        return "日";
      default:
        return "";
    }
  }

  // 改变状态栏背景颜色,默认改变为透明
  static changeStatusColor({Color color = Colors.white}) async {
    try {
      await FlutterStatusbarcolor.setStatusBarColor(color, animate: false);
      if (useWhiteForeground(color)) {
        FlutterStatusbarcolor.setStatusBarWhiteForeground(true);
      } else {
        FlutterStatusbarcolor.setStatusBarWhiteForeground(false);
      }
    } on PlatformException catch (e) {
      debugPrint(e.toString());
    }
  }

  //跳转拨打电话页面
  static goPhone(String? phoneNum) async {
    String url = "tel:$phoneNum";
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      LogUtil.e("Could not launch $url");
    }
  }

  //跳转小程序包间类型置满管理
  static goMiniProgramZm(BuildContext context, String subPath) {
    UserModel model = Provider.of<UserModel>(context, listen: false);
    Fluwx fluwx = Fluwx();
    fluwx.open(
        target: MiniProgram(
            username: "gh_487873d353b3",
            path:
                "pack-book/pages/book/b_index?seller_id=${model.user!.sellerid}&seller_openid=seller_openid&manager_id=&goPath=${subPath}",
            miniProgramType: Constant.wxMiniProgramType));
  }

  //跳转小程序新建店铺页面
  static goMiniProgramCreatePage(BuildContext context) {
    // UserModel model = Provider.of<UserModel>(context, listen: false);
    Fluwx fluwx = Fluwx();
    fluwx.open(
        target: MiniProgram(
            username: "gh_1007de739c65",
            path: "pages/login/l_login",
            miniProgramType: Constant.wxMiniProgramType));
  }

  //分享排菜单
  static goShareOrderFoodToWeChatPaicai(BuildContext context,
      {List<MenuModel>? data,
      String? title,
      String? rid,
      String? oid,
      String? img,
      String? priceSum,
      String? memberPriceSum,
      String? planPriceSum,
      String? remark,
      String? name,
      String? address,
      String? service}) async {
    Loading.showLoading(context);
    String _webPageUrl = "http://colorcun.com/";
    // String _thumbnail = img;
    String? sellerImage =
        Provider.of<UserModel>(context, listen: false).user!.sellerimage;
    // String _thumbnail = sellerImage == null || sellerImage == ''
    //     ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
    //     : sellerImage;
    String _thumbnail =
        'https://nosqn.colorcun.com/share_advanced_order_new.png';

    String? _title = title;
    String _userName = "gh_487873d353b3";
    // String _path =
    //     "pack-cookbook/pages/success?rid=$rid&identity=2&hasOnlyShow=1";
    print(data);
    String _path =
        "pack-cookbook/pages/success_new?cookbooklist=${Convert.json.encode(data)}&hasSuccess=1&oid=$oid&rid=$rid&identity=1&hasOnlyShow=1&sellerName=${Provider.of<UserModel>(context, listen: false).user!.sellername}&sid=${Provider.of<UserModel>(context, listen: false).user!.sellerid}&type=2&priceSum=${priceSum}&memberPriceSum=${memberPriceSum}&planPriceSum=${planPriceSum}&remark=${remark}&name=${name}&address=${address}&service=${service}";
    String _description = "OneKey";
    // Uint8List source = await testComporessList(context, _thumbnail);
    print(_path);

    Fluwx fluwx = Fluwx();
    Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
    Uint8List? result = pngByte;

    if (pngByte != null && await isImageLargerThan120KB(pngByte)) {
      Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
      result = resultnew == null
          ? null
          : await compressImage(resultnew, mb: 120 / 1024);
    }
    var model = new WeChatShareMiniProgramModel(
        miniProgramType: Constant.wxMiniProgramType,
        webPageUrl: _webPageUrl,
        userName: _userName,
        title: _title,
        path: _path,
        description: _description,
        thumbData: Platform.isIOS ? null : result,
        hdImageData: result
        // thumbnail: WeChatImage.binary(source)
        );
    bool isShare = await fluwx.share(model);
    print(isShare);
    Loading.hideLoading(context);
  }

  //请客人反馈----跳转小程序请客人反馈
  static goShareFeedbackPageToWeChat(BuildContext context,
      {String? title,
      String? rid,
      String? img,
      String? oid,
      String? sid}) async {
    Loading.showLoading(context);
    String _webPageUrl = "http://colorcun.com/";
    // String _thumbnail = img;

    // String _thumbnail = sellerImage == null || sellerImage == ''
    //     ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
    //     : sellerImage;
    String _thumbnail = 'https://nosqn.colorcun.com/share_feedback.jpg';
    String? _title = title;
    String _userName = "gh_487873d353b3";
    // String _path = "pack-cookbook/pages/index?rid=$rid&identity=2&sid=$sid";
    String _path =
        "pages/pinglun/createOpinion?oid=$rid&types=1&sellerid=$sid&sellerName=${Provider.of<UserModel>(context, listen: false).user!.sellername}";

    String _description = "OneKey";
    // Uint8List source = await testComporessList(context, _thumbnail);
    Fluwx fluwx = Fluwx();
    Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
    Uint8List? result = pngByte;
    if (pngByte != null && await isImageLargerThan120KB(pngByte)) {
      Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
      result = resultnew == null
          ? null
          : await compressImage(resultnew, mb: 120 / 1024);
    }
    var model = new WeChatShareMiniProgramModel(
        // miniProgramType: , //体验版
        miniProgramType: Constant.wxMiniProgramType, //正式版
        // miniProgramType:  //开发版
        webPageUrl: _webPageUrl,
        userName: _userName,
        title: _title,
        path: _path,
        // thumbnail: WeChatImage.asset(Utils.getImgPath('mini_image')),
        description: _description,

        // thumbnail: WeChatImage.binary(source)

        thumbData: Platform.isIOS ? null : result,
        hdImageData: result);
    bool isShare = await fluwx.share(model);
    print(isShare);
    Loading.hideLoading(context);
  }

  //请客户点菜----跳转小程序提前点餐
  static goShareOrderPageToWeChat(BuildContext context,
      {String? title,
      String? rid,
      String? img,
      String? oid,
      String? sid}) async {
    Loading.showLoading(context);
    String _webPageUrl = "http://colorcun.com/";
    // String _thumbnail = img;
    String? sellerImage =
        Provider.of<UserModel>(context, listen: false).user!.sellerimage;
    // String _thumbnail = sellerImage == null || sellerImage == ''
    //     ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
    //     : sellerImage;
    String _thumbnail =
        'https://nosqn.colorcun.com/share_advanced_order_new.png';
    String? _title = title;
    String _userName = "gh_487873d353b3";
    // String _path = "pack-cookbook/pages/index?rid=$rid&identity=2&sid=$sid";
    String _path =
        "pack-cookbook/pages/index_new?rid=$rid&identity=2&sid=$sid&oid=&sellerName=${Provider.of<UserModel>(context, listen: false).user!.sellername}";

    String _description = "OneKey";
    // Uint8List source = await testComporessList(context, _thumbnail);
    Fluwx fluwx = Fluwx();
    Uint8List? result = await WxSdk.fetchImageAsUint8List(_thumbnail);
    var model = new WeChatShareMiniProgramModel(
        // miniProgramType: , //体验版
        miniProgramType: Constant.wxMiniProgramType, //正式版
        // miniProgramType:  //开发版
        webPageUrl: _webPageUrl,
        userName: _userName,
        title: _title,
        path: _path,
        // thumbnail: WeChatImage.asset(Utils.getImgPath('mini_image')),
        description: _description,

        // thumbnail: WeChatImage.binary(source)

        thumbData: Platform.isIOS ? null : result,
        hdImageData: result);
    bool isShare = await fluwx.share(model);
    print(isShare);
    Loading.hideLoading(context);
  }

  //分享已点菜品
  static goShareOrderFoodToWeChat(BuildContext context,
      {String? title, String? rid, String? oid, String? img}) async {
    Loading.showLoading(context);
    String _webPageUrl = "http://colorcun.com/";
    // String _thumbnail = img;
    String? sellerImage =
        Provider.of<UserModel>(context, listen: false).user!.sellerimage;
    // String _thumbnail = sellerImage == null || sellerImage == ''
    //     ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
    //     : sellerImage;
    String _thumbnail =
        'https://nosqn.colorcun.com/share_advanced_order_new.png';

    String? _title = title;
    String _userName = "gh_487873d353b3";
    // String _path =
    //     "pack-cookbook/pages/success?rid=$rid&identity=2&hasOnlyShow=1";
    String _path =
        "pack-cookbook/pages/success_new?hasSuccess=1&oid=$oid&rid=$rid&identity=1&hasOnlyShow=1&sellerName=${Provider.of<UserModel>(context, listen: false).user!.sellername}&sid=${Provider.of<UserModel>(context, listen: false).user!.sellerid}&type=1";
    String _description = "OneKey";
    // Uint8List source = await testComporessList(context, _thumbnail);
    Fluwx fluwx = Fluwx();
    Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
    Uint8List? result = pngByte;
    if (pngByte != null && await isImageLargerThan120KB(pngByte)) {
      Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
      result = resultnew == null
          ? null
          : await compressImage(resultnew, mb: 120 / 1024);
    }
    var model = new WeChatShareMiniProgramModel(
        miniProgramType: Constant.wxMiniProgramType,
        webPageUrl: _webPageUrl,
        userName: _userName,
        title: _title,
        path: _path,
        description: _description,
        thumbData: Platform.isIOS ? null : result,
        hdImageData: result
        // thumbnail: WeChatImage.binary(source)
        );
    bool isShare = await fluwx.share(model);
    print(isShare);
    Loading.hideLoading(context);
  }

  //拉起小程序已点菜品
  // static goMiniProgramOrderFood({String rid}) {
  //   launchWeChatMiniProgram(
  //       username: "gh_487873d353b3",
  //       path: "pack-cookbook/pages/success?rid=$rid&identity=2",
  //       miniProgramType: WXMiniProgramType.RELEASE);
  // }

  //跳转帮助与反馈页面
  static goHelp(BuildContext context) async {
    //此页面已经注释,不能使用
    NavigatorUtil.goWebviewPage(context);
  }

  //获取应用版本昊
  static getCurrVersion() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    String version = packageInfo.version;
    return version;
  }

  //获取当前构建版本号
  static Future<int> getCurrBuildNum() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    return int.parse(packageInfo.buildNumber);
  }

  //获取唯一标识
  static Future<String> getUUID() async {
    DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
    if (Platform.isAndroid) {
      AndroidDeviceInfo androidDeviceInfo = await deviceInfoPlugin.androidInfo;
      return androidDeviceInfo.androidId;
    } else {
      IosDeviceInfo iosDeviceInfo = await deviceInfoPlugin.iosInfo;
      return iosDeviceInfo.identifierForVendor;
    }
  }

  //比较两个日期是否同一天
  static isOneDay(DateTime one, DateTime two) {
    if (one.year == two.year && one.month == two.month && one.day == two.day)
      return true;
    return false;
  }

  /// 下载图片
  static downloadFile(String url) async {
    // if (await Permission.storage.request().isGranted) {

    var response = await Dio()
        .get(url, options: Options(responseType: ResponseType.bytes));
    Uint8List result = Uint8List.fromList(response.data);

    return result;
    // print(result);
    // if (result["isSuccess"]) {
    //   showToast("下载成功");
    // } else {
    //   showToast("下载失败");
    // }
    // }else{
    //   showToast("未获取存储权限");
    // }
  }

  ///本地选择 图片压缩 Uint8List -> Uint8List
  static Future<Uint8List?> testFromFileComporessList(
      BuildContext context, Uint8List list,
      {bool needResize = false}) async {
    Loading.showLoading(context);

    Uint8List? result = list;
    Uint8List? resultnew;
    if (needResize) {
      result = (await resizeImage(list)) ?? null; //重置图片尺寸,裁剪5:4尺寸
      if (result == null) {
        //取消重置尺寸
        Loading.hideLoading(context);
        return null;
      }
      resultnew = await realComporessList(result); //压缩图片
    } else {
      resultnew = await compressImage(list);
      debugPrint("压缩后图片的大小:${size(resultnew!.length)}");
    }

    Loading.hideLoading(context);
    return resultnew;
    // if (result.length < 128 * 1024) {
    //   return result;
    // } else {
    //   result = await realComporessList(result);
    //   return result;
    // }
  }

  ///本地选择 图片压缩 Uint8List -> Uint8List
  static Future<Uint8List?> testFromFileComporessList5R4(
    BuildContext context,
    Uint8List list,
  ) async {
    Loading.showLoading(context);

    // Uint8List? result = list;

    // result = (await resizeImage(list))!; //重置图片尺寸,裁剪5:4尺寸
    // if (result == null) {
    //   //取消重置尺寸
    //   Loading.hideLoading(context);
    //   return null;
    // }

    Uint8List? resultnew = await compressImage(list);
    // debugPrint("压缩后图片的大小:${size(result.length)}");

    Loading.hideLoading(context);
    return resultnew;
  }

  /// 图片压缩 Uint8List -> Uint8List
  // static Future<Uint8List> testComporessList(
  //     BuildContext context, String url) async {
  //   Loading.showLoading(context);
  //   Uint8List list = await downloadFile(url); //下载图片
  //   Uint8List result = await resizeImage(list); //重置图片尺寸
  //   if (result == null) {
  //     //取消重置尺寸
  //     Loading.hideLoading(context);
  //     return null;
  //   }
  //   Uint8List resultnew = await realComporessList(result); //压缩图片

  //   Loading.hideLoading(context);
  //   return resultnew;
  //   // if (result.length < 128 * 1024) {
  //   //   return result;
  //   // } else {
  //   //   result = await realComporessList(result);
  //   //   return result;
  //   // }
  // }

  static realComporessList(Uint8List list) async {
    debugPrint("压缩前图片的大小:${size(list.length)}");
    int minHeight = 457; // 指定最小分辨率的高度
    int minWidth = 572; // 指定最小分辨率的宽度
    int quality = imageQuality(list.length);

    print(size(list.length));
    Uint8List result = await FlutterImageCompress.compressWithList(
      list,
      minWidth: minWidth,
      minHeight: minHeight,
      quality: quality,
    );
    print(size(result.length));
    return result;
  }

  // 异步方法,压缩图片到指定大小
  static Future<Uint8List?> compressImage(Uint8List imageBytes,
      {int quality = 90, double mb = 2}) async {
    try {
      print("图片初始大小:${imageBytes.length / 1024 / 1024}MB");

      // 控制压缩后图片大小,不得超过0.5MB
      // int quality = 90;
      while (imageBytes.length > 1024 * 1024 * mb && quality > 0) {
        imageBytes = await FlutterImageCompress.compressWithList(
          imageBytes,
          quality: quality,
        );
        print('压缩后大小: ${imageBytes.length / 1024 / 1024}MB');
        quality -= 2;
      }

      return imageBytes;
    } catch (e) {
      // 处理异常情况
      print('压缩图片出错:$e');
      return null;
    }
  }

  // 异步方法,压缩图片到指定大小
  static Future<File?> compressImageToFile(String path,
      {int quality = 90}) async {
    try {
      File image = File(path);
      Uint8List imageBytes = await image.readAsBytes();
      print("图片初始大小:${imageBytes.length / 1024 / 1024}MB");

      // 控制压缩后图片大小,不得超过0.5MB
      // int quality = 90;
      while (imageBytes.length > 1024 * 1024 * 2 && quality > 0) {
        imageBytes = await FlutterImageCompress.compressWithList(
          imageBytes,
          quality: quality,
        );
        print('压缩后大小: ${imageBytes.length / 1024 / 1024}MB');
        quality -= 2;
      }
      String imgPath = (await saveImage(imageBytes))!;
      return File(imgPath);
    } catch (e) {
      // 处理异常情况
      print('压缩图片出错:$e');
      return null;
    }
  }

  /// 根据传入的图片字节长度,返回指定的图片质量
  static int imageQuality(int length) {
    debugPrint("压缩前图片的大小:${size(length)}");
    int quality = 100; // 图片质量指数
    int m = 1024 * 1024; // 1 兆
    if (length < 0.5 * m) {
      quality = 70;
      debugPrint("图片小于 0.5 兆,质量设置为 70");
    } else if (length >= 0.5 * m && length < 1 * m) {
      quality = 60;
      debugPrint("图片大于 0.5 兆小于 1 兆,质量设置为 60");
    } else if (length >= 1 * m && length < 2 * m) {
      quality = 50;
      debugPrint("图片大于 1 兆小于 2 兆,质量设置为 50");
    } else if (length >= 2 * m && length < 3 * m) {
      quality = 40;
      debugPrint("图片大于 2 兆小于 3 兆,质量设置为 40");
    } else if (length >= 3 * m && length < 4 * m) {
      quality = 30;
      debugPrint("图片大于 3 兆小于 4 兆,质量设置为 30");
    } else {
      quality = 20;
      debugPrint("图片大于 4 兆,质量设置为 20");
    }
    return quality;
  }

//裁剪图片,改变图片大小
  static Future<Uint8List?> resizeImage(Uint8List data) async {
    /** 

    //image插件改变图片尺寸    copyCrop、copyResize 两个方法
      Uint8List resizedData = data;
    IMG.Image decodedImage = IMG.decodeImage(data);
    print(decodedImage.width);
    print(decodedImage.height);
    var cropSize = min(decodedImage.width, decodedImage.height);
    int offsetX =
        (decodedImage.width - min(decodedImage.width, decodedImage.height)) ~/
            2;
    int offsetY =
        (decodedImage.height - min(decodedImage.width, decodedImage.height)) ~/
            2;
    IMG.Image resized = IMG.copyCrop(decodedImage,
        x: offsetX, y: offsetY, width: 572, height: 457);
    // IMG.Image resized = IMG.copyResize(decodedImage,
    //     width: 572, interpolation: IMG.Interpolation.cubic);
    resizedData = IMG.encodeJpg(resized);
    print(size(resizedData.length));
    ui.Image im = await fun1(resizedData);
    print(im.width);
    print(im.height);
    return resizedData;
    */
//image_cropper插件,中心点裁剪固定比例的图片
    String? imgPath = await saveImage(data);
    // Uint8List afterImg = data;
    Uint8List? afterImg;
    if (imgPath != null) {
      final croppedImage = await ImageCropper().cropImage(
        sourcePath: imgPath,
        //
        compressQuality: 100,
        compressFormat: ImageCompressFormat.jpg,
        //
        aspectRatio: const CropAspectRatio(ratioX: 5, ratioY: 4),
        uiSettings: [
          AndroidUiSettings(
              // backgroundColor: Colors.red,
              // toolbarTitle: 'Cropper',
              // toolbarColor: Colors.deepOrange,
              // toolbarWidgetColor: Colors.white,
              // initAspectRatio: CropAspectRatioPreset.ratio5x4,
              cropStyle: CropStyle.rectangle,
              aspectRatioPresets: [CropAspectRatioPreset.ratio5x4],
              hideBottomControls: true,
              lockAspectRatio: true),
          IOSUiSettings(
              // title: 'Cropper',
              // rotateButtonsHidden: true,
              // rotateClockwiseButtonHidden: true,
              cropStyle: CropStyle.rectangle,
              aspectRatioPresets: [CropAspectRatioPreset.ratio5x4],
              resetAspectRatioEnabled: false,
              doneButtonTitle: '确定',
              cancelButtonTitle: '取消',
              aspectRatioLockEnabled: true),
          // WebUiSettings(
          //   context: context,
          // ),
        ],
      );
      print(croppedImage);
      if (croppedImage != null) {
        File yourFile = File(croppedImage.path);

        afterImg = await yourFile.readAsBytes();
      }
    }

    // IMG.Image decodedImage = IMG.decodeImage(data);
    // print(decodedImage.width);
    // print(decodedImage.height);

    // IMG.Image decodedImageafterImg = IMG.decodeImage(afterImg);
    // print(decodedImageafterImg.width);
    // print(decodedImageafterImg.height);
    // debugPrint("newnenwnewnnwen图片的大小:${size(afterImg.length)}");
    return afterImg;
  }

  //将回调拿到的Uint8List格式的图片转换为File格式
  static Future<String?> saveImage(Uint8List? imageByte) async {
    bool isGranted = await checkPermissionStorage();
    if (isGranted) {
      //获取临时目录
      var tempDir = await getTemporaryDirectory();
      //生成file文件格式
      var file =
          await File('${tempDir.path}/image_${DateTime.now().millisecond}.jpg')
              .create();
      //转成file文件
      file.writeAsBytesSync(imageByte!);
      print("${file.path}");
      return file.path;
      // setState(() {
      //   path = file.path;
      //   // turn(file);
      //   _imageUint8=imageByte;
      // });
    }
    return null;
  }

  /// 根据传入的字节长度,转换成相应的 M 和 KB
  static String size(int length) {
    String res = "";
    final int unit = 1024;
    final int m = unit * unit; // 1M
    // 如果小于 1 兆,显示 KB
    if (length < 1 * m) {
      res = (length / unit).toStringAsFixed(0) + " KB";
    }
    // 如果大于 1 兆,显示 MB,并保留一位小数
    if (length >= 1 * m) {
      res = (length / m).toStringAsFixed(1) + " MB";
    }
    return res;
  }

  /// 大于3.99 压缩
  static Future<bool> sizeNeed(File file) async {
    Uint8List afterImg = await file.readAsBytes();
    String res = "";
    final int unit = 1024;
    final int m = unit * unit; // 1M
    // 如果小于 1 兆,显示 KB
    // if (length < 1 * m) {
    //   res = (length / unit).toStringAsFixed(0) + " KB";
    // }
    // 如果大于 1 兆,显示 MB,并保留一位小数
    if (afterImg.length / m > 3.99) {
      return true;
    }
    return false;
  }

  /// Uint8List 转 Image 方式一

  /// Uint8List 转 Image 方式二
  static Future<ui.Image> fun1(Uint8List list) async {
    ui.Codec codec = await ui.instantiateImageCodec(list);
    ui.FrameInfo frame = await codec.getNextFrame();
    return frame.image;
  }

  //跳转到充值优惠列表
  static goShareRechargeListToWeChat(BuildContext context) async {
    String _webPageUrl = "http://colorcun.com/";
    // String _thumbnail =
    //     "https://xt04.colorcun.com/h5/index.html#/?id=163854&hasInvitation=1";
    // String _thumbnail =
    //     "https://qn.colorcun.com/reserve/images/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_201911151148572.jpg";
    // String sellerImage =
    //     Provider.of<UserModel>(context, listen: false).user.sellerimage;
    String _thumbnail = 'https://nosqn.colorcun.com/share_recharge.png';
    String _title =
        "${Provider.of<UserModel>(context, listen: false).user!.sellername}诚邀您参加储值优惠活动,点击查看详情。";
    String _userName = "gh_487873d353b3";
    String _path =
        "pack-cookbook/pages/favourableList?sellerName=${Provider.of<UserModel>(context, listen: false).user!.sellername}&sellerid=${Provider.of<UserModel>(context, listen: false).user!.sellerid}&types=3";
    // if (Provider.of<UserModel>(context, listen: false).user.sellerid == '677') {
    //   //京厨九跳转新的邀请函地址
    //   _path =
    //       "pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
    // }
    String _description = "诚邀您参加储值优惠活动,点击查看详情。";
    // Uint8List source = await testComporessList(context, _thumbnail);
    Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
    Uint8List? result = pngByte;
    if (pngByte != null && await isImageLargerThan120KB(pngByte)) {
      Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
      result = resultnew == null
          ? null
          : await compressImage(resultnew, mb: 120 / 1024);
    }

    //跳转小程序
    Fluwx fluwx = Fluwx();
    var model = new WeChatShareMiniProgramModel(
        webPageUrl: _webPageUrl,
        userName: _userName,
        title: _title,
        path: _path,
        description: _description,
        // miniProgramType: , //体验版
        miniProgramType: Constant.wxMiniProgramType, //正式版
        // miniProgramType:  //开发版
        // thumbnail: WeChatImage.binary(source)
        thumbData: Platform.isIOS ? null : result,
        hdImageData: result
        // thumbnail: WeChatImage.binary(image)
        );
    //分享链接
    // var model = WeChatShareWebPageModel(
    //   // 'https://xt04.colorcun.com/h5/index.html#/?id=$rid&hasInvitation=1',
    //   'https://xt04.colorcun.com/h5/index.html?id=$rid&hasInvitation=1&hasSellerShare=1',
    //   title: _title,
    //   description: _description,
    //   thumbnail: WeChatImage.network(_thumbnail),
    //   scene: WeChatScene.SESSION,
    // );

    bool isSuccess = await fluwx.share(model);
    return isSuccess;
  }

  //跳转到优惠券购买页面
  static goShareBuyCouponToWeChatMy(BuildContext context, String? couponid,
      String? managerName, CouponSunModel couponSunModel) async {
    String _webPageUrl = "http://colorcun.com/";
    // String _thumbnail =
    //     "https://xt04.colorcun.com/h5/index.html#/?id=163854&hasInvitation=1";
    // String _thumbnail =
    //     "https://qn.colorcun.com/reserve/images/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_201911151148572.jpg";
    // String sellerImage =
    //     Provider.of<UserModel>(context, listen: false).user.sellerimage;

    String _thumbnail = 'https://nosqn.colorcun.com/share_coupon.jpg';
    String _title = "${managerName}给您赠送${couponSunModel.aname},点击查看详情";

    String _userName = "gh_487873d353b3";
    String _path =
        "pack-activity/pack/buyCoupon?id=$couponid&name=${Provider.of<UserModel>(context, listen: false).user!.sellername}&sid=${Provider.of<UserModel>(context, listen: false).user!.sellerid}&types=2";
    // if (Provider.of<UserModel>(context, listen: false).user.sellerid == '677') {
    //   //京厨九跳转新的邀请函地址
    //   _path =
    //       "pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
    // }
    String _description = "进入查看包间详情,转发同行好友,还可一键导航到饭店";
    // Uint8List source = await testComporessList(context, _thumbnail);
    Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
    Uint8List? result = pngByte;
    if (pngByte != null && await isImageLargerThan120KB(pngByte)) {
      Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
      result = resultnew == null
          ? null
          : await compressImage(resultnew, mb: 120 / 1024);
    }
    //跳转小程序
    Fluwx fluwx = Fluwx();
    var model = new WeChatShareMiniProgramModel(
        webPageUrl: _webPageUrl,
        userName: _userName,
        title: _title,
        path: _path,
        // description: 'hhh',
        // miniProgramType: , //体验版
        miniProgramType: Constant.wxMiniProgramType, //正式版
        // miniProgramType:  //开发版
        // thumbnail: WeChatImage.binary(source)
        thumbData: Platform.isIOS ? null : result,
        hdImageData: result
        // hdImagePath: WeChatImage.network(_thumbnail), thumbnail: null,
        // thumbnail: WeChatImage.binary(image)
        );
    //分享链接
    // var model = WeChatShareWebPageModel(
    //   // 'https://xt04.colorcun.com/h5/index.html#/?id=$rid&hasInvitation=1',
    //   'https://xt04.colorcun.com/h5/index.html?id=$rid&hasInvitation=1&hasSellerShare=1',
    //   title: _title,
    //   description: _description,
    //   thumbnail: WeChatImage.network(_thumbnail),
    //   scene: WeChatScene.SESSION,
    // );

    bool isSuccess = await fluwx.share(model);
    return isSuccess;
  }

  //跳转到优惠券购买页面
  static goShareBuyCouponToWeChat(BuildContext context, String? couponid,
      String? type, CouponUse? use, CouponSunModel? couponSunModel) async {
    String _webPageUrl = "http://colorcun.com/";
    // String _thumbnail =
    //     "https://xt04.colorcun.com/h5/index.html#/?id=163854&hasInvitation=1";
    // String _thumbnail =
    //     "https://qn.colorcun.com/reserve/images/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_201911151148572.jpg";
    // String sellerImage =
    //     Provider.of<UserModel>(context, listen: false).user.sellerimage;
    String? price = couponSunModel!.price;
    String _thumbnail = 'https://nosqn.colorcun.com/share_recharge.png';
    String _title =
        "${Provider.of<UserModel>(context, listen: false).user!.sellername}向您推荐一张优惠券,点击获取。";
    if (use != null) {
      if (use.isCash) {
        _thumbnail = 'https://nosqn.colorcun.com/share_money.png';
        if (price == '0') {
          _title =
              '免费获取${Provider.of<UserModel>(context, listen: false).user!.sellername}${use.cash}元代金券,点击查看详情。';
        } else {
          _title =
              '仅需${price}元,获取${Provider.of<UserModel>(context, listen: false).user!.sellername}${use.cash}元代金券,点击查看详情。';
        }
      } else if (use.isDiscount) {
        _thumbnail = 'https://nosqn.colorcun.com/share_discount.png';
        if (price == '0') {
          _title =
              '免费获取${Provider.of<UserModel>(context, listen: false).user!.sellername}${use.discount}折折扣券,点击查看详情。';
        } else {
          _title =
              '仅需${price}元,获取${Provider.of<UserModel>(context, listen: false).user!.sellername}${use.discount}折折扣券,点击查看详情。';
        }
      } else if (use.isDish) {
        _thumbnail = 'https://nosqn.colorcun.com/share_dish.png';
        if (use.images.length > 0) {
          _thumbnail = use.images[0];
        }
        if (price == '0') {
          _title =
              '免费获取${Provider.of<UserModel>(context, listen: false).user!.sellername}${couponSunModel.aname},点击查看详情。';
        } else {
          _title =
              '仅需${price}元,获取${Provider.of<UserModel>(context, listen: false).user!.sellername}${couponSunModel.aname},点击查看详情。';
        }
      }
    }

    String _userName = "gh_487873d353b3";
    String _path;
    if (type == '3') {
      _thumbnail = 'https://nosqn.colorcun.com/share_money.png';
      _title =
          '免费获取${Provider.of<UserModel>(context, listen: false).user!.sellername}${couponSunModel.price}元代金券,点击查看详情。';
      _path =
          "pack-activity/pack/receiveCoupon?id=$couponid&sid=${Provider.of<UserModel>(context, listen: false).user!.sellerid}&types=3";
    } else {
      _path =
          "pack-activity/pack/buyCoupon?id=$couponid&name=${Provider.of<UserModel>(context, listen: false).user!.sellername}&sid=${Provider.of<UserModel>(context, listen: false).user!.sellerid}&types=3";
    }

    // if (Provider.of<UserModel>(context, listen: false).user.sellerid == '677') {
    //   //京厨九跳转新的邀请函地址
    //   _path =
    //       "pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
    // }
    String _description = "进入查看包间详情,转发同行好友,还可一键导航到饭店";
    // Uint8List source = await testComporessList(context, _thumbnail);
    Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
    Uint8List? result = pngByte;
    if (pngByte != null && await isImageLargerThan120KB(pngByte)) {
      Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
      result = resultnew == null
          ? null
          : await compressImage(resultnew, mb: 120 / 1024);
    }
    //  print(result!.length/1024);
    //跳转小程序

    Fluwx fluwx = Fluwx();
    var model = new WeChatShareMiniProgramModel(
        webPageUrl: _webPageUrl,
        userName: _userName,
        title: _title,
        path: _path,
        // description: 'hhh',
        // miniProgramType: , //体验版
        miniProgramType: Constant.wxMiniProgramType, //正式版
        // miniProgramType:  //开发版
        // thumbnail: WeChatImage.binary(source)
        thumbData: Platform.isIOS ? null : result,
        hdImageData: result
        // hdImagePath: WeChatImage.network(_thumbnail), thumbnail: null,
        // thumbnail: WeChatImage.binary(image)
        );
    //分享链接
    // var model = WeChatShareWebPageModel(
    //   // 'https://xt04.colorcun.com/h5/index.html#/?id=$rid&hasInvitation=1',
    //   'https://xt04.colorcun.com/h5/index.html?id=$rid&hasInvitation=1&hasSellerShare=1',
    //   title: _title,
    //   description: _description,
    //   thumbnail: WeChatImage.network(_thumbnail),
    //   scene: WeChatScene.SESSION,
    // );

    bool isSuccess = await fluwx.share(model);
    return isSuccess;
  }

  //跳转到充值优惠购买页面
  static goShareBuyRechargeToWeChat(BuildContext context, String? rechargeid,
      RechargeListSunModel rechargeListSunModel) async {
    String _webPageUrl = "http://colorcun.com/";
    // String _thumbnail =
    //     "https://xt04.colorcun.com/h5/index.html#/?id=163854&hasInvitation=1";
    // String _thumbnail =
    //     "https://qn.colorcun.com/reserve/images/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_201911151148572.jpg";
    // String sellerImage =
    //     Provider.of<UserModel>(context, listen: false).user.sellerimage;
    String _thumbnail = 'https://nosqn.colorcun.com/share_recharge.png';

    String _title =
        "${Provider.of<UserModel>(context, listen: false).user!.sellername}诚邀您参加“${rechargeListSunModel.rname}”,点击查看详情。";
    String _userName = "gh_487873d353b3";
    String _path =
        "pack-activity/pack/vipRecharge?id=$rechargeid&name=${Provider.of<UserModel>(context, listen: false).user!.sellername}&sid=${Provider.of<UserModel>(context, listen: false).user!.sellerid}&types=3";
    // if (Provider.of<UserModel>(context, listen: false).user.sellerid == '677') {
    //   //京厨九跳转新的邀请函地址
    //   _path =
    //       "pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
    // }
    String _description =
        "${Provider.of<UserModel>(context, listen: false).user!.sellername}诚邀您参加“${rechargeListSunModel.rname}”,点击查看详情。";
    // Uint8List source = await testComporessList(context, _thumbnail);

    //跳转小程序
    Fluwx fluwx = Fluwx();
    Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
    Uint8List? result = pngByte;
    if (pngByte != null && await isImageLargerThan120KB(pngByte)) {
      Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
      result = resultnew == null
          ? null
          : await compressImage(resultnew, mb: 120 / 1024);
    }
    var model = new WeChatShareMiniProgramModel(
        webPageUrl: _webPageUrl,
        userName: _userName,
        title: _title,
        path: _path,
        description: _description,
        // miniProgramType: , //体验版
        miniProgramType: Constant.wxMiniProgramType, //正式版
        // miniProgramType:  //开发版
        // thumbnail: WeChatImage.binary(source)
        thumbData: Platform.isIOS ? null : result,
        hdImageData: result
        // thumbnail: WeChatImage.binary(image)
        );
    //分享链接
    // var model = WeChatShareWebPageModel(
    //   // 'https://xt04.colorcun.com/h5/index.html#/?id=$rid&hasInvitation=1',
    //   'https://xt04.colorcun.com/h5/index.html?id=$rid&hasInvitation=1&hasSellerShare=1',
    //   title: _title,
    //   description: _description,
    //   thumbnail: WeChatImage.network(_thumbnail),
    //   scene: WeChatScene.SESSION,
    // );

    bool isSuccess = await fluwx.share(model);
    return isSuccess;
  }

  static Future<ui.Image> loadImage(var path, bool isUrl) async {
    ImageStream stream;
    if (isUrl) {
      stream = NetworkImage(path).resolve(ImageConfiguration.empty);
    } else {
      stream = AssetImage(path, bundle: rootBundle)
          .resolve(ImageConfiguration.empty);
    }
    Completer<ui.Image> completer = Completer<ui.Image>();
    void listener(ImageInfo frame, bool synchronousCall) {
      final ui.Image image = frame.image;
      completer.complete(image);
      stream.removeListener(ImageStreamListener(listener));
    }

    stream.addListener(ImageStreamListener(listener));
    return completer.future;
  }

//  static   Future<ui.Image> getImage(String asset) async {
//     ByteData data = await rootBundle.load(asset);
//     Codec codec = await ui.instantiateImageCodec(data.buffer.asUint8List());
//     FrameInfo fi = await codec.getNextFrame();
//     return fi.image;
//   }
  // static Future<Uint8List> canvas(
  //     context, String _thumbnail, String month, String week) async {
  //   var pictureRecorder = new ui.PictureRecorder(); // 图片记录仪
  //   var canvas = new Canvas(pictureRecorder); //canvas接受一个图片记录仪
  //   var images = await loadImage(_thumbnail, true); // 使用方法获取Unit8List格式的图片
  //   print(images);
  //   // Paint _linePaint = new Paint()
  //   //   ..color = Colors.blue
  //   //   ..style = PaintingStyle.fill
  //   //   ..isAntiAlias = true
  //   //   ..strokeCap = StrokeCap.round
  //   //   ..strokeWidth = 500;
  //   // Paint selfPaint = Paint()
  //   //   ..color = Colors.red
  //   //   ..style = PaintingStyle.fill
  //   //   ..isAntiAlias = true
  //   //   ..strokeCap = StrokeCap.butt
  //   //   ..strokeWidth = 2;
  //   final paint = Paint()
  //     // ..color = Colors.red
  //     // ..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
  //     ..style = PaintingStyle.fill;

  //   // 绘制一个矩形作为蒙版
  //   // canvas.drawRect(Rect.fromLTRB(10, 10, 80, 80), paint);

  //   // // 应用蒙版后,再绘制其他图形
  //   // paint.maskFilter = null;
  //   // canvas.drawCircle(Offset(60, 60), 30, paint);

  //   // canvas.drawRect(Rect.fromLTWH(0, 0, 500, 400), paint);

  //   // canvas.drawImage(images, Offset(0, 0), paint);

  //   // 定义源矩形,通常是图像的全部
  //   final Rect source = Rect.fromLTWH(
  //       0.0, 0.0, images.width.toDouble(), images.height.toDouble());
  //   // 定义目标矩形,即画布的大小
  //   final Rect destination = Rect.fromLTWH(0.0, 0.0, 500, 400);
  //   // 绘制图像
  //   canvas.drawImageRect(images, source, destination, paint);

  //   final paint1 = Paint()
  //     ..color = Colors.black.withOpacity(0.4)
  //     ..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
  //     ..style = PaintingStyle.fill;

  //   // 绘制一个矩形作为蒙版
  //   canvas.drawRect(Rect.fromLTRB(0, 0, 500, 400), paint1);

  //   // 在画布上绘制图片,使用BoxFit来适配画布大小
  //   // canvas.drawImageRect(
  //   //     images,
  //   //     Rect.fromLTWH(0, 0, images.width.toDouble(), images.height.toDouble()),
  //   //     Rect.fromLTWH(0, 0, images.width.toDouble(), images.height.toDouble()),
  //   //     paint);

  //   // 绘制文字
  //   ui.ParagraphBuilder pb2 = ui.ParagraphBuilder(ui.ParagraphStyle(
  //       textAlign: TextAlign.center,
  //       fontWeight: FontWeight.normal,
  //       fontStyle: FontStyle.normal,

  //       //  :MyColours.color_000000,
  //       fontSize: 26));
  //   pb2.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 26));
  //   pb2.addText(
  //       '${Provider.of<UserModel>(context, listen: false).user.sellername}');

  //   // 设置文本的宽度约束
  //   ParagraphConstraints pc2 = ui.ParagraphConstraints(width: 500);
  //   ui.Paragraph paragraph2 = pb2.build()..layout(pc2);
  //   canvas.drawParagraph(paragraph2, Offset(10, 40));

  //   // 绘制文字
  //   ui.ParagraphBuilder pb = ui.ParagraphBuilder(ui.ParagraphStyle(
  //       textAlign: TextAlign.center,
  //       fontWeight: FontWeight.bold,
  //       fontStyle: FontStyle.normal,

  //       //  :MyColours.color_000000,
  //       fontSize: 48));
  //   pb.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 48));
  //   pb.addText(month);

  //   // 设置文本的宽度约束
  //   ParagraphConstraints pc = ui.ParagraphConstraints(width: 500);
  //   ui.Paragraph paragraph = pb.build()..layout(pc);
  //   canvas.drawParagraph(paragraph, Offset(10, 150));

  //   // 绘制文字
  //   ui.ParagraphBuilder pb3 = ui.ParagraphBuilder(ui.ParagraphStyle(
  //       textAlign: TextAlign.center,
  //       fontWeight: FontWeight.bold,
  //       fontStyle: FontStyle.normal,

  //       //  :MyColours.color_000000,
  //       fontSize: 42));
  //   pb3.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 42));
  //   pb3.addText(week);

  //   // 设置文本的宽度约束
  //   ParagraphConstraints pc3 = ui.ParagraphConstraints(width: 500);
  //   ui.Paragraph paragraph3 = pb3.build()..layout(pc3);
  //   canvas.drawParagraph(paragraph3, Offset(10, 230));

  //   //下面的代码是生成图片的关键代码,以上绘制文字和圆圈的代码可以忽略不计
  //   var picture =
  //       await pictureRecorder.endRecording().toImage(500, 400); //设置生成图片的宽和高
  //   var pngImageBytes =
  //       await picture.toByteData(format: ui.ImageByteFormat.png);
  //   // var imgBytes = Uint8List.view(pngImageBytes.buffer); //这一行和下面这一行都是生成Uint8List格式的图片(原理还不知道)
  //   Uint8List pngBytes = pngImageBytes.buffer.asUint8List();
  //   print(pngBytes); //pngBytes可以放在Image.memory()中预览
  //   // setState(() {
  //   //   imageMemory = pngBytes;
  //   // Uint8List result = await resizeImage(pngBytes); //重置图片尺寸
  //   Uint8List result = await testFromFileComporessList(context, pngBytes);
  //   return result;
  // }
  static String returnWeek(DateTime day, BuildContext context) {
    String date = "周${Utils.formatWeekDayNum(day.weekday)}  ";

    return date;
  }

  static Future<Uint8List> canvas(context, String _thumbnail, DateTime date,
      String liteStyle, String dsolt, String ddateHm, String mname) async {
    var pictureRecorder = new ui.PictureRecorder(); // 图片记录仪
    var canvas = new Canvas(pictureRecorder); //canvas接受一个图片记录仪
    var images = await loadImage(_thumbnail, true); // 使用方法获取Unit8List格式的图片
    print(images);
    final Paint paint = Paint();
    double scaleX = images.width / 210;
    double scaleY = images.height / 168;
    canvas.drawImage(images, Offset.zero, paint); //绘制原始图片

    List<String> subType = liteStyle.split('-');
    // String subType0 = subType[0]; //几号模版
    String subType1 = subType[1]; //模版下面的子样式
    String month =
        '${Utils.addZeroNumber(date.month)}月${Utils.addZeroNumber(date.day)}日  ';
    String week = returnWeek(date, context);
    String hour = subType1 == '1' || subType1 == '3' ? '${ddateHm}  ' : '';
    String section = subType1 == '1' || subType1 == '4'
        ? _getDsoltStrShow(dsolt, mname)
        : subType1 == '2'
            ? _getDsoltStrShow(dsolt, mname, isCan: false)
            : '';

    String time = month + week + hour + section;

    paint.color = MyColours.color_99000000;
    paint.style = PaintingStyle.fill;
    // if (Platform.isIOS) {
    //   paint.style = PaintingStyle.fill;
    // }
    // 定义源矩形,通常是图像的全部
    // final Rect source = Rect.fromLTWH(
    //     0.0, 0.0, images.width.toDouble(), images.height.toDouble());
    // // 定义目标矩形,即画布的大小
    // final Rect destination = Rect.fromLTWH(0.0, 0.0, w(210), w(168));
    // // 绘制图像
    canvas.drawRect(
        Rect.fromLTWH(0, 0, images.width.toDouble(), 28 * scaleY), paint);
    // canvas.drawImageRect(images, source, destination, paint);

    // 定义源矩形,通常是图像的全部
    // final Rect source2 = Rect.fromLTWH(
    //     0.0, w(142), images.width.toDouble(), images.height.toDouble());
    // // 定义目标矩形,即画布的大小
    // final Rect destination2 = Rect.fromLTWH(0.0, 0.0, 500, 400);
    // // 绘制图像
    // canvas.drawImageRect(images, source2, destination2, paint);
    // if (Platform.isIOS) {
    //   final paint1 = Paint()
    //     ..color = MyColours.color_99000000
    //     ..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
    //     ..style = PaintingStyle.fill;
    //   // 绘制一个矩形作为蒙版
    //   canvas.drawRect(Rect.fromLTRB(0, 0, 500, 400), paint1);
    // }
    // 绘制文字
    ui.ParagraphBuilder pb2 = ui.ParagraphBuilder(ui.ParagraphStyle(
        textAlign: TextAlign.center,
        fontWeight: FontWeight.bold,
        fontStyle: FontStyle.normal,
        height: 1,
        maxLines: 1,
        ellipsis: '3',
        fontSize: 38));
    pb2.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 38));
    pb2.addText(
        '${Provider.of<UserModel>(context, listen: false).user!.sellername}');

    // 设置文本的宽度约束
    ParagraphConstraints pc2 =
        ui.ParagraphConstraints(width: images.width.toDouble());
    ui.Paragraph paragraph2 = pb2.build()..layout(pc2);
    canvas.drawParagraph(paragraph2, Offset(0, 8 * scaleY));

    canvas.drawRect(
        Rect.fromLTWH(0, images.height - 28 * scaleY, images.width.toDouble(),
            28 * scaleY),
        paint);

    // 绘制文字
    ui.ParagraphBuilder pb = ui.ParagraphBuilder(ui.ParagraphStyle(
        textAlign: TextAlign.center,
        fontWeight: FontWeight.bold,
        fontStyle: FontStyle.normal,
        height: 1,
        fontSize: 38));
    pb.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 38));
    pb.addText(time);

    // 设置文本的宽度约束
    ParagraphConstraints pc =
        ui.ParagraphConstraints(width: images.width.toDouble());
    ui.Paragraph paragraph = pb.build()..layout(pc);
    canvas.drawParagraph(
        paragraph, Offset(0, images.height - 28 * scaleY + 8 * scaleY));

    // 绘制文字
    // ui.ParagraphBuilder pb3 = ui.ParagraphBuilder(ui.ParagraphStyle(
    //     textAlign: TextAlign.center,
    //     fontWeight: FontWeight.bold,
    //     fontStyle: FontStyle.normal,
    //     fontSize: 42));
    // pb3.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 42));
    // pb3.addText(week);

    // // 设置文本的宽度约束
    // ParagraphConstraints pc3 = ui.ParagraphConstraints(width: 500);
    // ui.Paragraph paragraph3 = pb3.build()..layout(pc3);
    // canvas.drawParagraph(paragraph3, Offset(10, 230));

    //下面的代码是生成图片的关键代码,以上绘制文字和圆圈的代码可以忽略不计
    var picture = await pictureRecorder
        .endRecording()
        .toImage(images.width, images.height); //设置生成图片的宽和高
    var pngImageBytes =
        (await picture.toByteData(format: ui.ImageByteFormat.png))!;
    // var imgBytes = Uint8List.view(pngImageBytes.buffer); //这一行和下面这一行都是生成Uint8List格式的图片(原理还不知道)
    Uint8List pngBytes = pngImageBytes.buffer.asUint8List();
    print(pngBytes); //pngBytes可以放在Image.memory()中预览

    Uint8List result = await realComporessList(pngBytes); //压缩图片
    return result;
  }

  static Future<Uint8List> canvas2(context, String _thumbnail, DateTime date,
      String liteStyle, String dsolt, String ddateHm, String mname) async {
    var pictureRecorder = new ui.PictureRecorder(); // 图片记录仪
    var canvas = new Canvas(pictureRecorder); //canvas接受一个图片记录仪
    var images = await loadImage(_thumbnail, true); // 使用方法获取Unit8List格式的图片
    print(images);
    final Paint paint = Paint();
    double scaleX = images.width / 210;
    double scaleY = images.height / 168;

    canvas.drawImage(images, Offset.zero, paint); //绘制原始图片

    List<String> subType = liteStyle.split('-');
    // String subType0 = subType[0]; //几号模版
    String subType1 = subType[1]; //模版下面的子样式
    String month =
        '${Utils.addZeroNumber(date.month)}/${Utils.addZeroNumber(date.day)}';
    String week = returnWeek(date, context);
    String hour = subType1 == '1' || subType1 == '3' ? '${ddateHm}  ' : '';
    String section = subType1 == '1' || subType1 == '4'
        ? _getDsoltStrShow(dsolt, mname)
        : subType1 == '2'
            ? _getDsoltStrShow(dsolt, mname, isCan: false)
            : '';

    String time = week + hour + section;

    paint.color = MyColours.color_99000000;
    paint.style = PaintingStyle.fill;
    // if (Platform.isIOS) {
    //   paint.style = PaintingStyle.fill;
    // }
    // // 绘制图像
    canvas.drawRect(
        Rect.fromLTWH(0, 0, images.width.toDouble(), images.height.toDouble()),
        paint);

    // if (Platform.isIOS) {
    //   final paint1 = Paint()
    //     ..color = MyColours.color_99000000
    //     ..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
    //     ..style = PaintingStyle.fill;
    //   // 绘制一个矩形作为蒙版
    //   canvas.drawRect(Rect.fromLTRB(0, 0, 500, 400), paint1);
    // }
    // 绘制文字
    ui.ParagraphBuilder pb2 = ui.ParagraphBuilder(ui.ParagraphStyle(
        textAlign: TextAlign.center,
        fontWeight: FontWeight.bold,
        maxLines: 2,
        height: 1,
        fontStyle: FontStyle.normal,
        fontSize: 42));
    pb2.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 42));
    pb2.addText(
        '${Provider.of<UserModel>(context, listen: false).user!.sellername}');

    // 设置文本的宽度约束
    ParagraphConstraints pc2 =
        ui.ParagraphConstraints(width: images.width.toDouble());
    ui.Paragraph paragraph2 = pb2.build()..layout(pc2);
    canvas.drawParagraph(paragraph2, Offset(0, 32 * scaleY));

    // 绘制文字
    ui.ParagraphBuilder pb3 = ui.ParagraphBuilder(ui.ParagraphStyle(
        textAlign: TextAlign.center,
        fontWeight: FontWeight.bold,
        height: 1,
        fontStyle: FontStyle.normal,
        fontSize: 86));
    pb3.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 86));
    pb3.addText(month);

    // 设置文本的宽度约束
    ParagraphConstraints pc3 =
        ui.ParagraphConstraints(width: images.width.toDouble());
    ui.Paragraph paragraph3 = pb3.build()..layout(pc3);
    canvas.drawParagraph(paragraph3, Offset(0, 79 * scaleY));

    // 绘制文字
    ui.ParagraphBuilder pb = ui.ParagraphBuilder(ui.ParagraphStyle(
        textAlign: TextAlign.center,
        fontWeight: FontWeight.bold,
        fontStyle: FontStyle.normal,
        height: 1,
        fontSize: 42));
    pb.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 42));
    pb.addText(time);

    // 设置文本的宽度约束
    ParagraphConstraints pc =
        ui.ParagraphConstraints(width: images.width.toDouble());
    ui.Paragraph paragraph = pb.build()..layout(pc);
    canvas.drawParagraph(paragraph, Offset(0, 120 * scaleY));

    //下面的代码是生成图片的关键代码,以上绘制文字和圆圈的代码可以忽略不计
    var picture = await pictureRecorder
        .endRecording()
        .toImage(images.width, images.height); //设置生成图片的宽和高
    var pngImageBytes =
        (await picture.toByteData(format: ui.ImageByteFormat.png))!;
    // var imgBytes = Uint8List.view(pngImageBytes.buffer); //这一行和下面这一行都是生成Uint8List格式的图片(原理还不知道)
    Uint8List pngBytes = pngImageBytes.buffer.asUint8List();
    print(pngBytes); //pngBytes可以放在Image.memory()中预览

    Uint8List result = await realComporessList(pngBytes); //压缩图片
    return result;
  }

  static Future<Uint8List> canvas3(context, String _thumbnail, DateTime date,
      String liteStyle, String dsolt, String ddateHm, String mname) async {
    var pictureRecorder = new ui.PictureRecorder(); // 图片记录仪
    var canvas = new Canvas(pictureRecorder); //canvas接受一个图片记录仪
    var images = await loadImage(_thumbnail, true); // 使用方法获取Unit8List格式的图片
    print(images);
    final Paint paint = Paint();
    canvas.drawImage(images, Offset.zero, paint); //绘制原始图片
    double scaleX = images.width / 210;
    double scaleY = images.height / 168;

    List<String> subType = liteStyle.split('-');
    // String subType0 = subType[0]; //几号模版
    String subType1 = subType[1]; //模版下面的子样式
    String month =
        '${Utils.addZeroNumber(date.month)}/${Utils.addZeroNumber(date.day)}';
    String week = returnWeek(date, context);
    String hour = subType1 == '1' || subType1 == '3' ? '${ddateHm}' : '';
    String section = subType1 == '1' || subType1 == '4'
        ? _getDsoltStrShow(dsolt, mname)
        : subType1 == '2'
            ? _getDsoltStrShow(dsolt, mname, isCan: false)
            : '';

    if (hour != '' && section != '') {
      section = section + '  ';
    }

    String time = section + hour;

    paint.color = MyColours.color_99000000;
    paint.style = PaintingStyle.fill;
    // if (Platform.isIOS) {
    //   paint.style = PaintingStyle.fill;
    // }
    // // 绘制图像
    canvas.drawRect(
        Rect.fromLTWH(0, 0, images.width.toDouble(), images.height.toDouble()),
        paint);

    // if (Platform.isIOS) {
    //   final paint1 = Paint()
    //     ..color = MyColours.color_99000000
    //     ..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
    //     ..style = PaintingStyle.fill;
    //   // 绘制一个矩形作为蒙版
    //   canvas.drawRect(Rect.fromLTRB(0, 0, 500, 400), paint1);
    // }
    // 绘制文字
    ui.ParagraphBuilder pb2 = ui.ParagraphBuilder(ui.ParagraphStyle(
        textAlign: TextAlign.left,
        fontWeight: FontWeight.bold,
        fontStyle: FontStyle.normal,
        maxLines: 2,
        fontSize: 38));
    pb2.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 38));
    pb2.addText(
        '${Provider.of<UserModel>(context, listen: false).user!.sellername}');

    // 设置文本的宽度约束
    ParagraphConstraints pc2 = ui.ParagraphConstraints(width: 500);
    ui.Paragraph paragraph2 = pb2.build()..layout(pc2);
    canvas.drawParagraph(paragraph2, Offset(35, 50));

    // 绘制文字
    ui.ParagraphBuilder pb3 = ui.ParagraphBuilder(ui.ParagraphStyle(
        textAlign: TextAlign.center,
        fontWeight: FontWeight.bold,
        fontStyle: FontStyle.normal,
        height: 1,
        fontSize: 88));
    pb3.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 88));
    pb3.addText(month);

    // 设置文本的宽度约束
    ParagraphConstraints pc3 = ui.ParagraphConstraints(width: 270);
    ui.Paragraph paragraph3 = pb3.build()..layout(pc3);
    canvas.drawParagraph(
        paragraph3, Offset(images.width - 340, images.height - 180));

    // 绘制文字
    ui.ParagraphBuilder pb4 = ui.ParagraphBuilder(ui.ParagraphStyle(
        textAlign: TextAlign.center,
        height: 1,
        fontWeight: FontWeight.bold,
        fontStyle: FontStyle.normal,
        fontSize: 38));
    pb4.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 38));
    pb4.addText(week);

    // 设置文本的宽度约束
    ParagraphConstraints pc4 = ui.ParagraphConstraints(width: 40);
    ui.Paragraph paragraph4 = pb4.build()..layout(pc4);
    canvas.drawParagraph(
        paragraph4, Offset(images.width - 70, images.height - 180));

    Rect rect = subType1 == '1'
        ? Rect.fromLTWH(images.width - 250, images.height - 90, 220, 50)
        : Rect.fromLTWH(158 * scaleX, images.height - 90, 40 * scaleX, 50);
    paint.color = MyColours.color_66FFEFC5;
    RRect rRect = RRect.fromRectAndRadius(rect, Radius.circular(6));
    canvas.drawRRect(rRect, paint);
    paint.color = MyColours.color_99000000;

    // 绘制文字
    ui.ParagraphBuilder pb = ui.ParagraphBuilder(ui.ParagraphStyle(
        textAlign: TextAlign.center,
        fontWeight: FontWeight.bold,
        height: 1,
        fontStyle: FontStyle.normal,
        fontSize: 38));
    pb.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 38));
    pb.addText(time);

    // 设置文本的宽度约束
    double width = subType1 == '1' ? 240 : 40 * scaleX;
    Offset offset = subType1 == '1'
        ? Offset(images.width - 260, images.height - 80)
        : Offset(158 * scaleX, images.height - 80);
    ParagraphConstraints pc = ui.ParagraphConstraints(width: width);
    ui.Paragraph paragraph = pb.build()..layout(pc);
    canvas.drawParagraph(paragraph, offset);

    //下面的代码是生成图片的关键代码,以上绘制文字和圆圈的代码可以忽略不计
    var picture = await pictureRecorder
        .endRecording()
        .toImage(images.width, images.height); //设置生成图片的宽和高
    var pngImageBytes =
        (await picture.toByteData(format: ui.ImageByteFormat.png))!;
    // var imgBytes = Uint8List.view(pngImageBytes.buffer); //这一行和下面这一行都是生成Uint8List格式的图片(原理还不知道)
    Uint8List pngBytes = pngImageBytes.buffer.asUint8List();
    print(pngBytes); //pngBytes可以放在Image.memory()中预览

    Uint8List result = await realComporessList(pngBytes); //压缩图片
    return result;
  }

  static Future<Uint8List> canvas4(context, String _thumbnail, DateTime date,
      String liteStyle, String dsolt, String ddateHm, String mname) async {
    var pictureRecorder = new ui.PictureRecorder(); // 图片记录仪
    var canvas = new Canvas(pictureRecorder); //canvas接受一个图片记录仪
    var images = await loadImage(_thumbnail, true); // 使用方法获取Unit8List格式的图片
    print(images);
    final Paint paint = Paint();
    canvas.drawImage(images, Offset.zero, paint); //绘制原始图片

    List<String> subType = liteStyle.split('-');
    // String subType0 = subType[0]; //几号模版
    String subType1 = subType[1]; //模版下面的子样式

    String month =
        '${Utils.addZeroNumber(date.month)}/${Utils.addZeroNumber(date.day)}  ';
    String week = returnWeek(date, context);
    String hour = subType1 == '1' || subType1 == '3' ? '${ddateHm}' : '';
    String section = subType1 == '1' || subType1 == '4'
        ? _getDsoltStrShow(dsolt, mname)
        : subType1 == '2'
            ? _getDsoltStrShow(dsolt, mname, isCan: false)
            : '';

    if (section != '' && hour != '') {
      hour = hour + ' ';
    }

    String time = hour + section;

    paint.color = MyColours.color_99000000;
    paint.style = PaintingStyle.fill;
    // if (Platform.isIOS) {
    //   paint.style = PaintingStyle.fill;
    // }
    // // 绘制图像
    double scaleX = images.width / 210;
    double scaleY = images.height / 168;
    canvas.drawRect(
        Rect.fromLTWH(0, 112 * scaleY, images.width.toDouble(), 56 * scaleY),
        paint);

    // if (Platform.isIOS) {
    //   final paint1 = Paint()
    //     ..color = MyColours.color_99000000
    //     ..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
    //     ..style = PaintingStyle.fill;
    //   // 绘制一个矩形作为蒙版
    //   canvas.drawRect(Rect.fromLTWH(0, 300, 500, 100), paint1);
    // }
    // 绘制文字
    ui.ParagraphBuilder pb2 = ui.ParagraphBuilder(ui.ParagraphStyle(
        textAlign: TextAlign.center,
        fontWeight: FontWeight.bold,
        fontStyle: FontStyle.normal,
        maxLines: 1,
        fontSize: 38));
    pb2.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 38));
    pb2.addText(
        '${Provider.of<UserModel>(context, listen: false).user!.sellername}');

    // 设置文本的宽度约束
    ParagraphConstraints pc2 =
        ui.ParagraphConstraints(width: images.width.toDouble());
    ui.Paragraph paragraph2 = pb2.build()..layout(pc2);
    canvas.drawParagraph(paragraph2, Offset(0, 118 * scaleY));

    // 绘制文字
    ui.ParagraphBuilder pb3 = ui.ParagraphBuilder(ui.ParagraphStyle(
        textAlign: TextAlign.center,
        height: 1,
        fontWeight: FontWeight.bold,
        fontStyle: FontStyle.normal,
        fontSize: 38));
    pb3.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 38));
    pb3.addText(month + week);

    // 设置文本的宽度约束
    ParagraphConstraints pc3 = ui.ParagraphConstraints(width: 240);
    ui.Paragraph paragraph3 = pb3.build()..layout(pc3);
    canvas.drawParagraph(paragraph3,
        Offset(subType1 == '1' ? 17 * scaleX : 35 * scaleX, 146 * scaleY));

    // // 绘制文字
    // ui.ParagraphBuilder pb4 = ui.ParagraphBuilder(ui.ParagraphStyle(
    //     textAlign: TextAlign.center,
    //     height: 1,
    //     fontWeight: FontWeight.bold,
    //     fontStyle: FontStyle.normal,
    //     fontSize: 20));
    // pb4.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 20));
    // pb4.addText(week);

    // // 设置文本的宽度约束
    // ParagraphConstraints pc4 = ui.ParagraphConstraints(width: 50);
    // ui.Paragraph paragraph4 = pb4.build()..layout(pc4);
    // canvas.drawParagraph(paragraph4, Offset(420, 320));

    Rect rect = Rect.fromLTWH(subType1 == '1' ? 107 * scaleX : 127 * scaleX,
        142 * scaleY, subType1 == '1' ? 80 * scaleX : 40 * scaleX, 20 * scaleY);
    paint.color = MyColours.color_66FFEFC5;
    RRect rRect = RRect.fromRectAndRadius(rect, Radius.circular(6));
    canvas.drawRRect(rRect, paint);

    paint.color = MyColours.color_99000000;

    // 绘制文字
    ui.ParagraphBuilder pb = ui.ParagraphBuilder(ui.ParagraphStyle(
        textAlign: TextAlign.center,
        fontWeight: FontWeight.bold,
        height: 1,
        fontStyle: FontStyle.normal,
        fontSize: 38));
    pb.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 38));
    pb.addText(time);

    // 设置文本的宽度约束

    Offset offset = subType1 == '1'
        ? Offset(
            103 * scaleX,
            146 * scaleY,
          )
        : Offset(
            126 * scaleX,
            146 * scaleY,
          );
    ParagraphConstraints pc = ui.ParagraphConstraints(
        width: subType1 == '1' ? 87 * scaleX : 41 * scaleX);
    ui.Paragraph paragraph = pb.build()..layout(pc);
    canvas.drawParagraph(paragraph, offset);

    //下面的代码是生成图片的关键代码,以上绘制文字和圆圈的代码可以忽略不计
    var picture = await pictureRecorder
        .endRecording()
        .toImage(images.width, images.height); //设置生成图片的宽和高
    var pngImageBytes =
        (await picture.toByteData(format: ui.ImageByteFormat.png))!;
    // var imgBytes = Uint8List.view(pngImageBytes.buffer); //这一行和下面这一行都是生成Uint8List格式的图片(原理还不知道)
    Uint8List pngBytes = pngImageBytes.buffer.asUint8List();
    print(pngBytes); //pngBytes可以放在Image.memory()中预览

    Uint8List result = await realComporessList(pngBytes); //压缩图片
    return result;
  }

  static Future<Uint8List> canvasold(
      context, String _thumbnail, String month, String week) async {
    var pictureRecorder = new ui.PictureRecorder(); // 图片记录仪
    var canvas = new Canvas(pictureRecorder); //canvas接受一个图片记录仪
    var images = await loadImage(_thumbnail, true); // 使用方法获取Unit8List格式的图片
    print(images);

    final Paint paint = Paint();
    canvas.drawImage(images, Offset.zero, paint); //绘制原始图片 Paint paint = Paint()
    paint.color = MyColours.color_99000000;
    paint.style = PaintingStyle.fill;
    // if (Platform.isIOS) {
    //   paint = Paint()..style = PaintingStyle.fill;
    // }

    // paint.color = MyColours.color_99000000;
    // paint.style = PaintingStyle.fill;
    // if (Platform.isIOS) {
    //   paint.style = PaintingStyle.fill;
    // }
    // // 绘制图像
    double scaleX = images.width / 210;
    double scaleY = images.height / 168;
    canvas.drawRect(
        Rect.fromLTWH(0, 0, images.width.toDouble(), images.height.toDouble()),
        paint);

    // // 定义源矩形,通常是图像的全部
    // final Rect source = Rect.fromLTWH(
    //     0.0, 0.0, images.width.toDouble(), images.height.toDouble());
    // // 定义目标矩形,即画布的大小
    // final Rect destination = Rect.fromLTWH(0.0, 0.0, 500, 400);
    // // 绘制图像
    // canvas.drawImageRect(images, source, destination, paint);
    // if (Platform.isIOS) {
    //   final paint1 = Paint()
    //     ..color = Colors.black.withOpacity(0.6)
    //     ..maskFilter = MaskFilter.blur(BlurStyle.normal, 5.0)
    //     ..style = PaintingStyle.fill;
    //   // 绘制一个矩形作为蒙版
    //   // canvas.drawRect(Rect.fromLTRB(0, 0, 500, 400), paint1);
    // }
    // 绘制文字
    ui.ParagraphBuilder pb2 = ui.ParagraphBuilder(ui.ParagraphStyle(
        textAlign: TextAlign.center,
        fontWeight: FontWeight.normal,
        fontStyle: FontStyle.normal,
        height: 1,
        fontSize: 28));
    pb2.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 28));
    pb2.addText(
        '${Provider.of<UserModel>(context, listen: false).user!.sellername}');

    // 设置文本的宽度约束
    ParagraphConstraints pc2 =
        ui.ParagraphConstraints(width: images.width.toDouble());
    ui.Paragraph paragraph2 = pb2.build()..layout(pc2);
    canvas.drawParagraph(paragraph2, Offset(0, 15 * scaleY));

    // 绘制文字
    ui.ParagraphBuilder pb = ui.ParagraphBuilder(ui.ParagraphStyle(
        textAlign: TextAlign.center,
        fontWeight: FontWeight.bold,
        height: 1,
        fontStyle: FontStyle.normal,
        fontSize: 72));
    pb.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 72));
    pb.addText(month);

    // 设置文本的宽度约束
    ParagraphConstraints pc =
        ui.ParagraphConstraints(width: images.width.toDouble());
    ui.Paragraph paragraph = pb.build()..layout(pc);
    canvas.drawParagraph(paragraph, Offset(0, 70 * scaleY));

    // 绘制文字
    ui.ParagraphBuilder pb3 = ui.ParagraphBuilder(ui.ParagraphStyle(
        textAlign: TextAlign.center,
        height: 1,
        fontWeight: FontWeight.bold,
        fontStyle: FontStyle.normal,
        fontSize: 36));
    pb3.pushStyle(ui.TextStyle(color: MyColours.color_FFEFC5, fontSize: 36));
    pb3.addText(week);

    // 设置文本的宽度约束
    ParagraphConstraints pc3 =
        ui.ParagraphConstraints(width: images.width.toDouble());
    ui.Paragraph paragraph3 = pb3.build()..layout(pc3);
    canvas.drawParagraph(paragraph3, Offset(0, 109 * scaleY));

    //下面的代码是生成图片的关键代码,以上绘制文字和圆圈的代码可以忽略不计
    // var picture = await pictureRecorder
    //     .endRecording()
    //     .toImage(w(210).toInt(), w(168).toInt()); //设置生成图片的宽和高
    // var pngImageBytes =
    //     (await picture.toByteData(format: ui.ImageByteFormat.png))!;
    // // var imgBytes = Uint8List.view(pngImageBytes.buffer); //这一行和下面这一行都是生成Uint8List格式的图片(原理还不知道)
    // Uint8List pngBytes = pngImageBytes.buffer.asUint8List();
    // print(pngBytes); //pngBytes可以放在Image.memory()中预览

    // Uint8List result = await realComporessList(pngBytes); //压缩图片
    // return result;
    //下面的代码是生成图片的关键代码,以上绘制文字和圆圈的代码可以忽略不计
    var picture = await pictureRecorder
        .endRecording()
        .toImage(images.width, images.height); //设置生成图片的宽和高
    var pngImageBytes =
        (await picture.toByteData(format: ui.ImageByteFormat.png))!;
    // var imgBytes = Uint8List.view(pngImageBytes.buffer); //这一行和下面这一行都是生成Uint8List格式的图片(原理还不知道)
    Uint8List pngBytes = pngImageBytes.buffer.asUint8List();
    print(pngBytes); //pngBytes可以放在Image.memory()中预览

    Uint8List result = await realComporessList(pngBytes); //压缩图片
    return result;
  }

  static goWeChatShareText(String source) async {
    // WeChatShareTextModel(
    // this.source, {
    // this.scene = WeChatScene.SESSION,
    // this.mediaTagName,
    // this.messageAction,
    // this.messageExt,
    // this.msgSignature,
    // String? description,
    // String? title,
    // })

    if (source == '') {
      Utils.showToast('没有内容');
      return;
    }
    var model = new WeChatShareTextModel(
      source,
      // userName: _userName,
      // title: _title,
      // path: _path,
      // description: _description,
      // miniProgramType: Constant.wxMiniProgramType, //
      // miniProgramType: WXMiniProgramType.RELEASE, //正式版
      // miniProgramType:  //开发版
      // thumbnail: WeChatImage.binary(source)
      // thumbnail: WeChatImage.network(_thumbnail)
    );
    Fluwx fluwx = Fluwx();
    bool isSuccess = await fluwx.share(model);
  }

  //分享邀请函
  static goShareInvicationToWeChatSim(
    BuildContext context,
    String rid,
    String? uid,
    // String ddateHm,
    // DateTime dateTime,
    // String ddateSolt,
    String? liteStyle, {
    bool isWechat = true,
    String? depositId,
  }) async {
    String _webPageUrl = "http://colorcun.com/";
    // String _thumbnail =
    //     "https://xt04.colorcun.com/h5/index.html#/?id=163854&hasInvitation=1";
    // String _thumbnail =
    //     "https://qn.colorcun.com/reserve/images/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_201911151148572.jpg";
    String? sellerImage =
        Provider.of<UserModel>(context, listen: false).user!.sellerimage;
    String _thumbnail = sellerImage == null || sellerImage == ''
        ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
        : sellerImage;
    late Uint8List _thumbnailUint8List;
    print(size(_thumbnail.length));
    // if (liteStyle != '0') {
    //   _thumbnailUint8List = await canvasold(
    //       context,
    //       sellerImage == null || sellerImage == ''
    //           ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
    //           : sellerImage,
    //       month,
    //       week);
    // }
    String _title =
        "您预订的${Provider.of<UserModel>(context, listen: false).user!.sellername},已经安排,点击查看详情";
    // String _title =
    //     "${Provider.of<UserModel>(context, listen: false).user.sellername}加长版加长版加长-全体员工恭候您的光临!预订详情,请点击查看";
    // if (Provider.of<UserModel>(context, listen: false).user.sellerid == '677') {
    //   //京厨九跳转新的邀请函地址
    //   _path =
    //       "pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
    // }
    String _description = "进入查看包间详情,转发同行好友,还可一键导航到饭店";
    // Uint8List source = await testComporessList(context, _thumbnail);

    bool isSuccess = false;
    if (isWechat) {
//跳转小程序
      String _userName = "gh_487873d353b3";
      // String _path =
      //     "pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
      String _path =
          "pages/customer/detail_owner_invitation_new?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
      if (depositId != null) {
        _path =
            "pages/customer/detail_owner_invitation_new?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid&paymentId=$depositId";
      }
      Fluwx fluwx = Fluwx();
      Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
      Uint8List? result = pngByte;
      // if (liteStyle == '0') {

      if (pngByte != null && await isImageLargerThan120KB(pngByte)) {
        Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
        result = resultnew == null
            ? null
            : await compressImage(resultnew, mb: 120 / 1024);
      }
      // }

      var model = new WeChatShareMiniProgramModel(
          webPageUrl: _webPageUrl,
          userName: _userName,
          title: _title,
          path: _path,
          description: _description,
          miniProgramType: Constant.wxMiniProgramType, //
          // miniProgramType: WXMiniProgramType.RELEASE, //正式版
          // miniProgramType:  //开发版
          // thumbnail: WeChatImage.binary(source)
          // thumbnail: WeChatImage.network(_thumbnail)
          thumbData: Platform.isIOS ? null : result,
          hdImageData: result);

      isSuccess = await fluwx.share(model);
    } else {
      // Loading.showLoading(context);

      // // String _path =
      // //     "pages/customer/index.html?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
      // String _path =
      //     "pages/customer/detail_owner_invitation_new.html?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
      //    if(depositId != null){
      //        _path =
      //     "pages/customer/detail_owner_invitation_new.html?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid&paymentId=$depositId";
      //     }
      // FlutterWxwork flutterWxwork = FlutterWxwork();
      // bool isAppInstalled = await flutterWxwork.isAppInstalled();
      // print(isAppInstalled);
      // if (isAppInstalled) {
      //   bool registerResult = await flutterWxwork.registerApp(
      //       'wwauthbdca186ec4257973000003', 'wwbdca186ec4257973', '1000003');
      //   print(registerResult);

      //   // isSuccess = await flutterWxwork.shareText(text: "dddddddd");
      //   dynamic isSuccess = await flutterWxwork.shareMiniProgram(
      //     userName: 'gh_487873d353b3@app',
      //     path: _path,
      //     hdImageData: _thumbnail,
      //     title: _title,
      //     description: _description,
      //   );
      //   Loading.hideLoading(context);

      //   // var isSuccess = await flutterWxwork.shareImage();
      //   print(isSuccess);
      // } else {
      //   Loading.hideLoading(context);
      //   Utils.showToast('未安装企业微信');
      // }
    }

    return isSuccess;
  }

  static _getDsoltStrShow(String ddateSolt, String mname, {bool isCan = true}) {
    String dsoltStr = '';
    if (!isCan) {
      if (mname == '早餐' || mname == '午餐' || mname == '晚餐') {
        dsoltStr = ddateSolt == '1'
            ? '早上'
            : ddateSolt == '2'
                ? '中午'
                : '晚上';
      } else {
        dsoltStr = mname;
      }
    } else {
      if (mname == '早餐' || mname == '午餐' || mname == '晚餐') {
        dsoltStr = ddateSolt == '1'
            ? '早餐'
            : ddateSolt == '2'
                ? '午餐'
                : '晚餐';
      } else {
        dsoltStr = mname;
      }
    }
    return dsoltStr;
  }

  static _getDsoltStrShowOld(
    String? ddateHm,
    String? liteStyle,
    String ddateSolt,
    String mname,
  ) {
    String dsoltStr = '${ddateHm == null || ddateHm == '' ? '' : ddateHm}';
    if (liteStyle == '1') {
      if (mname == '早餐' || mname == '午餐' || mname == '晚餐') {
        dsoltStr = ddateSolt == '1'
            ? '早上'
            : ddateSolt == '2'
                ? '中午'
                : '晚上';
      } else {
        dsoltStr = mname;
      }
    } else if (liteStyle == '3') {
      if (mname == '早餐' || mname == '午餐' || mname == '晚餐') {
        dsoltStr = ddateSolt == '1'
            ? '早餐'
            : ddateSolt == '2'
                ? '午餐'
                : '晚餐';
      } else {
        dsoltStr = mname;
      }
    }
    return dsoltStr;
  }

  //分享邀请函
  static goShareInvicationToWeChat(
      BuildContext context,
      String rid,
      String? uid,
      String ddateHm,
      DateTime dateTime,
      String ddateSolt,
      String mname,
      String? liteStyle,
      String? liteStyleTitle,
      {bool isWechat = true,
      String? depositId}) async {
    String _webPageUrl = "http://colorcun.com/";
    // String _thumbnail =
    //     "https://xt04.colorcun.com/h5/index.html#/?id=163854&hasInvitation=1";
    // String _thumbnail =
    //     "https://qn.colorcun.com/reserve/images/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_201911151148572.jpg";
    String? sellerImage =
        Provider.of<UserModel>(context, listen: false).user!.sellerimage;
    String _thumbnail = sellerImage == null || sellerImage == ''
        ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
        : sellerImage;
    Uint8List? _thumbnailUint8List =
        await WxSdk.fetchImageAsUint8List(_thumbnail);
    print(size(_thumbnail.length));

    // dsoltStr = _getDsoltStrShow(liteStyle!, ddateSolt);
    if (liteStyle != '0') {
      //画图
      // 4种情况的图分别画出来
      if (liteStyle == '1' || liteStyle == '2' || liteStyle == '3') {
        String month =
            '${Utils.addZeroNumber(dateTime.month)}月${Utils.addZeroNumber(dateTime.day)}日';
        String weekAndDsolt = returnWeek(dateTime, context) +
            _getDsoltStrShowOld(ddateHm, liteStyle, ddateSolt, mname);
        _thumbnailUint8List = await canvasold(
            context,
            sellerImage == null || sellerImage == ''
                ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
                : sellerImage,
            month,
            weekAndDsolt);
      } else {
        List<String> subType = liteStyle!.split('-');
        String subType0 = subType[0]; //几号模版
        if (subType0 == '1') {
          _thumbnailUint8List = await canvas(
              context,
              sellerImage == null || sellerImage == ''
                  ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
                  : sellerImage,
              dateTime,
              liteStyle,
              ddateSolt,
              ddateHm,
              mname);
        } else if (subType0 == '2') {
          _thumbnailUint8List = await canvas2(
              context,
              sellerImage == null || sellerImage == ''
                  ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
                  : sellerImage,
              dateTime,
              liteStyle,
              ddateSolt,
              ddateHm,
              mname);
        } else if (subType0 == '3') {
          _thumbnailUint8List = await canvas3(
              context,
              sellerImage == null || sellerImage == ''
                  ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
                  : sellerImage,
              dateTime,
              liteStyle,
              ddateSolt,
              ddateHm,
              mname);
        } else {
          _thumbnailUint8List = await canvas4(
              context,
              sellerImage == null || sellerImage == ''
                  ? 'http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png'
                  : sellerImage,
              dateTime,
              liteStyle,
              ddateSolt,
              ddateHm,
              mname);
        }
      }
    }
    String _title = liteStyleTitle ??
        "您预订的${Provider.of<UserModel>(context, listen: false).user!.sellername},已经安排,点击查看详情";
    // String _title =
    //     "${Provider.of<UserModel>(context, listen: false).user.sellername}加长版加长版加长-全体员工恭候您的光临!预订详情,请点击查看";
    // if (Provider.of<UserModel>(context, listen: false).user.sellerid == '677') {
    //   //京厨九跳转新的邀请函地址
    //   _path =
    //       "pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
    // }
    String _description = "进入查看包间详情,转发同行好友,还可一键导航到饭店";
    // Uint8List source = await testComporessList(context, _thumbnail);

    bool isSuccess = false;
    if (isWechat) {
//跳转小程序
      String _userName = "gh_487873d353b3";
      // String _path =
      //     "pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
      String _path =
          "pages/customer/detail_owner_invitation_new?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
      if (depositId != null) {
        _path =
            "pages/customer/detail_owner_invitation_new?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid&paymentId=$depositId";
      }
      Fluwx fluwx = Fluwx();
      // Uint8List? result;
      if (liteStyle == '0') {
        Uint8List? pngByte = await WxSdk.fetchImageAsUint8List(_thumbnail);
        _thumbnailUint8List = pngByte;
        if (pngByte != null && await isImageLargerThan120KB(pngByte)) {
          Uint8List? resultnew = await realComporessList(pngByte); //压缩图片
          _thumbnailUint8List = resultnew == null
              ? null
              : await compressImage(resultnew, mb: 120 / 1024);
        }
      } else {
        if (_thumbnailUint8List != null &&
            await isImageLargerThan120KB(_thumbnailUint8List)) {
          Uint8List? resultnew =
              await realComporessList(_thumbnailUint8List); //压缩图片
          _thumbnailUint8List = resultnew == null
              ? null
              : await compressImage(resultnew, mb: 120 / 1024);
        }
      }
      // print(_thumbnailUint8List.length/1024);
      var model = new WeChatShareMiniProgramModel(
          webPageUrl: _webPageUrl,
          userName: _userName,
          title: _title,
          path: _path,
          description: _description,
          miniProgramType: Constant.wxMiniProgramType, //
          // miniProgramType: WXMiniProgramType.RELEASE, //正式版
          // miniProgramType:  //开发版
          // thumbnail: WeChatImage.binary(source)
          // thumbnail: WeChatImage.network(_thumbnail)

          thumbData: Platform.isIOS ? null : _thumbnailUint8List,
          hdImageData: _thumbnailUint8List);

      // thumbData: );

      isSuccess = await fluwx.share(model);
    } else {
      // Loading.showLoading(context);

      // // String _path =
      // //     "pages/customer/index.html?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
      // String _path =
      //     "pages/customer/detail_owner_invitation_new.html?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
      //    if(depositId != null){
      //        _path =
      //     "pages/customer/detail_owner_invitation_new.html?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid&paymentId=$depositId";
      //     }
      // FlutterWxwork flutterWxwork = FlutterWxwork();
      // bool isAppInstalled = await flutterWxwork.isAppInstalled();
      // print(isAppInstalled);
      // if (isAppInstalled) {
      //   bool registerResult = await flutterWxwork.registerApp(
      //       'wwauthbdca186ec4257973000003', 'wwbdca186ec4257973', '1000003');
      //   print(registerResult);

      //   // isSuccess = await flutterWxwork.shareText(text: "dddddddd");
      //   dynamic isSuccess = await flutterWxwork.shareMiniProgram(
      //     userName: 'gh_487873d353b3@app',
      //     path: _path,
      //     hdImageData: _thumbnail,
      //     title: _title,
      //     description: _description,
      //   );
      //   Loading.hideLoading(context);

      //   // var isSuccess = await flutterWxwork.shareImage();
      //   print(isSuccess);
      // } else {
      //   Loading.hideLoading(context);
      //   Utils.showToast('未安装企业微信');
      // }
    }

    return isSuccess;
  }

  //检查网络连接
  static Future<bool> checkConnectiviy() async {
    var connectivityResult = await (new Connectivity().checkConnectivity());
    if (connectivityResult == ConnectivityResult.mobile) {
      // I am connected to a mobile network.
      return true;
    } else if (connectivityResult == ConnectivityResult.wifi) {
      // I am connected to a wifi network.
      return true;
    }
    return false;
  }

  static String? listToString(List<String?> list) {
    if (list == null) {
      return null;
    }
    String? result;
    list.forEach((string) {
      if (result == null) {
        result = string;
      } else {
        result = '$result,$string';
      }
    });
    return result.toString();
  }

  static String listToStringEnglish1(List<dynamic> list) {
    if (list == null) {
      return '';
    }
    String? result;
    list.forEach((string) {
      if (result == null) {
        result = string;
      } else {
        result = '$result,$string';
      }
    });
    return result.toString();
  }

  static String? listToStringEnglish3(List<dynamic>? list) {
    if (list == null) {
      return null;
    }
    String? result;
    list.forEach((string) {
      if (result == null) {
        result = string;
      } else {
        result = '$result、$string';
      }
    });
    return result.toString();
  }

  static String listToStringEnglish(List<String?> list) {
    if (list == null) {
      return '';
    }
    String? result;
    list.forEach((string) {
      if (result == null) {
        result = string;
      } else {
        result = '$result,$string';
      }
    });
    return result.toString();
  }

  /// 获取日期  今天  明天  后天等等
  static int? getDdate(List dateList) {
    String? ymyStr = ""; //年月日
    //今天 明天 其他天
    for (var item in dateList) {
      if (item['select'] == true) {
        ymyStr = item['title'];
      }
    }
    String timeStr = ymyStr! + ' ' + "00:00:00";
    int? ddate = DateUtil.getDateMsByTimeStr(timeStr); //筛选日期时间戳
    return ddate;
  }

  /// 获取早餐、午餐、晚餐字段 1 ,2, 3
  static String getDdateSolt(List sunDateList) {
    String ddateSolt = '';
    for (var item in sunDateList) {
      if (item['isSelect']) {
        ddateSolt = '${item['ddateSolt']}';
      }
    }
    return ddateSolt;
  }

  ///  选中前面的按钮获取人数,输入的自己获取
  static String? getPnum(List personNumList) {
    String? pnum = '6';
    for (var item in personNumList) {
      if (item['isSelect']) {
        pnum = item['dateText'];
      }
    }
    if (pnum == '更多') {
      pnum = '6';
    }
    return pnum;
  }

  ///工具
  ///  组装成07:00
  static getTimeString(dynamic hour, String minute) {
    return '${hour}:${minute}';
  }

  /// 组装成 07:00-10:00
  static getTimelLongString(String? start, String? end) {
    return '${start}-${end}';
  }

  /// 从07:00中获取07
  static getHourFromhourAndMinute(String hourAndMinute) {
    return hourAndMinute.substring(0, 2);
  }

  ///从深夜00时中获取00
  static getHourFromTitle(String title) {
    return title.substring(2, 4);
  }

  /// 0 还是 30
  /// 从07:00中获取0 或者 30
  static getMinuteFromhourAndMinute(String hourAndMinute) {
    return hourAndMinute.substring(3, 5);
  }

  /// a < b  则 a = b
  static compareDateTime(String? a, String? b, BookTimeSetCallback callback) {
    if (a == null || b == null) {
      callback(false);
    } else {
      String tempa = '${DateUtil.getNowDateStr().substring(0, 10)} ${a}:00';
      String tempb = '${DateUtil.getNowDateStr().substring(0, 10)} ${b}:00';
      int aMs = DateUtil.getDateMsByTimeStr(tempa)!;
      int bMs = DateUtil.getDateMsByTimeStr(tempb)!;
      if (aMs < bMs) {
        callback(true);
      } else {
        callback(false);
      }
    }
  }

  ///获取时间选择器数据
  static getPickerData(String lastTime, List dateData) {
    String hour = Utils.getHourFromhourAndMinute(lastTime);
    String minute = Utils.getMinuteFromhourAndMinute(lastTime);
    List tempList = [];
    // if (minute == '45') {
    //   hour = '${int.parse(hour) + 1}';
    // }

    tempList.addAll(dateData);
    tempList.removeRange(0, int.parse(hour));

    // if (minute != '45') {
    Map<String, List<int>> map = tempList[0];
    Map mapNew = {};
    //  map.map((key, value) {

    //    mapNew[key]
    //  });

    List<int> list = [];
    map.forEach((key, value) {
      value.forEach((element) {
        if (int.parse(minute) <= element) {
          list.add(element);
        }
      });
      mapNew[key] = list;
    });
    tempList.removeAt(0);
    tempList.insert(0, mapNew);
    // }

    // tempList.replaceRange(0, 0, mapNew);
    if (tempList.length == 0) {
      tempList = [
        {
          '晚上23时': [45]
        }
      ];
    }
    return tempList;
  }
}