mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 12:14:11 +00:00 
			
		
		
		
	Can create a group
This commit is contained in:
		@@ -54,28 +54,38 @@ class _GroupsListScreenState extends SafeState<GroupsListScreen> {
 | 
			
		||||
          onRefresh: () => this._refreshList(),
 | 
			
		||||
          child: _groups == null
 | 
			
		||||
              ? Container()
 | 
			
		||||
              : ListView(
 | 
			
		||||
                  children: _groups.values
 | 
			
		||||
                      .map((g) => ListTile(
 | 
			
		||||
                            leading: GroupIcon(group: g),
 | 
			
		||||
                            title: Text(g.displayName),
 | 
			
		||||
                            subtitle: GroupMembershipWidget(
 | 
			
		||||
                              group: g,
 | 
			
		||||
                              onUpdated: () =>
 | 
			
		||||
                                  _refreshIndicatorKey.currentState.show(),
 | 
			
		||||
                            ),
 | 
			
		||||
                            trailing: IconButton(
 | 
			
		||||
                                icon: Icon(Icons.delete),
 | 
			
		||||
                                onPressed: () => _deleteGroup(g)),
 | 
			
		||||
                    onTap: () => MainController.of(context).openGroup(g.id),
 | 
			
		||||
                          ))
 | 
			
		||||
                      .toList(),
 | 
			
		||||
                ),
 | 
			
		||||
              : Stack(children: [_buildGroupsList(), _buildCreateButton()]),
 | 
			
		||||
        ))
 | 
			
		||||
      ],
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Widget _buildGroupsList() => ListView(
 | 
			
		||||
        children: _groups.values
 | 
			
		||||
            .map((g) => ListTile(
 | 
			
		||||
                  leading: GroupIcon(group: g),
 | 
			
		||||
                  title: Text(g.displayName),
 | 
			
		||||
                  subtitle: GroupMembershipWidget(
 | 
			
		||||
                    group: g,
 | 
			
		||||
                    onUpdated: () => _refreshIndicatorKey.currentState.show(),
 | 
			
		||||
                  ),
 | 
			
		||||
                  trailing: IconButton(
 | 
			
		||||
                      icon: Icon(Icons.delete),
 | 
			
		||||
                      onPressed: () => _deleteGroup(g)),
 | 
			
		||||
                  onTap: () => MainController.of(context).openGroup(g.id),
 | 
			
		||||
                ))
 | 
			
		||||
            .toList(),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  Widget _buildCreateButton() => Positioned(
 | 
			
		||||
        right: 15,
 | 
			
		||||
        bottom: 15,
 | 
			
		||||
        child: FloatingActionButton(
 | 
			
		||||
          child: Icon(Icons.add),
 | 
			
		||||
          onPressed: _createGroup,
 | 
			
		||||
        ),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  /// Refresh the list of groups
 | 
			
		||||
  Future<void> _refreshList() async {
 | 
			
		||||
    try {
 | 
			
		||||
@@ -109,4 +119,27 @@ class _GroupsListScreenState extends SafeState<GroupsListScreen> {
 | 
			
		||||
    // Refresh the list of groups
 | 
			
		||||
    _refreshIndicatorKey.currentState.show();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Add a group
 | 
			
		||||
  void _createGroup() async {
 | 
			
		||||
    try {
 | 
			
		||||
      final name = await askUserString(
 | 
			
		||||
        context: context,
 | 
			
		||||
        title: tr("Group name"),
 | 
			
		||||
        message: tr("Name of the group to create"),
 | 
			
		||||
        defaultValue: "",
 | 
			
		||||
        hint: tr("Name of the group"),
 | 
			
		||||
        maxLength: 50,
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      if (name == null) return;
 | 
			
		||||
 | 
			
		||||
      final groupID = await GroupsHelper.create(name);
 | 
			
		||||
 | 
			
		||||
      MainController.of(context).openGroup(groupID);
 | 
			
		||||
    } catch (e, s) {
 | 
			
		||||
      print("Could not create a new group! $e\n$s");
 | 
			
		||||
      showSimpleSnack(context, tr("Could not create a new group!"));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user