Core Libraries Tour

dart:core (auto-imported) Numbers, strings, collections, DateTime, Duration, Uri, RegExp, Stopwatch, Object, errors, print

Future, Stream, Completer, Timer, Zone, StreamController

Math functions, Random, Point, Rectangle JSON, UTF-8, Base64, ASCII, Latin1, codecs, LineSplitter

Queues, linked and splay-tree maps/sets, views Uint8List, Float64List, ByteData, SIMD types (Float32x4)

Files, directories, processes, sockets, HTTP server/client, platform info (not on the web) Isolates and ports C interop (native)

dart:js_interop / dart:js_interop_unsafe JS interop (web, JS and Wasm)

debugger(), log(), Timeline, service extensions Reflection (JIT VM only, not supported with AOT/Flutter/web)

31.1 DateTime and Duration

final now = DateTime.now();
final utc = DateTime.now().toUtc();
final birthday = DateTime(1995, 6, 15);
final parsed = DateTime.parse('2025-10-24T10:30:00Z');
print((now.year, now.month, now.weekday, now.isAfter(birthday)));
final tomorrow = now.add(const Duration(days: 1));
final age = now.difference(birthday).inDays ~/ 365;
print((now.toIso8601String(), now.millisecondsSinceEpoch));
const timeout = Duration(minutes: 1, seconds: 30);
print((timeout.inSeconds, timeout * 2));
final sw = Stopwatch()..start();
// ... work ...
print('${sw.elapsedMilliseconds} ms');
// Formatting with locales: the intl package (DateFormat('yyyy-MM-dd').format(now))

31.2 RegExp and Uri

final re = RegExp(r'(\d{4})-(\d{2})-(\d{2})');
final match = re.firstMatch('Shipped on 2025-10-24');
print((match?.group(1), match?[2]));
final named = RegExp(r'(?<user>\w+)@(?<domain>\w+\.\w+)');
final m = named.firstMatch('[email protected]')!;
print(m.namedGroup('user'));
print(RegExp(r'\d+').allMatches('a1b22c333').map((m) => m[0]).toList());
print('2025-10-24'.replaceAllMapped(re, (m) => '${m[3]}/${m[2]}/${m[1]}'));
print(RegExp(r'^\w+$', caseSensitive: false, multiLine: true).hasMatch('Dart'));

final uri = Uri.https('api.example.com', '/search', {'q': 'dart lang', 'page': '1'});
print((uri, uri.queryParameters['q'], uri.host, uri.path));
final parsedUri = Uri.parse('https://example.com/a/b?x=1#top');
print((Uri.encodeComponent('a b&c'), Uri.decodeComponent('a%20b')));

31.3 Typed Data and Encoding

import 'dart:typed_data';
import 'dart:convert';
final bytes = Uint8List.fromList([72, 105]);
final view = ByteData.sublistView(bytes);
print(view.getUint8(0));
final encoded = base64Encode(utf8.encode('Hello'));
print((encoded, utf8.decode(base64Decode(encoded))));