问题描述
在我的应用程序中,我有此弹出菜单,尽管有一些触发器,但该菜单除外。因此,我尝试将其创建为分离文件,然后在需要时将其调用。
它似乎不起作用。我需要使用在调用类时定义的自定义文本来实现此目的。因此,当您单击按钮时,信息文本必须为X,另一个为Y。
PopupMenu文件:
import [...]
void customWebLaunch(command) async {
[...]
}
class PopUpMenu extends StatelessWidget {
final String title;
final String info;
const PopUpMenu({Key key,@required this.title,@required this.info})
: assert(title != null),super(key: key);
@override
Widget build(BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder (
borderRadius: BorderRadius.circular(borderRadius*3/2),),child: [...]
);
}
}
[under Widget build{ [...] }]
sendEmailPopUp(BuildContext context) {
showDialog(
context: context,builder: (BuildContext context){
return Dialog(
shape: RoundedRectangleBorder (
borderRadius: BorderRadius.circular(borderRadius*3/2),child: [...]
);
}
);
}
解决方法
您可以检查以下代码。
class test {
final BuildContext context;
final bool crossButton;
// ignore: non_constant_identifier_names
final bool cross_Button_Left;
final double message_to_button_gap;
test({
Key key,@required this.context,this.crossButton = false,this.cross_Button_Left = false,this.message_to_button_gap = 18.0,});
@override
Future show() => showDialog(
context: this.context,builder: (BuildContext context) {
return Theme(
data: ThemeData(dialogBackgroundColor: Colors.lightGreenAccent),child: AlertDialog(
elevation: 10,clipBehavior: Clip.antiAliasWithSaveLayer,title: Column(
children: <Widget>[
crossButton
? Align(
alignment: cross_Button_Left
? Alignment.topRight
: Alignment.topLeft,child: InkWell(
child: Icon(Icons.close),onTap: () {
Navigator.pop(context);
},),)
: Container(),crossButton
? SizedBox(
height: 20,width: 8,Icon(
Icons.dashboard,color: Colors.red,size: 22,SizedBox(
height: 8,new Text(
"message",style: TextStyle(fontSize: 22,color: Colors.black),SizedBox(
height: message_to_button_gap,FloatingActionButton.extended(
onPressed: () async {
Navigator.pop(context);
},backgroundColor: Color(0xff8154b7),label: Text(
"buttonName",style: TextStyle(color: Color(0xff230238)),],);
});
}
并从下面的另一个文件中调用它。
RaisedButton(
child: Text("abc"),onPressed: () {
PositiveAlert(context: context,messageIcon: false).show();
},)