<code>class ProfileView extends StatelessWidget {
const ProfileView({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => ProfileCubit(
context.read<AuthenticationRepository>(),
context.read<RemoteRepository>(),
sessionCubit: context.read<SessionCubit>(),
),
child: const ProfileViewContent(),
);
}
}
class ProfileViewContent extends StatefulWidget {
const ProfileViewContent({super.key});
@override
State<ProfileViewContent> createState() => _ProfileViewContentState();
}
class _ProfileViewContentState extends State<ProfileViewContent>
with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return Scaffold(
body: BlocBuilder<SessionCubit, SessionState>(
builder: (context, state) {
return state.authStatus.maybeWhen(
<...>
authenticated: (_) => DefaultTabController(
length: 2,
child: Scaffold(
appBar: const _AuthenticatedAppBar(),
body: CustomScrollView(
shrinkWrap: true,
slivers: [
<...>
const SliverFillRemaining(
child: TabBarView(
children: [
_MySightingsList(),
],
),
),
<...>
}
class _MySightingsList extends StatelessWidget {
const _MySightingsList();
@override
Widget build(BuildContext context) {
return BlocBuilder<ProfileCubit, ProfileState>(
builder: (context, state) {
<...>
return GridView.builder(
<...>
itemBuilder: (_, i) {
final item = state.records![i];
return GestureDetector(
onTap: () {
_onTapped(context, item);
},
<...>
}
void _onTapped(BuildContext context, Sighting item) {
final Sighting sighting = item;
final Atlas atlas = context.read<ProfileCubit>().state.activeAtlas;
showModalBottomSheet(
<...>
builder: (context) => ContextMenu(
items: [
ContextMenuItem(
<...>
),
ContextMenuItem(
<...>
onTap: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
),
<...>
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
translate("activities.delete_popup.description"),
),
const SizedBox(height: 24),
CustomElevatedButton(
onPressed: () async {
await context
.read<ProfileCubit>()
.deleteSighting(sighting, atlas); // Throws error
<...>
}
</code>
<code>class ProfileView extends StatelessWidget {
const ProfileView({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => ProfileCubit(
context.read<AuthenticationRepository>(),
context.read<RemoteRepository>(),
sessionCubit: context.read<SessionCubit>(),
),
child: const ProfileViewContent(),
);
}
}
class ProfileViewContent extends StatefulWidget {
const ProfileViewContent({super.key});
@override
State<ProfileViewContent> createState() => _ProfileViewContentState();
}
class _ProfileViewContentState extends State<ProfileViewContent>
with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return Scaffold(
body: BlocBuilder<SessionCubit, SessionState>(
builder: (context, state) {
return state.authStatus.maybeWhen(
<...>
authenticated: (_) => DefaultTabController(
length: 2,
child: Scaffold(
appBar: const _AuthenticatedAppBar(),
body: CustomScrollView(
shrinkWrap: true,
slivers: [
<...>
const SliverFillRemaining(
child: TabBarView(
children: [
_MySightingsList(),
],
),
),
<...>
}
class _MySightingsList extends StatelessWidget {
const _MySightingsList();
@override
Widget build(BuildContext context) {
return BlocBuilder<ProfileCubit, ProfileState>(
builder: (context, state) {
<...>
return GridView.builder(
<...>
itemBuilder: (_, i) {
final item = state.records![i];
return GestureDetector(
onTap: () {
_onTapped(context, item);
},
<...>
}
void _onTapped(BuildContext context, Sighting item) {
final Sighting sighting = item;
final Atlas atlas = context.read<ProfileCubit>().state.activeAtlas;
showModalBottomSheet(
<...>
builder: (context) => ContextMenu(
items: [
ContextMenuItem(
<...>
),
ContextMenuItem(
<...>
onTap: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
),
<...>
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
translate("activities.delete_popup.description"),
),
const SizedBox(height: 24),
CustomElevatedButton(
onPressed: () async {
await context
.read<ProfileCubit>()
.deleteSighting(sighting, atlas); // Throws error
<...>
}
</code>
class ProfileView extends StatelessWidget {
const ProfileView({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => ProfileCubit(
context.read<AuthenticationRepository>(),
context.read<RemoteRepository>(),
sessionCubit: context.read<SessionCubit>(),
),
child: const ProfileViewContent(),
);
}
}
class ProfileViewContent extends StatefulWidget {
const ProfileViewContent({super.key});
@override
State<ProfileViewContent> createState() => _ProfileViewContentState();
}
class _ProfileViewContentState extends State<ProfileViewContent>
with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return Scaffold(
body: BlocBuilder<SessionCubit, SessionState>(
builder: (context, state) {
return state.authStatus.maybeWhen(
<...>
authenticated: (_) => DefaultTabController(
length: 2,
child: Scaffold(
appBar: const _AuthenticatedAppBar(),
body: CustomScrollView(
shrinkWrap: true,
slivers: [
<...>
const SliverFillRemaining(
child: TabBarView(
children: [
_MySightingsList(),
],
),
),
<...>
}
class _MySightingsList extends StatelessWidget {
const _MySightingsList();
@override
Widget build(BuildContext context) {
return BlocBuilder<ProfileCubit, ProfileState>(
builder: (context, state) {
<...>
return GridView.builder(
<...>
itemBuilder: (_, i) {
final item = state.records![i];
return GestureDetector(
onTap: () {
_onTapped(context, item);
},
<...>
}
void _onTapped(BuildContext context, Sighting item) {
final Sighting sighting = item;
final Atlas atlas = context.read<ProfileCubit>().state.activeAtlas;
showModalBottomSheet(
<...>
builder: (context) => ContextMenu(
items: [
ContextMenuItem(
<...>
),
ContextMenuItem(
<...>
onTap: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
),
<...>
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
translate("activities.delete_popup.description"),
),
const SizedBox(height: 24),
CustomElevatedButton(
onPressed: () async {
await context
.read<ProfileCubit>()
.deleteSighting(sighting, atlas); // Throws error
<...>
}
I have an issue in my flutter app. When the deleteSighting() function is being called, I get the following error:
<code>[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Error: Could not find the correct Provider<ProfileCubit> above this Builder Widget
</code>
<code>[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Error: Could not find the correct Provider<ProfileCubit> above this Builder Widget
</code>
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Error: Could not find the correct Provider<ProfileCubit> above this Builder Widget
This doesn’t seem to happen at other points in my _onTapped function, for example I can access my “state.activeAtlas” just fine. I don’t really understand why that is the case. Can someone help me out here?