main.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_alipay/flutter_alipay.dart';
  5. import 'package:fluwx/fluwx.dart';
  6. import 'package:flutter_localizations/flutter_localizations.dart';
  7. import 'package:path_provider/path_provider.dart';
  8. import 'package:ysairplane2/code/YSWelcome.dart';
  9. import 'package:ysairplane2/tools/YSTools.dart';
  10. import 'code/YSTabbar.dart';
  11. import 'tools/YSLocalizationsDelegate.dart';
  12. void main() {
  13. try{
  14. WidgetsFlutterBinding.ensureInitialized();
  15. SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(statusBarColor: Colors.transparent,statusBarIconBrightness: Brightness.dark,),);
  16. SystemChrome.setPreferredOrientations([
  17. DeviceOrientation.portraitUp,
  18. DeviceOrientation.portraitDown
  19. ]);
  20. _clearCache();
  21. PaintingBinding.instance.imageCache.clear();
  22. PaintingBinding.instance.imageCache.maximumSize=2000; //最多2000张
  23. PaintingBinding.instance.imageCache.maximumSizeBytes = 1000 << 20; //最大200M
  24. _initFluwx();
  25. FlutterAlipay.setIosUrlSchema("feijizhifubao");
  26. checkVersion().then((value){
  27. runApp(MyApp(isnFirst: value,));
  28. });
  29. }catch(e){
  30. print('===============================$e===============================');
  31. }
  32. }
  33. class MyApp extends StatelessWidget {
  34. final isnFirst;
  35. const MyApp({Key key, this.isnFirst}) : super(key: key);
  36. @override
  37. Widget build(BuildContext context) {
  38. return MaterialApp(
  39. debugShowCheckedModeBanner: false,
  40. theme: ThemeData(
  41. primaryColor: Color(0xFF0088FF),
  42. visualDensity: VisualDensity.adaptivePlatformDensity,
  43. backgroundColor: Color(0xFFF5F6F8),
  44. ),
  45. routes: {
  46. "/home": (BuildContext context) => YSTabbar(),
  47. },
  48. localeListResolutionCallback:
  49. (List<Locale> locales, Iterable<Locale> supportedLocales) {
  50. return Locale('zh');
  51. },
  52. localeResolutionCallback:
  53. (Locale locale, Iterable<Locale> supportedLocales) {
  54. return Locale('zh');
  55. },
  56. localizationsDelegates: [
  57. ZhCupertinoLocalizations.delegate,
  58. GlobalMaterialLocalizations.delegate,
  59. GlobalWidgetsLocalizations.delegate,
  60. GlobalCupertinoLocalizations.delegate,
  61. ],
  62. supportedLocales: [
  63. const Locale('zh', 'CH'),
  64. const Locale('en', 'US'),
  65. ],
  66. home: isnFirst==true?YSTabbar():YSWelcome()
  67. );
  68. }
  69. }
  70. _initFluwx() async {
  71. await registerWxApi(
  72. appId: "wx7e62294a5bf6e206",
  73. doOnAndroid: true,
  74. doOnIOS: true,
  75. universalLink: "https://api.s-fly.cn/app/");
  76. var result = await isWeChatInstalled;
  77. print("is installed $result");
  78. }
  79. void _clearCache() async {
  80. Directory tempDir = await getTemporaryDirectory();
  81. //删除缓存目录
  82. await delDir(tempDir);
  83. }
  84. Future<Null> delDir(FileSystemEntity file) async {
  85. if (file is Directory) {
  86. final List<FileSystemEntity> children = file.listSync();
  87. for (final FileSystemEntity child in children) {
  88. var isHave =await child.exists(); //返回真假
  89. if(isHave){
  90. await delDir(child);
  91. }
  92. }
  93. }
  94. await file.delete();
  95. }