• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Flutter 게시판 (질문) 폰 연락처 앱 전화번호 오류와 정렬 문제 문의

(질문) 폰 연락처 앱 전화번호 오류와 정렬 문제 문의

7 글 보임 - 1 에서 7 까지 (총 7 중에서)
  • 글쓴이
  • #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);
    });
    },
    ),
    );
    },
    ),

     

    #26682

    codingapple
    키 마스터

    phones라고 꺼내면 [] 안에 담겨오나봅니다

    phones[0].toString() 해봅시다 

    sort()만 쓰면 단순하게 문자나 숫자 담긴 list를 정렬해주는데 list of objects 정렬하는 법을 찾아보아야할듯합니다 

    #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값이 있을 수 있다고 해서 해준다고 해줬는데 해결이 안되네요 ㅠㅠ

    #27835

    codingapple
    키 마스터

    .phones?[0]

    느낌표나 물음표 왼쪽에 붙여봅시다 

    #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()

    #55665

    시와
    참가자
    contact.phones?[0].value.toString()  도 되네요.
    혼자 한다고 쌩고생 했는데... 물음표 넣으니깐 되네요... 현타...
    #70895

    박상용
    참가자
      댓글보고 해결했습니다. 
    for (var contact in contacts) {
        print(contact.phones?.length==0?"none":contact.phones?[0].value.toString());
    }
    자바스크립트였으면, 그냥 리스트뽑아오는걸.. 이따구로 가져와야하다니...
    플러터 즌짜 너무 빡치게만드네요 ㅠㅠ
    
    
     
7 글 보임 - 1 에서 7 까지 (총 7 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠