diff --git a/lib/app.dart b/lib/app.dart index 86aa8f7..a18bf37 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -1,19 +1,44 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:injector/injector.dart'; import 'package:prosappco/blocs/authentication_bloc/authentication_bloc.dart'; +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'; class MainApp extends StatelessWidget { - final UserRepository userRepository; - const MainApp(this.userRepository, {super.key}); + const MainApp({super.key}); @override Widget build(BuildContext context) { - return MultiRepositoryProvider(providers: [ - RepositoryProvider( - create: (_) => AuthenticationBloc(myUserRepository: userRepository)) - ], child: const MyAppView()); + 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) { + return const MyAppView(); + })); } } diff --git a/lib/app_view.dart b/lib/app_view.dart index ee1eb64..0fc5c0e 100644 --- a/lib/app_view.dart +++ b/lib/app_view.dart @@ -32,29 +32,30 @@ class MyAppView extends StatelessWidget { home: BlocBuilder( builder: (context, state) { if (state.status == AuthenticationStatus.authenticated) { - return 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(), - ); + // 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(); } diff --git a/lib/blocs/authentication_bloc/authentication_bloc.dart b/lib/blocs/authentication_bloc/authentication_bloc.dart index 02c7196..fed1394 100644 --- a/lib/blocs/authentication_bloc/authentication_bloc.dart +++ b/lib/blocs/authentication_bloc/authentication_bloc.dart @@ -12,12 +12,12 @@ part 'authentication_state.dart'; class AuthenticationBloc extends Bloc { final UserRepository userRepository; - late final StreamSubscription _userSubscription; + late final StreamSubscription _userSubscription; AuthenticationBloc({required UserRepository myUserRepository}) : userRepository = myUserRepository, super(const AuthenticationState.unknown()) { - _userSubscription = userRepository.user.listen((authUser) { + _userSubscription = userRepository.streamUser().listen((authUser) { add(AuthenticationUserChanged(authUser)); }); on((event, emit) { diff --git a/lib/blocs/authentication_bloc/authentication_event.dart b/lib/blocs/authentication_bloc/authentication_event.dart index d0a02e2..9809c59 100644 --- a/lib/blocs/authentication_bloc/authentication_event.dart +++ b/lib/blocs/authentication_bloc/authentication_event.dart @@ -11,7 +11,7 @@ abstract class AuthenticationEvent extends Equatable { class AuthenticationUserChanged extends AuthenticationEvent { const AuthenticationUserChanged(this.user); - final User? user; + final MyUser? user; } class AuthenticationLogoutRequested extends AuthenticationEvent {} diff --git a/lib/blocs/authentication_bloc/authentication_state.dart b/lib/blocs/authentication_bloc/authentication_state.dart index 4dc0957..3bfe160 100644 --- a/lib/blocs/authentication_bloc/authentication_state.dart +++ b/lib/blocs/authentication_bloc/authentication_state.dart @@ -4,7 +4,7 @@ enum AuthenticationStatus { authenticated, unauthenticated, unknown } class AuthenticationState extends Equatable { final AuthenticationStatus status; - final User? user; + final MyUser? user; const AuthenticationState._({ this.status = AuthenticationStatus.unknown, @@ -13,7 +13,7 @@ class AuthenticationState extends Equatable { const AuthenticationState.unknown() : this._(); - const AuthenticationState.authenticated(User user) + const AuthenticationState.authenticated(MyUser user) : this._(status: AuthenticationStatus.authenticated, user: user); const AuthenticationState.unauthenticated() diff --git a/lib/blocs/my_user_bloc/my_user_bloc.dart b/lib/blocs/my_user_bloc/my_user_bloc.dart index bb046ee..9276a1d 100644 --- a/lib/blocs/my_user_bloc/my_user_bloc.dart +++ b/lib/blocs/my_user_bloc/my_user_bloc.dart @@ -1,3 +1,6 @@ +import 'dart:async'; +import 'dart:developer'; + import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:user_repository/user_repository.dart'; @@ -11,16 +14,62 @@ class MyUserBloc extends Bloc { MyUserBloc({required UserRepository myUserRepository}) : _userRepository = myUserRepository, super(const MyUserState.loading()) { - on(_onGetMyUser); + _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!)); + } + }); + + // 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 _onGetMyUser(GetMyUser event, Emitter emit) async { - emit(const MyUserState.loading()); - try { - MyUser myUser = await _userRepository.getMyUser(event.myUserId); - emit(MyUserState.success(myUser)); - } catch (e) { + void _onUserChanged(UserChanged event, Emitter emit) { + log('UserChanged: ${event.user}'); + if (event.user == null) { + log('UserChanged: ${event.user}'); emit(const MyUserState.failure()); + } else { + log('UserChanged: ${event.user}'); + 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/blocs/my_user_bloc/my_user_event.dart b/lib/blocs/my_user_bloc/my_user_event.dart index fbe45c6..cdf22dd 100644 --- a/lib/blocs/my_user_bloc/my_user_event.dart +++ b/lib/blocs/my_user_bloc/my_user_event.dart @@ -4,14 +4,23 @@ abstract class MyUserEvent extends Equatable { const MyUserEvent(); @override - List get props => []; + List get props => []; } -class GetMyUser extends MyUserEvent { - final String myUserId; +// class GetMyUser extends MyUserEvent { +// final String myUserId; - const GetMyUser({required this.myUserId}); +// const GetMyUser({required this.myUserId}); + +// @override +// List get props => [myUserId]; +// } + +class UserChanged extends MyUserEvent { + final MyUser? user; + + const UserChanged({required this.user}); @override - List get props => [myUserId]; + List get props => [user]; } diff --git a/lib/dependency_user/user_di.dart b/lib/dependency_user/user_di.dart new file mode 100644 index 0000000..5ef991f --- /dev/null +++ b/lib/dependency_user/user_di.dart @@ -0,0 +1,32 @@ +import 'package:firebase_auth/firebase_auth.dart'; +import 'package:injector/injector.dart'; +import 'package:prosappco/blocs/authentication_bloc/authentication_bloc.dart'; +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:user_repository/user_repository.dart'; + +class UserDI { + void register() { + final injector = Injector.appInstance; + + injector.registerSingleton( + (() => FirebaseUserRepository(FirebaseAuth.instance))); + + injector.registerSingleton((() => + AuthenticationBloc(myUserRepository: injector.get()))); + + injector.registerSingleton( + (() => MyUserBloc(myUserRepository: injector.get()))); + + injector.registerSingleton((() => + UpdateUserInfoBloc(userRepository: injector.get()))); + + injector.registerSingleton( + (() => SignInBloc(userRepository: injector.get()))); + + injector.registerSingleton( + (() => SignUpBloc(userRepository: injector.get()))); + } +} diff --git a/lib/main.dart b/lib/main.dart index c95aa4d..ad063b9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -173,6 +173,7 @@ import 'package:flutter/material.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:prosappco/dependency_user/user_di.dart'; import 'package:user_repository/user_repository.dart'; import 'app.dart'; import 'simple_bloc_observer.dart'; @@ -182,5 +183,6 @@ void main() async { await Firebase.initializeApp(); Bloc.observer = SimpleBlocObserver(); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); - runApp(MainApp(FirebaseUserRepository())); + UserDI().register(); + runApp(const MainApp()); } diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index c763ba2..82b7f43 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -1,7 +1,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:image_picker/image_picker.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'; @@ -26,114 +25,119 @@ 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(), + 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: 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!, + 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, ), - fit: BoxFit.cover, ), ), - ), - const SizedBox(height: 12), - Text( - context.read().state.user!.name, - style: const TextStyle( - fontSize: 24, - color: Colors.white, + 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, - ), - ) - ], + Text( + state.user!.email, + style: const TextStyle( + fontSize: 15, + color: Colors.white, + ), + ) + ], + ), ), ), ), - ), - 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', - ), - ) - ], - ), - ) - ], + 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', + ), + ) + ], + ), + ) + ], + ), ), - ), - ); - } else { - return Drawer( + ); + } else { + return Drawer( backgroundColor: Theme.of(context).colorScheme.background, child: const Center( child: CircularProgressIndicator(), - )); - } - }), - appBar: AppBar(), - body: const Placeholder(), - ), + ), + ); + } + }), + appBar: AppBar(), + body: Center( + child: Text( + context.read().state.user?.name ?? 'null', + ), + )), ); } } diff --git a/lib/screens/profile/profile_screen.dart b/lib/screens/profile/profile_screen.dart index aa592bd..da65bab 100644 --- a/lib/screens/profile/profile_screen.dart +++ b/lib/screens/profile/profile_screen.dart @@ -17,153 +17,154 @@ class ProfileScreen extends StatefulWidget { class _ProfileScreenState extends State { @override Widget build(BuildContext context) { - return MultiBlocProvider( - providers: [ - BlocProvider( - create: (context) => MyUserBloc( - myUserRepository: - context.read().userRepository) - ..add(GetMyUser( - myUserId: context.read().state.user!.uid)), - ), - BlocProvider( - create: (context) => UpdateUserInfoBloc( - userRepository: context.read().userRepository, - ), - ) - ], - child: BlocListener( - listener: (context, state) { - if (state is UploadPictureSuccess) { - setState(() { - context.read().state.user!.picture = state.userImage; - }); - } - }, - child: Scaffold( - appBar: PopAppbar( - onPressed: () { - Navigator.pop(context); - }, - label: 'Perfil', - ), - body: - BlocBuilder(builder: (context, state) { - if (state.status == MyUserStatus.success) { - return Padding( - padding: const EdgeInsets.all(20.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - GestureDetector( - onTap: () async { - final ImagePicker picker = ImagePicker(); - final XFile? image = await picker.pickImage( - source: ImageSource.gallery, - maxHeight: 500, - maxWidth: 500, - imageQuality: 40, - ); + return - if (image != null) { - context.read().add( - UploadPicture(image.path, state.user!.id), - ); - } - }, - child: state.user!.picture == "" - ? Container( - width: 120, - height: 120, - decoration: BoxDecoration( - color: Colors.grey.shade300, - shape: BoxShape.circle, - ), - child: Icon( - CupertinoIcons.person, - color: Colors.grey.shade400, - size: 40, - ), - ) - : Container( - width: 120, - height: 120, - decoration: BoxDecoration( - color: Colors.grey, - shape: BoxShape.circle, - image: DecorationImage( - image: NetworkImage( - state.user!.picture!, - ), - fit: BoxFit.cover, + // MultiBlocProvider( + // providers: [ + // BlocProvider( + // create: (context) => MyUserBloc( + // myUserRepository: + // context.read().userRepository) + // ..add(GetMyUser( + // myUserId: context.read().state.user!.uid)), + // ), + // BlocProvider( + // create: (context) => UpdateUserInfoBloc( + // userRepository: context.read().userRepository, + // ), + // ) + // ], + // child: + + BlocListener( + listener: (context, state) { + if (state is UploadPictureSuccess) { + setState(() { + context.read().state.user!.picture = state.userImage; + }); + } + }, + child: Scaffold( + appBar: PopAppbar( + onPressed: () { + Navigator.pop(context); + }, + label: 'Perfil', + ), + body: BlocBuilder(builder: (context, state) { + if (state.status == MyUserStatus.success) { + return Padding( + padding: const EdgeInsets.all(20.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + GestureDetector( + onTap: () async { + final ImagePicker picker = ImagePicker(); + final XFile? image = await picker.pickImage( + source: ImageSource.gallery, + maxHeight: 500, + maxWidth: 500, + imageQuality: 40, + ); + + if (image != null) { + context.read().add( + UploadPicture(image.path, state.user!.id), + ); + } + }, + child: state.user!.picture == "" + ? Container( + width: 120, + height: 120, + decoration: BoxDecoration( + color: Colors.grey.shade300, + shape: BoxShape.circle, + ), + child: Icon( + CupertinoIcons.person, + color: Colors.grey.shade400, + size: 40, + ), + ) + : Container( + width: 120, + height: 120, + decoration: BoxDecoration( + color: Colors.grey, + shape: BoxShape.circle, + image: DecorationImage( + image: NetworkImage( + state.user!.picture!, ), + fit: BoxFit.cover, ), ), - ), - const SizedBox(height: 20.0), - TextFormField( - initialValue: state.user?.name, - decoration: const InputDecoration( - labelText: 'Nombre', - prefixIcon: Icon(Icons.person), - hintText: 'Nombre (obligatorio)', - border: OutlineInputBorder( - borderRadius: BorderRadius.all( - Radius.circular(25.0), - )), - errorBorder: OutlineInputBorder( - borderSide: BorderSide(color: Colors.red), - ), - focusedErrorBorder: OutlineInputBorder( - borderSide: - BorderSide(color: Colors.red, width: 2.0), - ), + ), + ), + const SizedBox(height: 20.0), + TextFormField( + initialValue: state.user?.name, + decoration: const InputDecoration( + labelText: 'Nombre', + prefixIcon: Icon(Icons.person), + hintText: 'Nombre (obligatorio)', + border: OutlineInputBorder( + borderRadius: BorderRadius.all( + Radius.circular(25.0), + )), + errorBorder: OutlineInputBorder( + borderSide: BorderSide(color: Colors.red), ), - validator: (value) { - if (value == null || value.isEmpty) { - return 'Por favor, ingrese su nombre'; - } - return null; - }, - ), - const SizedBox(height: 20.0), - TextFormField( - initialValue: state.user?.email, - decoration: const InputDecoration( - labelText: 'Nombre', - prefixIcon: Icon(Icons.person), - hintText: 'Nombre (obligatorio)', - border: OutlineInputBorder( - borderRadius: BorderRadius.all( - Radius.circular(25.0), - )), - errorBorder: OutlineInputBorder( - borderSide: BorderSide(color: Colors.red), - ), - focusedErrorBorder: OutlineInputBorder( - borderSide: - BorderSide(color: Colors.red, width: 2.0), - ), + focusedErrorBorder: OutlineInputBorder( + borderSide: BorderSide(color: Colors.red, width: 2.0), ), - validator: (value) { - if (value == null || value.isEmpty) { - return 'Por favor, ingrese su nombre'; - } - return null; - }, ), - ElevatedButton( - onPressed: () {}, - child: const Text('Guardar'), + validator: (value) { + if (value == null || value.isEmpty) { + return 'Por favor, ingrese su nombre'; + } + return null; + }, + ), + const SizedBox(height: 20.0), + TextFormField( + initialValue: state.user?.email, + decoration: const InputDecoration( + labelText: 'Nombre', + prefixIcon: Icon(Icons.person), + hintText: 'Nombre (obligatorio)', + border: OutlineInputBorder( + borderRadius: BorderRadius.all( + Radius.circular(25.0), + )), + errorBorder: OutlineInputBorder( + borderSide: BorderSide(color: Colors.red), + ), + focusedErrorBorder: OutlineInputBorder( + borderSide: BorderSide(color: Colors.red, width: 2.0), + ), ), - ], - ), - ); - } else { - return const Center(child: CircularProgressIndicator()); - } - })), - ), + validator: (value) { + if (value == null || value.isEmpty) { + return 'Por favor, ingrese su nombre'; + } + return null; + }, + ), + ElevatedButton( + onPressed: () {}, + child: const Text('Guardar'), + ), + ], + ), + ); + } else { + return const Center(child: CircularProgressIndicator()); + } + })), + // ), ); } } diff --git a/packages/user_repository/lib/src/firebase_user_repository.dart b/packages/user_repository/lib/src/firebase_user_repository.dart index 952203a..12cafc9 100644 --- a/packages/user_repository/lib/src/firebase_user_repository.dart +++ b/packages/user_repository/lib/src/firebase_user_repository.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:developer'; import 'dart:io'; @@ -9,21 +10,46 @@ import 'entities/entities.dart'; import 'user_repo.dart'; class FirebaseUserRepository implements UserRepository { - FirebaseUserRepository({ - FirebaseAuth? firebaseAuth, - }) : _firebaseAuth = firebaseAuth ?? FirebaseAuth.instance; - final FirebaseAuth _firebaseAuth; final usersCollection = FirebaseFirestore.instance.collection('users'); + final StreamController _userStreamController = + StreamController.broadcast(); - @override - Stream get user { - return _firebaseAuth.authStateChanges().map((firebaseUser) { - final user = firebaseUser; - return user; + FirebaseUserRepository(this._firebaseAuth) { + _firebaseAuth.userChanges().listen((user) async { + if (user != null) { + try { + final myUser = await getMyUser(user.uid); + _userStreamController.add(myUser); + } catch (e) { + log('Error en FirebaseUserRepository ${e.toString()}'); + _userStreamController.add(null); + } + } else { + _userStreamController.add(null); + } + }); + + this.streamUser().listen((event) { + log('xd - : ${event}'); }); } + // Stream get user => _userStreamController.stream; + + @override + Stream streamUser() { + return _userStreamController.stream; + } + + // @override + // Stream get user { + // return _firebaseAuth.authStateChanges().map((firebaseUser) { + // final user = firebaseUser; + // return user; + // }); + // } + // Sign up @override Future signUp(MyUser myUser, String password) async { diff --git a/packages/user_repository/lib/src/user_repo.dart b/packages/user_repository/lib/src/user_repo.dart index 74cd3c6..f505888 100644 --- a/packages/user_repository/lib/src/user_repo.dart +++ b/packages/user_repository/lib/src/user_repo.dart @@ -3,7 +3,8 @@ import 'package:firebase_auth/firebase_auth.dart'; import '../user_repository.dart'; abstract class UserRepository { - Stream get user; + // Stream get user; + Stream streamUser(); Future signIn(String email, String password); diff --git a/pubspec.lock b/pubspec.lock index dd2661d..c2c34c9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -741,6 +741,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.1+1" + injector: + dependency: "direct main" + description: + name: injector + sha256: ed389bed5b48a699d5b9561c985023d0d5cc88dd5ff2237aadcce5a5ab433e4e + url: "https://pub.dev" + source: hosted + version: "3.0.0" intl: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index e226435..7be31da 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,6 +39,7 @@ dependencies: google_sign_in: ^6.1.4 http: ^1.1.0 image_picker: ^1.0.7 + injector: ^3.0.0 intl: any intl_phone_field: null location: ^5.0.3 @@ -60,7 +61,6 @@ dev_dependencies: sdk: flutter flutter: - uses-material-design: true assets: