How to get element/value from a future of a list2019 Community Moderator ElectionHow to list the tables in a SQLite database file that was opened with ATTACH?How to get a list of column names on sqlite3 / iPhone?While Inserting records in SQLite returns -1How to transform Future<List<Map> to List<Map> in Dart language?Is there a way to get the Future from setMethodCallHandler?Future Builder to make Sliver ListsIs there a way to convert Future<List<String>> to List<dynamic>?Get the value of the Future<Map<String,String>> in FutureBuilderHow to get primitive value from Future object (Future<int>) in flutter?return List of Strings from Future / Stream

Should this registration form include field for password now or after user passes review?

In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?

How to draw cubes in a 3 dimensional plane

PTIJ: Should I kill my computer after installing software?

Counting all the hearts

Is "history" a male-biased word ("his+story")?

They call me Inspector Morse

How to detect if C code (which needs 'extern C') is compiled in C++

Are there historical instances of the capital of a colonising country being temporarily or permanently shifted to one of its colonies?

How can I ensure my trip to the UK will not have to be cancelled because of Brexit?

What are some noteworthy "mic-drop" moments in math?

Why does liquid water form when we exhale on a mirror?

Why was Goose renamed from Chewie for the Captain Marvel film?

Virginia employer terminated employee and wants signing bonus returned

NASA's RS-25 Engines shut down time

Find longest word in a string: are any of these algorithms good?

When traveling to Europe from North America, do I need to purchase a different power strip?

Difference on montgomery curve equation between EFD and RFC7748

Why would one plane in this picture not have gear down yet?

Is it necessary to separate DC power cables and data cables?

What problems would a superhuman have whose skin is constantly hot?

finite abelian groups tensor product.

Should I tell my boss the work he did was worthless

Rewrite the power sum in terms of convolution



How to get element/value from a future of a list



2019 Community Moderator ElectionHow to list the tables in a SQLite database file that was opened with ATTACH?How to get a list of column names on sqlite3 / iPhone?While Inserting records in SQLite returns -1How to transform Future<List<Map> to List<Map> in Dart language?Is there a way to get the Future from setMethodCallHandler?Future Builder to make Sliver ListsIs there a way to convert Future<List<String>> to List<dynamic>?Get the value of the Future<Map<String,String>> in FutureBuilderHow to get primitive value from Future object (Future<int>) in flutter?return List of Strings from Future / Stream










2















I used SQLite for the cache. Everything is working well. But I don't know how to display value from this promise? (display() returns Future<List<Token>>)



What I want is properly something like var value = display().refreshToken



print statement printing List values



print(await display());


Database.dart



 // Open the database and store the reference
import 'dart:async';

import 'package:path/path.dart';
import 'package:reborn_next_job02/models/Token.dart';
import 'package:sqflite/sqflite.dart';

databaseToken(
String tokenModel, String refreshTokenModel, String method) async
final database = openDatabase(
join(await getDatabasesPath(), 'tokenDB.db'),
onCreate: (db, version)
return db.execute(
"CREATE TABLE tokenTable(id INTEGER PRIMARY KEY, token TEXT, refreshToken TEXT)",
);
,
version: 1,
);

Future<void> insert(Token token) async
final Database db = await database;
await db.insert(
'tokenTable',
token.toMap(),
//same use insert multiple times using ConfiictAlgorithm
conflictAlgorithm: ConflictAlgorithm.replace,
);


Future<List<Token>> display() async
final Database db = await database;
final List<Map<String, dynamic>> maps = await db.query('tokenTable');

return List.generate(maps.length, (i)
return Token(
id: maps[i]['id'],
token: maps[i]['token'],
refreshToken: maps[i]['refreshToken'],
);
);


Future<void> update(Token token) async
final db = await database;

await db.update(
'tokenTable',
token.toMap(),
where: "id = ?",
whereArgs: [token.id],
);


Future<void> delete(int id) async
final db = await database;

await db.delete(
'tokenTable',
where: "id = ?",
whereArgs: [id],
);



if (method == "insert")
var token = Token(
id: 1,
token: tokenModel,
refreshToken: refreshTokenModel,
);
await insert(token);
print(await display());
else if (method == "update")
var token = Token(
id: 1,
token: tokenModel,
refreshToken: refreshTokenModel,
);
await update(token);
print(await display());




Model.dart



class Token 
int id;
String token;
String refreshToken;

Token(this.id,this.token, this.refreshToken);

factory Token.fromJson(Map<String, dynamic> json)
return Token(
id: json['id'],
token:json['token'],
refreshToken: json['refreshToken']
);

Map<String, dynamic> toMap()
return
'id': id,
'token': token,
'refreshToken': refreshToken,
;


@override
String toString()
return 'Tokenid: $id, token: $token, refreshToken: $refreshToken';











share|improve this question



















  • 1





    Perhaps you want to look into the BLoC pattern.

    – Günter Zöchbauer
    Mar 7 at 7:06











  • @GünterZöchbauer Thank Sir.

    – Bhanuka Isuru
    Mar 7 at 7:44















2















I used SQLite for the cache. Everything is working well. But I don't know how to display value from this promise? (display() returns Future<List<Token>>)



What I want is properly something like var value = display().refreshToken



print statement printing List values



print(await display());


Database.dart



 // Open the database and store the reference
import 'dart:async';

import 'package:path/path.dart';
import 'package:reborn_next_job02/models/Token.dart';
import 'package:sqflite/sqflite.dart';

databaseToken(
String tokenModel, String refreshTokenModel, String method) async
final database = openDatabase(
join(await getDatabasesPath(), 'tokenDB.db'),
onCreate: (db, version)
return db.execute(
"CREATE TABLE tokenTable(id INTEGER PRIMARY KEY, token TEXT, refreshToken TEXT)",
);
,
version: 1,
);

Future<void> insert(Token token) async
final Database db = await database;
await db.insert(
'tokenTable',
token.toMap(),
//same use insert multiple times using ConfiictAlgorithm
conflictAlgorithm: ConflictAlgorithm.replace,
);


Future<List<Token>> display() async
final Database db = await database;
final List<Map<String, dynamic>> maps = await db.query('tokenTable');

return List.generate(maps.length, (i)
return Token(
id: maps[i]['id'],
token: maps[i]['token'],
refreshToken: maps[i]['refreshToken'],
);
);


Future<void> update(Token token) async
final db = await database;

await db.update(
'tokenTable',
token.toMap(),
where: "id = ?",
whereArgs: [token.id],
);


Future<void> delete(int id) async
final db = await database;

await db.delete(
'tokenTable',
where: "id = ?",
whereArgs: [id],
);



if (method == "insert")
var token = Token(
id: 1,
token: tokenModel,
refreshToken: refreshTokenModel,
);
await insert(token);
print(await display());
else if (method == "update")
var token = Token(
id: 1,
token: tokenModel,
refreshToken: refreshTokenModel,
);
await update(token);
print(await display());




Model.dart



class Token 
int id;
String token;
String refreshToken;

Token(this.id,this.token, this.refreshToken);

factory Token.fromJson(Map<String, dynamic> json)
return Token(
id: json['id'],
token:json['token'],
refreshToken: json['refreshToken']
);

Map<String, dynamic> toMap()
return
'id': id,
'token': token,
'refreshToken': refreshToken,
;


@override
String toString()
return 'Tokenid: $id, token: $token, refreshToken: $refreshToken';











share|improve this question



















  • 1





    Perhaps you want to look into the BLoC pattern.

    – Günter Zöchbauer
    Mar 7 at 7:06











  • @GünterZöchbauer Thank Sir.

    – Bhanuka Isuru
    Mar 7 at 7:44













2












2








2








I used SQLite for the cache. Everything is working well. But I don't know how to display value from this promise? (display() returns Future<List<Token>>)



What I want is properly something like var value = display().refreshToken



print statement printing List values



print(await display());


Database.dart



 // Open the database and store the reference
import 'dart:async';

import 'package:path/path.dart';
import 'package:reborn_next_job02/models/Token.dart';
import 'package:sqflite/sqflite.dart';

databaseToken(
String tokenModel, String refreshTokenModel, String method) async
final database = openDatabase(
join(await getDatabasesPath(), 'tokenDB.db'),
onCreate: (db, version)
return db.execute(
"CREATE TABLE tokenTable(id INTEGER PRIMARY KEY, token TEXT, refreshToken TEXT)",
);
,
version: 1,
);

Future<void> insert(Token token) async
final Database db = await database;
await db.insert(
'tokenTable',
token.toMap(),
//same use insert multiple times using ConfiictAlgorithm
conflictAlgorithm: ConflictAlgorithm.replace,
);


Future<List<Token>> display() async
final Database db = await database;
final List<Map<String, dynamic>> maps = await db.query('tokenTable');

return List.generate(maps.length, (i)
return Token(
id: maps[i]['id'],
token: maps[i]['token'],
refreshToken: maps[i]['refreshToken'],
);
);


Future<void> update(Token token) async
final db = await database;

await db.update(
'tokenTable',
token.toMap(),
where: "id = ?",
whereArgs: [token.id],
);


Future<void> delete(int id) async
final db = await database;

await db.delete(
'tokenTable',
where: "id = ?",
whereArgs: [id],
);



if (method == "insert")
var token = Token(
id: 1,
token: tokenModel,
refreshToken: refreshTokenModel,
);
await insert(token);
print(await display());
else if (method == "update")
var token = Token(
id: 1,
token: tokenModel,
refreshToken: refreshTokenModel,
);
await update(token);
print(await display());




Model.dart



class Token 
int id;
String token;
String refreshToken;

Token(this.id,this.token, this.refreshToken);

factory Token.fromJson(Map<String, dynamic> json)
return Token(
id: json['id'],
token:json['token'],
refreshToken: json['refreshToken']
);

Map<String, dynamic> toMap()
return
'id': id,
'token': token,
'refreshToken': refreshToken,
;


@override
String toString()
return 'Tokenid: $id, token: $token, refreshToken: $refreshToken';











share|improve this question
















I used SQLite for the cache. Everything is working well. But I don't know how to display value from this promise? (display() returns Future<List<Token>>)



What I want is properly something like var value = display().refreshToken



print statement printing List values



print(await display());


Database.dart



 // Open the database and store the reference
import 'dart:async';

import 'package:path/path.dart';
import 'package:reborn_next_job02/models/Token.dart';
import 'package:sqflite/sqflite.dart';

databaseToken(
String tokenModel, String refreshTokenModel, String method) async
final database = openDatabase(
join(await getDatabasesPath(), 'tokenDB.db'),
onCreate: (db, version)
return db.execute(
"CREATE TABLE tokenTable(id INTEGER PRIMARY KEY, token TEXT, refreshToken TEXT)",
);
,
version: 1,
);

Future<void> insert(Token token) async
final Database db = await database;
await db.insert(
'tokenTable',
token.toMap(),
//same use insert multiple times using ConfiictAlgorithm
conflictAlgorithm: ConflictAlgorithm.replace,
);


Future<List<Token>> display() async
final Database db = await database;
final List<Map<String, dynamic>> maps = await db.query('tokenTable');

return List.generate(maps.length, (i)
return Token(
id: maps[i]['id'],
token: maps[i]['token'],
refreshToken: maps[i]['refreshToken'],
);
);


Future<void> update(Token token) async
final db = await database;

await db.update(
'tokenTable',
token.toMap(),
where: "id = ?",
whereArgs: [token.id],
);


Future<void> delete(int id) async
final db = await database;

await db.delete(
'tokenTable',
where: "id = ?",
whereArgs: [id],
);



if (method == "insert")
var token = Token(
id: 1,
token: tokenModel,
refreshToken: refreshTokenModel,
);
await insert(token);
print(await display());
else if (method == "update")
var token = Token(
id: 1,
token: tokenModel,
refreshToken: refreshTokenModel,
);
await update(token);
print(await display());




Model.dart



class Token 
int id;
String token;
String refreshToken;

Token(this.id,this.token, this.refreshToken);

factory Token.fromJson(Map<String, dynamic> json)
return Token(
id: json['id'],
token:json['token'],
refreshToken: json['refreshToken']
);

Map<String, dynamic> toMap()
return
'id': id,
'token': token,
'refreshToken': refreshToken,
;


@override
String toString()
return 'Tokenid: $id, token: $token, refreshToken: $refreshToken';








sqlite dart flutter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 10:36









TruongSinh

1,493822




1,493822










asked Mar 7 at 6:29









Bhanuka IsuruBhanuka Isuru

1039




1039







  • 1





    Perhaps you want to look into the BLoC pattern.

    – Günter Zöchbauer
    Mar 7 at 7:06











  • @GünterZöchbauer Thank Sir.

    – Bhanuka Isuru
    Mar 7 at 7:44












  • 1





    Perhaps you want to look into the BLoC pattern.

    – Günter Zöchbauer
    Mar 7 at 7:06











  • @GünterZöchbauer Thank Sir.

    – Bhanuka Isuru
    Mar 7 at 7:44







1




1





Perhaps you want to look into the BLoC pattern.

– Günter Zöchbauer
Mar 7 at 7:06





Perhaps you want to look into the BLoC pattern.

– Günter Zöchbauer
Mar 7 at 7:06













@GünterZöchbauer Thank Sir.

– Bhanuka Isuru
Mar 7 at 7:44





@GünterZöchbauer Thank Sir.

– Bhanuka Isuru
Mar 7 at 7:44












1 Answer
1






active

oldest

votes


















1














You can get it with
print((await display())?.elementAt(0)?.refreshToken);



display() returns a future of list, so you have to wrap (await display()) before doing list manipulation, such as get an element from a list. list[0] is equivalent to list.elementAt(0), but list.elementAt(0)? is null-safe and out-of-bound-safe.






share|improve this answer


















  • 1





    can you explain what do you mean by "not working", does it crash, print nothing, or print something while you expect something else?

    – TruongSinh
    Mar 7 at 8:25











  • thanks bro...my mistake

    – Bhanuka Isuru
    Mar 7 at 8:57










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037384%2fhow-to-get-element-value-from-a-future-of-a-list%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can get it with
print((await display())?.elementAt(0)?.refreshToken);



display() returns a future of list, so you have to wrap (await display()) before doing list manipulation, such as get an element from a list. list[0] is equivalent to list.elementAt(0), but list.elementAt(0)? is null-safe and out-of-bound-safe.






share|improve this answer


















  • 1





    can you explain what do you mean by "not working", does it crash, print nothing, or print something while you expect something else?

    – TruongSinh
    Mar 7 at 8:25











  • thanks bro...my mistake

    – Bhanuka Isuru
    Mar 7 at 8:57















1














You can get it with
print((await display())?.elementAt(0)?.refreshToken);



display() returns a future of list, so you have to wrap (await display()) before doing list manipulation, such as get an element from a list. list[0] is equivalent to list.elementAt(0), but list.elementAt(0)? is null-safe and out-of-bound-safe.






share|improve this answer


















  • 1





    can you explain what do you mean by "not working", does it crash, print nothing, or print something while you expect something else?

    – TruongSinh
    Mar 7 at 8:25











  • thanks bro...my mistake

    – Bhanuka Isuru
    Mar 7 at 8:57













1












1








1







You can get it with
print((await display())?.elementAt(0)?.refreshToken);



display() returns a future of list, so you have to wrap (await display()) before doing list manipulation, such as get an element from a list. list[0] is equivalent to list.elementAt(0), but list.elementAt(0)? is null-safe and out-of-bound-safe.






share|improve this answer













You can get it with
print((await display())?.elementAt(0)?.refreshToken);



display() returns a future of list, so you have to wrap (await display()) before doing list manipulation, such as get an element from a list. list[0] is equivalent to list.elementAt(0), but list.elementAt(0)? is null-safe and out-of-bound-safe.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 7 at 7:09









TruongSinhTruongSinh

1,493822




1,493822







  • 1





    can you explain what do you mean by "not working", does it crash, print nothing, or print something while you expect something else?

    – TruongSinh
    Mar 7 at 8:25











  • thanks bro...my mistake

    – Bhanuka Isuru
    Mar 7 at 8:57












  • 1





    can you explain what do you mean by "not working", does it crash, print nothing, or print something while you expect something else?

    – TruongSinh
    Mar 7 at 8:25











  • thanks bro...my mistake

    – Bhanuka Isuru
    Mar 7 at 8:57







1




1





can you explain what do you mean by "not working", does it crash, print nothing, or print something while you expect something else?

– TruongSinh
Mar 7 at 8:25





can you explain what do you mean by "not working", does it crash, print nothing, or print something while you expect something else?

– TruongSinh
Mar 7 at 8:25













thanks bro...my mistake

– Bhanuka Isuru
Mar 7 at 8:57





thanks bro...my mistake

– Bhanuka Isuru
Mar 7 at 8:57



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037384%2fhow-to-get-element-value-from-a-future-of-a-list%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229