1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00

Update screen

This commit is contained in:
Pierre HUBERT 2020-04-26 15:25:56 +02:00
parent ace7b44595
commit c09670ad64

View File

@ -1,6 +1,7 @@
import 'package:comunic/helpers/conversations_helper.dart';
import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/conversation.dart';
import 'package:comunic/models/user.dart';
import 'package:comunic/ui/routes/main_route.dart';
import 'package:comunic/ui/tiles/simple_user_tile.dart';
import 'package:comunic/ui/widgets/pick_user_widget.dart';
@ -37,6 +38,10 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
get isOwner => !isUpdating || widget.initialSettings.isOwner;
Conversation get _initialSettings => widget.initialSettings;
bool get _canAddMembers => isOwner || _initialSettings.canEveryoneAddMembers;
@override
void initState() {
super.initState();
@ -52,7 +57,8 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
@override
Widget build(BuildContext context) {
return Container(
return SingleChildScrollView(
child: Container(
padding: EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
@ -66,46 +72,6 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
),
),
// Add a member to the conversation
PickUserWidget(
resetOnChoose: true,
keepFocusOnChoose: true,
label: tr("Add member"),
enabled: isOwner,
onSelectUser: (user) => setState(() {
if (!_members.contains(user)) _members.add(user);
}),
),
//Conversation members
Container(
child: _members.length == 0
? null
: Flexible(
child: ListView.builder(
itemCount: _members.length,
itemBuilder: (b, i) {
return SimpleUserTile(
user: _members[i],
trailing: isOwner
? PopupMenuButton<_MembersMenuChoices>(
onSelected: (choice) =>
_membersMenuItemSelected(i, choice),
itemBuilder: (c) =>
<PopupMenuEntry<_MembersMenuChoices>>[
PopupMenuItem(
child: Text(tr("Remove")),
value: _MembersMenuChoices.REMOVE,
)
],
)
: null,
);
},
),
),
),
// Follow conversation ?
Row(
children: <Widget>[
@ -134,6 +100,44 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
],
),
// Add a member to the conversation
PickUserWidget(
resetOnChoose: true,
keepFocusOnChoose: true,
label: tr("Add member"),
enabled: _canAddMembers,
onSelectUser: (user) => setState(() {
if (!_members.contains(user)) _members.add(user);
}),
),
//Conversation members
Column(
children: _members
.map((f) => SimpleUserTile(
user: f,
trailing: _canAddMembers
? PopupMenuButton<_MembersMenuChoices>(
captureInheritedThemes: false,
onSelected: (choice) =>
_membersMenuItemSelected(f, choice),
itemBuilder: (c) =>
<PopupMenuEntry<_MembersMenuChoices>>[
PopupMenuItem(
child: Text(tr("Remove")),
value: _MembersMenuChoices.REMOVE,
enabled: isOwner ||
(_canEveryoneAddMembers &&
!_initialSettings.members
.contains(f.id)),
)
],
)
: null,
))
.toList(),
),
// Submit button
RaisedButton(
onPressed: _members.length < 1 ? null : _submitForm,
@ -143,16 +147,17 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
)
],
),
),
);
}
/// An option of the members menu has been selected
void _membersMenuItemSelected(int index, _MembersMenuChoices choice) {
void _membersMenuItemSelected(User user, _MembersMenuChoices choice) {
if (choice == null) return;
if (choice == _MembersMenuChoices.REMOVE)
return setState(() {
_members.removeAt(index);
setState(() {
_members.removeWhere((u) => u.id == user.id);
});
}