@@ -5,77 +5,80 @@ import 'package:go_router/go_router.dart';
55import 'movie_state.dart' ;
66import 'models/movie.dart' ;
77import 'movies_connector/movies.dart' ;
8+ import 'util/auth.dart' ;
89import 'widgets/list_movies.dart' ;
910import 'widgets/list_reviews.dart' ;
11+ import 'widgets/login_guard.dart' ;
1012
1113class Profile extends StatelessWidget {
1214 const Profile ({super .key});
1315
1416 @override
1517 Widget build (BuildContext context) {
16- return StreamBuilder (
17- stream: MovieState .subscribeToCurrentUser (),
18- builder: (context, snapshot) {
19- final res = snapshot.data;
20- if (res == null ) {
21- return const Center (
22- child: CircularProgressIndicator (),
23- );
24- }
25- final displayName = res.data.user! .name;
26- final favoriteMovies =
27- res.data.user! .favoriteMovies.map ((e) => e.movie).toList ();
28- final reviews = res.data.user! .reviews;
29- final currentUser = res.data.user;
30- return RefreshIndicator (
31- child: SingleChildScrollView (
32- physics: const AlwaysScrollableScrollPhysics (),
33- child: Container (
34- padding: const EdgeInsets .all (30 ),
35- child: Column (
36- mainAxisAlignment: MainAxisAlignment .start,
37- crossAxisAlignment: CrossAxisAlignment .start,
38- children: [
39- Column (
40- children: [
41- Text ('Welcome back $displayName !' ),
42- TextButton (
43- onPressed: () async {
44- FirebaseAuth .instance.signOut ();
45- context.go ('/login' );
46- },
47- child: const Text ('Sign out' ))
48- ],
49- ),
50- ListMovies (
51- title: "Favorite Movies" ,
52- movies: favoriteMovies
53- .map (
54- (e) => Movie (
55- id: e.id,
56- title: e.title,
57- imageUrl: e.imageUrl),
58- )
59- .toList ()),
60- ListReviews (
61- reviews: reviews
62- .map (
63- (e) => Review (
64- reviewText: e.reviewText! ,
65- rating: e.rating! ,
66- username: currentUser! .username,
67- date: e.reviewDate),
68- )
69- .toList (),
70- title: "Reviews" ),
71- ],
18+ return LoginGuard (builder: (context) {
19+ return StreamBuilder (
20+ stream: MovieState .subscribeToCurrentUser (),
21+ builder: (context, snapshot) {
22+ final res = snapshot.data;
23+ if (res == null ) {
24+ return const Center (
25+ child: CircularProgressIndicator (),
26+ );
27+ }
28+ final displayName = res.data.user! .name;
29+ final favoriteMovies =
30+ res.data.user! .favoriteMovies.map ((e) => e.movie).toList ();
31+ final reviews = res.data.user! .reviews;
32+ return RefreshIndicator (
33+ child: SingleChildScrollView (
34+ physics: const AlwaysScrollableScrollPhysics (),
35+ child: Container (
36+ padding: const EdgeInsets .all (30 ),
37+ child: Column (
38+ mainAxisAlignment: MainAxisAlignment .start,
39+ crossAxisAlignment: CrossAxisAlignment .start,
40+ children: [
41+ Column (
42+ children: [
43+ Text ('Welcome back $displayName !' ),
44+ TextButton (
45+ onPressed: () async {
46+ FirebaseAuth .instance.signOut ();
47+ context.go ('/login' );
48+ },
49+ child: const Text ('Sign out' ))
50+ ],
51+ ),
52+ ListMovies (
53+ title: "Favorite Movies" ,
54+ movies: favoriteMovies
55+ .map (
56+ (e) => Movie (
57+ id: e.id,
58+ title: e.title,
59+ imageUrl: e.imageUrl),
60+ )
61+ .toList ()),
62+ ListReviews (
63+ reviews: reviews
64+ .map (
65+ (e) => Review (
66+ reviewText: e.reviewText! ,
67+ rating: e.rating! ,
68+ username: Auth .instance.currentUser! .email! ,
69+ date: e.reviewDate),
70+ )
71+ .toList (),
72+ title: "Reviews" ),
73+ ],
74+ ),
7275 ),
7376 ),
74- ),
75- onRefresh : () async {
76- MoviesConnector .instance. getCurrentUser (). execute ();
77- },
78- );
79- });
77+ onRefresh : () async {
78+ MoviesConnector .instance. getCurrentUser (). execute ();
79+ },
80+ );
81+ } );
82+ });
8083 }
8184}
0 commit comments