I think my lack of in-depth oop or async/wait knowledge may be hurting me here but I could not seem to find a working solution for myself. Please be kind.
Creating a basic countdown app for which I'm avoiding hard-coding the end-date but instead calling the data from my Flask API server so that I could make changes remotely when needed. Data is a simple Json key/value pair like {"dDate": '2012-02-27 13:27:00'}.
My goal is to receive that string API value and use it with DateTime.parse like below
DateTime myTime = DateTime.parse(dDate);
From there I'll use the myTime DateTime value to do additional calculations like below
class _TimerAppState extends State<TimerApp> {
static const duration = Duration(seconds: 1);
int timeDiff = myTime.difference(DateTime.now()).inSeconds;
Once timeDiff is calculated, then its value will be displayed on my Widget.
Where I'm struggling is transforming the following Future instance into a string that I can use. The following is what I've done so far.
Future<String> fetchDDate() async {
var dateUrl = 'my localhost addr';
var dateresponse = await http.get(Uri.parse(dateUrl));
var datedata = await jsonDecode(dateresponse.body);
var datewelcome = await datedata['dDate'];
// print(datewelcome);
return datewelcome;
}
How should I go about getting fetchDDate()'s value into my DateTime like DateTime myTime = DateTime.parse(fetchDDate());
I appreciate any guidance.