main.dart 3.2 KB

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