-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
80 lines (74 loc) · 2.8 KB
/
main.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
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:genuno_flutter/providers/user_provider.dart';
import 'package:genuno_flutter/responsive/mobile_screen_layout.dart';
import 'package:genuno_flutter/responsive/responsive_layout_screen.dart';
import 'package:genuno_flutter/responsive/web_screen_layout.dart';
import 'package:genuno_flutter/screens/login_screen.dart';
import 'package:genuno_flutter/utils/colors.dart';
import 'package:provider/provider.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// initialise app based on platform- web or mobile
if (kIsWeb) {
await Firebase.initializeApp(
options: const FirebaseOptions(
apiKey: "AIzaSyAcMSkAzh0xHcosFuJkdms1kDTx2eY3jxI",
appId: "1:359951087284:android:bf9cb14ac6c1e0a27109e1",
messagingSenderId: "585119731880",
projectId: "genuno-f6ce8",
storageBucket: 'genuno-f6ce8.appspot.com'),
);
} else {
await Firebase.initializeApp();
}
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (_) => UserProvider(),
),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'GenUno',
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: mobileBackgroundColor,
),
home: StreamBuilder(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.active) {
// Checking if the snapshot has any data or not
if (snapshot.hasData) {
// if snapshot has data which means user is logged in then we check the width of screen and accordingly display the screen layout
return const ResponsiveLayout(
mobileScreenLayout: MobileScreenLayout(),
webScreenLayout: WebScreenLayout(),
);
} else if (snapshot.hasError) {
return Center(
child: Text('${snapshot.error}'),
);
}
}
// means connection to future hasnt been made yet
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(
child: CircularProgressIndicator(),
);
}
return const LoginScreen();
},
),
),
);
}
}