CupertinoAlertDialog


Shows a simple Cupertino style pop-up dialog fully customizable with 2 buttons
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | import 'package:flutter/cupertino.dart' ; import 'package:flutter/material.dart' ; class ShowDialogCupertino extends StatefulWidget { const ShowDialogCupertino({Key? key}) : super (key: key); @override _ShowDialogCupertinoState createState() => _ShowDialogCupertinoState(); } class _ShowDialogCupertinoState extends State<ShowDialogCupertino> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text( "CupertinoAlertDialog" )), body: Container( padding: const EdgeInsets.all( 20 ), alignment: Alignment.center, child: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ oneSingleButton(context), ], ) ) ); } /// ********************************************************************** /// This button just for calling the AlertDialog /// ********************************************************************** Widget oneSingleButton(BuildContext context) { return ElevatedButton( onPressed: () { confirmPhoto(context); }, style: ElevatedButton.styleFrom( backgroundColor: Colors.blue, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular( 20.0 )) ), child: const Text( "Tap here" ) ); } /// ********************************************************************** /// Cupertino style dialog /// ********************************************************************** Future< void > confirmPhoto(BuildContext context) async { showCupertinoDialog( context: context, builder: (builder) => CupertinoAlertDialog( title: const Text( "Delete photo ?" ), content: const Text( "Please confirm" ), actions: [ CupertinoDialogAction( child: const Text( "Cancel" ), onPressed: () { print( "Canceled" ); Navigator.of(context).pop(); } ), CupertinoDialogAction( child: const Text( "Confirm" ), onPressed: (){ print( "Confirmed" ); Navigator.of(context).pop(); } ) ], ) ); } } |