I have a problem with Dismissible widget. I use that to close actual page by calling a function:

onDismissed: (_) => Navigator.of(context).pop().

so what I did: wrap whole scaffold by Dismissible.

Everything worked fine until delivered to the page state with bool information about the logged in user (admin or no). Now i get error like this:

FlutterError (A dismissed Dissmisible widget is still part of the tree. Make sure to implement the onDismissed handler and to immediately remove the Dismissible widget from the application once that has fired.)

Screen: ErrorScreen

I tried "key" changes but it didn't help.

Page code with Dismissible:

class OtherDetailsPage extends StatelessWidget {
  const OtherDetailsPage({required this.id, Key? key}) : super(key: key);

  final String id;

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) =>
          OtherDetailsCubit(OtherRemoteDataSource())..getDetailsWithID(id),
      child: BlocBuilder<OtherDetailsCubit, OtherDetailsState>(
        builder: (context, details) {
          final detail = details.detailsState;
          return BlocBuilder<RootCubit, RootState>(
            builder: (context, root) {
              bool? admin = root.admin;

              if (admin == null || detail == null) {
                return const LoadingPage();
              }
              return Dismissible(
                key: const Key('key'),
                // key: Key(UniqueKey().toString()),
                direction: DismissDirection.down,
                onDismissed: (_) => Navigator.of(context).pop(),
                child: Scaffold(
                    body: Column(
                  children: [
                    Header(detail: detail),
                    const SizedBox(
                      height: 20,
                    ),
                    DetailsDescription(detail: detail),
                    const SizedBox(
                      height: 50,
                    ),
                    admin
                        ? SwitchValueButton(id: id, detail: detail)
                        : const SizedBox(
                            height: 1,
                          ),
                    const AnimatedArrowDown()
                  ],
                )),
              );
            },
          );
        },
      ),
    );
  }
}