-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplash.dart
109 lines (96 loc) · 3.52 KB
/
splash.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
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:quick_actions/quick_actions.dart';
import 'screens/bottom_bar/bottom_bar_logic.dart';
import 'screens/#/#_screen.dart';
import 'utils/firebase_auth.dart';
import 'utils/hive_helper.dart';
import 'utils/theme_helper.dart';
class SplashScreen extends StatefulWidget {
final Widget child;
const SplashScreen({Key? key, required this.child}) : super(key: key);
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
late FirebaseAppAuth appAuth;
@override
void initState() {
appAuth = Provider.of<FirebaseAppAuth>(context, listen: false);
_initApp();
super.initState();
}
Future<void> _initApp() async {
//make all our date in russian
await initializeDateFormatting('ru');
Intl.defaultLocale = 'ru';
const QuickActions quickActions = QuickActions();
if (appAuth.accountInfo.isLoggedIn) {
// if app running on Android or iOS, make QuickActions
if (defaultTargetPlatform == TargetPlatform.android || defaultTargetPlatform == TargetPlatform.iOS) {
quickActions.initialize((shortcutType) {
switch (shortcutType) {
case 'action_news':
context.read<BottomBarLogic>().setIndex(0);
break;
case 'action_announcements':
context.read<BottomBarLogic>().setIndex(1);
break;
case 'action_schedule':
context.read<BottomBarLogic>().setIndex(2);
break;
case 'action_map':
context.read<BottomBarLogic>().setIndex(3);
break;
}
FirebaseAnalytics.instance.logEvent(name: 'quick_action_used', parameters: {
'shortcut_type': shortcutType,
});
});
quickActions.setShortcutItems(<ShortcutItem>[
const ShortcutItem(
type: 'action_news',
localizedTitle: 'События',
icon: 'ic_news',
),
const ShortcutItem(
type: 'action_announcements',
localizedTitle: 'Объявления',
icon: 'ic_alerts',
),
const ShortcutItem(
type: 'action_schedule',
localizedTitle: 'Расписание занятий',
icon: 'ic_timetable',
),
const ShortcutItem(
type: 'action_map',
localizedTitle: 'Карта кабинетов',
icon: 'ic_maps',
),
]);
}
// open bottom bar index by setting "launch on start"
if (HiveHelper.getValue('launchOnStart') != null) {
int givenIndex = HiveHelper.getValue('launchOnStart');
context.read<BottomBarLogic>().setIndex(givenIndex);
}
FlutterLocalNotificationsPlugin()
.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()
?.requestPermission();
} else {
quickActions.clearShortcutItems();
}
FirebaseAnalytics.instance.logAppOpen();
}
@override
Widget build(BuildContext context) {
ThemeHelper.colorSystemChrome();
return appAuth.accountInfo.isLoggedIn ? widget.child : const LoginScreen();
}
}