main.dart 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:flutter_localizations/flutter_localizations.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. import 'package:flutter_wallet/generated/l10n.dart';
  6. import 'package:flutter_wallet/tools/YSColors.dart';
  7. import 'package:flutter_wallet/tools/YSSqflite.dart';
  8. import 'package:flutter_wallet/tools/YSTools.dart';
  9. import 'package:flutter_wallet/wallet/YSWalletManager.dart';
  10. import 'package:provider/provider.dart';
  11. import 'login/YSLogo.dart';
  12. import 'login/view/YSHelpView.dart';
  13. void main() async{
  14. WidgetsFlutterBinding.ensureInitialized();
  15. SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(statusBarColor: Colors.transparent));
  16. runApp(MultiProvider(
  17. providers: [
  18. ChangeNotifierProvider(create: (context) => CurrentLocale()),
  19. ChangeNotifierProvider(create: (context) => ThemeManager()),
  20. ChangeNotifierProvider(create: (context) => YSWalletNotifier()),
  21. ChangeNotifierProvider(create: (context) => YSBalanceNotifier()),
  22. ChangeNotifierProvider(create: (context) => YSTokenNotifier()),
  23. ChangeNotifierProvider(create: (context) => YSBalanceTotalNotifier()),
  24. ChangeNotifierProvider(create: (context) => YSPriceTypeNotifier()),
  25. ChangeNotifierProvider(create: (context) => YSUnitNotifier()),
  26. ],
  27. child: const MyApp(),
  28. ));
  29. }
  30. class MyApp extends StatefulWidget {
  31. const MyApp({Key? key}) : super(key: key);
  32. @override
  33. MyAppState createState() => MyAppState();
  34. }
  35. class MyAppState extends State<MyApp> {
  36. @override
  37. void initState() {
  38. _getValue();
  39. super.initState();
  40. }
  41. _getValue() async{
  42. YSUserRecord().them = await YSSharedPreferences.getStringValue('them');
  43. if(YSUserRecord().them.isEmpty){
  44. YSSharedPreferences.setStringValue('them', 'dart');
  45. YSUserRecord().them = 'light';
  46. }
  47. YSUserRecord().language = await YSSharedPreferences.getStringValue('language');
  48. if(YSUserRecord().language.isEmpty){
  49. YSSharedPreferences.setStringValue('language', 'zh');
  50. YSUserRecord().language = 'zh';
  51. }
  52. YSUserRecord().price = await YSSharedPreferences.getStringValue('price');
  53. if(YSUserRecord().price.isEmpty){
  54. YSSharedPreferences.setStringValue('price', '1');
  55. YSUserRecord().price = '1';
  56. }
  57. YSUserRecord().unit = await YSSharedPreferences.getStringValue('unit');
  58. if(YSUserRecord().unit.isEmpty){
  59. YSSharedPreferences.setStringValue('unit', 'dollar');
  60. YSUserRecord().unit = 'dollar';
  61. }
  62. YSUserRecord().lock = await YSSharedPreferences.getStringValue('lock');
  63. if(YSUserRecord().lock.isEmpty){
  64. YSSharedPreferences.setStringValue('lock', '0');
  65. YSUserRecord().lock = '0';
  66. }
  67. YSUserRecord().install = await YSSharedPreferences.getStringValue('install');
  68. YSUserRecord().priceType = await YSSharedPreferences.getStringValue('priceType');
  69. if(YSUserRecord().priceType.isEmpty){
  70. YSSharedPreferences.setStringValue('priceType', '1');
  71. YSUserRecord().priceType = '1';
  72. }
  73. if(!mounted)return;
  74. setThemFunc(context, YSUserRecord().them=='dart'?darkTheme:lightTheme);
  75. YSLanguage().changeLanguage(context, YSUserRecord().language);
  76. }
  77. @override
  78. Widget build(BuildContext context) {
  79. return ScreenUtilInit(
  80. designSize: const Size(375, 812),
  81. minTextAdapt: true,
  82. splitScreenMode: true,
  83. builder: (BuildContext context, Widget? child) {
  84. return Container(
  85. color: Colors.white,
  86. child: Consumer2(
  87. builder: (context, CurrentLocale cure, ThemeManager them,child) {
  88. // if('${them.value}'=='ThemeData#541ad'){
  89. // SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(statusBarColor: Colors.transparent));
  90. // }else if('${them.value}'=='ThemeData#54398'){
  91. // SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(statusBarColor: Colors.transparent));
  92. // }
  93. return MaterialApp(
  94. debugShowCheckedModeBanner: false,
  95. title: 'Bake Wallet',
  96. theme: them.value,
  97. localizationsDelegates: const [
  98. S.delegate,
  99. GlobalMaterialLocalizations.delegate,
  100. GlobalWidgetsLocalizations.delegate,
  101. GlobalCupertinoLocalizations.delegate,
  102. ],
  103. routes: {
  104. "YSWalletManager": (context) => const YSWalletManager(),
  105. },
  106. supportedLocales: S.delegate.supportedLocales,
  107. locale: cure.value,
  108. home: const YSLogo(),
  109. );
  110. },
  111. ),
  112. );
  113. },
  114. );
  115. }
  116. }
  117. // class MyApp extends StatelessWidget {
  118. // const MyApp({Key? key}) : super(key: key);
  119. //
  120. // @override
  121. // Widget build(BuildContext context) {
  122. // return ScreenUtilInit(
  123. // designSize: const Size(375, 812),
  124. // minTextAdapt: true,
  125. // splitScreenMode: true,
  126. // builder: (BuildContext context, Widget? child) {
  127. // return Consumer2(
  128. // builder: (context, CurrentLocale cure, ThemeManager them,child) {
  129. // // if('${them.value}'=='ThemeData#541ad'){
  130. // // SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(statusBarColor: Colors.transparent));
  131. // // }else if('${them.value}'=='ThemeData#54398'){
  132. // // SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(statusBarColor: Colors.transparent));
  133. // // }
  134. // return MaterialApp(
  135. // debugShowCheckedModeBanner: false,
  136. // title: 'Bake Wallet',
  137. // theme: them.value,
  138. // localizationsDelegates: const [
  139. // S.delegate,
  140. // GlobalMaterialLocalizations.delegate,
  141. // GlobalWidgetsLocalizations.delegate,
  142. // GlobalCupertinoLocalizations.delegate,
  143. // ],
  144. // routes: {
  145. // "YSWalletManager": (context) => const YSWalletManager(),
  146. // },
  147. // supportedLocales: S.delegate.supportedLocales,
  148. // locale: cure.value,
  149. // home: const YSLogo(),
  150. // );
  151. // },
  152. // );
  153. // },
  154. // );
  155. // }
  156. // }