[앱개발] 예보 : 마음을 읽다.

[예보:마음을 읽는] 친구 리스트 화면 개발 [MVVM 모델]

godofwisdom 2022. 4. 11. 00:03
schema

 

 

 

 

 

 

 

  • "user" 컬렉션에 friends 필드를추가하여서 친구 리스트를 보여주도록 한다.
  • 친구 추가는 firebase의 deeplink를 통하여서 쉽게 추가 할수 있도록 개발
  • kakao의 친구리스트를 통하여서 친구 추가 할수있도록 개발 (예정)

 

개발 예상 화면

 

  • UserModeView 를 통하여서 회원 정보를 가지고 온다.
  • 회원 정보의 firends를 통하여서 리스트 화면 갱신
  • 친구 추가/삭제 로직 추가 
MemberListEvent.dart
개인 정보를 UserModel을 가지고 오는 로직
Future<void> _getUserById(String uid) async {
  UserModel? userModel = await userRepository.getUserById(uid);
  _userState = _userState.copyWith(userModel: userModel);
  notifyListeners();
}

 

MemberListEvent.dart
개인정보 변경 및 친구 추가/제거후에 업데이트 로직
Future<void> _updateUser(UserModel userModel) async {
  userRepository.updateUser(userModel);
  _getUserById(userModel.uid);
}

 

친구 추가/제거를 위한 firends List 관련 로직
//Searches the list from index start to the end of the list. The first time an object o is encountered so that o == element, the index of o is returned.
final notes = <String>['do', 're', 'mi', 're'];
print(notes.indexOf('re')); // 1

final indexWithStart = notes.indexOf('re', 2); // 3

//Returns -1 if element is not found.
final notes = <String>['do', 're', 'mi', 're'];
final index = notes.indexOf('fa'); // -1

//Implementation
int indexOf(E element, [int start = 0]);

 

참고 사이트

https://dev-dain.tistory.com/137

 


my_list5.addAll([6, 7, 8]);
my_list5.add(9);

my_list5.insert(3, 3);
my_list5.insertAll(1, [1, 2]);


my_list5.remove(0);  //제일 먼저 등장하는 0 삭제
my_list5.removeAt(3);  // 3번 인덱스의 값을 지운다.
// 이 때 인덱스는 0번부터 시작하므로 실질적으로 4번째 원소를 지운다는 것을 기억하자

//마지막 삭제
my_list5.removeLast();

//전체삭제
my_list5.clear();

<위의 링크의 글의 일부 내용 참조하였습니다.>