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 7877577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:24:45+00:00 2026-06-03T03:24:45+00:00

Does Dart support the concept of variable functions/methods? So to call a method by

  • 0

Does Dart support the concept of variable functions/methods? So to call a method by its name stored in a variable.

For example in PHP this can be done not only for methods:

// With functions...
function foo()
{
    echo 'Running foo...';
}

$function = 'foo';
$function();

// With classes...
public static function factory($view)
{
    $class = 'View_' . ucfirst($view);
    return new $class();
}

I did not found it in the language tour or API. Are others ways to do something like this?

  • 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-03T03:24:47+00:00Added an answer on June 3, 2026 at 3:24 am

    To store the name of a function in variable and call it later you will have to wait until reflection arrives in Dart (or get creative with noSuchMethod). You can however store functions directly in variables like in JavaScript

    main() {
      var f = (String s) => print(s);
      f("hello world");
    }
    

    and even inline them, which come in handy if you are doing recusion:

    main() {
       g(int i) {
          if(i > 0) {
             print("$i is larger than zero");
             g(i-1);
          } else {
             print("zero or negative");
          } 
       }
       g(10);
    }
    

    The functions stored can then be passed around to other functions

    main() {
       var function;
       function = (String s) => print(s);
       doWork(function);
    }
    
    doWork(f(String s)) {
       f("hello world");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does jQuery 1.5.1 support attribute selectors in the closest method? Given the structure below,
Does this line of Perl really do anything? $variable =~ s/^(\d+)\b/$1/sg; The only thing
Does the Google Dart JavaScript converter support older browsers or is it only supporting
Does anyone know how to generate the following generic method declaration using CodeModel? public
I wonder how does Dart handle JSON? More specifically: Can I access item in
Does anyone know how to make this code stop the knob from rotating past
Does anyone know why this bean is getting instantiated multiple times? I only ever
Does anyone know the name of the context menu that you get when right
Does anyone have a working, step-by-step example of how to implement IEnumerable and IEnumerator
Does the Java language have delegate features, similar to how C# has support for

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.