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> {
late bool clicked;
@override
void initState() {
if (MyApp.userViewModel.isFriend(widget.user.id)) {
clicked = true;
} else {
clicked = false;
}
super.initState();
}
@override
Widget build(BuildContext context) {
clicked = MyApp.userViewModel.isFriend(widget.user.id);
return Container(
padding: const EdgeInsets.only(bottom: 5),
child: Row(
@ -47,22 +38,38 @@ class _ProfileListComponentState extends State<ProfileListComponent> {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
ScrollConfiguration(
behavior: ScrollBehavior().copyWith(scrollbars: false),
child: Text(
widget.user.uniquePseudo,
style: GoogleFonts.plusJakartaSans(fontSize: 16, color: Colors.white, fontWeight: FontWeight.w700),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
Text(
widget.user.pseudo,
style: GoogleFonts.plusJakartaSans(fontSize: 16, color: Colors.white, fontWeight: FontWeight.w700),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
ScrollConfiguration(
behavior: ScrollBehavior().copyWith(scrollbars: false),
child: Text(
widget.user.pseudo,
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)),
),
child: Text(
"Vous suit",
overflow: TextOverflow.ellipsis,
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,
child: InkWell(
splashColor: Colors.white.withOpacity(0.3),
onTap: () {
MyApp.userViewModel.addOrDeleteFriend(widget.user.id);
setState(() {
clicked = !clicked;
});
onTap: () async {
await MyApp.userViewModel.addOrDeleteFriend(widget.user.id);
setState(() {});
},
child: Container(
padding: EdgeInsets.fromLTRB(28, 7, 28, 7),
@ -93,11 +98,9 @@ class _ProfileListComponentState extends State<ProfileListComponent> {
color: primaryColor,
child: InkWell(
splashColor: Colors.white.withOpacity(0.3),
onTap: () {
MyApp.userViewModel.addOrDeleteFriend(widget.user.id);
setState(() {
clicked = !clicked;
});
onTap: () async {
await MyApp.userViewModel.addOrDeleteFriend(widget.user.id);
setState(() {});
},
child: Container(
padding: EdgeInsets.fromLTRB(25, 7, 25, 7),

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

@ -19,20 +19,29 @@ class UserService {
}
addOrDeleteFriend(String id) async {
var userRef = MyApp.db.collection("users").doc(MyApp.userViewModel.userCurrent.id);
var actionUserRef = MyApp.db.collection("users").doc(id);
if (MyApp.userViewModel.isFriend(id)) {
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);
} else {
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);
}
}
}

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

Loading…
Cancel
Save