|
1 | 1 | # SendEmailFeedbackButton |
2 | 2 |
|
3 | | -A simple Flutter button widget that opens the user's default email client with a pre-filled recipient and subject for sending feedback. |
| 3 | +A reusable Flutter button and utility API that opens the user's default email |
| 4 | +client with a pre-filled feedback message. |
4 | 5 |
|
5 | 6 |  |
6 | 7 |
|
7 | 8 | ## Features |
8 | 9 |
|
9 | | -- Opens the default email app on tap. |
10 | | -- Pre-fills recipient email address and subject line. |
11 | | -- Uses `url_launcher` under the hood. |
12 | | -- Lightweight and easy to use. |
13 | | -- Exposes `sendEmail` utility function for custom button implementations. |
| 10 | +- Pre-fills the recipient, subject, and optional email body. |
| 11 | +- Optionally includes application and operating-system diagnostics. |
| 12 | +- Accepts application-specific diagnostic fields. |
14 | 13 |
|
15 | | -## Usage |
| 14 | +## Requirements |
16 | 15 |
|
17 | | -### Using the Widget |
| 16 | +- Dart 3.6 or later. |
| 17 | +- Flutter 3.27 or later. |
| 18 | +- This package uses `package_info_plus` 8.3.1 through 8.x. |
| 19 | +- Android builds require API 19 or later, compile SDK 34, Java 17, Android |
| 20 | + Gradle Plugin 8.3 or later, and Gradle 8.4 or later. |
| 21 | +- Apple builds require iOS 12 or later and macOS 10.14 or later. |
18 | 22 |
|
19 | | -``` Dart |
| 23 | +## Using the widget |
| 24 | + |
| 25 | +```dart |
20 | 26 | import 'package:flutter/material.dart'; |
21 | 27 | import 'package:send_email_feedback_button/send_email_feedback_button.dart'; |
22 | 28 |
|
23 | | -class MyApp extends StatelessWidget { |
| 29 | +class FeedbackButton extends StatelessWidget { |
| 30 | + const FeedbackButton({super.key}); |
| 31 | +
|
24 | 32 | @override |
25 | 33 | Widget build(BuildContext context) { |
26 | | - return MaterialApp( |
27 | | - home: Scaffold( |
28 | | - body: Center( |
29 | | - child: SendEmailFeedbackButton( |
30 | | - emailAddress: "support@example.com", |
31 | | - emailSubject: "App Feedback", |
32 | | - ), |
33 | | - ), |
34 | | - ), |
| 34 | + return const SendEmailFeedbackButton( |
| 35 | + emailAddress: 'support@example.com', |
| 36 | + emailSubject: 'App feedback', |
| 37 | + emailBody: 'Please describe the issue:', |
| 38 | + includeRuntimeDiagnostics: true, |
| 39 | + additionalDiagnostics: { |
| 40 | + 'Most recent error': 'FileSystemException', |
| 41 | + 'Publication mode': 'exclusive copy', |
| 42 | + }, |
| 43 | + diagnosticsHeading: 'Diagnostics:', |
35 | 44 | ); |
36 | 45 | } |
37 | 46 | } |
38 | 47 | ``` |
39 | 48 |
|
40 | | -### Using the Utility Function |
| 49 | +When runtime diagnostics are enabled, the package includes the application |
| 50 | +name, package identifier, version/build number, operating-system name, and OS |
| 51 | +version. Values passed through `additionalDiagnostics` are controlled entirely |
| 52 | +by the calling application. |
41 | 53 |
|
42 | | -For custom button implementations, you can use the `sendEmail` function directly: |
| 54 | +If runtime metadata cannot be collected, the email launch is still attempted |
| 55 | +and the message reports that runtime diagnostics were unavailable. |
43 | 56 |
|
44 | | -``` Dart |
45 | | -import 'package:flutter/material.dart'; |
46 | | -import 'package:send_email_feedback_button/send_email_feedback_button.dart'; |
| 57 | +Collecting runtime metadata can delay the launch by up to two seconds. The |
| 58 | +widget is disabled while a launch is in progress so repeated taps do not open |
| 59 | +multiple email composers. On web, a diagnostics-enabled launch uses the current |
| 60 | +browsing context because browsers may block a new window after an asynchronous |
| 61 | +metadata lookup. |
47 | 62 |
|
48 | | -class MyApp extends StatelessWidget { |
49 | | - @override |
50 | | - Widget build(BuildContext context) { |
51 | | - return MaterialApp( |
52 | | - home: Scaffold( |
53 | | - body: Center( |
54 | | - child: OutlinedButton.icon( |
55 | | - onPressed: () => sendEmail( |
56 | | - emailAddress: "support@example.com", |
57 | | - emailSubject: "App Feedback", |
58 | | - ), |
59 | | - icon: Icon(Icons.email), |
60 | | - label: Text("Send Feedback"), |
61 | | - ), |
62 | | - ), |
63 | | - ), |
64 | | - ); |
65 | | - } |
| 63 | +## Using the utility function |
| 64 | + |
| 65 | +For a custom button, call `sendEmail` directly: |
| 66 | + |
| 67 | +```dart |
| 68 | +final launchRequested = await sendEmail( |
| 69 | + emailAddress: 'support@example.com', |
| 70 | + emailSubject: 'App feedback', |
| 71 | + emailBody: 'Please describe the issue:', |
| 72 | + includeRuntimeDiagnostics: true, |
| 73 | + additionalDiagnostics: { |
| 74 | + 'Current screen': 'Export', |
| 75 | + }, |
| 76 | +); |
| 77 | +
|
| 78 | +if (!launchRequested) { |
| 79 | + // Show an alternative contact method. |
66 | 80 | } |
67 | | -``` |
| 81 | +``` |
0 commit comments