Skip to content

Instantly share code, notes, and snippets.

import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:go_router/go_router.dart';
enum AuthState {
guest,
registered,
}
final authProvider = StateProvider((ref) => AuthState.guest);
void main() {
final astronauts = 0;
try {
if (astronauts == 0) {
throw StateError('No astronauts.');
}
} catch (e) {
print(e);
}
class Spacecraft {
final String name;
Spacecraft(this.name);
}
const oneSecond = Duration(seconds: 1);
// ···
Future<void> printWithDelay(String message) async {
await Future.delayed(oneSecond);
class Spacecraft {
void describe() {
print('hi');
}
}
class MockSpaceship implements Spacecraft {
@override
void describe() {
print('mock');
class Spacecraft {}
mixin Piloted {
int astronauts = 1;
void describeCrew() {
print('Number of astronauts: $astronauts');
}
}
class Spacecraft {
String name;
DateTime? launchDate;
int? get launchYear => launchDate?.year;
Spacecraft(this.name, this.launchDate) {}
Spacecraft.unlaunched(String name) : this(name, null);
enum PlanetType { terrestrial, gas, ice }
/// 太陽系の惑星を列挙する
enum Planet {
mercury(planetType: PlanetType.terrestrial, moons: 0, hasRings: false),
venus(planetType: PlanetType.terrestrial, moons: 0, hasRings: false),
// ···
uranus(planetType: PlanetType.ice, moons: 27, hasRings: true),
neptune(planetType: PlanetType.ice, moons: 14, hasRings: true);
class Spacecraft {
// プロパティ
String name;
DateTime? launchDate;
// 読み込み専用プロパティのgetter
int? get launchYear => launchDate?.year;
// コンストラクタ。`this.`の糖衣構文によって引数をメンバに代入しています
Spacecraft(this.name, this.launchDate) {
// Dartコアライブラリをインポート
import 'dart:math';
// パッケージのライブラリをインポート
import 'package:test/test.dart';
// 別ファイルをインポート
// ファイルがないためコメントアウト
// import 'path/to/my_other_file.dart';
// 通常の一行コメントです。
/// ドキュメンテーションコメントです。
/// クラスやメンバーの説明を文書として説明できます。
/// IDEやエディタでは見やすく表示されます。
/* このようなコメントもサポートされています。 */
void main() {
}