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/helpers/conversations_helper.dart';
import 'package:comunic/lists/users_list.dart'; import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/conversation.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/routes/main_route.dart';
import 'package:comunic/ui/tiles/simple_user_tile.dart'; import 'package:comunic/ui/tiles/simple_user_tile.dart';
import 'package:comunic/ui/widgets/pick_user_widget.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; get isOwner => !isUpdating || widget.initialSettings.isOwner;
Conversation get _initialSettings => widget.initialSettings;
bool get _canAddMembers => isOwner || _initialSettings.canEveryoneAddMembers;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -52,107 +57,107 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return SingleChildScrollView(
padding: EdgeInsets.all(8.0), child: Container(
child: Column( padding: EdgeInsets.all(8.0),
children: <Widget>[ child: Column(
// Conversation name children: <Widget>[
TextField( // Conversation name
controller: _nameController, TextField(
decoration: InputDecoration( controller: _nameController,
labelText: tr("Conversation name (optionnal)"), decoration: InputDecoration(
alignLabelWithHint: true, labelText: tr("Conversation name (optionnal)"),
enabled: isOwner, alignLabelWithHint: true,
enabled: isOwner,
),
), ),
),
// Add a member to the conversation // Follow conversation ?
PickUserWidget( Row(
resetOnChoose: true, children: <Widget>[
keepFocusOnChoose: true, Switch.adaptive(
label: tr("Add member"), value: _followConversation,
enabled: isOwner, onChanged: (b) => setState(() {
onSelectUser: (user) => setState(() { _followConversation = b;
if (!_members.contains(user)) _members.add(user); }),
}), ),
), Text(tr("Follow conversation"))
],
),
//Conversation members // Allow every members of the conversation to add users ?
Container( Row(
child: _members.length == 0 children: <Widget>[
? null Switch.adaptive(
: Flexible( value: _canEveryoneAddMembers,
child: ListView.builder( onChanged: isOwner
itemCount: _members.length, ? (b) => setState(() {
itemBuilder: (b, i) { _canEveryoneAddMembers = b;
return SimpleUserTile( })
user: _members[i], : null,
trailing: isOwner ),
? PopupMenuButton<_MembersMenuChoices>( Text(tr("Allow all members of the conversation to add users"))
onSelected: (choice) => ],
_membersMenuItemSelected(i, choice), ),
itemBuilder: (c) =>
<PopupMenuEntry<_MembersMenuChoices>>[
PopupMenuItem(
child: Text(tr("Remove")),
value: _MembersMenuChoices.REMOVE,
)
],
)
: null,
);
},
),
),
),
// Follow conversation ? // Add a member to the conversation
Row( PickUserWidget(
children: <Widget>[ resetOnChoose: true,
Switch.adaptive( keepFocusOnChoose: true,
value: _followConversation, label: tr("Add member"),
onChanged: (b) => setState(() { enabled: _canAddMembers,
_followConversation = b; onSelectUser: (user) => setState(() {
}), if (!_members.contains(user)) _members.add(user);
), }),
Text(tr("Follow conversation")) ),
],
),
// Allow every members of the conversation to add users ? //Conversation members
Row( Column(
children: <Widget>[ children: _members
Switch.adaptive( .map((f) => SimpleUserTile(
value: _canEveryoneAddMembers, user: f,
onChanged: isOwner trailing: _canAddMembers
? (b) => setState(() { ? PopupMenuButton<_MembersMenuChoices>(
_canEveryoneAddMembers = b; captureInheritedThemes: false,
}) onSelected: (choice) =>
: null, _membersMenuItemSelected(f, choice),
), itemBuilder: (c) =>
Text(tr("Allow all members of the conversation to add users")) <PopupMenuEntry<_MembersMenuChoices>>[
], PopupMenuItem(
), child: Text(tr("Remove")),
value: _MembersMenuChoices.REMOVE,
enabled: isOwner ||
(_canEveryoneAddMembers &&
!_initialSettings.members
.contains(f.id)),
)
],
)
: null,
))
.toList(),
),
// Submit button // Submit button
RaisedButton( RaisedButton(
onPressed: _members.length < 1 ? null : _submitForm, onPressed: _members.length < 1 ? null : _submitForm,
child: Text(isUpdating child: Text(isUpdating
? tr("Update the conversation") ? tr("Update the conversation")
: tr("Create the conversation")), : tr("Create the conversation")),
) )
], ],
),
), ),
); );
} }
/// An option of the members menu has been selected /// 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 == null) return;
if (choice == _MembersMenuChoices.REMOVE) if (choice == _MembersMenuChoices.REMOVE)
return setState(() { setState(() {
_members.removeAt(index); _members.removeWhere((u) => u.id == user.id);
}); });
} }