在我的情况下,我使用简单的 textInput 和一个按钮创建对话框,当用户单击按钮时,以编程方式处理 edittext
class MyDialogs {
bool showed = false;
void dismiss(BuildContext context) {
if (showed) {
Navigator.pop(context);
}
}
void showCaptcha(
BuildContext context,
) {
String? errorText;
showDialog(
barrierDismissible: false,
context: context,
builder: (context) {
showed = true;
const Color accentColor = Colors.teal;
TextEditingController editingController = TextEditingController();
return StatefulBuilder(builder: (context, setState) {
return Dialog(
backgroundColor: Colors.transparent,
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Container(
width: 360,
child: TextField(
controller: editingController,
decoration: const InputDecoration(
border: InputBorder.none,
hintText: 'Enter seen text',
hintStyle: TextStyle(color: Colors.grey),
))),
TextButton(
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
backgroundColor: accentColor,
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: const [
Text(
'authorize ',
style: TextStyle(
color: Colors.white, fontSize: 18),
),
Icon(
Icons.security,
color: Colors.white,
)
],
),
),
onPressed: () {
{
String text = editingController.text;
if (text.isEmpty) {
setState(() {
errorText = 'please enter seen text';
});
return;
}
editingController.dispose();
dismiss(context);
// if (onClicker != null) {}
}
},
),
],
));
});
});
}
}