在此處輸入圖像描述void cruptoalert(){ showDialog( context: context, builder: (BuildContext context) =>
CupertinoAlertDialog(
title: Text('Accept?'),
content: Text('Do you accept?'),
actions: [
CupertinoDialogAction(child: Text("Yes"),onPressed:() {
Navigator.pop(context);
alert();
}),
CupertinoDialogAction(child: Text("No"))]),
barrierDismissible: 假, ); }我已經創建的警報對話框調用的函數,而是按照我的需要,我可以不設計,圖片鏈接在下面
您需要構建自定義對話框,如果我沒猜錯,您會期待這個:
class CustomView extends StatelessWidget {
const CustomView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () {
showFancyCustomDialog(context);
},
child: const Text("Open"))));
}
}
void showFancyCustomDialog(BuildContext context) {
Dialog fancyDialog = Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
),
height: 200.0,
width: 200.0,
child: Stack(
children: <Widget>[
Container(
alignment: Alignment.center,
width: double.infinity,
height: 200,
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(12.0),
),
child: Text(
"Do you want to discard your\nFeedback",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.blue,
fontSize: 18,
fontWeight: FontWeight.w600),
),
),
Container(
width: double.infinity,
height: 50,
alignment: Alignment.bottomCenter,
decoration: BoxDecoration(
color: Colors.white,
border: Border(
bottom: BorderSide(width: 2.0, color: Colors.black26),
),
),
child: Align(
alignment: Alignment.center,
child: Text(
"Confirmation",
style: TextStyle(
color: Colors.blue.shade900,
fontSize: 20,
fontWeight: FontWeight.w600),
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
width: double.infinity,
height: 50,
decoration: BoxDecoration(
color: Colors.white,
border: Border(
top: BorderSide(width: 2.0, color: Colors.black26),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: InkWell(
onTap: () {
Navigator.of(context).pop();
},
child: Container(
alignment: Alignment.center,
child: Text(
"No",
style: TextStyle(
color: Colors.blue,
fontSize: 20,
fontWeight: FontWeight.w600),
),
),
),
),
VerticalDivider(
thickness: 1,
color: Colors.grey[300],
),
Expanded(
child: InkWell(
onTap: () {
Navigator.of(context).pop();
},
child: Container(
alignment: Alignment.center,
child: Text(
"Yes",
style: TextStyle(
color: Colors.blue,
fontSize: 20,
fontWeight: FontWeight.w600),
),
),
),
),
],
)),
),
],
),
),
);
showDialog(context: context, builder: (BuildContext context) => fancyDialog);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句