How do I check type of an object in a switch/case?

后端 未结 3 2075
旧巷少年郎
旧巷少年郎 2020-12-19 01:36

I see in examples this code:

if (obj is User) { // do something }

I want to check the type of the object in a switch/case flow, and found a

3条回答
  •  無奈伤痛
    2020-12-19 02:07

    switch string works.

    switchType(Object object) {
      switch (MirrorSystem.getName(new Symbol(object.runtimeType.toString()))) {
        case "Animal":
          print('animal basic');
          break;
        case 'Cat':
          print('Mouse for cat');
          break;
      }
    }
    

提交回复
热议问题