-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlanding.dart
156 lines (142 loc) · 4.26 KB
/
landing.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
import 'package:animate_do/animate_do.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/audio/sounds.dart';
import 'package:flutter_demo/main.dart';
import 'package:flutter_demo/providers/ads.dart';
import 'package:flutter_demo/providers/auth.dart';
import 'package:flutter_demo/widgets/admob.dart';
import 'package:flutter_demo/widgets/firebase.dart';
import 'package:flutter_translate/flutter_translate.dart';
import 'package:provider/provider.dart';
import 'package:unicons/unicons.dart';
import 'package:audioplayers/audioplayers.dart';
class LandingPage extends StatefulWidget {
const LandingPage({super.key});
@override
State<LandingPage> createState() => _LandingPageState();
}
class _LandingPageState extends State<LandingPage> {
late AnimationController appTitleController;
late AudioPlayer backgroundPlayer = AudioPlayer();
late bool _music;
@override
void initState() {
super.initState();
initMusic();
Provider.of<Ads>(context, listen: false).initAds();
}
void initMusic() async {
_music = prefs.getBool('music')!;
if (!_music) return;
sounds.playBackground();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: Provider.of<Auth>(context).auth.currentUser != null
? photoURL()
: null,
title: Provider.of<Auth>(context).auth.currentUser != null
? Text(
Provider.of<Auth>(context).auth.currentUser?.email ?? '',
style: const TextStyle(fontSize: 15),
)
: null,
actions: <Widget>[
IconButton(
icon: const Icon(UniconsLine.bars),
onPressed: () {
Navigator.of(context).pushNamed(
'/options',
);
},
)
],
),
body:
// appTitle(),
DefaultTabController(
length: 3,
child: Scaffold(
bottomNavigationBar: menu(),
body: TabBarView(
children: [
appTitle(),
// ignore: prefer_const_constructors
Firebase(),
// ignore: prefer_const_constructors
Admob(),
],
),
),
),
);
}
Widget photoURL() {
// as an example, we are getting the email from Google's API
// but the photoURL, it's the one we have saved in Firestore (1st it's also from Google)
return StreamBuilder<DocumentSnapshot>(
stream: FirebaseFirestore.instance
.collection('users')
.doc(Provider.of<Auth>(context).auth.currentUser?.uid)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
}
if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
}
if (snapshot.hasData && snapshot.data!.exists) {
Map<String, dynamic> data =
snapshot.data!.data() as Map<String, dynamic>;
return Padding(
padding: const EdgeInsets.all(8.0),
child: CircleAvatar(
backgroundImage: NetworkImage(data['photoURL']),
),
);
} else {
return const Text('User does not exist');
}
},
);
}
Widget appTitle() {
return JelloIn(
controller: (controller) => appTitleController = controller,
child: Center(
child: Text(
translate('app_title'),
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 90),
),
),
);
}
Widget menu() {
return Container(
color: Theme.of(context).primaryColor,
child: const TabBar(
labelColor: Colors.white,
unselectedLabelColor: Colors.white,
indicatorSize: TabBarIndicatorSize.tab,
indicatorPadding: EdgeInsets.all(5.0),
indicatorColor: Colors.white,
tabs: [
Tab(
icon: Icon(UniconsLine.grin),
),
Tab(
icon: Icon(UniconsLine.user),
),
Tab(
icon: Icon(UniconsLine.coins),
),
],
),
);
}
}