NavigationDrawer custom widget not accepted

Advertisements

A few weeks ago I was able to launch a project without errors.

Now, I am trying to launch the project again but there are some errors on it.

Here you have the code for the widget NavigationDrawer:

class NavigationDrawer extends StatefulWidget {
  const NavigationDrawer({Key? key}) : super(key: key);

  @override
  State<NavigationDrawer> createState() => _NavigationDrawerState();
}

class _NavigationDrawerState extends State<NavigationDrawer> {



  @override
  Widget build(BuildContext context) {
    User? usuario = FirebaseAuth.instance.currentUser;
    var correo = usuario!.email;
    bool esAmbassador = false;
    String avatar ="";
    String alias = "";

    //global key para el DRawer

    GlobalKey<ScaffoldState> _key = GlobalKey();


    Stream<DocumentSnapshot<Map<String, dynamic>>> documentStream = FirebaseFirestore.instance.collection('perfiles').doc(correo).snapshots();

    return StreamBuilder<DocumentSnapshot<Map<String, dynamic>>>(
      stream: documentStream,
      builder: (context, snapshot) {

        if(snapshot.connectionState == ConnectionState.active){
          print("avatar es ${snapshot.data!['alias']}");
          print("esBmx es ${snapshot.data!['esBmx']}");
          print("esAmb es ${snapshot.data!['esAmbassador']}");

          avatar = snapshot.data!['avatar'];
          alias = snapshot.data!['alias'];

          if(snapshot.data!['esAmbassador']){
            esAmbassador = true;
          }
          else{
            esAmbassador = false;
          }
        }
        return Drawer(
          child:ListView(
            children: [
              DrawerHeader(
                decoration: BoxDecoration(
                  color: AppColors.rojoMovMap,
                ),
                child: Center(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            Container(
                              width: 100,
                              height: 100,
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(180),
                                border: Border.all(color: Colors.black, width: 4),
                                image: DecorationImage(
                                    fit: BoxFit.fill, image: NetworkImage(avatar)),
                              ),
                            ),
                          ],
                        ),
                      ),
                      Row(
                        children: [
                          Text(alias,style: TextStyle(fontSize: 18,fontWeight: FontWeight.bold,color: Colors.white),)
                        ],
                      )
                    ],
                  ),
                ),
              ),
              ListTile(
                title: Text("drawer1".tr(),style: TextStyle(fontSize: 16),),
                leading: Container(
                  width: 30,
                  height: 30,
                  decoration: BoxDecoration(
                      image: DecorationImage(
                          image: AssetImage("assets/images/edit_profile.png")
                      )
                  ),
                ),
                onTap: ()
                {

                  Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) => EditarPerfil1(), //#0006
                      ));

                },
              ),

              ListTile(
                title: Text("drawer2".tr(),style: TextStyle(fontSize: 16),),
                leading: Container(
                  width: 30,
                  height: 30,
                  decoration: BoxDecoration(
                    image: DecorationImage(
                      image: AssetImage("assets/images/mi_network.png")
                    )
                  ),
                ),
                onTap: ()
                {

                  Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) => MiNetwork(), //#0006
                      ));

                },
              ),

              ListTile(
                title: Text("drawer3".tr(),style: TextStyle(fontSize: 16),),
                leading: Container(
        width: 30,
        height: 30,
        decoration: BoxDecoration(
        image: DecorationImage(
        image: AssetImage("assets/images/privacy.png")
        )
        ),
        ),
                onTap: ()
                {

                  Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) => TermsUso(), //#0006
                      ));

                },
              ),
              ListTile(
                title: Text("drawer4".tr(),style: TextStyle(fontSize: 16),),
                leading: Container(
                  width: 30,
                  height: 30,
                  decoration: BoxDecoration(
                      image: DecorationImage(
                          image: AssetImage("assets/images/contact.png")
                      )
                  ),
                ),
                onTap: ()
                {

                  Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) => Contacto(), //#0006
                      ));

                },
              ),
              ListTile(
                title: Text("drawer5".tr(),style: TextStyle(fontSize: 16),),
                leading: Container(
                  width: 30,
                  height: 30,
                  decoration: BoxDecoration(
                      image: DecorationImage(
                          image: AssetImage("assets/images/about.png")
                      )
                  ),
                ),
                onTap: ()
                {

                  Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) =>  AcercaDe(), //#0006
                      ));

                },
              ),
              ListTile(
                title: Text("drawer6".tr(),style: TextStyle(fontSize: 16),),
                leading: Container(
                  width: 30,
                  height: 30,
                  decoration: BoxDecoration(
                      image: DecorationImage(
                          image: AssetImage("assets/images/ic_ambassador.png")
                      )
                  ),
                ),
                onTap: ()
                {

                  Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) => ConvertirAmb(), //#0006
                      ));

                },
              ),
              ListTile(
                title: Text("drawer7".tr(),style: TextStyle(fontSize: 16),),
                leading: Container(
                  width: 30,
                  height: 30,
                  decoration: BoxDecoration(
                      image: DecorationImage(
                          image: AssetImage("assets/images/salir.png")
                      )
                  ),
                ),
                onTap: ()
                {

                  ServiciosFirebaseUsuario().cerrarSesion(context);

                },
              )
            ],
          ) ,
        );
    });
      }




}

All errors are related to that widget, like here in class UsuarioPage:

   return SafeArea(

      child: Scaffold(
        drawer: NavigationDrawer(key: widget.key,),
        appBar: AppBar(
          title: Text(miEmail!),
        ),


        body:
              Column(
                children:[

And this is the error output:

>Solution :

NavigationDrawer is name of a flutter Widget,try changing the name of your class to something else

Leave a ReplyCancel reply