如何解决使用凸起按钮显示对话框
所以我试图使用凸起的按钮显示一个对话框。但是当我按下它时,屏幕会变黑。谁能告诉我我的代码有什么问题:
这是我的按钮的代码:
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(),)
);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。