Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to find Bloc of type _BlocProvider<FaltasBloc> #11

Open
freynetraul opened this issue Mar 31, 2021 · 2 comments
Open

Unable to find Bloc of type _BlocProvider<FaltasBloc> #11

freynetraul opened this issue Mar 31, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@freynetraul
Copy link

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 {
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> 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: [
Container(
margin: EdgeInsets.only(
left: 25.0, right: 10.0, top: 5.0, bottom: 3.0),
child: Row(
children: [
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: [
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: [
Container(
child: Column(
children: [
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'),
      ),
    ],
  ) ,
);

}
}

@robertohuertasm
Copy link
Owner

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

@robertohuertasm robertohuertasm added the bug Something isn't working label Apr 1, 2021
@fredgrott
Copy link

its probably updateShouldNotifyOverride types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants