Flutter for Java developers
inspired by Java Champion Ian Darwin
From the talk: "Flutter is the new Java - or is it??"
Video-> https://youtu.be/0A1YZAz073w
We, as developers, are afloat and aflutter in a sea of new devices:
To avoid being adrift, you need to write code once and run it everywhere.
Who cares? Why cross-platform matters?
The challenge is to know which cross-platform tools to use? Which way is better?
Let's just pick ONE that works!
Flutter, of course! But we need to talk.
Flutter:
But, remember, there is no one-size-fits-all solution.
How we got here, and where to go: (a bit of history)
Other WORA schemes:
Flutter delivers WORA
Dart is the programming language used in Flutter, Flutter being the SDK (toolkit) using Dart.
Let's take a look at Dart language !
Dart language:
Dart overview:
main() {
print("Hello, World");
}
->Running it is simple:
dart hello.dart
Dart source files & organization:
* Flutter convention is to omit 'bin' folder, keep main in 'lib' folder: only one source directory
* main.dart - main program
* new_course.dart - NewCourse class and friends
class CoursePage {
// ...
addTab(new ContactsTab());
// ...
}
class ContactsTab {
// ...
}
Other naming conventions:
int myUsefulValue=31;
Visibility:
class X {
int _someInt; //private
int anotherInt; // not private
static int oneMore; //static, not private
static int _counter; //static and private
}
Getting stuff out:
* like e.g., System.out.println() in Java, print() in Python, etc.
print("Hello world");
Typing and variable inference
* int i = 42; // creates an int object
* i = 27; // creates a new int object
* var x =42; // x is int
* var y =42.0 // y is double
Dart Strings
String interpolation
var _hostname = "darwinsys.com", page="", x=42;
var url = "https://$_hostname/$page";
print(url);
//print("x is"+x); won't compile
print("x is "+x.toString()); // no automatic toString here, but ...
print("x is $x"); //much more concise!
Dart operators
Dart languages keywords
Const vs Final
Classes and interfaces
class One {
void doSomething() {...}
}
class Two implements One {
void doSomething() { /* own implementation */}
}
class Zombie implements One, Alpha {...}
领英推荐
Enums
Enum Color {RED, YELLOW, GREEN};
enum OpsUnit {NA, SA, EURO, APAC};
OpsUnit opsUnitFromString(String input){
OpsUnit.values.forEach((f){
if(f.toString()==input){
return f;
}
});
throws 'Unknown ops unit from String ${input}';
}
will always throw exception. Why?
Two problems on code above:
->'return' inside a closure just returns from the closure (same as Java)
->enum toString includes class name, e.g.: OpsUnit.NA
This below does work:
OpsUnit opsUnitFromString(String input){
var found = null;
OpsUnit.values.forEach((f){
if(f.toString().endsWith(input)){
found = f;
}
});
if (found!=null)
return found
throws 'Unknown ops unit from String ${input}';
}
Dart null-aware operators
* Common source of program errors and crashes
'expr1 ?? expr2' gives 'expr1' if not null, else 'expr2'
'v??=expr' gets 'v' assigned 'expr' only if 'v' is 'null'
'x?.p' gives 'x.p' if 'x' is not null, else gives 'null'
'x?m()' invokes 'm' only if 'x' is not null
if x true, evaluate true_expr, else evaluate false-expr
Strong typing, the easy way:
Dart coding?conventions:
* These are made by 'experts' and those who created Dart itself
Dart/Flutter packages
Dart extra packages
There's more!
* Generators/Iterators
Let's get back to Flutter !
Flutter runs (almost) everywhere:
Development tools
->NOTE that to build for any platform, you must have the native toolkit
~~>Can only build on Windows
->Then you can pick and IDE
One other thing..
There are a lot of librairies:
Design patterns
Is there a dark side to Flutter?
Flutter: What's next for Flutter?
Conclusion:
->Flutter offers a solid path to cross-platform development
~~>CPU portability handled by Dart
~~>Operating system portability handled in libraries
->Not the only cross-platform solution
Your plan to evaluate Flutter for yourself:
Resources:
Video-> https://youtu.be/0A1YZAz073w