0

In flutter, using the sqflite package I can create a database, using this raw query... A

await db.execute('CREATE TABLE Article (id INTEGER PRIMARY KEY, title TEXT, description TEXT, url TEXT, urltoimage TEXT, publishedat TEXT)');`

I can then write data to the database like this... B

await txn.rawInsert('INSERT INTO Article(title, description, url, urltoimage, publishedat) VALUES("$title", "$description", "$url", "$urlToImage", "$publishedAt")');

Then I can retrieve this data as so... C

List<Map> title = await database.rawQuery('SELECT title FROM Article');

And finally use this data in flutter like this... D

Text('${title[index]}'),

When I use this method, I get this result upon execution of step D...

{title: Op-Ed: Does the Video Game Industry Really Need Blockchain?}

I'm aware that in properly returning this data, I'm missing a few steps. What I really want instead is something like this... E

Op-Ed: Does the Video Game Industry Really Need Blockchain?

How could I get a result like E instead?

2 Answers 2

4

type of query is List<Map<String, dynamic>>

you can return the result by getting a key like this

Text('${title[index]["title"]}'),
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Ahmed I’ll take a look at this soon
1

Your title variable is type of List of Map and the one element of list is in map for that what you see:

{title: Op-Ed: Does the Video Game Industry Really Need Blockchain?}

key is the title and value is Op-Ed: Does the Video Game Industry Really Need Blockchain?

So, in order to access the value you have to use your title key with list index:

ex: title[0]['title']

To get all element in list you can map like below:

Column(
  children: title.map((e) => {
    return Text(e['title'] ?? '');//if title is empty add empty string by ??
  }).toList();
),

or you can use ListView.builder or any..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.