- [Flutter]변수를 문자열(string)로 치환하여 프린트(print) 하기($ 사용) 목차
반응형
숫자를 문자열(String)으로 변환하여 문자열 출력을 하거나 파일 이름을 찾는 경우에 사용할 수 있다
int intValue = 3;
String anotherValue = 'the value is $intValue';
print(anotherValue);
출력문은 the value is 3
리스트에서 값을 추출하여 파일명으로 사용하는 경우
myFinal[0][0] = 3 인 경우
Image.asset('images/ball_${myFinal[0][0]}.png'),
실제로 적용되는 값은 Image.asset('images/ball_3.png'),
참고) 다음처럼 변수값을 String으로 변환하는 방법도 있다
int intValue = 12;
String stringValue = intValue.toString();
String hexValue = intValue.toRadixString(16); => 16진수 값으로 변환한다
print(stringValue); => 12
print(hexValue); => c
참고) String을 int로 변환하는 방법
String s = "45";
int i = int.parse(s);
print(i);
출력되는 값은 45
즐거운 시간되세요^^
반응형
'flutter' 카테고리의 다른 글
[flutter]The instance member '_number' can't be accessed in an initializer. (0) | 2020.12.26 |
---|---|
[flutter]'await' applied to 'String', which is not a 'Future' (0) | 2020.12.26 |
[Flutter]Dart 2차원 배열(list, 리스트) 데이터 저장 및 가져오기(List.generate()) (0) | 2020.12.13 |
[Flutter]SQLite에 사용하는 toMap( ) List.generate(maps.length, (i)) (0) | 2020.10.25 |
[Flutter] 위젯간 Data 전달하기(생성자 변수, 함수 포인터) (0) | 2020.10.25 |