0

Im am trying to get userData by id to show userProfile. I create a cubitProfile for this reason but when I go to the profile page the app ProviderNotFoundException(T, context.widget.runtimeType) apears. Can u help me with this error?

Here is my code:

profile

class ProfileScreen extends StatelessWidget {
  final String id;

  const ProfileScreen({Key? key, required this.id}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return BlocBuilder<ProfileCubit, ProfileStates>(builder: (context, state) {
      var cubit = ProfileCubit.get(context);

      return Scaffold(
       ...

profileCubit

class ProfileCubit extends Cubit<ProfileStates> {
  ProfileCubit() : super(ProfileInitState());

  static ProfileCubit get(context) => BlocProvider.of(context);

  late UserData userData;

  void getUserDataById(String id) {
    emit(ProfileGetUserLoadingState());
    FirebaseFirestore.instance.collection('users').doc(id).get().then((value) {
      userData = UserData.fromJson(jsonDecode(jsonEncode(value.data())));
      emit(ProfileGetUserSuccessState());
    }).catchError((error) {
      print(error);
      emit(ProfileGetUserErrorState());
    });
  }

  bool isSameUser(String uid) {
    if (FirebaseAuth.instance.currentUser!.uid != uid) {
      return false;
    } else {
      return true;
    }
  }
}
Mus
  • 67
  • 1
  • 13
  • Could you add the code where you provide the BLoC to the Widget tree using `BlocProvider`, or you haven't done this? – mkobuolys Mar 12 '22 at 11:57
  • I think I don't have it. Maybe I should add it at the begining of ProfileScreen? – Mus Mar 12 '22 at 12:05
  • 1
    You can reference [this](https://www.youtube.com/watch?v=laqnY0NjU3M) video on how to provide BLoC to your widget tree. – mkobuolys Mar 12 '22 at 12:11

0 Answers0