액티브 스킬/플러터

<Flutter> dynamic 변수의 타입 확인

디벅잉 2022. 11. 10. 21:12
728x90

 

🧭

 

변수의 타입을 왜 확인해야 하는가?

모든 변수를 정적 타입으로 선언했다면 타입을 확인할 필요가 없을 것입니다.

오래된 프로젝트를 업그레이드 한다든지 하는 경우 dynamic 타입의 변수를 마주할 수 있고 타입을 확인하고 싶은 경우가 있을 수 있습니다.

플러터의 모든 변수들의 조상격인 Object 타입에는 runtimeType이라는 프로퍼티가 있습니다.

어떤 변수든 runtimeType 프로퍼티를 불러와서 출력하면 타입을 확인할 수 있습니다.

dynamic variable;
print(variable.runtimeType); // dynamic

 

📌

 

https://www.kindacode.com/article/how-to-check-type-of-a-variable-in-flutter/

 

How to check Type of a Variable in Flutter - Kindacode

To check the type of a variable in Flutter and Dart, you can use the runtimeType property. Example The code: Output: Further reading: Understanding Typedefs (Type Aliases) in Dart and Flutter Dart: Convert Class Instances (Objects)...

www.kindacode.com

 

728x90