Dart: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(→Tipps) |
|||
Zeile 6: | Zeile 6: | ||
* https://dartpad.dev | * https://dartpad.dev | ||
= | = Statements = | ||
<pre>for (var ix in list) {} | |||
<pre> | for (int ix = 0; ix < 10; ix++) {} | ||
while (doIt()){ } | |||
</pre> | </pre> | ||
Zeile 53: | Zeile 47: | ||
sprintf("%02d %s", [1, "Hi"]); | sprintf("%02d %s", [1, "Hi"]); | ||
print("${new DateTime.now().toString()}: $message\n"); | print("${new DateTime.now().toString()}: $message\n"); | ||
</pre> | |||
= Besonderheiten = | |||
* entweder optionale Positionsparameter oder optionale Namensparameter, nicht beide. | |||
<pre>String substr(String str, int pos, [int length, bool uppercase]){ ... } | |||
<pre>String substr2(String str, int pos, {int length, bool uppercase, Logger logger}){ ... } | |||
x = substr('Hi world', 3, 2); | |||
y = substr2('Hi world', 3, length:2, logger:logger); | |||
</pre> | |||
* ..-Operator: Mehrfachzugriff auf voriges Objekt: | |||
<pre>var person = Person()..name='Joe'..id=25; | |||
var p = Point(10, -12)..setColor(green)..setWeight(1.22); | |||
</pre> | </pre> |
Version vom 3. Januar 2020, 21:26 Uhr
Links
Statements
for (var ix in list) {} for (int ix = 0; ix < 10; ix++) {} while (doIt()){ }
Class
abstract class BaseLogger { int _errors = 0; void BaseLogger(){ } // abstract function: void log(string message); void error(string message){ _errors++; log('+++ ' + message); } class Logger extends BaseLogger { } ... var logger = Logger('std.log');
Interface
- Jede Klasse kann Interface sein. Dann muss jede Methode überschrieben werden
class D implements A, B, C { @override void doIt(){ // ... } }
DateTime
var date = new DateTime.now();
String
Formatierung
import 'package:sprintf/sprintf.dart'; sprintf("%02d %s", [1, "Hi"]); print("${new DateTime.now().toString()}: $message\n");
Besonderheiten
- entweder optionale Positionsparameter oder optionale Namensparameter, nicht beide.
String substr(String str, int pos, [int length, bool uppercase]){ ... } <pre>String substr2(String str, int pos, {int length, bool uppercase, Logger logger}){ ... } x = substr('Hi world', 3, 2); y = substr2('Hi world', 3, length:2, logger:logger);
- ..-Operator: Mehrfachzugriff auf voriges Objekt:
var person = Person()..name='Joe'..id=25; var p = Point(10, -12)..setColor(green)..setWeight(1.22);