I’m new to flutter
How do I print the data from getAge() to ListTile(title: )?
Here’s the code:
const Divider(),
const ListTile(
leading: Icon(Icons.face),
title: Text(''),
subtitle: Text('Age'),
),
];
return ListView(children: listTiles);
}
}
void getAge() {
final DateTime now = DateTime.now();
final DateTime birthday = DateTime.parse('1985-8-13');
final age = now.year -
birthday.year -
(now.month > birthday.month
? 0
: now.month == birthday.month
? now.day >= birthday.day
? 0
: 1
: 1);
print(age);
}
Here’s the image:
3
Answers
You don’t "print" to a Widget. you provide it by making it return from the function. Change your function to
And then use like
your first issue is your time format, your month should be
08
, then return age fromgetAge()
:then call it like this, don forgot to remove
const
beforeListTile
: