0

I am Trying to build an app. which fetching the user credential data and shows in profile page. I am getting an error => Bad state: cannot get a field on a DocumentSnapshotPlatform which does not exist in the profile section need help

Widget headerProfile(BuildContext context,  DocumentSnapshot snapshot) {
return SizedBox(
  height: MediaQuery.of(context).size.height * 0.25,
  width: MediaQuery.of(context).size.width,
  child: Row(
    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
    children: [
      Expanded(
        child: Container(
          height: 200.0,
          width: 180.0,
          child: Column(
            children: [
              GestureDetector(
                onTap: () {},
                child: CircleAvatar(
                  backgroundColor: constantColors.transperant,
                  radius: 60.0,
                  backgroundImage: NetworkImage(snapshot['userimage']),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(top: 8.0),
                child: Text(snapshot['username'],
                    style: TextStyle(
                        color: constantColors.whiteColor,
                        fontWeight: FontWeight.bold,
                        fontSize: 16.0)),
              ),
              Padding(
                padding: const EdgeInsets.only(top: 8.0),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Icon(EvaIcons.email, color: constantColors.greenColor),
                    Padding(
                      padding: const EdgeInsets.only(left:9.0),
                      child: Text(snapshot['useremail'],
                          style: TextStyle(
                              color: constantColors.whiteColor,
                              fontWeight: FontWeight.bold,
                              fontSize: 13.0)),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
      Container(
        // width: 200.0,
        width: 200.0,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Padding(
              padding: const EdgeInsets.only(top:16.0, right: 30.0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Container(
                    decoration: BoxDecoration(
                        color: constantColors.darkColor,
                        borderRadius: BorderRadius.circular(15.0)),
                    height: 70.0,
                    width: 80.0,
                    child: Column(
                      children: [
                        Text(
                          '0',
                          style: TextStyle(
                              color: constantColors.whiteColor,
                              fontWeight: FontWeight.bold,
                              fontSize: 28.0),
                        ),
                        Text(
                          'Followers',
                          style: TextStyle(
                              color: constantColors.whiteColor,
                              fontWeight: FontWeight.bold,
                              fontSize: 12.0),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    decoration: BoxDecoration(
                        color: constantColors.darkColor,
                        borderRadius: BorderRadius.circular(15.0)),
                    height: 70.0,
                    width: 80.0,
                    child: Column(
                      children: [
                        Text(
                          '0',
                          style: TextStyle(
                              color: constantColors.whiteColor,
                              fontWeight: FontWeight.bold,
                              fontSize: 28.0),
                        ),
                        Text(
                          'Following',
                          style: TextStyle(
                              color: constantColors.whiteColor,
                              fontWeight: FontWeight.bold,
                              fontSize: 12.0),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(top:16.0),
              child: Container(
                decoration: BoxDecoration(
                    color: constantColors.darkColor,
                    borderRadius: BorderRadius.circular(15.0)),
                height: 70.0,
                width: 80.0,
                child: Column(
                  children: [
                    Text(
                      '0',
                      style: TextStyle(
                          color: constantColors.whiteColor,
                          fontWeight: FontWeight.bold,
                          fontSize: 28.0),
                    ),
                    Text(
                      'Posts',
                      style: TextStyle(
                          color: constantColors.whiteColor,
                          fontWeight: FontWeight.bold,
                          fontSize: 12.0),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      )
    ],
  ),
);

}

I think the error is coming from the snapshot['username'], snapshot['userimage'] and snapshot['useremail'].....

This is my Profile.dart

Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(
    centerTitle: true,
    leading: IconButton(
        onPressed: () {},
        icon: Icon(
          EvaIcons.settings2Outline,
          color: constantColors.lightBlueColor,
        )),
    actions: [
      IconButton(
          onPressed: () {},
          icon: Icon(EvaIcons.logOutOutline,
              color: constantColors.greenColor)),
    ],
    backgroundColor: constantColors.blueGreyColor.withOpacity(0.4),
    title: RichText(
        text: TextSpan(
            text: 'My ',
            style: TextStyle(
              color: constantColors.whiteColor,
              fontWeight: FontWeight.bold,
              fontSize: 20.0,
            ),
            children: <TextSpan>[
          TextSpan(
            text: 'Profile',
            style: TextStyle(
              color: constantColors.blueColor,
              fontWeight: FontWeight.bold,
              fontSize: 20.0,
            ),
          ),
        ])),
  ),
  body: SingleChildScrollView(
    child: Padding(
      padding: const EdgeInsets.all(8.0),
      child: Container(
        height: MediaQuery.of(context).size.height,
        width: MediaQuery.of(context).size.width,
        child: StreamBuilder<DocumentSnapshot>(
          stream: FirebaseFirestore.instance
              .collection('users')
              .doc(Provider.of<Authentication>(context, listen: false)
                  .getUserUid)
              .snapshots(),
          builder: (context, snapshot) {
            if (snapshot.connectionState == ConnectionState.waiting) {
              return Center(
                child: CircularProgressIndicator(),
              );
            } else {
              return new Column(
                children: [
                  Provider.of<ProfileHelpers>(context, listen: false).headerProfile(context, snapshot.data)
                ],
              );
            }
          },
        ),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(15.0),
            color: constantColors.blueGreyColor.withOpacity(0.6)),
      ),
    ),
  ),
);

}

and below is the FirebaseOperations.dart

Future initUserData(BuildContext context) async {
return FirebaseFirestore.instance
    .collection('users')
    .doc(Provider.of<Authentication>(context, listen: false).getUserUid)
    .get()
    .then((doc) {
      print('Fetching user data...');
      initUserName = doc.data()['username'];
      initUserEmail = doc.data()['useremail'];
      initUserImage = doc.data()['userimage'];
      print(initUserName);
      print(initUserEmail);
      print(initUserImage);
      notifyListeners();
    });

String initUserEmail, initUserName, initUserImage;
String get getInitUserName => initUserName;
String get getInitUserEmail => initUserEmail;
String get getInitUserImage => initUserImage;

All my code is this please help and there is user profile circle avatar at the bottom navbar it is also not the the image

Widget bottomNavBar(BuildContext context, int index, PageController pageController) {
return CustomNavigationBar(
    currentIndex: index,
    bubbleCurve: Curves.bounceIn,
    scaleCurve: Curves.decelerate,
    selectedColor: constantColors.blueColor,
    unSelectedColor: constantColors.whiteColor,
    strokeColor: constantColors.blueColor,
    scaleFactor: 0.5,
    iconSize: 30.0,
    onTap: (val) {
      index = val;
      pageController.jumpToPage(val);
      notifyListeners();
    },
    backgroundColor: Color(0xff040307),
    items: [
      CustomNavigationBarItem(icon: Icon(EvaIcons.home)),
      CustomNavigationBarItem(icon: Icon(Icons.message_rounded)),
      CustomNavigationBarItem(
          icon: CircleAvatar(
        radius: 35.0,
        backgroundColor: constantColors.blueGreyColor,
        backgroundImage: NetworkImage(Provider.of<FirebaseOperations>(context, listen: false).initUserImage),
      )),
    ]);

}

Homepage.dart

Widget build(BuildContext context) {
return Scaffold(
  backgroundColor: constantColors.darkColor,
  body: PageView(
    controller: homepageController,
    children: [
      Feed(),
      Chatroom(),
      Profile(),
    ],
    physics: NeverScrollableScrollPhysics(),
    onPageChanged: (page) {
      setState(() {
        pageIndex = page;
      });
    },
  ),
  bottomNavigationBar: Provider.of<HomepageHelpers>(context, listen: false)
      .bottomNavBar(context, pageIndex, homepageController),
);

}

Please Help

  • Can you please give some more clarity from which part of the code or specifically from which line of the code you are getting the error? You can refer to these StackOverFlow threads : https://stackoverflow.com/questions/66232053 and https://stackoverflow.com/questions/64949640 which might be helpful. – Prabir Aug 31 '21 at 16:55
  • thank u for helping but the issue is been solved –  Sep 04 '21 at 03:40

0 Answers0