使用凸起按钮显示对话框

问题描述

所以我试图使用凸起的按钮显示一个对话框。但是当我按下它时,屏幕会变黑。谁能告诉我我的代码有什么问题:

这是我的按钮的代码:

 Container(
        child: SizedBox(
          height: 50.0,width: 150.0,child: RaisedButton(
            onPressed: () {
              Navigator.of(context).pop();
              SuccessfulDialog();
            },child: Text(
              "Send Request",style: TextStyle(
                fontFamily: "Poppins",fontSize: 17,fontWeight: FontWeight.w500,),color: Colors.blue,textColor: Colors.white,

这是我的对话框的代码,它放在我的库的 components 文件夹中

import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SuccessfulDialog extends StatefulWidget {
final String title;
final String description;
final List<Widget> actions;
final String imageAsset;
const SuccessfulDialog({
Key key,this.title,this.description,this.imageAsset,this.actions,}) : super(key: key);

@override
_SuccessfulDialogState createState() => _SuccessfulDialogState();
}

class _SuccessfulDialogState extends State<SuccessfulDialog> {
double padding = 50;
double avatarRadius = 45;
double width = Get.width;

 @override
 Widget build(BuildContext context) {
  return Dialog(
  shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.circular(20),elevation: 0,backgroundColor: Colors.transparent,child: contentBox(context),);

}

contentBox(context) {
var sidePadding = width * .17;
return Scaffold(
  body: Container(
    width: width,child: SingleChildScrollView(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
          SizedBox(
            height: 38,Image(
            image: AssetImage('assets/images/logo.png'),width: width,SizedBox(
            height: 15,],);
  }

   Widget buildAppointmentText() {
  return Padding(
    padding: EdgeInsets.only(left: 10,top: 10,right: 10,bottom: 10),child:
        Text(' You have added and appointment' + 'with {Exhibitor Name} on',style: TextStyle(
              color: Colors.blue,fontFamily: "DMSans",fontSize: 15,)));
   }

 Widget buildDateText() {
 return Padding(
  padding: EdgeInsets.all(
    10,child: Text('May 27,2021,Tuesday' + '5:30 PM',style: TextStyle(
        color: Colors.black,)),);
 }

 Widget buildViewButton() {
return Padding(
  padding: EdgeInsets.only(
    left: 35.0,right: 35.0,top: 100,child: SizedBox(
    width: 400.0,height: 60.0,child: RaisedButton(
      onPressed: () {},child: Text(
        "Reset Password",style: TextStyle(
          fontFamily: "Poppins",letterSpacing: -0.3,fontSize: 14.0,shape: new RoundedRectangleBorder(
        borderRadius: new BorderRadius.circular(
          40.0,);
  }

  Widget buildReturnText() {
  return Padding(
    padding: EdgeInsets.only(right: 10,left: 10,child: Text("Return to Exhibitor's Booth",style: TextStyle(
          color: Colors.blue,fontFamily: "Poppins",fontSize: 14,)));
            }
        }

或者有没有其他方法可以做到这一点?

解决方法

您可以使用 showDialog 函数显示自定义对话框

onPressed: () {
    showDialog(context: context,builder: (BuildContext context){
          return SuccessfulDialog(
             title: "Custom Dialog Title",descriptions: "Dialog description",);
       }
     );
}
,

你可以使用showDialog来显示对话框请参考下面的代码

showDialog(
        context: context,builder: (_) => AlertDialog(
            title: Text('Dialog Title'),content: SuccessfulDialog(),)
    );

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...