add friend is live !!!

pull/32/head
Lucas Delanier 2 years ago
parent 1fe178c662
commit 5c8950a2ad

@ -15,18 +15,9 @@ class ProfileListComponent extends StatefulWidget {
class _ProfileListComponentState extends State<ProfileListComponent> { class _ProfileListComponentState extends State<ProfileListComponent> {
late bool clicked; late bool clicked;
@override
void initState() {
if (MyApp.userViewModel.isFriend(widget.user.id)) {
clicked = true;
} else {
clicked = false;
}
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
clicked = MyApp.userViewModel.isFriend(widget.user.id);
return Container( return Container(
padding: const EdgeInsets.only(bottom: 5), padding: const EdgeInsets.only(bottom: 5),
child: Row( child: Row(
@ -47,22 +38,38 @@ class _ProfileListComponentState extends State<ProfileListComponent> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
ScrollConfiguration( Text(
behavior: ScrollBehavior().copyWith(scrollbars: false), widget.user.pseudo,
child: Text(
widget.user.uniquePseudo,
style: GoogleFonts.plusJakartaSans(fontSize: 16, color: Colors.white, fontWeight: FontWeight.w700), style: GoogleFonts.plusJakartaSans(fontSize: 16, color: Colors.white, fontWeight: FontWeight.w700),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
maxLines: 1, maxLines: 1,
), ),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
widget.user.uniquePseudo,
overflow: TextOverflow.ellipsis,
style: GoogleFonts.plusJakartaSans(color: Colors.grey, fontWeight: FontWeight.w400),
),
widget.user.followed.contains(MyApp.userViewModel.userCurrent.id)
? Container(
padding: const EdgeInsets.all(2),
margin: const EdgeInsets.only(left: 10),
decoration: const BoxDecoration(
color: grayColor,
borderRadius: BorderRadius.all(Radius.circular(3)),
), ),
ScrollConfiguration(
behavior: ScrollBehavior().copyWith(scrollbars: false),
child: Text( child: Text(
widget.user.pseudo, "Vous suit",
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: GoogleFonts.plusJakartaSans(color: Colors.grey, fontWeight: FontWeight.w400), style: GoogleFonts.plusJakartaSans(
)) color: Colors.grey.withOpacity(0.4), fontWeight: FontWeight.w700, fontSize: 12),
),
)
: Container(),
],
)
], ],
), ),
), ),
@ -73,11 +80,9 @@ class _ProfileListComponentState extends State<ProfileListComponent> {
color: selectedButton, color: selectedButton,
child: InkWell( child: InkWell(
splashColor: Colors.white.withOpacity(0.3), splashColor: Colors.white.withOpacity(0.3),
onTap: () { onTap: () async {
MyApp.userViewModel.addOrDeleteFriend(widget.user.id); await MyApp.userViewModel.addOrDeleteFriend(widget.user.id);
setState(() { setState(() {});
clicked = !clicked;
});
}, },
child: Container( child: Container(
padding: EdgeInsets.fromLTRB(28, 7, 28, 7), padding: EdgeInsets.fromLTRB(28, 7, 28, 7),
@ -93,11 +98,9 @@ class _ProfileListComponentState extends State<ProfileListComponent> {
color: primaryColor, color: primaryColor,
child: InkWell( child: InkWell(
splashColor: Colors.white.withOpacity(0.3), splashColor: Colors.white.withOpacity(0.3),
onTap: () { onTap: () async {
MyApp.userViewModel.addOrDeleteFriend(widget.user.id); await MyApp.userViewModel.addOrDeleteFriend(widget.user.id);
setState(() { setState(() {});
clicked = !clicked;
});
}, },
child: Container( child: Container(
padding: EdgeInsets.fromLTRB(25, 7, 25, 7), padding: EdgeInsets.fromLTRB(25, 7, 25, 7),

@ -91,6 +91,10 @@ class _AddFriendScreenState extends State<AddFriendScreen> {
onSubmitted: (value) async { onSubmitted: (value) async {
if (_textEditingController.text.isNotEmpty) { if (_textEditingController.text.isNotEmpty) {
updateList(value); updateList(value);
} else {
setState(() {
_listUsers = [];
});
} }
}, },
cursorColor: Colors.white, cursorColor: Colors.white,

@ -19,20 +19,29 @@ class UserService {
} }
addOrDeleteFriend(String id) async { addOrDeleteFriend(String id) async {
var userRef = MyApp.db.collection("users").doc(MyApp.userViewModel.userCurrent.id); var userRef = MyApp.db.collection("users").doc(MyApp.userViewModel.userCurrent.id);
var actionUserRef = MyApp.db.collection("users").doc(id);
if (MyApp.userViewModel.isFriend(id)) { if (MyApp.userViewModel.isFriend(id)) {
await MyApp.db.runTransaction((transaction) async { await MyApp.db.runTransaction((transaction) async {
transaction.update(userRef, {'followed': FieldValue.arrayRemove([id])}); transaction.update(userRef, {
'followed': FieldValue.arrayRemove([id])
});
transaction.update(actionUserRef, {
'followers': FieldValue.arrayRemove([id])
});
}); });
MyApp.userViewModel.userCurrent.followed.remove(id); MyApp.userViewModel.userCurrent.followed.remove(id);
} else { } else {
await MyApp.db.runTransaction((transaction) async { await MyApp.db.runTransaction((transaction) async {
transaction.update(userRef, {'followed': FieldValue.arrayUnion([id])}); transaction.update(userRef, {
'followed': FieldValue.arrayUnion([id])
});
transaction.update(actionUserRef, {
'followers': FieldValue.arrayUnion([id])
});
}); });
MyApp.userViewModel.userCurrent.followed.add(id); MyApp.userViewModel.userCurrent.followed.add(id);
} }
} }
} }

@ -78,10 +78,10 @@ class UserViewModel {
} }
} }
AddOrDeleteFriend(String id) async { addOrDeleteFriend(String id) async {
try { try {
await _userService.addOrDeleteFriend(id); await _userService.addOrDeleteFriend(id);
} catch(e) { } catch (e) {
print(e); print(e);
rethrow; rethrow;
} }
@ -94,6 +94,4 @@ class UserViewModel {
bool isFriend(String id) { bool isFriend(String id) {
return _userCurrent.followed.contains(id); return _userCurrent.followed.contains(id);
} }
void addOrDeleteFriend(String id) {}
} }

Loading…
Cancel
Save