mattermost_flutter 1.0.8
mattermost_flutter: ^1.0.8 copied to clipboard
A complete Flutter package for interacting with the Mattermost API, featuring comprehensive endpoint coverage, WebSocket support, and robust error handling. Build custom Mattermost clients and integra [...]
Mattermost Flutter #
#
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.
Features #
- 🔐 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
Installation #
Add this to your package's pubspec.yaml
file:
dependencies:
mattermost_flutter: ^1.0.0
Then run:
flutter pub get
Basic Usage #
Initialize the Client #
import 'package:mattermost_flutter/mattermost_flutter.dart';
// Initialize the client
final client = MattermostClient(
config: MattermostConfig(
baseUrl: 'https://your-mattermost-server.com',
enableDebugLogs: true,
),
);
Authentication #
// 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();
Working with Users #
// 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',
),
);
Working with Teams #
// 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
),
);
Working with Channels #
// 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');
Working with Posts #
// 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',
),
);
Using WebSockets for Real-time Updates #
// 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();
API Documentation #
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
Configuration Options #
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',
);
Complete Example #
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.
Error Handling #
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');
}
}
Contributing #
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
Contributors #
License #
This project is licensed under the MIT License - see the LICENSE file for details.