How to make a popup after a successful update and make it disappear after 5 seconds using the cubit/bloc method?

Viewed 13
   BlocBuilder<Cubit, State>(
              bloc: _Cubit,
              builder: (context, state) {
                if (state is Loading) {
                  return SpinKitDoubleBounce(duration: const Duration(seconds: 2), color: 
                         Colors.cyan.shade300, size: 40);
                }
                if (state is VinylUpdated){
                // Answer
                }

================================================================================= STATE

 class Updated extends State {
   const Updated(MainState InitialState) : super(InitialState);
 }
1 Answers

you can just use:

showDialog(
      barrierDismissible: false,
      context: context,
      builder: (dialogContext) => YourCustomDialogWidget(
        title: title,
        description: description,
        onOk:(){..}
        onClose: (){..},
        key: key,
      ),
    );

where:

class YourCustomDialogWidget extends StatelessWidget {
      const YourCustomDialogWidget({
          required this.title,
          required this.description,
          this.onOk,
          this.onClose,
          super.key,
        });

  final String title;
  final String description;
  final VoidCallback? onOk;
  final VoidCallback? onClose;
...
}

if you need pop automatically, then use stateful widget:

class YourCustomDialogWidget extends StatefulWidget {
}

class YourCustomDialogWidgetState{

...
@override
  void initState() {
    super.initState();
    await Future.delayed(const Duration(seconds: 5), (){
      Navigator.of(context).pop();
    });
  }
...
}
Related