Line data Source code
1 : import 'package:cwtch/widgets/passwordfield.dart'; 2 : import 'package:flutter/material.dart'; 3 : import 'package:cwtch/l10n/app_localizations.dart'; 4 : 5 0 : void showPasswordDialog(BuildContext context, String title, String action, Function(String) onEntered) { 6 0 : TextEditingController passwordController = TextEditingController(); 7 0 : CwtchPasswordField passwordField = CwtchPasswordField( 8 : controller: passwordController, 9 0 : validator: (passsword) { 10 : return null; 11 : }, 12 : ); 13 : 14 : // set up the buttons 15 0 : Widget cancelButton = ElevatedButton( 16 0 : child: Text(AppLocalizations.of(context)!.cancel), 17 0 : onPressed: () { 18 0 : Navigator.of(context).pop(); // dismiss dialog 19 : }, 20 : ); 21 0 : Widget continueButton = ElevatedButton( 22 0 : child: Text(action), 23 0 : onPressed: () { 24 0 : onEntered(passwordController.value.text); 25 : }, 26 : ); 27 : 28 : // set up the AlertDialog 29 0 : AlertDialog alert = AlertDialog(title: Text(title), content: passwordField, actions: [cancelButton, continueButton]); 30 : 31 : // show the dialog 32 0 : showDialog( 33 : context: context, 34 0 : builder: (BuildContext context) { 35 : return alert; 36 : }, 37 : ); 38 : }