i have a screen that have many tiles, when i click the tile button, a custom showDialog must appear, in the custom dialog i want to call a bloc event, but i have the following error:
Error: Could not find the correct Provider above this
Builder Widget
Here is the tile code:
class EditTile extends StatefulWidget {
final String currentText;
final String field;
final Row row;
const EditTile({super.key, required this.row, required this.field, required this.currentText});
@override
State<EditTile> createState() => _EditTileState();
}
class _EditTileState extends State<EditTile> {
@override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height * .05,
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).colorScheme.secondary,
width: 1,
),
borderRadius: BorderRadius.circular(8)),
child:
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
SizedBox(
width: MediaQuery.of(context).size.height * .01,
),
widget.row,
EditPen(
onTap: () {
showEditFieldDialog(context, widget.currentText , "name");
},
)
]));
}
}
and here is my custom dialog code:
Future showEditFieldDialog(
BuildContext context, String currentText, String editedField)async {
return showDialog(
context: context,
builder: (context) {
editingController.text = currentText;
return AlertDialog(
backgroundColor: Colors.white,
title: Text(editedField),
content: SizedBox(
height: MediaQuery.of(context).size.height * 0.09,
child: MyTextField(
controller: editingController,
hintText: "$editedField",
obscureText: false,
keyboardType: TextInputType.phone,
validator: (val) {
if (val!.isEmpty) {
return "fill This Field";
}
return null;
}),
),
actions: [
TextButton(
onPressed: () {
context.read<EditDriverBloc>().add(UpdateInput(editedField, editingController.text));
},
child: Text(
"Submit",
style:
TextStyle(color: Theme.of(context).colorScheme.secondary),
)),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: Text("Cancel",
style: TextStyle(
color: Theme.of(context).colorScheme.secondary))),
],
);
},
);
}
i tried to add BlocProvider and BlocProvider.value before navigating to the screen that has the tiles, and adding it before every tile and adding it before showDialog and before AlertDialog
but non of the tries has worked and it keeps showing the same error