main.dart 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. // dialogBackgroundColor: Colors.orange,
  36. cardColor: Color(0xFF2B2B42),
  37. backgroundColor: Color(0xFF222335),
  38. primaryColor: Color(0xFFC2524D),
  39. buttonColor: Color(0xFFC2524D),
  40. // highlightColor: Color(0xFF933E3E),
  41. accentColor: Color(0xFFC2524D),
  42. textSelectionColor: Colors.white,
  43. textTheme: TextTheme(
  44. subhead: TextStyle(color: Colors.white),
  45. ),
  46. buttonTheme: ButtonThemeData(
  47. buttonColor: Color(0xFFC2524D),
  48. highlightColor: Color(0xFF9B4040),
  49. splashColor: Color(0xFF9B4040),
  50. shape: RoundedRectangleBorder(
  51. borderRadius: BorderRadius.all(Radius.circular(0))
  52. ),
  53. )),
  54. home: store.state.userInfo != null ? HomePage() : LoginFirst(),
  55. routes: {"/home": (BuildContext context) => HomePage()},
  56. ),
  57. );
  58. }
  59. }
  60. void main() async {
  61. SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(
  62. statusBarColor: Colors.transparent,
  63. ));
  64. await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  65. JPush jpush = new JPush();
  66. jpush.setup(
  67. appKey: "868cc9036e14c71e2b698f46",
  68. channel: "theChannel",
  69. production: true,
  70. debug: true,
  71. );
  72. jpush.applyPushAuthority(new NotificationSettingsIOS(sound: true, alert: true, badge: true));
  73. final prefs = await SharedPreferences.getInstance();
  74. print(prefs.getString('token'));
  75. HttpManager.token = prefs.getString('token') ?? "";
  76. Result result = await HttpManager.get("userInfo/getUserInfo");
  77. AppState state = AppState.empty();
  78. if (result.success && result.data != null) {
  79. UserInfo userInfo = UserInfo.fromJson(result.data);
  80. state.userInfo = userInfo;
  81. jpush.setAlias(userInfo.id.toString()).then((map) {});
  82. }
  83. Store<AppState> store = Store<AppState>(appReducer, initialState: state);
  84. runApp(new MobileCyberGamesApp(store));
  85. }