Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The method 'UserUid' isn't defined for the type '_HomeState'

I’m developing a Flutter mobile app. I’m doing the authentication using Firebase, but I have a problem. I want to add a button to log out, but I’m facing this error, how can I solve it? I need help.
UserUid(), OutButton(), I am getting error in these two places.With the help of Firebase, I wanted to take the current user and log out with the signOut method, but I wanted to add it to a button in the method and add it as a widget, but I could not solve the error.

Errors: The method ‘UserUid’ isn’t defined for the type ‘_HomeState’.
Errors: The method ‘OutButton’ isn’t defined for the type ‘_HomeState’.

I think it is because I use statefull widget but I have to use statefull and I definitely need to add a exit button to this page.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class Home extends StatefulWidget {
 static String routeName="/home";
 Home({Key? key}) : super(key: key);
 final User? user = Auth().currentUser;

 Future<void> signOut() async {
   await Auth().signOut();
 }

 Widget Title_() {
   return const Text('Firebase Auth');
 }

 Widget UserUid() {
   return Text(user?.email ?? 'User email');
 }

 Widget OutButton() {
   return ElevatedButton(
     onPressed: signOut,
     child: const Text('Sign Out'),
   );
 }


 @override
 _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
 String getEmoji(String text) {
   if (text == "anger") {
     return '😠️ 💢';
   } else if (text == "joy") {
     return "😂 😭 🤣";
   } else if (text == "sadness") {
     return "😥 😔 😓";
   } else if (text == "fear") {
     return "😨 😱";
   } else if (text == "love") {
     return "❤ 💕 🥰";
   } else if (text == "surprise") {
     return "😯 😮 😲";
   } else {
     return "❓";
   }
 }
 String url = '';
 var data='';
 String output = 'Initial Output';
 @override
 Widget build(BuildContext context) {
   return Scaffold(
     appBar: AppBar(title: Text('Emoji Suggester')),
     body: Center(
       child: Container(
         padding: EdgeInsets.all(20),
         child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
           TextField(
             onChanged: (value) {
               url = 'http://10.0.2.2:5000/emotions?text=' + value;
             },
           ),
           TextButton(
               onPressed: () async {
                 data = await fetchdata(url);
                 setState(() {
                   output = data;
                 });
               },
               child: Text(
                 'Emotions Suggester',
                 style: TextStyle(fontSize: 20),
               )),
           Text(
             getEmoji(data)+data,
             style: TextStyle(fontSize: 25, color: Colors.green),
           ),
           UserUid(),
           OutButton(),
         ]
         ),
       ),
     ),
   );
 }
}

>Solution :

If you want to access something from your StatefulWidget class in your state class, you need to use widget. like this:

Text(
   getEmoji(data)+data,
   style: TextStyle(fontSize: 25, color: Colors.green),
),
widget.UserUid(), // <=== change this
OutButton(),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading