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

  • Home
  • SEARCH
  • 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 8582845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:23:49+00:00 2026-06-11T21:23:49+00:00

I have read the description, and I understand that it is a function-type alias.

  • 0

I have read the description, and I understand that it is a function-type alias.

  • A typedef, or function-type alias, gives a function type a name that you can use when declaring fields and return types. A typedef retains type information when a function type is assigned to a variable.

  • http://www.dartlang.org/docs/spec/latest/dart-language-specification.html#kix.yyd520hand9j

But how do I use it? Why declaring fields with a function-type? When do I use it? What problem does it solve?

I think I need one or two real code examples.

  • 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-11T21:23:51+00:00Added an answer on June 11, 2026 at 9:23 pm

    A common usage pattern of typedef in Dart is defining a callback interface. For example:

    typedef void LoggerOutputFunction(String msg);
    
    class Logger {
      LoggerOutputFunction out;
      Logger() {
        out = print;
      }
      void log(String msg) {
        out(msg);
      }
    }
    
    void timestampLoggerOutputFunction(String msg) {
      String timeStamp = new Date.now().toString();
      print('${timeStamp}: $msg');
    }
    
    void main() {
      Logger l = new Logger();
      l.log('Hello World');
      l.out = timestampLoggerOutputFunction;
      l.log('Hello World');
    }
    

    Running the above sample yields the following output:

    Hello World
    2012-09-22 10:19:15.139: Hello World

    The typedef line says that LoggerOutputFunction takes a String parameter and returns void.

    timestampLoggerOutputFunction matches that definition and thus can be assigned to the out field.

    Let me know if you need another example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my homework, but please read my problem description first. I have to
I have read that GLSL (specifically v1.0.17: my application is running under WebGL) compilers
When a reader starts to read the function code, he should already have a
I'm trying to understand ThreadPoolExecutor class. I have read this answer and the Javadoc.
I have read many answers to questions about dynamically resizing NSWindows and nothing has
I have read various posts in stackoverflow and I am trying to figure out
I have read the Apple documentation, and many postings on the subject on SO,
I have read pretty much the entire documentation even beyond on the AWS AS
I have read few articles about table partioning but still I am bit confused
I have read some of the questions and answers here, but it none match

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.