I’m trying to use _showWindow function but I’m getting
A value of type ‘Object’ can’t be assigned to a variable of type
‘List’
error.
void _addBook(BuildContext context) async {
List<dynamic> result = await _showWindow(context, "Enter the book name") ?? [];
}
_showWindow function:
Future<String?> _showWindow(BuildContext context, String title) {
return showDialog<String>(
context: context,
builder: (context) {
String result = "";
return AlertDialog(
title: Text(title),
content: TextField(
keyboardType: TextInputType.text,
onChanged: (String inputText) {
result = inputText;
},
),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.pop(context, "");
},
child: Text("Cancel")),
TextButton(
onPressed: () {
Navigator.pop(context, result.trim());
},
child: Text("Approve"))
],
);
});
}
How can I solve my problem? Thank you.
3
Answers
showDialog is not a list type, you will need to update your whole logic and code structure assuming what you want to do is keep a list of all the Books entered from the Dialog.
_showWindow
returnsString?
notList<dynamic>
.Here’s one way to handle this:
}
**You need to return the List of Object you can’t return the Widget in the Future<String?> U Need To return List in _showWindow Please Modify the code **