-
글쓴이글
-
2022년 2월 7일 16:05 #26637
Chris참가자안녕하세요. 두가지 문제가 있어 문의 드립니다.
1) 폰에 저장된 연락처 전화번호 보여주기 코드 실행하면 화면에 전화번호가 아닌 [instance of 'item'] 으로 나옵니다.
family name 이나 given name은 잘 나오는대 전화번호만 나오지 않네요.
2) sort 버튼 실행 시키면 'type 'Contact' is not a subtype of type 'Comparable<dynamic>' in type cast' 라는 메세지와 함께 리스트 정렬이 되지 않습니다.
appBar: AppBar(
title: Text('인원수: ${name.length.toInt()} 명'),
actions: [
IconButton(
onPressed: () {
getPermission();
},
icon: Icon(Icons.contacts)),
IconButton(
onPressed: () {
setState(() {
name.sort();
});
},
icon: Icon(Icons.sort_by_alpha))],
),
body: ListView.builder(
itemCount: name.length,
itemBuilder: (context, i) {
return ListTile(
leading: Icon(Icons.account_circle_rounded),
title: Row(
children: [
Text(
name[i].givenName.toString()),
SizedBox(width: 5),
Text(
name[i].phones.toString()),
],
),
trailing: IconButton(
icon: Icon(Icons.delete_outline),
onPressed: () {
setState(() {
name.removeAt(i);
});
},
),
);
},
),2022년 2월 7일 22:08 #26682
codingapple키 마스터phones라고 꺼내면 [] 안에 담겨오나봅니다
phones[0].toString() 해봅시다
sort()만 쓰면 단순하게 문자나 숫자 담긴 list를 정렬해주는데 list of objects 정렬하는 법을 찾아보아야할듯합니다
2022년 2월 21일 11:52 #27824
최민혁참가자Text(widget.contact.phones[0].toString())! ?? '번호없음', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold) )
Error : Operator '[]' cannot be called on 'List<Item>?' because it is potentially null.
[0] 부분에 오류가 뜹니다. null값이 있을 수 있다고 해서 해준다고 해줬는데 해결이 안되네요 ㅠㅠ
2022년 2월 22일 13:21 #27915
최민혁참가자//실제 코드
Text((widget.contact.phones?.length ==0 ? '번호없음': widget.contact.phones?.elementAt(0).value.toString())!,
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold) )
이렇게 써서 해결했습니다.
contact.phones?.elementAt(0).value.toString()
-
글쓴이글
- 답변은 로그인 후 가능합니다.