Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9231655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:07:32+00:00 2026-06-18T06:07:32+00:00

I would like to know how to define the data type and how to

  • 0

I would like to know how to define the data type and how to return the object (record) using getObject(). Currently, the only way that I have been able to use the result (record) outside of the function that obtains it is to call another function with the result. That way, the data-type does not need to be specified. However if I want to return the value, I need to define the data-type and I can’t find what it is. I tried “dynamic” but that didn’t appear to work. For example “:

fDbSelectOneClient(String sKey, Function fSuccess, String sErmes) {
  try {
    idb.Transaction oDbTxn      =   ogDb1.transaction(sgTblClient, 'readwrite');
    idb.ObjectStore oDbTable    =   oDbTxn.objectStore(sgTblClient); 
    idb.Request     oDbReqGet   =   oDbTable.getObject(sKey);
    oDbReqGet.onSuccess.listen((val){
      if (oDbReqGet.result == null) {
        window.alert("Record $sKey was not found - $sErmes");
      } else {
    ///////return oDbReqGet.result;    /// THIS IS WHAT i WANT TO DO
        fSuccess(oDbReqGet.result);    /// THIS IS WHAT i'm HAVING TO DO  
      }});
    oDbReqGet.onError.first.then((e){window.alert(
      "Error reading single Client. Key = $sKey. Error = ${e}");});
  } catch (oError) {
    window.alert("Error attempting to read record for Client $sKey.
       Error = ${oError}");    
  }
}
fAfterAddOrUpdateClient(oDbRec) {
  /// this is one of the functions used as "fSuccess above
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:07:33+00:00Added an answer on June 18, 2026 at 6:07 am

    As someone else once said (can’t remember who), once you start using an async API, everything needs to be async.

    A typical “Dart” pattern to do this would be to use a Future + Completer pair (although there’s nothing inherently wrong with what you’ve done in your question above – it’s more a question of style…).

    Conceptually, the fDbSelectOneClient function creates a completer object, and the function returns the completer.future. Then, when the async call completes, you call completer.complete, passing the value in.

    A user of the function would call fDbSelectOneClient(...).then((result) => print(result)); to make use of the result in an async way

    Your code above could be refactored as follows:

    import 'dart:async'; // required for Completer
    
    Future fDbSelectOneClient(String sKey) {
      var completer = new Completer();
    
      try {
        idb.Transaction oDbTxn      =   ogDb1.transaction(sgTblClient, 'readwrite');
        idb.ObjectStore oDbTable    =   oDbTxn.objectStore(sgTblClient); 
        idb.Request     oDbReqGet   =   oDbTable.getObject(sKey);
    
        oDbReqGet.onSuccess.listen((val) => completer.complete(oDbReqGet.result));
        oDbReqGet.onError.first.then((err) => completer.completeError(err));
      } 
      catch (oError) {
        completer.completeError(oError);
      }
    
      return completer.future; // return the future
    }
    
    // calling code elsewhere
    foo() {
      var key = "Mr Blue";
    
      fDbSelectOneClient(key)
        .then((result) {
          // do something with result (note, may be null)
        })
        ..catchError((err) {  // note method chaining ..
         // do something with error
        };
    }
    

    This future/completer pair only works for one shot (ie, if the onSuccess.listen is called multiple times, then the second time you will get a “Future already completed” error. (I’ve made an assumption on the basis of the function name fDbSelectOneClient that you are only expecting to select a single record.

    To return a value from a single future multiple times, you’ll probably have to use the new streams feature of the Future – see here for more details: http://news.dartlang.org/2012/11/introducing-new-streams-api.html

    Note also, that Futures and Completers support generics, so you can strongly type the return type as follows:

    // strongly typed future
    Future<SomeReturnType> fDbSelectOneClient(String sKey) { 
      var completer = new Completer<SomeReturnType>(); 
    
      completer.complete(new SomeReturnType());
    }
    
    foo() {
      // strongly typed result
      fDbSelectOneClient("Mr Blue").then((SomeReturnType result) => print(result));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how I define multiple containers in Maven, one for
I would like to know how to define a returntype in a function in
Would like to know the c# code to actually retrieve the IP type: Static
I'm using a library that defines some data type classes usually implemented as tight
I would like to create an object in PHP based on a type defined
I am building an automation system using Powershell and I would like to define
I would like to know if the following approach is supported: Define grid schema
I would like to know if there is a way to disable automatic loading
i would like know some reference. I know i can googling it. but prefer
Would like to know what a programmer should know to become a good at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.