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

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page