generic_bloc_provider icon indicating copy to clipboard operation
generic_bloc_provider copied to clipboard

Unable to find Bloc of type _BlocProvider<FaltasBloc>

Open freynetraul opened this issue 4 years ago • 2 comments

I have been killing my head with this problem, I do not know why it is happening, the worst thing is that it happens to me in a single sequence, here is my code

class FaltasEstudiante extends StatelessWidget { @override Widget build(BuildContext context) { // TODO: implement build return BlocProvider( child: Scaffold( body: ListFaltas(), floatingActionButton: FloatingActionButton( backgroundColor: Colors.white, foregroundColor: Colors.blue, child: Icon( Icons.add, size: 29.0, ), onPressed: () { Navigator.push(context, MaterialPageRoute(builder: (context) { return InputsFaltaScreen(); })); }, ), ), bloc: FaltasBloc()); } }

class ListFaltas extends StatefulWidget { ListFaltas({Key key}) : super(key: key);

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

class _ListaFaltas extends State<ListFaltas> { SessionBloc estebloc; FaltasBloc faltasBloc; EstudiantesBloc estudiantesBloc;

@override Widget build(BuildContext context) { estebloc = BlocProvider.of(context); faltasBloc = BlocProvider.of(context); estudiantesBloc = BlocProvider.of(context); faltasBloc.initE(estudiantesBloc.modelEstudiante.identificacion, 0); return StreamBuilder( stream: faltasBloc.counterStreamE, builder: (BuildContext context, AsyncSnapshot<List<FaltaModel>> snapshot) { if (estebloc.isOffline) { return SinConxion(); //construir pantalla sin conexión } else { if (snapshot.data != null) { if (snapshot.data.length == 0) { return Center(child: Text("No hay datos para mostrar")); } return ListView.builder( itemBuilder: (context, index) { return ReviewFaltasEstudiante(snapshot.data[index]); }, itemCount: snapshot.data.length); } else { return carga(); } } }); } }

class ReviewFaltasEstudiante extends StatelessWidget { FaltaModel faltaModel; FaltasBloc faltasBloc; ReviewFaltasEstudiante(this.faltaModel);

@override Widget build(BuildContext context) { faltasBloc = BlocProvider.of(context); // TODO: implement build return InkWell( onTap: () { print('${faltasBloc.fal[0].idNovedad} esto es prueba de que si cogio el Bloc'); /// HERE DOES WORK Navigator.push(context, new MaterialPageRoute( builder: (context) => new VerDetalle(detallefalta)) ); }, child: Card( color: Colors.blueAccent, margin: EdgeInsets.only(left: 10.0, right: 10.0, top: 5.0, bottom: 3.0), elevation: 5, child: Container( padding: EdgeInsets.only(left: 5.0, right: 3.0, top: 10.0, bottom: 5.0), child: Column( children: <Widget>[ Container( margin: EdgeInsets.only( left: 25.0, right: 10.0, top: 5.0, bottom: 3.0), child: Row( children: <Widget>[ Text( "TIPO ${faltaModel.tipo}", style: TextStyle( color: Colors.white.withOpacity(1.0), fontSize: 18, fontFamily: 'Jost', fontWeight: FontWeight.bold), ), ], ), ), Container( margin: EdgeInsets.only( left: 25.0, right: 10.0, top: 5.0, bottom: 3.0), child: Row( children: <Widget>[ Text( "Fecha ${faltaModel.fecha} ", style: TextStyle( color: Colors.white.withOpacity(1.0), fontSize: 14, fontFamily: 'Jost', ), ), ], )), Container( color: Colors.black12, margin: EdgeInsets.only( left: 15.0, right: 15.0, top: 5.0, bottom: 5.0), padding: EdgeInsets.only(top: 0.8, bottom: 0.8), ), Container( color: Colors.blueAccent, child: Row( mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[ Container( child: Column( children: <Widget>[ Text( "${faltaModel.diligenciador} ", style: TextStyle( color: Colors.white.withOpacity(1.0), fontSize: 16, fontFamily: 'Jost', fontWeight: FontWeight.bold), ), Text( "${faltaModel.sede}", style: TextStyle( color: Colors.white.withOpacity(1.0), fontSize: 16, fontFamily: 'Jost', ), ) ], )), Container( margin: EdgeInsets.only( left: 10.0, right: 5.0, top: 5.0, bottom: 5.0), height: 85, width: 85, decoration: BoxDecoration( shape: BoxShape.circle, color: Colors.white), ), ], ), ) ], ), ),

  ),
);

}

}

class VerDetalle extends StatelessWidget { FaltaModel detallefalta; VerDetalle(this.detallefalta) ; SessionBloc sessionBloc; FaltasBloc faltasBloc; @override Widget build(BuildContext context) {

faltasBloc = BlocProvider.of(context); //HERE DOES NOT WORK, DOES NOT FIND ANCESTOR WITH EXACT TYPE...
sessionBloc= BlocProvider.of(context);
return Scaffold(
  appBar: new AppBar(
    elevation: 1,
    iconTheme: IconThemeData(color: Colors.lightBlue),
    backgroundColor: Colors.white,
    title: new Center(
        child: new Text(
      "Reporte Completo",
      textAlign: TextAlign.center,
      style: new TextStyle(
          color: Colors.black,
         fontWeight: FontWeight.bold,  fontFamily: 'Jost'
         ),
    )),
  ),
  body: DetalleFalta(detallefalta),
  floatingActionButton:SpeedDial(
    marginRight: 18,
    marginBottom: 20,
    animatedIcon: AnimatedIcons.menu_home,
    animatedIconTheme: IconThemeData(size: 22.0),
    visible: detallefalta.idDiligenciador==sessionBloc.aux.id ,//
    closeManually: false,
    curve: Curves.bounceIn,
    overlayColor: Colors.black,
    overlayOpacity: 0.5,
    onOpen: () => print('OPENING DIAL'),
    onClose: () => print('DIAL CLOSED'),
    tooltip: 'Speed Dial',
    heroTag: 'speed-dial-hero-tag',
    backgroundColor: Colors.indigo,
    foregroundColor: Colors.white,
    elevation: 8.0,
    shape: CircleBorder(),
    children: [
      SpeedDialChild(
          child: Icon(Icons.edit),
          backgroundColor: Colors.lightBlue,
          label: 'Editar',
          labelStyle: TextStyle(fontSize: 18.0),
          onTap: () { /*
            print('entro');
               faltasBloc.EliminarFalta(detallefalta.idNovedad).then((elimino) => {
                 if(elimino){
                   print('elimino')
                 }else{
                   print('no elimino')
                 }
               }); */
          }),
      SpeedDialChild(
        child: Icon(Icons.delete_forever),
        backgroundColor: Colors.red,
        label: 'Eliminar',
        labelStyle: TextStyle(fontSize: 18.0),
        onTap: () => print('SECOND CHILD'),
      ),
    ],
  ) ,
);

} }

freynetraul avatar Mar 31 '21 22:03 freynetraul

It would be nice if you could prepare a minimal repo to reproduce this and share it with me.

robertohuertasm avatar Apr 01 '21 09:04 robertohuertasm

its probably updateShouldNotifyOverride types

fredgrott avatar Aug 02 '21 12:08 fredgrott