Home > Software design >  flutter custom popup menu or show dialog
flutter custom popup menu or show dialog

Time:04-07

enter image description here

how can i do this i tried to use popupmenubutton but it didn't work as i wanted. is there any widget or something you can suggest?What can i do for this anyone know?Can i use showdialog.What is the solve of this problem in flutter.How can i show this popup on screen.I tried almost everything anyone help pls.is there a way to do this in flutter

CodePudding user response:

first use this code where you want to call the dialog box like in onTap function

 showGeneralDialog(
                                        context: context,
                                        barrierDismissible: true,
                                        
                                        barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
                                        barrierColor: Colors.black.withOpacity(0.5),
                                        pageBuilder: (context, animation1, animation2) =>BargainRespondDialog(),
                                        transitionDuration: Duration(milliseconds: 500),
                                        transitionBuilder: (context, a1, a2, widget) {
                                      
                                            return Transform.scale(
                                              scale: a1.value,
                                              child: Opacity(
                                                opacity: a1.value,
                                                child: widget,
                                              ),
                                            );
                                          
                                        },
                                      );

make a class and use this code

import 'package:flutter/material.dart';


class BargainRespondDialog extends StatefulWidget {

  @override
  State<BargainRespondDialog> createState() => _BargainRespondDialogState();
}

class _BargainRespondDialogState extends State<BargainRespondDialog> {


  @override
  Widget build(BuildContext context) {

    return Dialog(
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0)),
      child: SingleChildScrollView(
        child:Column(
          children:[
            SizedBox(height:10),
                             Icon(Icons.beenhere_sharp ),
                             SizedBox(height:10),
                             Text('We have received your bargain request', style: TextStyle(fontSize: 18,color: Colors.blue), textAlign: TextAlign.center,
                             ),
                                Padding(
                                  padding: EdgeInsets.only(top:15,left:5,right:5),
                                  child: Text('Our team will review your request and get back to you within 24 to 48 hours.', textAlign: TextAlign.center),
                                ),
                                SizedBox(height:10),
                                 GestureDetector(
                                   onTap: (){
                                     Navigator.of(context).pop();
                                   },
                                   child: Padding(
                                     padding: const EdgeInsets.all(8.0),
                                     child: Container(
                                       height: 30,
                                       width: 50,
                                       color: Colors.blue,
                                       child: Center(
                                         child: Text('OK', style: TextStyle(fontSize: 15,color: Colors.white), textAlign: TextAlign.center,
                                                                    ),
                                       ),
                                     ),
                                   ),
                                 ),
                                
                             ]), ),
    );

  }
  
}

if it helps you .please mark it as an accepted answer

CodePudding user response:

enter image description here

void showCustomDialog(BuildContext context) {
      showGeneralDialog(
        context: context,
        barrierLabel: "Barrier",
        barrierDismissible: true,
        barrierColor: Colors.black.withOpacity(0.6),
        transitionDuration: Duration(milliseconds: 800),
        pageBuilder: (_, __, ___) {
          return Center(
            child: Container(
              height: 250,
              child: SizedBox.expand(child: FlutterLogo()),
              margin: EdgeInsets.symmetric(horizontal: 20),
              decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(30)),
            ),
          );
        },
        transitionBuilder: (_, anim, __, child) {
          Tween<Offset> tween;
          if (anim.status == AnimationStatus.reverse) {
            tween = Tween(begin: Offset(-1, 0), end: Offset.zero);
          } else {
            tween = Tween(begin: Offset(1, 0), end: Offset.zero);
          }
      
          return SlideTransition(
            position: tween.animate(anim),
            child: FadeTransition(
              opacity: anim,
              child: child,
            ),
          );
        },
      );
    }
  • Related