2021年3月11日星期四

Flutter , building widgets with futures, just getting a value out of the DB

So I've got a menu, and I want to simply get a single value from the db (the version ) to display...

        ListTile(                contentPadding: EdgeInsets.fromLTRB(20, 30, 0, 0),                title: FutureBuilder<Text>(                    future: getTextDbVersion(context),                    builder:                        (BuildContext context, AsyncSnapshot<Text> snapshot) {                      return snapshot.hasData ? snapshot.data : Text("not ready");                    }))            

But of course, what I'm getting is a Text widget with the text

'an instance of Future'

the method getTextDbVersion(context) , is a bit funny now as I'm trying to find my way through, but here it is.

  Future<Text> getTextDbVersion(context) async {      var val = getDbVersion(context);      print(val);      return Text(val.toString());    }      Future<int> getDbVersion(context) async {      final ContactTrackerApp app = Provider.of<ContactTrackerApp>(context);      var storage = await app.storage;        if (storage == null) {        return null;      }        return await storage.version();    }  

I'm a bit new to this full async programming, and am now sure how I just get a damn value into a string

Any help appreciated

https://stackoverflow.com/questions/66593209/flutter-building-widgets-with-futures-just-getting-a-value-out-of-the-db March 12, 2021 at 10:08AM

没有评论:

发表评论