title: Add image from gallery to user document id using Flutter and Firebase
body: <p>I am developing an app, and I want to create a user profile for each logged-in user. With my code now, I am able to get the user information from the cloud Firestore of each user uid document, but I want the user to be able to add an image to firebase storage, and then get this image, add to the specific user uid doc, and display on the app. Basically, I know how to get the data I have already, I just don't know how to update the user doc, especially with images.</p>
  <p>Here is the code I have for the user profile:</p>
  <pre><code>import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:firebase_auth/firebase_auth.dart';
  import 'package:flutter/material.dart';
  import 'package:tradie_app/scr/providers/authService.dart';
  import 'package:tradie_app/scr/screens/edit_company_email.dart';
  import 'package:tradie_app/scr/widgets/loading.dart';
  
  import 'home.dart';
  
  class CompanyProfile extends StatefulWidget {
    @override
    _CompanyProfileState createState() =&gt; _CompanyProfileState();
  }
  
  class _CompanyProfileState extends State&lt;CompanyProfile&gt; {
    // Keep track of the form for validation
    final _formKey = GlobalKey&lt;FormState&gt;();
  
    // Loading Icon
    bool loading = false;
  
    final AuthService _authService = AuthService();
    final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
    final FirebaseFirestore _firebaseFirestore = FirebaseFirestore.instance;
  
    Future getCompanyNameData() async {
      final CollectionReference users =
          _firebaseFirestore.collection(&quot;Companies&quot;);
      final String uid = _firebaseAuth.currentUser.uid;
      final result = await users.doc(uid).get();
      return result.data()[&quot;companyName&quot;];
    }
  
    Future getCompanyEmailData() async {
      final CollectionReference users =
          _firebaseFirestore.collection(&quot;Companies&quot;);
      final String uid = _firebaseAuth.currentUser.uid;
      final result = await users.doc(uid).get();
      return result.data()[&quot;companyEmail&quot;];
    }
  
    @override
    Widget build(BuildContext context) {
      return loading
          ? Loading()
          : Scaffold(
              backgroundColor: Colors.white,
              appBar: AppBar(
                iconTheme: IconThemeData(color: Colors.black),
                backgroundColor: Colors.white,
                title: Text(
                  &quot;Create the company profile&quot;,
                  style: TextStyle(
                    color: Colors.black,
                  ),
                ),
                elevation: 0.0,
              ),
              drawer: Drawer(
                child: ListView(
                  padding: EdgeInsets.zero,
                  children: &lt;Widget&gt;[
                    UserAccountsDrawerHeader(
                      accountName: FutureBuilder(
                        future: getCompanyNameData(),
                        builder: (_, AsyncSnapshot snapshot) {
                          if (snapshot.connectionState ==
                              ConnectionState.waiting) {
                            return Text(&quot;Loading&quot;);
                          }
                          return Text(snapshot.data);
                        },
                      ),
                    ),
                    ListTile(
                      leading: Icon(Icons.logout),
                      title: Text(
                        &quot;Log Out&quot;,
                      ),
                      onTap: () async {
                        await _authService.signOut();
                      },
                    ),
                  ],
                ),
              ),
              body: Padding(
                padding: const EdgeInsets.all(18.0),
                child: SingleChildScrollView(
                  child: Container(
                    child: Form(
                      key: _formKey,
                      child: Column(
                        children: [
                          Row(
                            children: [
                              Text(
                                &quot;Company name: &quot;,
                                style: TextStyle(
                                  color: Colors.black,
                                  fontSize: 20.0,
                                ),
                              ),
                            ],
                          ),
                          SizedBox(
                            height: 10.0,
                          ),
                          Row(
                            children: [
                              FutureBuilder(
                                future: getCompanyNameData(),
                                builder: (_, AsyncSnapshot snapshot) {
                                  if (snapshot.connectionState ==
                                      ConnectionState.waiting) {
                                    return Text(&quot;Loading&quot;);
                                  }
                                  return Text(
                                    snapshot.data,
                                    style: TextStyle(
                                        color: Colors.black, fontSize: 15.0),
                                  );
                                },
                              ),
                            ],
                          ),
                          SizedBox(
                            height: 20.0,
                          ),
                          Row(
                            children: [
                              Text(
                                &quot;Company email: &quot;,
                                style: TextStyle(
                                  color: Colors.black,
                                  fontSize: 20.0,
                                ),
                              ),
                            ],
                          ),
                          SizedBox(
                            height: 10.0,
                          ),
                          Row(
                            children: [
                              FutureBuilder(
                                future: getCompanyEmailData(),
                                builder: (_, AsyncSnapshot snapshot) {
                                  if (snapshot.connectionState ==
                                      ConnectionState.waiting) {
                                    return Text(&quot;Loading&quot;);
                                  }
                                  return Text(
                                    snapshot.data,
                                    style: TextStyle(
                                      color: Colors.black,
                                      fontSize: 15.0,
                                    ),
                                  );
                                },
                              ),
                              IconButton(
                                icon: Icon(Icons.edit),
                                onPressed: () =&gt; Navigator.of(context).push(
                                  MaterialPageRoute(
                                    builder: (context) =&gt;
                                        EditCompanyEmailScreen(),
                                  ),
                                ),
                              ),
                            ],
                          ),
                          SizedBox(
                            height: 20.0,
                          ),
                          Row(
                            children: [
                              Text(
                                &quot;Company phone number: &quot;,
                                style: TextStyle(
                                  color: Colors.black,
                                  fontSize: 20.0,
                                ),
                              ),
                            ],
                          ),
                          SizedBox(
                            height: 20.0,
                          ),
                          // Here is where I want to add the image
                          Row(
                            children: &lt;Widget&gt;[],
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ),
            );
    }
  }
  </code></pre>