### Flutter App Example Source: https://pub.dev/packages/open_mail_launcher/example This is the main example file for the open_mail_launcher plugin. It demonstrates how to load available mail apps, compose an email with various fields (to, cc, bcc, subject, body), and open the default mail app or a specific one. ```dart import 'package:flutter/material.dart'; import 'package:open_mail_launcher/open_mail_launcher.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Open Mail Launcher Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue), useMaterial3: true, ), home: const HomePage(), ); } } class HomePage extends StatefulWidget { const HomePage({super.key}); @override State createState() => _HomePageState(); } class _HomePageState extends State { List _mailApps = []; bool _isLoading = false; String _statusMessage = ''; // Email content controllers final _toController = TextEditingController(text: 'example@email.com'); final _ccController = TextEditingController(); final _bccController = TextEditingController(); final _subjectController = TextEditingController( text: 'Test Email from Flutter', ); final _bodyController = TextEditingController( text: 'This is a test email sent from the Open Mail Launcher Flutter plugin.', ); @override void initState() { super.initState(); _loadMailApps(); } @override void dispose() { _toController.dispose(); _ccController.dispose(); _bccController.dispose(); _subjectController.dispose(); _bodyController.dispose(); super.dispose(); } Future _loadMailApps() async { setState(() { _isLoading = true; _statusMessage = ''; }); try { final apps = await OpenMailLauncher.getMailApps(); setState(() { _mailApps = apps; _isLoading = false; _statusMessage = 'Found ${apps.length} mail app(s)'; }); } catch (e) { setState(() { _isLoading = false; _statusMessage = 'Error loading mail apps: $e'; }); } } /// Null when every field is empty — the plugin then opens the mail app /// itself (inbox / main screen) instead of a compose window. EmailContent? _createEmailContent() { final content = EmailContent( to: _toController.text .split(',') .map((e) => e.trim()) .where((e) => e.isNotEmpty) .toList(), cc: _ccController.text .split(',') .map((e) => e.trim()) .where((e) => e.isNotEmpty) .toList(), bcc: _bccController.text .split(',') .map((e) => e.trim()) .where((e) => e.isNotEmpty) .toList(), subject: _subjectController.text, body: _bodyController.text, ); final isEmpty = content.to.isEmpty && content.cc.isEmpty && content.bcc.isEmpty && (content.subject?.isEmpty ?? true) && (content.body?.isEmpty ?? true); return isEmpty ? null : content; } Future _openMailApp() async { setState(() { _statusMessage = 'Opening mail app...'; }); try { final result = await OpenMailLauncher.openMailApp( emailContent: _createEmailContent(), ); if (result.didOpen) { setState(() { _statusMessage = 'Mail app opened successfully'; }); } else if (result.canOpen && result.hasMultipleOptions) { // Show picker dialog for iOS or when Android doesn't show native picker if (mounted) { final selectedApp = await OpenMailLauncher.showMailAppPicker( context: context, mailApps: result.options, ); if (selectedApp != null) { await _openSpecificMailApp(selectedApp); } else { setState(() { _statusMessage = 'No app selected'; }); } } } else { setState(() { _statusMessage = 'No mail apps available'; }); _showNoMailAppsDialog(); } } catch (e) { setState(() { _statusMessage = 'Error: $e'; }); } } Future _openSpecificMailApp(MailApp mailApp) async { setState(() { _statusMessage = 'Opening ${mailApp.name}...'; }); try { final success = await OpenMailLauncher.openSpecificMailApp( mailApp: mailApp, emailContent: _createEmailContent(), ); ``` -------------------------------- ### Run flutter pub get Source: https://pub.dev/packages/open_mail_launcher/versions/0.0.1 After adding the dependency, run this command to fetch the package. ```bash flutter pub get ``` -------------------------------- ### Example pubspec.yaml Dependency Source: https://pub.dev/packages/open_mail_launcher/versions/0.1.1/install This is how the dependency will appear in your pubspec.yaml file after running the add command. ```yaml dependencies: open_mail_launcher: ^0.1.1 ``` -------------------------------- ### Check Email App Availability and Get Apps Source: https://pub.dev/packages/open_mail_launcher/versions/0.0.1 Demonstrates how to check if any email application is installed on the device and retrieve a list of all available email applications. ```dart import 'package:open_mail_launcher/open_mail_launcher.dart'; // Check if any email app is available bool available = await OpenMailLauncher.isMailAppAvailable(); // Get list of available email apps List apps = await OpenMailLauncher.getMailApps(); // Open any available email app OpenMailAppResult result = await OpenMailLauncher.openMailApp(); ``` -------------------------------- ### Flutter App Initialization and UI Setup Source: https://pub.dev/packages/open_mail_launcher/versions/0.1.1/example This snippet shows the basic structure of a Flutter application using the open_mail_launcher plugin. It includes setting up the main app widget, the home page, and controllers for email content. ```dart import 'package:flutter/material.dart'; import 'package:open_mail_launcher/open_mail_launcher.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Open Mail Launcher Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue), useMaterial3: true, ), home: const HomePage(), ); } } class HomePage extends StatefulWidget { const HomePage({super.key}); @override State createState() => _HomePageState(); } class _HomePageState extends State { List _mailApps = []; bool _isLoading = false; String _statusMessage = ''; // Email content controllers final _toController = TextEditingController(text: 'example@email.com'); final _ccController = TextEditingController(); final _bccController = TextEditingController(); final _subjectController = TextEditingController( text: 'Test Email from Flutter', ); final _bodyController = TextEditingController( text: 'This is a test email sent from the Open Mail Launcher Flutter plugin.', ); @override void initState() { super.initState(); _loadMailApps(); } @override void dispose() { _toController.dispose(); _ccController.dispose(); _bccController.dispose(); _subjectController.dispose(); _bodyController.dispose(); super.dispose(); } Future _loadMailApps() async { setState(() { _isLoading = true; _statusMessage = ''; }); try { final apps = await OpenMailLauncher.getMailApps(); setState(() { _mailApps = apps; _isLoading = false; _statusMessage = 'Found ${apps.length} mail app(s)'; }); } catch (e) { setState(() { _isLoading = false; _statusMessage = 'Error loading mail apps: $e'; }); } } EmailContent _createEmailContent() { return EmailContent( to: _toController.text .split(',') .map((e) => e.trim()) .where((e) => e.isNotEmpty) .toList(), cc: _ccController.text .split(',') .map((e) => e.trim()) .where((e) => e.isNotEmpty) .toList(), bcc: _bccController.text .split(',') .map((e) => e.trim()) .where((e) => e.isNotEmpty) .toList(), subject: _subjectController.text, body: _bodyController.text, ); } Future _openMailApp() async { setState(() { _statusMessage = 'Opening mail app...'; }); try { final result = await OpenMailLauncher.openMailApp( emailContent: _createEmailContent(), ); if (result.didOpen) { setState(() { _statusMessage = 'Mail app opened successfully'; }); } else if (result.canOpen && result.hasMultipleOptions) { // Show picker dialog for iOS or when Android doesn't show native picker if (mounted) { final selectedApp = await OpenMailLauncher.showMailAppPicker( context: context, mailApps: result.options, ); if (selectedApp != null) { await _openSpecificMailApp(selectedApp); } else { setState(() { _statusMessage = 'No app selected'; }); } } } else { setState(() { _statusMessage = 'No mail apps available'; }); _showNoMailAppsDialog(); } } catch (e) { setState(() { _statusMessage = 'Error: $e'; }); } } Future _openSpecificMailApp(MailApp mailApp) async { setState(() { _statusMessage = 'Opening ${mailApp.name}...'; }); try { final success = await OpenMailLauncher.openSpecificMailApp( mailApp: mailApp, emailContent: _createEmailContent(), ); setState(() { _statusMessage = success ? '${mailApp.name} opened successfully' : 'Failed to open ${mailApp.name}'; }); } catch (e) { setState(() { _statusMessage = 'Error: $e'; }); } } Future _composeEmail() async { setState(() { _statusMessage = 'Composing email...'; }); try { final success = await OpenMailLauncher.composeEmail( emailContent: _createEmailContent(), ); ``` -------------------------------- ### Get Available Email Apps Source: https://pub.dev/packages/open_mail_launcher/versions/0.4.0-beta.1 Retrieves a list of all installed email applications on the device. ```APIDOC ## getMailApps ### Description Retrieves a list of all installed email applications on the device. ### Method `static Future> getMailApps()` ### Returns - `Future>`: A future that resolves to a list of `MailApp` objects, each representing an available email application. ``` -------------------------------- ### Check Email App Availability and List Apps Source: https://pub.dev/packages/open_mail_launcher/versions/0.1.2 Use OpenMailLauncher to check if any email apps are installed and to retrieve a list of available email applications. ```dart import 'package:open_mail_launcher/open_mail_launcher.dart'; // Check if any email app is available bool available = await OpenMailLauncher.isMailAppAvailable(); // Get list of available email apps List apps = await OpenMailLauncher.getMailApps(); // Open any available email app OpenMailAppResult result = await OpenMailLauncher.openMailApp(); ``` -------------------------------- ### Handle Multiple Email Apps and Show Picker Source: https://pub.dev/packages/open_mail_launcher/versions/0.0.1 Illustrates how to handle scenarios where multiple email applications are installed. It shows how to display a picker dialog to the user for selecting an email app and then opening the selected app. ```dart OpenMailAppResult result = await OpenMailLauncher.openMailApp( emailContent: emailContent, ); if (result.didOpen) { // Email app opened successfully print('Email app opened!'); } else if (result.hasMultipleOptions) { // Show picker dialog for multiple apps MailApp? selectedApp = await OpenMailLauncher.showMailAppPicker( context: context, mailApps: result.options, title: 'Choose Email App', ); if (selectedApp != null) { // Open the selected email app bool opened = await OpenMailLauncher.openSpecificMailApp( mailApp: selectedApp, emailContent: emailContent, ); } } else { // No email apps available print('No email apps found'); } ``` -------------------------------- ### Displaying Available Mail Apps Source: https://pub.dev/packages/open_mail_launcher/versions/0.1.0/example Renders a list of installed mail apps, highlighting the default app. If no apps are found, it displays an informational card. ```dart if (_mailApps.isEmpty) const Card( child: ListTile( leading: Icon(Icons.info_outline), title: Text('No mail apps found'), subtitle: Text('Tap refresh to reload'), ), ) else ..._mailApps.map( (app) => Card( child: ListTile( leading: Icon( Icons.email, color: app.isDefault ? Colors.blue : null, ), title: Text(app.name), subtitle: Text(app.isDefault ? 'Default app' : app.id), trailing: IconButton( icon: const Icon(Icons.open_in_new), onPressed: () => _openSpecificMailApp(app), ), ), ), ) ``` -------------------------------- ### Import open_mail_launcher in Dart Source: https://pub.dev/packages/open_mail_launcher/install Import the open_mail_launcher package into your Dart files to start using its functionalities. ```dart import 'package:open_mail_launcher/open_mail_launcher.dart'; ``` -------------------------------- ### Open Specific Email App Source: https://pub.dev/packages/open_mail_launcher/versions/0.0.1 Demonstrates how to find and open a specific email application, such as Gmail, from the list of installed email apps. This is useful when you want to direct users to a particular email client. ```dart // Get available apps List apps = await OpenMailLauncher.getMailApps(); // Find and open Gmail specifically MailApp? gmail = apps.firstWhere( (app) => app.name.toLowerCase().contains('gmail'), orElse: () => null, ); if (gmail != null) { bool success = await OpenMailLauncher.openSpecificMailApp( mailApp: gmail, emailContent: emailContent, ); } ``` -------------------------------- ### Display Available Mail Apps Source: https://pub.dev/packages/open_mail_launcher/versions/0.4.0-beta.1/example Renders a list of installed mail applications, highlighting the default app. Each app in the list can be tapped to open it directly. ```dart if (_mailApps.isEmpty) const Card( child: ListTile( leading: Icon(Icons.info_outline), title: Text('No mail apps found'), subtitle: Text('Tap refresh to reload'), ), ) else ..._mailApps.map( (app) => Card( child: ListTile( leading: Icon( Icons.email, color: app.isDefault ? Colors.blue : null, ), title: Text(app.name), subtitle: Text(app.isDefault ? 'Default app' : app.id), trailing: IconButton( icon: const Icon(Icons.open_in_new), onPressed: () => _openSpecificMailApp(app), ), ), ), ), // ... Future _loadMailApps() async { final mailLauncher = OpenMailLauncher(); _mailApps = await mailLauncher.getMailApps(); setState(() {}); } Future _openSpecificMailApp(MailApp app) async { final mailLauncher = OpenMailLauncher(); await mailLauncher.launchSpecific(app.id); } ``` -------------------------------- ### Open Default Mail App Source: https://pub.dev/packages/open_mail_launcher/versions/0.4.0-beta.1/example Opens the user's default email application. Ensure the mail app is installed on the device. ```dart ElevatedButton.icon( onPressed: _openMailApp, icon: const Icon(Icons.email), label: const Text('Open Mail App'), style: ElevatedButton.styleFrom( minimumSize: const Size.fromHeight(48), ), ), // ... Future _openMailApp() async { final mailLauncher = OpenMailLauncher(); await mailLauncher.launch(); } ``` -------------------------------- ### Load and Display Mail Apps Source: https://pub.dev/packages/open_mail_launcher/versions/0.3.0/example Loads all installed mail applications on the device and displays their count. Handles loading states and errors. ```Dart import 'package:flutter/material.dart'; import 'package:open_mail_launcher/open_mail_launcher.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Open Mail Launcher Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue), useMaterial3: true, ), home: const HomePage(), ); } } class HomePage extends StatefulWidget { const HomePage({super.key}); @override State createState() => _HomePageState(); } class _HomePageState extends State { List _mailApps = []; bool _isLoading = false; String _statusMessage = ''; // Email content controllers final _toController = TextEditingController(text: 'example@email.com'); final _ccController = TextEditingController(); final _bccController = TextEditingController(); final _subjectController = TextEditingController( text: 'Test Email from Flutter', ); final _bodyController = TextEditingController( text: 'This is a test email sent from the Open Mail Launcher Flutter plugin.', ); @override void initState() { super.initState(); _loadMailApps(); } @override void dispose() { _toController.dispose(); _ccController.dispose(); _bccController.dispose(); _subjectController.dispose(); _bodyController.dispose(); super.dispose(); } Future _loadMailApps() async { setState(() { _isLoading = true; _statusMessage = ''; }); try { final apps = await OpenMailLauncher.getMailApps(); setState(() { _mailApps = apps; _isLoading = false; _statusMessage = 'Found ${apps.length} mail app(s)'; }); } catch (e) { setState(() { _isLoading = false; _statusMessage = 'Error loading mail apps: $e'; }); } } /// Null when every field is empty — the plugin then opens the mail app /// itself (inbox / main screen) instead of a compose window. EmailContent? _createEmailContent() { final content = EmailContent( to: _toController.text .split(',') .map((e) => e.trim()) .where((e) => e.isNotEmpty) .toList(), cc: _ccController.text .split(',') .map((e) => e.trim()) .where((e) => e.isNotEmpty) .toList(), bcc: _bccController.text .split(',') .map((e) => e.trim()) .where((e) => e.isNotEmpty) .toList(), subject: _subjectController.text, body: _bodyController.text, ); final isEmpty = content.to.isEmpty && content.cc.isEmpty && content.bcc.isEmpty && (content.subject?.isEmpty ?? true) && (content.body?.isEmpty ?? true); return isEmpty ? null : content; } Future _openMailApp() async { setState(() { _statusMessage = 'Opening mail app...'; }); try { final result = await OpenMailLauncher.openMailApp( emailContent: _createEmailContent(), ); if (result.didOpen) { setState(() { _statusMessage = 'Mail app opened successfully'; }); } else if (result.canOpen && result.hasMultipleOptions) { // Show picker dialog for iOS or when Android doesn't show native picker if (mounted) { final selectedApp = await OpenMailLauncher.showMailAppPicker( context: context, mailApps: result.options, ); if (selectedApp != null) { await _openSpecificMailApp(selectedApp); } else { setState(() { _statusMessage = 'No app selected'; }); } } } else { setState(() { _statusMessage = 'No mail apps available'; }); _showNoMailAppsDialog(); } } catch (e) { setState(() { _statusMessage = 'Error: $e'; }); } } Future _openSpecificMailApp(MailApp mailApp) async { setState(() { _statusMessage = 'Opening ${mailApp.name}...'; }); try { final success = await OpenMailLauncher.openSpecificMailApp( mailApp: mailApp, emailContent: _createEmailContent(), ); ``` -------------------------------- ### Compose Email with Content Source: https://pub.dev/packages/open_mail_launcher/versions/0.0.1 Shows how to compose an email with specified recipients (To, CC, BCC), subject, and body. It can either open any available email app or prompt the user to select one if multiple are installed. ```dart final emailContent = EmailContent( to: ['john@example.com', 'jane@example.com'], cc: ['manager@example.com'], bcc: ['admin@example.com'], subject: 'Hello from Flutter!', body: 'This email was sent from my Flutter app.', ); // Compose email in any available app bool success = await OpenMailLauncher.composeEmail( emailContent: emailContent, ); // Or open with specific app selection OpenMailAppResult result = await OpenMailLauncher.openMailApp( emailContent: emailContent, ); ``` -------------------------------- ### Check Email App Availability Source: https://pub.dev/packages/open_mail_launcher/versions/0.4.0-beta.1 Checks if any email application is installed and available on the device. ```APIDOC ## isMailAppAvailable ### Description Checks if any email application is installed and available on the device. ### Method `static Future isMailAppAvailable()` ### Returns - `Future`: A future that resolves to `true` if an email app is available, `false` otherwise. ``` -------------------------------- ### Open Mail App with Content Source: https://pub.dev/packages/open_mail_launcher/versions/0.0.1/example Opens the default mail client with pre-filled 'To', 'CC', 'BCC', 'Subject', and 'Body' fields. Ensure all controllers are properly initialized. ```dart Future _openMailApp() async { setState(() { _isLoading = true; _statusMessage = ''; }); try { final success = await OpenMailLauncher.composeNewEmail( toRecipients: _toController.text.split(','), ccRecipients: _ccController.text.split(','), bccRecipients: _bccController.text.split(','), subject: _subjectController.text, body: _bodyController.text, ); setState(() { _statusMessage = success ? 'Compose window opened' : 'Failed to open compose window'; }); } catch (e) { setState(() { _statusMessage = 'Error: $e'; }); } finally { setState(() { _isLoading = false; }); } } ``` -------------------------------- ### Flutter App Initialization and Mail App Loading Source: https://pub.dev/packages/open_mail_launcher/versions/0.1.0/example This snippet shows the basic structure of a Flutter application using the open_mail_launcher plugin. It includes initializing the app, loading available mail applications on startup, and disposing of controllers. ```dart import 'package:flutter/material.dart'; import 'package:open_mail_launcher/open_mail_launcher.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Open Mail Launcher Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue), useMaterial3: true, ), home: const HomePage(), ); } } class HomePage extends StatefulWidget { const HomePage({super.key}); @override State createState() => _HomePageState(); } class _HomePageState extends State { List _mailApps = []; bool _isLoading = false; String _statusMessage = ''; // Email content controllers final _toController = TextEditingController(text: 'example@email.com'); final _ccController = TextEditingController(); final _bccController = TextEditingController(); final _subjectController = TextEditingController( text: 'Test Email from Flutter', ); final _bodyController = TextEditingController( text: 'This is a test email sent from the Open Mail Launcher Flutter plugin.', ); @override void initState() { super.initState(); _loadMailApps(); } @override void dispose() { _toController.dispose(); _ccController.dispose(); _bccController.dispose(); _subjectController.dispose(); _bodyController.dispose(); super.dispose(); } Future _loadMailApps() async { setState(() { _isLoading = true; _statusMessage = ''; }); try { final apps = await OpenMailLauncher.getMailApps(); setState(() { _mailApps = apps; _isLoading = false; _statusMessage = 'Found ${apps.length} mail app(s)'; }); } catch (e) { setState(() { _isLoading = false; _statusMessage = 'Error loading mail apps: $e'; }); } } EmailContent _createEmailContent() { return EmailContent( to: _toController.text .split(',') .map((e) => e.trim()) .where((e) => e.isNotEmpty) .toList(), cc: _ccController.text .split(',') .map((e) => e.trim()) .where((e) => e.isNotEmpty) .toList(), bcc: _bccController.text .split(',') .map((e) => e.trim()) .where((e) => e.isNotEmpty) .toList(), subject: _subjectController.text, body: _bodyController.text, ); } Future _openMailApp() async { setState(() { _statusMessage = 'Opening mail app...'; }); try { final result = await OpenMailLauncher.openMailApp( emailContent: _createEmailContent(), ); if (result.didOpen) { setState(() { _statusMessage = 'Mail app opened successfully'; }); } else if (result.canOpen && result.hasMultipleOptions) { // Show picker dialog for iOS or when Android doesn't show native picker if (mounted) { final selectedApp = await OpenMailLauncher.showMailAppPicker( context: context, mailApps: result.options, ); if (selectedApp != null) { await _openSpecificMailApp(selectedApp); } else { setState(() { _statusMessage = 'No app selected'; }); } } } else { setState(() { _statusMessage = 'No mail apps available'; }); _showNoMailAppsDialog(); } } catch (e) { setState(() { _statusMessage = 'Error: $e'; }); } } Future _openSpecificMailApp(MailApp mailApp) async { setState(() { _statusMessage = 'Opening ${mailApp.name}...'; }); try { final success = await OpenMailLauncher.openSpecificMailApp( mailApp: mailApp, emailContent: _createEmailContent(), ); setState(() { _statusMessage = success ? '${mailApp.name} opened successfully' : 'Failed to open ${mailApp.name}'; }); } catch (e) { setState(() { _statusMessage = 'Error: $e'; }); } } Future _composeEmail() async { setState(() { _statusMessage = 'Composing email...'; }); try { final success = await OpenMailLauncher.composeEmail( emailContent: _createEmailContent(), ); ``` -------------------------------- ### Check Mail App Availability Button Source: https://pub.dev/packages/open_mail_launcher/versions/0.1.0/example A button to check if any mail applications are installed on the device. ```dart OutlinedButton.icon( onPressed: _checkMailAppAvailable, icon: const Icon(Icons.check_circle), label: const Text('Check Mail App Available'), style: OutlinedButton.styleFrom( minimumSize: const Size.fromHeight(48), ), ) ``` -------------------------------- ### Check Mail App Availability Source: https://pub.dev/packages/open_mail_launcher/versions/0.4.0-beta.1/example Checks if any email applications are installed on the device. This is useful for providing user feedback or enabling/disabling features. ```dart OutlinedButton.icon( onPressed: _checkMailAppAvailable, icon: const Icon(Icons.check_circle), label: const Text('Check Mail App Available'), style: OutlinedButton.styleFrom( minimumSize: const Size.fromHeight(48), ), ), // ... Future _checkMailAppAvailable() async { final mailLauncher = OpenMailLauncher(); final available = await mailLauncher.isAvailable(); // Update UI based on 'available' boolean } ``` -------------------------------- ### Check Mail App Availability Button Source: https://pub.dev/packages/open_mail_launcher/versions/0.1.1/example A button to check if any mail applications are installed on the device. Requires a `_checkMailAppAvailable` method to be defined. ```dart OutlinedButton.icon( onPressed: _checkMailAppAvailable, icon: const Icon(Icons.check_circle), label: const Text('Check Mail App Available'), style: OutlinedButton.styleFrom( minimumSize: const Size.fromHeight(48), ), ) ``` -------------------------------- ### Handle Multiple Email Apps Source: https://pub.dev/packages/open_mail_launcher When multiple email apps are available, this snippet shows how to present a picker to the user and then open the selected app with the email content. ```dart OpenMailAppResult result = await OpenMailLauncher.openMailApp( emailContent: emailContent, ); if (result.didOpen) { // Email app opened successfully print('Email app opened!'); } else if (result.hasMultipleOptions) { // Show picker dialog for multiple apps MailApp? selectedApp = await OpenMailLauncher.showMailAppPicker( context: context, mailApps: result.options, title: 'Choose Email App', ); if (selectedApp != null) { // Open the selected email app bool opened = await OpenMailLauncher.openSpecificMailApp( mailApp: selectedApp, emailContent: emailContent, ); } } else { // No email apps available print('No email apps found'); } ``` -------------------------------- ### Compose Email Source: https://pub.dev/packages/open_mail_launcher/versions/0.4.0-beta.1/example Composes a new email with pre-filled subject and body, opening the default mail app. Requires the mail app to be installed. ```dart ElevatedButton.icon( onPressed: _composeEmail, icon: const Icon(Icons.edit), label: const Text('Compose Email'), style: ElevatedButton.styleFrom( minimumSize: const Size.fromHeight(48), ), ), // ... Future _composeEmail() async { final mailLauncher = OpenMailLauncher(); await mailLauncher.composeNew(subject: 'Test Subject', body: 'Test Body'); } ``` -------------------------------- ### Declare open_mail_launcher in pubspec.yaml Source: https://pub.dev/packages/open_mail_launcher/install This is how the open_mail_launcher dependency will appear in your pubspec.yaml file after running the add command. ```yaml dependencies: open_mail_launcher: ^0.3.1 ``` -------------------------------- ### iOS Info.plist Configuration Source: https://pub.dev/packages/open_mail_launcher/versions/0.1.2 Configure LSApplicationQueriesSchemes in your Info.plist to allow querying for specific email apps on iOS. ```xml LSApplicationQueriesSchemes mailto googlegmail ms-outlook ymail readdle-spark ``` -------------------------------- ### Handle Multiple Email App Options Source: https://pub.dev/packages/open_mail_launcher/versions/0.1.2 When multiple email apps are available, use showMailAppPicker to let the user choose, then open the selected app. ```dart OpenMailAppResult result = await OpenMailLauncher.openMailApp( emailContent: emailContent, ); if (result.didOpen) { // Email app opened successfully print('Email app opened!'); } else if (result.hasMultipleOptions) { // Show picker dialog for multiple apps MailApp? selectedApp = await OpenMailLauncher.showMailAppPicker( context: context, mailApps: result.options, title: 'Choose Email App', ); if (selectedApp != null) { // Open the selected email app bool opened = await OpenMailLauncher.openSpecificMailApp( mailApp: selectedApp, emailContent: emailContent, ); } } else { // No email apps available print('No email apps found'); } ``` -------------------------------- ### Show No Mail Apps Dialog Source: https://pub.dev/packages/open_mail_launcher/versions/0.1.0/example Displays an AlertDialog to inform the user that no email applications are installed on their device. Provides an 'OK' button to dismiss the dialog. ```dart void _showNoMailAppsDialog() { showDialog( context: context, builder: (context) { return AlertDialog( title: const Text('No Mail Apps'), content: const Text( 'No email applications are installed on this device.', ), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(), child: const Text('OK'), ), ], ); }, ); } ``` -------------------------------- ### Open Mail App Source: https://pub.dev/packages/open_mail_launcher/versions/0.2.0/example Opens the default mail application with pre-filled email content. Ensure the `OpenMailLauncher` is initialized and mail apps are available before calling. ```dart Future _openMailApp() async { setState(() { _isLoading = true; _statusMessage = ''; }); try { final bool success = await OpenMailLauncher.composeNewEmail( toRecipients: _toController.text.split(','), ccRecipients: _ccController.text.split(','), bccRecipients: _bccController.text.split(','), subject: _subjectController.text, body: _bodyController.text, ); setState(() { _statusMessage = success ? 'Compose window opened' : 'Failed to open compose window'; }); } catch (e) { setState(() { _statusMessage = 'Error: $e'; }); } finally { setState(() { _isLoading = false; }); } } ``` -------------------------------- ### Check Mail App Availability Source: https://pub.dev/packages/open_mail_launcher/versions/0.1.0/example Checks if any mail application is installed on the device. Updates the status message based on availability. Catches and displays any errors during the check. ```dart Future _checkMailAppAvailable() async { try { final available = await OpenMailLauncher.isMailAppAvailable(); setState(() { _statusMessage = available ? 'Mail app is available' : 'No mail app available'; }); } catch (e) { setState(() { _statusMessage = 'Error: $e'; }); } } ``` -------------------------------- ### Open Default Email App Source: https://pub.dev/packages/open_mail_launcher/versions/0.4.0-beta.1 Opens the default or a user-selected email application. If email content is provided, it will be pre-filled. ```APIDOC ## openMailApp ### Description Opens the default email application or presents a picker if multiple apps are available. Can pre-fill email content if provided. ### Method `static Future openMailApp({EmailContent? emailContent})` ### Parameters #### Optional Parameters - **emailContent** (`EmailContent`): An object containing details for the email (to, cc, bcc, subject, body). ### Returns - `Future`: A future that resolves to an `OpenMailAppResult` object indicating whether the app was opened and if there were multiple options. ``` -------------------------------- ### Add open_mail_launcher to Dart Project Source: https://pub.dev/packages/open_mail_launcher/versions/0.0.1/install Use this command to add the package as a dependency in your Dart project. ```bash $ dart pub add open_mail_launcher ``` -------------------------------- ### Check Mail App Availability Source: https://pub.dev/packages/open_mail_launcher/example Use this button to check if any mail applications are installed on the device. The `_checkMailAppAvailable` function should be implemented to call the plugin's availability check method. ```dart OutlinedButton.icon( onPressed: _checkMailAppAvailable, icon: const Icon(Icons.check_circle), label: const Text('Check Mail App Available'), style: OutlinedButton.styleFrom( minimumSize: const Size.fromHeight(48), ), ), ```