mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Create new conversations
This commit is contained in:
@ -3,6 +3,7 @@ import 'package:comunic/helpers/conversations_helper.dart';
|
||||
import 'package:comunic/helpers/users_helper.dart';
|
||||
import 'package:comunic/lists/conversations_list.dart';
|
||||
import 'package:comunic/ui/routes/conversation_route.dart';
|
||||
import 'package:comunic/ui/routes/create_conversation_route.dart';
|
||||
import 'package:comunic/ui/tiles/conversation_tile.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
@ -52,7 +53,7 @@ class _ConversationScreenState extends State<ConversationsListScreen> {
|
||||
|
||||
//Get the list of conversations
|
||||
var list;
|
||||
if(cached)
|
||||
if (cached)
|
||||
list = await _conversationsHelper.getCachedList();
|
||||
else
|
||||
list = await _conversationsHelper.downloadList();
|
||||
@ -90,12 +91,20 @@ class _ConversationScreenState extends State<ConversationsListScreen> {
|
||||
}
|
||||
|
||||
/// Open a conversation
|
||||
void _openConversation(BuildContext context, int conversationId){
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (c){
|
||||
return ConversationRoute(conversationID: conversationId,);
|
||||
void _openConversation(BuildContext context, int conversationId) {
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (c) {
|
||||
return ConversationRoute(
|
||||
conversationID: conversationId,
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
/// Create a new conversation
|
||||
void _createConversation(BuildContext context) {
|
||||
Navigator.of(context)
|
||||
.push(MaterialPageRoute(builder: (c) => CreateConversationRoute()));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_error == LoadErrorLevel.MAJOR) return _buildErrorCard();
|
||||
@ -116,7 +125,9 @@ class _ConversationScreenState extends State<ConversationsListScreen> {
|
||||
return ConversationTile(
|
||||
conversation: _list.elementAt(index),
|
||||
usersList: _list.users,
|
||||
onOpen: (c){_openConversation(context, c.id);},
|
||||
onOpen: (c) {
|
||||
_openConversation(context, c.id);
|
||||
},
|
||||
);
|
||||
},
|
||||
itemCount: _list.length,
|
||||
@ -124,6 +135,18 @@ class _ConversationScreenState extends State<ConversationsListScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// Add conversation button
|
||||
Positioned(
|
||||
right: 20.0,
|
||||
bottom: 20.0,
|
||||
child: FloatingActionButton(
|
||||
onPressed: () => _createConversation(context),
|
||||
child: Icon(Icons.add),
|
||||
),
|
||||
),
|
||||
|
||||
// Loading indicator
|
||||
Positioned(
|
||||
top: 8.0,
|
||||
left: 0.0,
|
||||
|
132
lib/ui/screens/update_conversation_screen.dart
Normal file
132
lib/ui/screens/update_conversation_screen.dart
Normal file
@ -0,0 +1,132 @@
|
||||
import 'package:comunic/helpers/conversations_helper.dart';
|
||||
import 'package:comunic/lists/users_list.dart';
|
||||
import 'package:comunic/models/conversation_settings.dart';
|
||||
import 'package:comunic/ui/routes/conversation_route.dart';
|
||||
import 'package:comunic/ui/tiles/simple_user_tile.dart';
|
||||
import 'package:comunic/ui/widgets/pick_user_widget.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Create / Update conversation screen
|
||||
///
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
enum _MembersMenuChoices { REMOVE }
|
||||
|
||||
class UpdateConversationScreen extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() => _UpdateConversationScreen();
|
||||
}
|
||||
|
||||
class _UpdateConversationScreen extends State<UpdateConversationScreen> {
|
||||
TextEditingController _nameController = TextEditingController();
|
||||
UsersList _members = UsersList();
|
||||
bool _followConversation = true;
|
||||
|
||||
@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),
|
||||
),
|
||||
|
||||
// Add a member to the conversation
|
||||
PickUserWidget(
|
||||
resetOnChoose: true,
|
||||
keepFocusOnChoose: true,
|
||||
label: tr("Add member"),
|
||||
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: PopupMenuButton<_MembersMenuChoices>(
|
||||
onSelected: (choice) =>
|
||||
_membersMenuItemSelected(i, choice),
|
||||
itemBuilder: (c) =>
|
||||
<PopupMenuEntry<_MembersMenuChoices>>[
|
||||
PopupMenuItem(
|
||||
child: Text(tr("Remove")),
|
||||
value: _MembersMenuChoices.REMOVE,
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Follow conversation ?
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Switch(
|
||||
value: _followConversation,
|
||||
onChanged: (b) => setState(() {
|
||||
_followConversation = b;
|
||||
}),
|
||||
),
|
||||
Text(tr("Follow conversation"))
|
||||
],
|
||||
),
|
||||
|
||||
// Submit button
|
||||
RaisedButton(
|
||||
onPressed: _members.length < 1 ? null : _submitForm,
|
||||
child: Text(tr("Create the conversation")),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// An option of the members menu has been selected
|
||||
void _membersMenuItemSelected(int index, _MembersMenuChoices choice) {
|
||||
if (choice == null) return;
|
||||
|
||||
if (choice == _MembersMenuChoices.REMOVE)
|
||||
return setState(() {
|
||||
_members.removeAt(index);
|
||||
});
|
||||
}
|
||||
|
||||
/// Submit the conversation
|
||||
Future<void> _submitForm() async {
|
||||
final settings = ConversationSettings(
|
||||
id: 0,
|
||||
name: _nameController.text,
|
||||
following: _followConversation,
|
||||
members: _members.usersID,
|
||||
);
|
||||
|
||||
// Create the conversation
|
||||
final conversationID = await ConversationsHelper().createConversation(settings);
|
||||
|
||||
// Check for errors
|
||||
if(conversationID < 1)
|
||||
return Scaffold.of(context).showSnackBar(
|
||||
SnackBar(content: Text(tr("Could not create the conversation!")), duration: Duration(seconds: 1),));
|
||||
|
||||
// Open the conversation
|
||||
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
||||
builder: (c) => ConversationRoute(conversationID: conversationID,)
|
||||
));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user