mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-26 04:48:51 +00:00
Update screen
This commit is contained in:
parent
ace7b44595
commit
c09670ad64
@ -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,107 +57,107 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
// Conversation name
|
||||
TextField(
|
||||
controller: _nameController,
|
||||
decoration: InputDecoration(
|
||||
labelText: tr("Conversation name (optionnal)"),
|
||||
alignLabelWithHint: true,
|
||||
enabled: isOwner,
|
||||
return SingleChildScrollView(
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
// Conversation name
|
||||
TextField(
|
||||
controller: _nameController,
|
||||
decoration: InputDecoration(
|
||||
labelText: tr("Conversation name (optionnal)"),
|
||||
alignLabelWithHint: true,
|
||||
enabled: isOwner,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 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);
|
||||
}),
|
||||
),
|
||||
// Follow conversation ?
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Switch.adaptive(
|
||||
value: _followConversation,
|
||||
onChanged: (b) => setState(() {
|
||||
_followConversation = b;
|
||||
}),
|
||||
),
|
||||
Text(tr("Follow conversation"))
|
||||
],
|
||||
),
|
||||
|
||||
//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,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
// Allow every members of the conversation to add users ?
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Switch.adaptive(
|
||||
value: _canEveryoneAddMembers,
|
||||
onChanged: isOwner
|
||||
? (b) => setState(() {
|
||||
_canEveryoneAddMembers = b;
|
||||
})
|
||||
: null,
|
||||
),
|
||||
Text(tr("Allow all members of the conversation to add users"))
|
||||
],
|
||||
),
|
||||
|
||||
// Follow conversation ?
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Switch.adaptive(
|
||||
value: _followConversation,
|
||||
onChanged: (b) => setState(() {
|
||||
_followConversation = b;
|
||||
}),
|
||||
),
|
||||
Text(tr("Follow conversation"))
|
||||
],
|
||||
),
|
||||
// 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);
|
||||
}),
|
||||
),
|
||||
|
||||
// Allow every members of the conversation to add users ?
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Switch.adaptive(
|
||||
value: _canEveryoneAddMembers,
|
||||
onChanged: isOwner
|
||||
? (b) => setState(() {
|
||||
_canEveryoneAddMembers = b;
|
||||
})
|
||||
: null,
|
||||
),
|
||||
Text(tr("Allow all members of the conversation to add users"))
|
||||
],
|
||||
),
|
||||
//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,
|
||||
child: Text(isUpdating
|
||||
? tr("Update the conversation")
|
||||
: tr("Create the conversation")),
|
||||
)
|
||||
],
|
||||
// Submit button
|
||||
RaisedButton(
|
||||
onPressed: _members.length < 1 ? null : _submitForm,
|
||||
child: Text(isUpdating
|
||||
? tr("Update the conversation")
|
||||
: tr("Create the conversation")),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 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);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user