How convert FirebaseUser to string in flutter?Getting values from Future instancesFlutter - How to pass user data to all viewsDart / Flutter Page Not Reloading After SetState?Flutter/Firebase : How can i access the current user without using '.then(…)' functionPass variable to void function in flutterSame Code, Two different results | Navigating to another Route in flutterFlutter/Dart - calling a function that is a Future<String> … but needs to return only a StringAsync/Await/then in Dart/FlutterFlutter: Shows some Firestore Collection with a StreamBuilder from an authenticated Firebase Auth UserFlutter Firebase Auth returns null, then returns the correct valueReplaying the same Flare animation in Flutter

Who voices the character "Finger" in The Fifth Element?

What is the purpose of putting a capacitor on the primary side of a step-down transformer?

Does a return economy-class seat between London and San Francisco release 5.28 t of CO2e?

Could the Q destroy the universe?

What's the easiest way for a whole party to be able to communicate with a creature that doesn't know Common?

Most important new papers in computational complexity

Symbol for "not absolutely continuous" in Latex

Was it really unprofessional of me to leave without asking for a raise first?

How can I add two boxes in minipages side by side?

Pairwise Scatter Plots with Histograms and Correlations

Picking balls from urns.

Matrix decomposition

How can I specify a local port when establishing SSH connections?

What's the rule for a natural 20 on a Perception check?

Why transcripts instead of degree certificates?

What could a reptilian race tell by candling their eggs?

Procedurally generate regions on island

How can my story take place on Earth without referring to our existing cities and countries?

How did researchers find articles before the Internet and the computer era?

One folder having two different locations on Ubuntu 18.04

Can I travel from Germany to England alone as an unaccompanied minor?

How hard is it to sell a home which is currently mortgaged?

Adjective for 'made of pus' or 'corrupted by pus' or something of something of pus

Why is copy constructor called instead of move constructor when returning?



How convert FirebaseUser to string in flutter?


Getting values from Future instancesFlutter - How to pass user data to all viewsDart / Flutter Page Not Reloading After SetState?Flutter/Firebase : How can i access the current user without using '.then(…)' functionPass variable to void function in flutterSame Code, Two different results | Navigating to another Route in flutterFlutter/Dart - calling a function that is a Future<String> … but needs to return only a StringAsync/Await/then in Dart/FlutterFlutter: Shows some Firestore Collection with a StreamBuilder from an authenticated Firebase Auth UserFlutter Firebase Auth returns null, then returns the correct valueReplaying the same Flare animation in Flutter






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Here is my code of a stateful class:



String id = FirebaseAuth.instance.currentUser().toString();


my function :



readLocal() async 
prefs = await SharedPreferences.getInstance();
id = prefs.getString('id') ?? '';
if (id.hashCode <= peerId.hashCode)
groupChatId = '$id-$peerId';
else
groupChatId = '$peerId-$id';

setState(() );



It works fine in String id.



I want the ID to be the same as the current user UID.










share|improve this question






























    0















    Here is my code of a stateful class:



    String id = FirebaseAuth.instance.currentUser().toString();


    my function :



    readLocal() async 
    prefs = await SharedPreferences.getInstance();
    id = prefs.getString('id') ?? '';
    if (id.hashCode <= peerId.hashCode)
    groupChatId = '$id-$peerId';
    else
    groupChatId = '$peerId-$id';

    setState(() );



    It works fine in String id.



    I want the ID to be the same as the current user UID.










    share|improve this question


























      0












      0








      0








      Here is my code of a stateful class:



      String id = FirebaseAuth.instance.currentUser().toString();


      my function :



      readLocal() async 
      prefs = await SharedPreferences.getInstance();
      id = prefs.getString('id') ?? '';
      if (id.hashCode <= peerId.hashCode)
      groupChatId = '$id-$peerId';
      else
      groupChatId = '$peerId-$id';

      setState(() );



      It works fine in String id.



      I want the ID to be the same as the current user UID.










      share|improve this question
















      Here is my code of a stateful class:



      String id = FirebaseAuth.instance.currentUser().toString();


      my function :



      readLocal() async 
      prefs = await SharedPreferences.getInstance();
      id = prefs.getString('id') ?? '';
      if (id.hashCode <= peerId.hashCode)
      groupChatId = '$id-$peerId';
      else
      groupChatId = '$peerId-$id';

      setState(() );



      It works fine in String id.



      I want the ID to be the same as the current user UID.







      flutter firebase-authentication






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 14:23









      Frank van Puffelen

      260k33 gold badges419 silver badges441 bronze badges




      260k33 gold badges419 silver badges441 bronze badges










      asked Mar 25 at 13:27









      richierichie

      388 bronze badges




      388 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Calling FirebaseAuth.instance.currentUser() return a FirebaseUser, which is an object with all user data. If you only want the UID of the user:



          FirebaseUser user = await FirebaseAuth.instance.currentUser();
          String uid = user.uid;



          Update: I just ran this and it prints the UID for me:



          void _getUser() async 
          FirebaseUser user = await FirebaseAuth.instance.currentUser();
          print(user.uid);



          Which printed:




          flutter: P07IXLCrwEahYlDhzO1Iv0SKDat2




          Things to notice:



          • In order to be able to use await in the code, the method must be marked as async.





          share|improve this answer

























          • Error is : The getter 'uid' isn't defined for the class 'Future<FirebaseUser>'.dart(undefined_getter)

            – richie
            Mar 25 at 14:42











          • Got it. currentUser is asynchronous, so you'll need to await the result. I updated my answer.

            – Frank van Puffelen
            Mar 25 at 14:54












          • Again error : A value of type 'Future<FirebaseUser>' can't be assigned to a variable of type 'FirebaseUser'.dart(invalid_assignment)

            – richie
            Mar 25 at 15:51











          • Are you sure you added the await keyword? That should unwrap the Future<FirebaseUser> into FirebaseUser.

            – Frank van Puffelen
            Mar 25 at 17:03











          • Yes, here is my code FirebaseUser user = await FirebaseAuth.instance.currentUser(); String uid = user.uid;

            – richie
            Mar 25 at 17:07










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55338896%2fhow-convert-firebaseuser-to-string-in-flutter%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Calling FirebaseAuth.instance.currentUser() return a FirebaseUser, which is an object with all user data. If you only want the UID of the user:



          FirebaseUser user = await FirebaseAuth.instance.currentUser();
          String uid = user.uid;



          Update: I just ran this and it prints the UID for me:



          void _getUser() async 
          FirebaseUser user = await FirebaseAuth.instance.currentUser();
          print(user.uid);



          Which printed:




          flutter: P07IXLCrwEahYlDhzO1Iv0SKDat2




          Things to notice:



          • In order to be able to use await in the code, the method must be marked as async.





          share|improve this answer

























          • Error is : The getter 'uid' isn't defined for the class 'Future<FirebaseUser>'.dart(undefined_getter)

            – richie
            Mar 25 at 14:42











          • Got it. currentUser is asynchronous, so you'll need to await the result. I updated my answer.

            – Frank van Puffelen
            Mar 25 at 14:54












          • Again error : A value of type 'Future<FirebaseUser>' can't be assigned to a variable of type 'FirebaseUser'.dart(invalid_assignment)

            – richie
            Mar 25 at 15:51











          • Are you sure you added the await keyword? That should unwrap the Future<FirebaseUser> into FirebaseUser.

            – Frank van Puffelen
            Mar 25 at 17:03











          • Yes, here is my code FirebaseUser user = await FirebaseAuth.instance.currentUser(); String uid = user.uid;

            – richie
            Mar 25 at 17:07















          0














          Calling FirebaseAuth.instance.currentUser() return a FirebaseUser, which is an object with all user data. If you only want the UID of the user:



          FirebaseUser user = await FirebaseAuth.instance.currentUser();
          String uid = user.uid;



          Update: I just ran this and it prints the UID for me:



          void _getUser() async 
          FirebaseUser user = await FirebaseAuth.instance.currentUser();
          print(user.uid);



          Which printed:




          flutter: P07IXLCrwEahYlDhzO1Iv0SKDat2




          Things to notice:



          • In order to be able to use await in the code, the method must be marked as async.





          share|improve this answer

























          • Error is : The getter 'uid' isn't defined for the class 'Future<FirebaseUser>'.dart(undefined_getter)

            – richie
            Mar 25 at 14:42











          • Got it. currentUser is asynchronous, so you'll need to await the result. I updated my answer.

            – Frank van Puffelen
            Mar 25 at 14:54












          • Again error : A value of type 'Future<FirebaseUser>' can't be assigned to a variable of type 'FirebaseUser'.dart(invalid_assignment)

            – richie
            Mar 25 at 15:51











          • Are you sure you added the await keyword? That should unwrap the Future<FirebaseUser> into FirebaseUser.

            – Frank van Puffelen
            Mar 25 at 17:03











          • Yes, here is my code FirebaseUser user = await FirebaseAuth.instance.currentUser(); String uid = user.uid;

            – richie
            Mar 25 at 17:07













          0












          0








          0







          Calling FirebaseAuth.instance.currentUser() return a FirebaseUser, which is an object with all user data. If you only want the UID of the user:



          FirebaseUser user = await FirebaseAuth.instance.currentUser();
          String uid = user.uid;



          Update: I just ran this and it prints the UID for me:



          void _getUser() async 
          FirebaseUser user = await FirebaseAuth.instance.currentUser();
          print(user.uid);



          Which printed:




          flutter: P07IXLCrwEahYlDhzO1Iv0SKDat2




          Things to notice:



          • In order to be able to use await in the code, the method must be marked as async.





          share|improve this answer















          Calling FirebaseAuth.instance.currentUser() return a FirebaseUser, which is an object with all user data. If you only want the UID of the user:



          FirebaseUser user = await FirebaseAuth.instance.currentUser();
          String uid = user.uid;



          Update: I just ran this and it prints the UID for me:



          void _getUser() async 
          FirebaseUser user = await FirebaseAuth.instance.currentUser();
          print(user.uid);



          Which printed:




          flutter: P07IXLCrwEahYlDhzO1Iv0SKDat2




          Things to notice:



          • In order to be able to use await in the code, the method must be marked as async.






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 27 at 1:43

























          answered Mar 25 at 14:25









          Frank van PuffelenFrank van Puffelen

          260k33 gold badges419 silver badges441 bronze badges




          260k33 gold badges419 silver badges441 bronze badges












          • Error is : The getter 'uid' isn't defined for the class 'Future<FirebaseUser>'.dart(undefined_getter)

            – richie
            Mar 25 at 14:42











          • Got it. currentUser is asynchronous, so you'll need to await the result. I updated my answer.

            – Frank van Puffelen
            Mar 25 at 14:54












          • Again error : A value of type 'Future<FirebaseUser>' can't be assigned to a variable of type 'FirebaseUser'.dart(invalid_assignment)

            – richie
            Mar 25 at 15:51











          • Are you sure you added the await keyword? That should unwrap the Future<FirebaseUser> into FirebaseUser.

            – Frank van Puffelen
            Mar 25 at 17:03











          • Yes, here is my code FirebaseUser user = await FirebaseAuth.instance.currentUser(); String uid = user.uid;

            – richie
            Mar 25 at 17:07

















          • Error is : The getter 'uid' isn't defined for the class 'Future<FirebaseUser>'.dart(undefined_getter)

            – richie
            Mar 25 at 14:42











          • Got it. currentUser is asynchronous, so you'll need to await the result. I updated my answer.

            – Frank van Puffelen
            Mar 25 at 14:54












          • Again error : A value of type 'Future<FirebaseUser>' can't be assigned to a variable of type 'FirebaseUser'.dart(invalid_assignment)

            – richie
            Mar 25 at 15:51











          • Are you sure you added the await keyword? That should unwrap the Future<FirebaseUser> into FirebaseUser.

            – Frank van Puffelen
            Mar 25 at 17:03











          • Yes, here is my code FirebaseUser user = await FirebaseAuth.instance.currentUser(); String uid = user.uid;

            – richie
            Mar 25 at 17:07
















          Error is : The getter 'uid' isn't defined for the class 'Future<FirebaseUser>'.dart(undefined_getter)

          – richie
          Mar 25 at 14:42





          Error is : The getter 'uid' isn't defined for the class 'Future<FirebaseUser>'.dart(undefined_getter)

          – richie
          Mar 25 at 14:42













          Got it. currentUser is asynchronous, so you'll need to await the result. I updated my answer.

          – Frank van Puffelen
          Mar 25 at 14:54






          Got it. currentUser is asynchronous, so you'll need to await the result. I updated my answer.

          – Frank van Puffelen
          Mar 25 at 14:54














          Again error : A value of type 'Future<FirebaseUser>' can't be assigned to a variable of type 'FirebaseUser'.dart(invalid_assignment)

          – richie
          Mar 25 at 15:51





          Again error : A value of type 'Future<FirebaseUser>' can't be assigned to a variable of type 'FirebaseUser'.dart(invalid_assignment)

          – richie
          Mar 25 at 15:51













          Are you sure you added the await keyword? That should unwrap the Future<FirebaseUser> into FirebaseUser.

          – Frank van Puffelen
          Mar 25 at 17:03





          Are you sure you added the await keyword? That should unwrap the Future<FirebaseUser> into FirebaseUser.

          – Frank van Puffelen
          Mar 25 at 17:03













          Yes, here is my code FirebaseUser user = await FirebaseAuth.instance.currentUser(); String uid = user.uid;

          – richie
          Mar 25 at 17:07





          Yes, here is my code FirebaseUser user = await FirebaseAuth.instance.currentUser(); String uid = user.uid;

          – richie
          Mar 25 at 17:07






          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55338896%2fhow-convert-firebaseuser-to-string-in-flutter%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현