-
Notifications
You must be signed in to change notification settings - Fork 465
/
circles_app.dart
183 lines (176 loc) · 6.98 KB
/
circles_app.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import "package:circles_app/data/calendar_repository.dart";
import "package:circles_app/data/group_repository.dart";
import "package:circles_app/data/file_repository.dart";
import "package:circles_app/data/user_repository.dart";
import "package:circles_app/domain/redux/attachment/attachment_middleware.dart";
import "package:circles_app/domain/redux/attachment/image_processor.dart";
import "package:circles_app/domain/redux/authentication/auth_actions.dart";
import "package:circles_app/domain/redux/authentication/auth_middleware.dart";
import "package:circles_app/domain/redux/calendar/calendar_middleware.dart";
import "package:circles_app/domain/redux/channel/channel_middleware.dart";
import "package:circles_app/data/message_repository.dart";
import "package:circles_app/domain/redux/message/message_middleware.dart";
import "package:circles_app/data/channel_repository.dart";
import "package:circles_app/circles_localization.dart";
import "package:circles_app/domain/redux/push/push_actions.dart";
import "package:circles_app/domain/redux/push/push_middleware.dart";
import "package:circles_app/domain/redux/user/user_middleware.dart";
import "package:circles_app/presentation/channel/create/create_channel.dart";
import "package:circles_app/presentation/channel/event/create_event.dart";
import "package:circles_app/presentation/channel/invite/invite_to_channel_screen.dart";
import "package:circles_app/presentation/channel/reaction/reaction_details.dart";
import "package:circles_app/domain/redux/app_middleware.dart";
import "package:circles_app/domain/redux/app_reducer.dart";
import "package:circles_app/domain/redux/app_state.dart";
import "package:circles_app/presentation/home/main_screen.dart";
import "package:circles_app/presentation/image/file_picker_screen.dart";
import "package:circles_app/presentation/image/image_pinch_screen.dart";
import "package:circles_app/presentation/image/image_screen.dart";
import "package:circles_app/presentation/login/loginscreen.dart";
import "package:circles_app/presentation/settings/settings_screen.dart";
import "package:circles_app/presentation/user/user_screen.dart";
import "package:circles_app/routes.dart";
import "package:circles_app/theme.dart";
import "package:circles_app/util/logger.dart";
import "package:cloud_firestore/cloud_firestore.dart";
import "package:firebase_auth/firebase_auth.dart";
import "package:firebase_storage/firebase_storage.dart";
import "package:flutter/material.dart";
import "package:flutter_redux/flutter_redux.dart";
import "package:redux/redux.dart";
import "package:firebase_messaging/firebase_messaging.dart";
import "domain/redux/user/user_actions.dart";
class CirclesApp extends StatefulWidget {
const CirclesApp({
Key key,
}) : super(key: key);
@override
_CirclesAppState createState() => _CirclesAppState();
}
class _CirclesAppState extends State<CirclesApp> {
Store<AppState> store;
static final _navigatorKey = GlobalKey<NavigatorState>();
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
final userRepo = UserRepository(FirebaseAuth.instance, Firestore.instance);
final channelRepository = ChannelRepository(Firestore.instance);
final groupRepository = GroupRepository(Firestore.instance);
final calendarRepository = CalendarRepository(Firestore.instance);
@override
void initState() {
super.initState();
store = Store<AppState>(
appReducer,
initialState: AppState.init(),
middleware: createStoreMiddleware(
groupRepository,
)
..addAll(createAuthenticationMiddleware(
userRepo,
_navigatorKey,
))
..addAll(createCalendarMiddleware(calendarRepository))
..addAll(createUserMiddleware(userRepo))
..addAll(createChannelsMiddleware(
channelRepository,
_navigatorKey,
))
..addAll(createMessagesMiddleware(
MessageRepository(Firestore.instance),
))
..addAll(createPushMiddleware(
userRepo,
_firebaseMessaging,
groupRepository,
channelRepository,
))
..addAll(createAttachmentMiddleware(
FileRepository(FirebaseStorage.instance),
ImageProcessor(),
userRepo,
)),
);
store.dispatch(VerifyAuthenticationState());
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
store.dispatch(OnPushNotificationReceivedAction(message));
},
onLaunch: (Map<String, dynamic> message) async {
store.dispatch(OnPushNotificationOpenAction(message));
},
onResume: (Map<String, dynamic> message) async {
store.dispatch(OnPushNotificationOpenAction(message));
},
);
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
Logger.d("Settings registered: $settings");
});
_firebaseMessaging.getToken().then((String token) {
assert(token != null);
Logger.d("Push Messaging token: $token");
store.dispatch(UpdateUserTokenAction(token));
});
}
// Used to propagate this users current locale to our backend (which then can send localized notifications).
_updateUserLocale(context) {
final localeCode = CirclesLocalizations.of(context).locale.languageCode;
StoreProvider.of<AppState>(context)
.dispatch(UpdateUserLocaleAction(localeCode));
}
@override
Widget build(BuildContext context) {
return StoreProvider(
store: store,
child: MaterialApp(
localizationsDelegates: localizationsDelegates,
supportedLocales: [
const Locale("de", "DE"),
const Locale("en", "EN"),
const Locale("pt_BR", "PT"),
],
title: "Circles App",
navigatorKey: _navigatorKey,
theme: AppTheme.theme,
routes: {
Routes.login: (context) {
return LoginScreen();
},
Routes.home: (context) {
// We need a context and a user. Both are present when loading MainScreen.
_updateUserLocale(context);
return MainScreen();
},
Routes.channelNew: (context) {
return CreateChannelScreen();
},
Routes.channelInvite: (context) {
return InviteToChannelScreen();
},
Routes.eventNew: (context) {
return CreateEventScreen();
},
Routes.image: (context) {
return ImageScreen();
},
Routes.imagePicker: (context) {
return FilePickerScreen();
},
Routes.imagePinch: (context) {
return ImagePinchScreen();
},
Routes.reaction: (context) {
return ReactionDetails();
},
Routes.user: (context) {
return UserScreen();
},
Routes.settings: (context) {
return SettingsScreen();
}
},
),
);
}
}