各変数の型が何になるか確認した時のメモです。
void main() {
print('---var---');
var nameVar = 'Bob';
print(nameVar.runtimeType);
print(nameVar);
print('');
print('---Object---');
Object nameObj = 'Bob';
print(nameObj.runtimeType);
print(nameObj);
print('');
print('---String---');
String nameStr = 'Bob';
print(nameStr.runtimeType);
print(nameStr);
print('');
print('---Map---');
Map mapDyn = {
1: 0,
2: 1,
'3': '2',
};
print(mapDyn.runtimeType);
print(mapDyn[2]);
print('');
print('--- Map<String, int>---');
Map<String, int> mapSta = {
'1': 0,
'2': 1,
'3': 2,
};
print(mapSta.runtimeType);
print(mapSta['2']);
print('');
print('---enum PlanetType.values---');
print(PlanetType.values.runtimeType);
print(PlanetType.values);
print('');
print('---enum PlanetType.terrestrial---');
print(PlanetType.terrestrial.runtimeType);
print(PlanetType.terrestrial);
print(PlanetType.terrestrial.name);
print(PlanetType.terrestrial.index);
print('');
print('---enum PlanetType.values[0]---');
print(PlanetType.values[0].runtimeType);
print(PlanetType.values[0]);
print(PlanetType.values[0].name);
print(PlanetType.values[0].index);
print('');
print('---enum Planet.values---');
print(Planet.values.runtimeType);
print(Planet.values);
print('');
print('---enum Planet.mercury---');
print(Planet.mercury.runtimeType);
print(Planet.mercury);
print('');
print('---enum Planet.mercury.planetType---');
print(Planet.mercury.planetType.runtimeType);
print(Planet.mercury.planetType);
}
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);
const Planet(
{required this.planetType, required this.moons, required this.hasRings});
final PlanetType planetType;
final int moons;
final bool hasRings;
bool get isGiant =>
planetType == PlanetType.gas || planetType == PlanetType.ice;
}