class Login
typedef Predicate<T> = bool Function(T value);
class Foo() {
const Foo([args])
}
@Foo(anArg)
class A {
/// ...
}
@Foo()
class B {
/// ...
}
library peg_parser.source_scanner;
import 'file_system.dart';
import 'dart:math' as math;
import 'package:js/js.dart' as js;
var item;
HttpRequest httpRequest;
void align(bool clearItems){
/// ...
}
const pi = 3.14;
const defaultTimeout = 1000;
final urlScheme = RegExp('^([a-z]+):');
使用一句简明扼要的话作为开头 空一格 将参数和返回值使用[]加持
/// Delete the file at [path] from the file system.
///
/// Throws an [IOError] if the file could not be found.Throws a
/// [PermissionError] if the file is present but could not be deleted.
void delete(String path){
...
}
import 'src/utils.dart';
/// Define isEnabled Params
///
/// return false if isEnabled is null
optionalThing?.isEnabled ?? false
raiseAlarm(
'ERROR: Parts of the spaceship are on fire. Other '
'parts are overrrun by ....');
'Hello, $name! You are ${year - birthday} years old. '
var points = [];
var addressses = {};
/// 指定类型
var points = <Point>[];
var addresses = <String, Address>{};
if(lunchBox.isEmpty) return 'so hungry...'
if(words.isNotEmpty) return words.join(' ');
var aquaticNames = animals
.where((animal) => animal.isAquatic)
.map((animal) => animal.name);
有两种方法可以获取Iterable,分别是List.from() 和 Iterable.toList()
/// 创建一个List<int>
var iterable = [1, 2, 3];
/// 输出`List<int>`
///
/// 如果使用List.from的话,会输出`List<dynamic>`
print(iterable.toList().runtimeType);
var objects = [1, 'a', 'b2', 2];
var ints = objects.whereType<int>();
void insert(Object item, { int at = 0 }) { ... }
class Circle {
num radius;
Circle (this.radius);
num get area = pi * radius * radius;
num get circumference = pi * 2.0 * radius;
}
class Box {
void contents;
}
class Point {
num x, y;
Point(this.x, this.y);
}
Widget build(BuildContext context) {
return Row(
children: [
RaisedButton(
child: Text('Increment'),
),
Text('Click!'),
],
);
}
#异常处理
try {
somethingRisky();
} catch (e) {
if (!canHandle(e)) rethrow;
handle(e);
}
var buffer = StringBuffer()
..write('one')
..write('two')
..write('three');