Search…
Introduction
What does DCli do?
Install DCli
Writing your first CLI app
Add DCli to your project
pub.dev
github
Dart basics
Dart lambda functions
Function Arguments
Futures
stdin/stdout/stderr a primer
Tour
Overview
Using DCli functions
User input
Displaying information
Managing Files And Directories
Environment variables
Calling apps
Command Line Arguments
Paths
Glob Expansion
Piping
Locking
Fetch
The evils of CD
Assets/Resources
Cross Platform
Elevated Privileges
Performance
Dependency Management
Dependency Management
Pubspec Managment
DCli Tools
DCli tools
Use a shebang #!
DCli Compile
DCli Clean
DCli Create
DCli Doctor
DCli Install
DCli Run
DCli Warmup
DCli Pack
Upgrade DCli
Internal Workings
Internal Workings
waitForEx
Contributing
References
Examples
Projects
Code
Articles
build CLI apps in dart - part 1
build CLI apps in dart - part 2
Dealing with permissions
Dart on Linux - the perfect CLI tooling
Improving your build environment
Olivier Revial - CLI apps made easy
Video: package of the week
Powered By
GitBook
Function Arguments
This section provides details on the Dart language:
To learn more about Dart's syntax read the Dart language tour.
https://dart.dev/guides/language/language-tour
​
Dart allows three types of arguments to be passed to a method or function.
Positional, optional and named.
Positional arguments are traditional 'C' style arguments that everyone is familiar with.
Optional arguments are positional arguments that are (you guessed it) optional.
Named arguments are a little trickier but depending on your current language experience you may already be familiar with them.
Named arguments allow you to pass an argument by name rather than position and they are (usually) optional.
To declare a named argument you use curly braces
{}
.
1
testMethod
(
String
arg1
,
[
String
arg2
],
{
String
arg3
,
String
arg4
});
Copied!
In the above example
arg1
is a positional argument,
arg2
is an optional argument with
arg3
and
arg4
being named arguments.
To call the test method passing values to all of the above arguments you would use:
1
testMethod
(
'value1'
,
'value2'
,
arg4
:
'value4'
,
arg3
:
'value3'
);
Copied!
Note that I've reversed the order of
arg3
and
arg4
. As they are named arguments you can place them in any position AFTER the named and optional arguments.
Lets finish with an example using the forEach method:
1
'tail /var/log/syslog'
.
forEach
((
line
)
=>
print
(
line
),
stderr
:(
line
)
=>
print
(
line
));
Copied!
The above example will print any output sent to stdout or stderr from the 'tail' command.
Dart basics - Previous
Dart lambda functions
Next - Dart basics
Futures
Last modified
7mo ago
Copy link