From 1b565d70f4379b09c9876756b31dcf4e221c7cb6 Mon Sep 17 00:00:00 2001 From: Felipe Date: Fri, 16 Feb 2024 11:37:12 -0500 Subject: [PATCH] stream image --- lib/app.dart | 46 ++--- lib/app_view.dart | 42 +--- .../authentication_bloc.dart | 1 - lib/blocs/my_user_bloc/my_user_bloc.dart | 41 +--- lib/components/strings.dart | 3 +- .../authentication/sign_up_screen.dart | 15 +- lib/screens/home/home_screen.dart | 188 +++++++++--------- .../lib/src/firebase_user_repository.dart | 4 - 8 files changed, 129 insertions(+), 211 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index a18bf37..b20119f 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -6,8 +6,6 @@ import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart'; import 'package:prosappco/blocs/sign_up_bloc/sign_up_bloc.dart'; import 'package:prosappco/blocs/sing_in_bloc/sign_in_bloc.dart'; import 'package:prosappco/blocs/update_user_info_bloc/update_user_info_bloc.dart'; -import 'package:prosappco/screens/home/home_screen.dart'; -import 'package:user_repository/user_repository.dart'; import 'app_view.dart'; @@ -17,28 +15,28 @@ class MainApp extends StatelessWidget { @override Widget build(BuildContext context) { return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => Injector.appInstance.get(), - ), - BlocProvider( - create: (context) => Injector.appInstance.get(), - ), - BlocProvider( - create: (context) => Injector.appInstance.get(), - ), - BlocProvider( - create: (context) => Injector.appInstance.get(), - ), - BlocProvider( - create: (context) => Injector.appInstance.get(), - ) - // RepositoryProvider( - // create: (_) => AuthenticationBloc(myUserRepository: userRepository), - // ), - ], - child: BlocBuilder(builder: (context, state) { + providers: [ + BlocProvider( + create: (context) => Injector.appInstance.get(), + ), + BlocProvider( + create: (context) => Injector.appInstance.get(), + ), + BlocProvider( + create: (context) => Injector.appInstance.get(), + ), + BlocProvider( + create: (context) => Injector.appInstance.get(), + ), + BlocProvider( + create: (context) => Injector.appInstance.get(), + ) + ], + child: BlocBuilder( + builder: (context, state) { return const MyAppView(); - })); + }, + ), + ); } } diff --git a/lib/app_view.dart b/lib/app_view.dart index 0fc5c0e..667a06e 100644 --- a/lib/app_view.dart +++ b/lib/app_view.dart @@ -1,11 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart'; -import 'package:prosappco/blocs/sing_in_bloc/sign_in_bloc.dart'; -import 'package:prosappco/blocs/update_user_info_bloc/update_user_info_bloc.dart'; import 'package:prosappco/screens/authentication/welcome_screen.dart'; import 'package:prosappco/screens/home/home_screen.dart'; -import 'package:prosappco/screens/profile/profile_screen.dart'; import 'blocs/authentication_bloc/authentication_bloc.dart'; @@ -31,33 +27,17 @@ class MyAppView extends StatelessWidget { ), home: BlocBuilder( builder: (context, state) { - if (state.status == AuthenticationStatus.authenticated) { - // MultiBlocProvider( - // providers: [ - // BlocProvider( - // create: (context) => SignInBloc( - // userRepository: - // context.read().userRepository), - // ), - // BlocProvider( - // create: (context) => UpdateUserInfoBloc( - // userRepository: - // context.read().userRepository), - // ), - // BlocProvider( - // create: (context) => MyUserBloc( - // myUserRepository: - // context.read().userRepository) - // ..add(GetMyUser( - // myUserId: - // context.read().state.user!.uid)), - // ), - // ], - // child: const HomeScreen(), - // ); - return const HomeScreen(); - } else { - return const WelcomeScreen(); + switch (state.status) { + case AuthenticationStatus.authenticated: + return const HomeScreen(); + + case AuthenticationStatus.unauthenticated: + return const WelcomeScreen(); + + case AuthenticationStatus.unknown: + return const Center( + child: CircularProgressIndicator(), // splash screen + ); } }), ); diff --git a/lib/blocs/authentication_bloc/authentication_bloc.dart b/lib/blocs/authentication_bloc/authentication_bloc.dart index fed1394..470fce1 100644 --- a/lib/blocs/authentication_bloc/authentication_bloc.dart +++ b/lib/blocs/authentication_bloc/authentication_bloc.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:equatable/equatable.dart'; -import 'package:firebase_auth/firebase_auth.dart'; import 'package:meta/meta.dart'; import 'package:user_repository/user_repository.dart'; diff --git a/lib/blocs/my_user_bloc/my_user_bloc.dart b/lib/blocs/my_user_bloc/my_user_bloc.dart index 9276a1d..1471d31 100644 --- a/lib/blocs/my_user_bloc/my_user_bloc.dart +++ b/lib/blocs/my_user_bloc/my_user_bloc.dart @@ -15,38 +15,12 @@ class MyUserBloc extends Bloc { : _userRepository = myUserRepository, super(const MyUserState.loading()) { _userRepository.streamUser().listen((event) { - log('xd ---: ${event}'); if (event == null) { - log('UserChanged: ${event}'); emit(const MyUserState.failure()); } else { - log('UserChanged: ${event}'); - emit(MyUserState.success(event!)); + emit(MyUserState.success(event)); } }); - - // on(_onUserChanged); - // _userRepository.user.first.then((user) { - // log('xd: ${user}'); - // if (user != null) { - // add(UserChanged(user: user)); - // _userSubscription = _userRepository.user.listen((user) { - // log('xd: ${user}'); - // add(UserChanged(user: user)); - // }); - // } - // }).catchError((e) { - // log('xd: ${e}'); - // add(UserChanged(user: null)); - // }); - // on(_onGetMyUser); - // _userRepository.user.listen((user) { - // if (user != null) { - // add(GetMyUser(myUserId: user.uid)); - // } - // }); - // emit(MyUserState.success(MyUser( - // name: 'John', id: '123', email: 'johndoe@gmail.com', picture: ''))); } void _onUserChanged(UserChanged event, Emitter emit) { @@ -59,17 +33,4 @@ class MyUserBloc extends Bloc { emit(MyUserState.success(event.user!)); } } - - // void _onGetMyUser(GetMyUser event, Emitter emit) async { - // log('GetMyUser: ${event.myUserId}'); - // emit(const MyUserState.loading()); - // try { - // MyUser myUser = await _userRepository.getMyUser(event.myUserId); - // log('GetMyUser: $myUser'); - // emit(MyUserState.success(myUser)); - // } catch (e) { - // log('GetMyUser: $e'); - // emit(const MyUserState.failure()); - // } - // } } diff --git a/lib/components/strings.dart b/lib/components/strings.dart index 1eaccdd..6cc3f91 100644 --- a/lib/components/strings.dart +++ b/lib/components/strings.dart @@ -1,7 +1,6 @@ RegExp emailRexExp = RegExp(r'^[\w-\.]+@([\w-]+.)+[\w-]{2,4}$'); -RegExp passwordRexExp = RegExp( - r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~`)\%\-(_+=;:,.<>/?"[{\]}\|^]).{8,}$'); +RegExp passwordRexExp = RegExp(r'^(?=.*?[A-Z])(?=.*?[0-9]).{8,}$'); RegExp specialCharRexExp = RegExp(r'^(?=.*?[!@#$&*~`)\%\-(_+=;:,.<>/?"[{\]}\|^])'); diff --git a/lib/screens/authentication/sign_up_screen.dart b/lib/screens/authentication/sign_up_screen.dart index 70a814b..eacdb39 100644 --- a/lib/screens/authentication/sign_up_screen.dart +++ b/lib/screens/authentication/sign_up_screen.dart @@ -169,29 +169,22 @@ class _SignUpScreenState extends State { ? Colors.green : Theme.of(context).colorScheme.onBackground), ), - Text( - "⚈ 1 number", - style: TextStyle( - color: containsNumber - ? Colors.green - : Theme.of(context).colorScheme.onBackground), - ), ], ), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - "⚈ 1 special character", + "⚈ 8 minimum character", style: TextStyle( - color: containsSpecialChar + color: contains8Length ? Colors.green : Theme.of(context).colorScheme.onBackground), ), Text( - "⚈ 8 minimum character", + "⚈ 1 number", style: TextStyle( - color: contains8Length + color: containsNumber ? Colors.green : Theme.of(context).colorScheme.onBackground), ), diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index 82b7f43..59805df 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -26,112 +26,104 @@ class _HomeScreenState extends State { }, child: Scaffold( backgroundColor: Theme.of(context).colorScheme.background, - drawer: - BlocBuilder(builder: (context, state) { - if (state.status == MyUserStatus.success) { - return Drawer( - backgroundColor: Theme.of(context).colorScheme.background, - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Material( - color: Theme.of(context).colorScheme.primary, - child: InkWell( - onTap: () { - Navigator.push( - context, - CupertinoPageRoute( - builder: (context) => const ProfileScreen(), - ), - ); - }, - child: Container( - padding: EdgeInsets.only( - top: 20 + MediaQuery.of(context).padding.top, - bottom: 20, - ), - child: Column( - children: [ - state.user!.picture == "" - ? Container( - width: 80, - height: 80, - decoration: BoxDecoration( - color: Colors.grey.shade300, - shape: BoxShape.circle, - ), - child: Icon( - CupertinoIcons.person, - color: Colors.grey.shade400, - size: 35, - ), - ) - : Container( - width: 80, - height: 80, - decoration: BoxDecoration( - color: Colors.grey, - shape: BoxShape.circle, - image: DecorationImage( - image: NetworkImage( - state.user!.picture!, - ), - fit: BoxFit.cover, - ), - ), - ), - const SizedBox(height: 12), - Text( - state.user!.name, - style: const TextStyle( - fontSize: 24, - color: Colors.white, - ), - ), - Text( - state.user!.email, - style: const TextStyle( - fontSize: 15, - color: Colors.white, - ), - ) - ], - ), + drawer: Drawer( + backgroundColor: Theme.of(context).colorScheme.background, + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Material( + color: Theme.of(context).colorScheme.primary, + child: InkWell( + onTap: () { + Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => const ProfileScreen(), ), + ); + }, + child: Container( + padding: EdgeInsets.only( + top: 20 + MediaQuery.of(context).padding.top, + bottom: 20, ), - ), - Container( - height: MediaQuery.of(context).size.height, - color: Theme.of(context).colorScheme.background, - child: ListView( + child: Column( children: [ - ListTile( - onTap: () { - context - .read() - .add(const SignOutRequired()); - }, - title: const Text( - 'Cerrar Sesión', + context.read().state.user!.picture == "" + ? Container( + width: 80, + height: 80, + decoration: BoxDecoration( + color: Colors.grey.shade300, + shape: BoxShape.circle, + ), + child: Icon( + CupertinoIcons.person, + color: Colors.grey.shade400, + size: 35, + ), + ) + : Container( + width: 80, + height: 80, + decoration: BoxDecoration( + color: Colors.grey, + shape: BoxShape.circle, + image: DecorationImage( + image: NetworkImage( + context + .read() + .state + .user! + .picture!, + ), + fit: BoxFit.cover, + ), + ), + ), + const SizedBox(height: 12), + Text( + context.read().state.user!.name, + style: const TextStyle( + fontSize: 24, + color: Colors.white, + ), + ), + Text( + context.read().state.user!.email, + style: const TextStyle( + fontSize: 15, + color: Colors.white, ), ) ], ), - ) - ], + ), + ), ), - ), - ); - } else { - return Drawer( - backgroundColor: Theme.of(context).colorScheme.background, - child: const Center( - child: CircularProgressIndicator(), - ), - ); - } - }), + Container( + height: MediaQuery.of(context).size.height, + color: Theme.of(context).colorScheme.background, + child: ListView( + children: [ + ListTile( + onTap: () { + context + .read() + .add(const SignOutRequired()); + }, + title: const Text( + 'Cerrar Sesión', + ), + ) + ], + ), + ) + ], + ), + ), + ), appBar: AppBar(), body: Center( child: Text( diff --git a/packages/user_repository/lib/src/firebase_user_repository.dart b/packages/user_repository/lib/src/firebase_user_repository.dart index 12cafc9..6004162 100644 --- a/packages/user_repository/lib/src/firebase_user_repository.dart +++ b/packages/user_repository/lib/src/firebase_user_repository.dart @@ -29,10 +29,6 @@ class FirebaseUserRepository implements UserRepository { _userStreamController.add(null); } }); - - this.streamUser().listen((event) { - log('xd - : ${event}'); - }); } // Stream get user => _userStreamController.stream;