I want to create functions that run tasks but don't return anything. But I keep getting _TypeError (type 'Null' is not a subtype of type 'Widget'). Please help me fix this! Below is the code for one of my functions and Widget build code block:
addToList()
if (dbc != false) {
times.add(dbc2);
};
if (ssc!= false) {
times.add(ssc2);
};
if (egc!= false) {
times.add(egc2);
};
if (dahc!= false) {
times.add(dahc2);
};
if (gfac!= false) {
times.add(gfac2);
};
if (trc!= false) {
times.add(trc2);
};
if (tsnc!= false) {
times.add(tsnc2);
};
if (yc!= false) {
times.add(yc2);
};
if (cac != false) {
times.add(cac2);
};
if (myoex!= false) {
times.add(myoex2);
};
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text('Hello!'),
),
body: Column(
children: <Widget>[
const Text(
'Here it is:',
style: TextStyle(fontSize: 30),
textAlign: TextAlign.left,
),
addToList(),
} ```
**After I run addToList(), I have more widgets in my column and have proper parenthesis - There are no errors with those. I'd appreciate any advice!**
CodePudding user response:
you are passing a function addTodoList() in your column and that's not possible as it's not a widget
CodePudding user response:
Could you please be more clear with what you are trying to achieve. You can refer to this for help.
As was previously stated, the widget tree can only return Widgets. Your function addtoList()
doesn't return anything.
Happy to try and help you resolve your issue but you will need to be more clear.
The Flutter docs have lots of useful information that I encourage you to refer to, they have certainly helped me become a better developer :)
CodePudding user response:
Sometimes we may encounter such errors due to type mismatches. For example, a year is a number but we can ask to write by a string I mean a TEXT. In similar cases, you can use .toString. For example;
print (mesaj); print ("Doğum yılı : " dogumYili.toString()); print("Oran : " oran.toString());