I'm trying to create a function which shows a AlertDialog with a text form field. user will enter a value into this field and then will push the "ok" button. I want to return entered string value when the ok button pressed. but I'm getting The return type 'String' isn't a 'void', as required by the closure's context. error at the return line. Also getting The body might complete normally, causing 'null' to be returned, but the return type, 'String', is a potentially non-nullable type error at the first line.
what should I do?
String enterValue(TextInputType keyType) {
String girilenDeger = '';
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('enter_value').tr(),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextFormField(
style: const TextStyle(fontSize: 18, color: Colors.black),
initialValue: '',
keyboardType: keyType,
autofocus: true,
onChanged: (val) {
girilenDeger = val;
},
),
],
),
actions: [
ElevatedButton(
onPressed: () {
return girilenDeger;
},
child: const Text('ok').tr(),
),
],
),
);
}
Please try this
btw, i remove your
.tr()