dwyl / learn-dart Goto Github PK
View Code? Open in Web Editor NEW🎯Learn the Dart programming language to build cross-platform (Mobile, Web & Desktop) Apps with Flutter!
License: GNU General Public License v2.0
🎯Learn the Dart programming language to build cross-platform (Mobile, Web & Desktop) Apps with Flutter!
License: GNU General Public License v2.0
We have published packages in several languages most recently in Elixir
and JavaScript
and documented the process extensively: code-reuse-hexpm.md
publishing-packages
and immediately create a new Pull Requestpublishing-packages-pub-dev.md
dart
package e.g: dwyl/dart_cid#1
Starting point: https://dart.dev/tools/pub/publishing
Add a functions
section in the README to describe how to create functions.
String hello() {
return 'hello';
}
We can see that the value's type returned by the function is the specify at the beginning of the function declaration. From some manual test I'm not sure however that the type is required as Dart might determine it automatically (need more searching on this). However I think this is always a good idea to specify it as it describes what the function returns.
void
keywords for a functions means that the function doesn't return any value.void hello() {
print('hello');
}
However I've tested with return null;
and the code compiled without error. I'm not sure if void
is a specific type (where null is consider a value of void, or a synonym?)
void hello() {
print('hello');
return null;
}
main
function. Entry point for Dart/flutter programString hello() => 'hello'
. I understand arrow function as a shortcut for functions with one returning line.Other questions to search:
Research how to use parameters
Add a section on metada which allow us to add more information about a function, for example deprecated, required, override...
Does Dart allow anonymous functions? https://dart.dev/guides/language/language-tour#anonymous-functions
I recently blocked on a line similar to:
final myList = const [1,2,3];
I wan't sure about the meaning of const
when initialising a final
variable.
In this situation const
is used to instanciate (create) a new immutable object.
This means that the list object [1, 2, 3]
can't be changed, and the following code won't work:
final myList = const [1, 2, 3];
myList.add(4); // error
If we ignore const
then we are able to use the function add
on the list, and this following code will work:
final myList = [1, 2, 3]
myList.add(4) // myList contains now the value [1, 2, 3, 4]
ref:
You can represent a string with either single quotes or double quotes without any difference.
const hello1 = "hello";
const hello2 = 'hello';
hello1 == hello2; //true
To escape specific characters in a string use \
Dart style guide let you decide which one you prefer to use, just be consistent.
Flutter style guide recommend to use single quote: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#prefer-single-quotes-for-strings
ref:
https://www.youtube.com/watch?v=iYhOU9AuaFs
By default the variables will not be able to be null.
You will need to specify if a variable can be null with ?
: var hello? = "hello";
This sounds similar to how some FP languages are using Maybe
We can use async
, await
keywords and the class Future
to manage asynchronous operation.
For example when retrieving data from an API the returned values might take a bit of time depending on the API server, network status...
then
is also sometimes used with asynchronous function, what is the difference with async/await
and then
Thinking of buying this ebook, both because the content looks good and to support the author who seems great!
https://gumroad.com/l/xfFpu
Via: https://youtu.be/SDE5d4GcAdc
In the article I'm summarizing, it talks about Effective Dart.
Should we put the summary in the learn-dart
or in the learn-flutter
repository ?
In Elixir we are use to apply multiple functions on a value with the pipe operator |>
"Hello there"
|> String.upcase()
|> String.split()
The pipe operator takes the returned value of the function and apply the next function. This works nicely because of Elixir values are immutable and functions return a new value with the updated change from the functions.
Dart is object oriented. This means that the following doesn't work:
var l = [1,2,3];
l.add(4).add(5);
Here l is an list and the add
function change the state of the list directly, it doesn't create a new list value. Moreover the add
function as the following declaration:
void add(E value)
So add
returns a void
value and not the list itself.
One solution to add multiple values in a list could be:
void main(){
var a = [1,2,3];
a.add(4);
a.add(5);
print(a);
}
However the cascade operator ..
is here to make the code a be nicer.
The operator apply a method on the receiver/object, discard the returned value of that method and instead returns the receiver/object itself.
void main(){
var a = [1,2,3]
..add(4)
..add(5);
print(a);
}
ref:
At present #efc23154
this repo is a good start but it does not have any code
.
Our objective with any learn-xyz
repo is to make it first place a person needs to go for learning that topic. E.g: https://github.com/dwyl/learn-elixir has everything the person needs to start learning Elixir
including the syntax/semantics and code examples.
I propose that we:
Add a section in README to describe how to use comments in Dart code
//
/*...*/
///
. Can be useful with dartdoc which is a tool to convert doc comment to html. Markdown format can be used in doc commentref: https://dart.dev/guides/language/effective-dart/documentation
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.