main.dart 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:jpush_flutter/jpush_flutter.dart';
  4. import 'package:redux/redux.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_redux/flutter_redux.dart';
  7. import 'package:shared_preferences/shared_preferences.dart';
  8. import 'redux/AppState.dart';
  9. import 'pages/HomePage.dart';
  10. import 'net/HttpManager.dart';
  11. import 'model/UserInfo.dart';
  12. import 'net/Result.dart';
  13. import 'pages/loginFirst.dart';
  14. import 'package:flutter_localizations/flutter_localizations.dart';
  15. import './Localizations.dart';
  16. class MobileCyberGamesApp extends StatelessWidget {
  17. final Store<AppState> store;
  18. MobileCyberGamesApp(this.store);
  19. @override
  20. Widget build(BuildContext context) {
  21. return StoreProvider(
  22. store: this.store,
  23. child: new MaterialApp(
  24. title: '全民电竞',
  25. supportedLocales: [
  26. const Locale('en'), // English
  27. const Locale('zh'), // China
  28. ],
  29. localizationsDelegates: [
  30. GlobalMaterialLocalizations.delegate,
  31. GlobalWidgetsLocalizations.delegate,
  32. ChineseCupertinoLocalizations.delegate,
  33. ],
  34. theme: ThemeData(
  35. cardColor: Color(0xFF2B2B42),
  36. backgroundColor: Color(0xFF222335),
  37. primaryColor: Color(0xFFC2524D),
  38. buttonColor: Color(0xFFC2524D),
  39. // highlightColor: Color(0xFF933E3E),
  40. accentColor: Color(0xFFC2524D),
  41. textSelectionColor: Colors.white,
  42. textTheme: TextTheme(
  43. subhead: TextStyle(color: Colors.white),
  44. ),
  45. buttonTheme: ButtonThemeData(
  46. buttonColor: Color(0xFFC2524D),
  47. highlightColor: Color(0xFF9B4040),
  48. splashColor: Color(0xFF9B4040),
  49. )),
  50. home: store.state.userInfo != null ? HomePage() : LoginFirst(),
  51. ),
  52. );
  53. }
  54. }
  55. void main() async {
  56. SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(
  57. statusBarColor: Colors.transparent,
  58. ));
  59. await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  60. JPush jpush = new JPush();
  61. jpush.setup(
  62. appKey: "868cc9036e14c71e2b698f46",
  63. channel: "theChannel",
  64. production: false,
  65. debug: true,
  66. );
  67. jpush.applyPushAuthority(new NotificationSettingsIOS(sound: true, alert: true, badge: true));
  68. final prefs = await SharedPreferences.getInstance();
  69. print(prefs.getString('token'));
  70. HttpManager.token = prefs.getString('token') ?? "";
  71. Result result = await HttpManager.get("userInfo/getUserInfo");
  72. AppState state = AppState.empty();
  73. if (result.success && result.data != null) {
  74. UserInfo userInfo = UserInfo.fromJson(result.data);
  75. state.userInfo = userInfo;
  76. }
  77. Store<AppState> store = Store<AppState>(appReducer, initialState: state);
  78. runApp(new MobileCyberGamesApp(store));
  79. }