A comprehensive Flutter package that provides complete access to the Mattermost API. This package enables Flutter developers to easily integrate Mattermost functionality into their applications with a clean, type-safe Dart interface.
The package covers all Mattermost API endpoints including authentication, users, teams, channels, posts, files, webhooks, and real-time WebSocket communication. It features robust error handling, comprehensive documentation, and practical examples to help you get started quickly.
Built with Flutter best practices and designed for performance, this package is ideal for building custom Mattermost clients, chat integrations, notification systems, or any application that needs to interact with a Mattermost server.
- π Complete Authentication: Login, logout, and token management
- π₯ Users & Teams: User management, team creation and management
- π¬ Channels & Messages: Create and manage channels, send and receive messages
- π File Uploads: Upload and manage files
- π Real-time Updates: WebSocket support for real-time events
- π§© Plugins & Integrations: Support for Mattermost plugins and integrations
- π Search: Comprehensive search capabilities
- π οΈ Admin Functions: Administrative operations support
Add this to your package's pubspec.yaml
file:
dependencies:
mattermost_flutter: ^1.0.0
Then run:
flutter pub get
import 'package:mattermost_flutter/mattermost_flutter.dart';
// Initialize the client
final client = MattermostClient(
config: MattermostConfig(
baseUrl: 'https://your-mattermost-server.com',
enableDebugLogs: true,
),
);
// Login with username/email and password
try {
await client.login(
loginId: 'username_or_email',
password: 'your_password',
);
print('Login successful!');
} catch (e) {
print('Login failed: $e');
}
// Logout
await client.logout();
// Get current user
final currentUser = await client.users.getMe();
print('Logged in as: ${currentUser.username}');
// Get user by ID
final user = await client.users.getUser('user_id');
// Update user
await client.users.updateUser(
'user_id',
MUpdateUserRequest(
firstName: 'New First Name',
lastName: 'New Last Name',
),
);
// Get teams for user
final teams = await client.teams.getTeamsForUser('user_id');
// Create a team
final newTeam = await client.teams.createTeam(
MCreateTeamRequest(
name: 'team-name',
displayName: 'Team Display Name',
type: 'O', // Open team
),
);
// Get channels for team
final channels = await client.channels.getChannelsForTeam('team_id');
// Create a channel
final newChannel = await client.channels.createChannel(
MCreateChannelRequest(
teamId: 'team_id',
name: 'channel-name',
displayName: 'Channel Display Name',
type: 'O', // Public channel
purpose: 'Channel purpose',
header: 'Channel header',
),
);
// Join a channel
await client.channels.addChannelMember('channel_id', 'user_id');
// Create a post
final post = await client.posts.createPost(
MCreatePostRequest(
channelId: 'channel_id',
message: 'Hello, Mattermost!',
),
);
// Get posts for a channel
final posts = await client.posts.getPostsForChannel(
'channel_id',
perPage: 30,
);
// Add a reaction to a post
await client.posts.addReaction(
MReactionRequest(
userId: 'user_id',
postId: 'post_id',
emojiName: '+1',
),
);
// Connect to WebSocket
client.webSocket.connect();
// Listen for events
client.webSocket.events.listen((event) {
if (event['event'] == 'posted') {
print('New message posted!');
// Handle new message
}
});
// Disconnect WebSocket
client.webSocket.disconnect();
The package provides access to all Mattermost API endpoints through the following classes:
MUsersApi
: User managementMTeamsApi
: Team managementMChannelsApi
: Channel operationsMPostsApi
: Post (message) operationsMFilesApi
: File upload and managementMSystemApi
: System configurationMWebhooksApi
: Webhook managementMPreferencesApi
: User preferencesMStatusApi
: User statusMEmojisApi
: Custom emoji managementMComplianceApi
: Compliance reportsMClustersApi
: Cluster managementMLDAPApi
: LDAP integrationMOAuthApi
: OAuth app managementMElasticsearchApi
: Elasticsearch configurationMPluginsApi
: Plugin managementMRolesApi
: Role managementMSchemesApi
: Scheme managementMIntegrationsApi
: Integration managementMBrandApi
: Brand image managementMCommandsApi
: Slash command managementMGroupsApi
: Group managementMBotsApi
: Bot account managementMJobsApi
: Background job managementMDataRetentionApi
: Data retention policiesMExportsApi
: Data exportMImportsApi
: Data importMSAMLApi
: SAML configurationMPermissionsApi
: Permission managementMSharedChannelsApi
: Shared channel managementMCloudApi
: Cloud service management
The MattermostConfig
class provides several configuration options:
final config = MattermostConfig(
baseUrl: 'https://your-mattermost-server.com',
enableDebugLogs: true,
timeout: const Duration(seconds: 30),
validateCertificate: true,
userAgent: 'MyMattermostApp/1.0',
);
Here's a more complete example showing how to build a simple Mattermost client:
check the example
directory for a full Flutter app that demonstrates the usage of this package.
Click here to explore the example app.
The package provides detailed error information when API calls fail:
try {
await client.login(
loginId: 'username_or_email',
password: 'wrong_password',
);
} catch (e) {
if (e is MattermostApiException) {
print('Status code: ${e.statusCode}');
print('Error message: ${e.message}');
print('Error details: ${e.details}');
} else {
print('Unexpected error: $e');
}
}
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.