From 8511f1891b32534a012a0f34ecc850bf3bed2e07 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sat, 26 Jun 2021 19:38:47 +0800 Subject: [PATCH] feedback: provide interactive feedback directly in the app by annotating a screenshot of the current page, as well as by adding text. --- src/ui/flutter_app/lib/main.dart | 7 +++- .../flutter_app/lib/widgets/about_page.dart | 41 ++++++++++++++++--- src/ui/flutter_app/pubspec.yaml | 2 + 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/ui/flutter_app/lib/main.dart b/src/ui/flutter_app/lib/main.dart index 4ec1816e..8da5c161 100644 --- a/src/ui/flutter_app/lib/main.dart +++ b/src/ui/flutter_app/lib/main.dart @@ -21,6 +21,7 @@ import 'dart:io'; import 'package:catcher/catcher.dart'; import 'package:double_back_to_close_app/double_back_to_close_app.dart'; +import 'package:feedback/feedback.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; @@ -34,7 +35,11 @@ import 'package:sanmill/widgets/navigation_home_screen.dart'; import 'services/audios.dart'; Future main() async { - var catcher = Catcher(rootWidget: SanmillApp(), ensureInitialized: true); + var catcher = Catcher( + rootWidget: BetterFeedback( + child: SanmillApp(), + ), + ensureInitialized: true); String externalDirStr; try { diff --git a/src/ui/flutter_app/lib/widgets/about_page.dart b/src/ui/flutter_app/lib/widgets/about_page.dart index 497ddd00..5a2429b7 100644 --- a/src/ui/flutter_app/lib/widgets/about_page.dart +++ b/src/ui/flutter_app/lib/widgets/about_page.dart @@ -17,11 +17,15 @@ */ import 'dart:io'; +import 'dart:typed_data'; import 'package:devicelocale/devicelocale.dart'; +import 'package:feedback/feedback.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_email_sender/flutter_email_sender.dart'; import 'package:package_info_plus/package_info_plus.dart'; +import 'package:path_provider/path_provider.dart'; import 'package:sanmill/generated/flutter_version.dart'; import 'package:sanmill/generated/l10n.dart'; import 'package:sanmill/style/app_theme.dart'; @@ -62,6 +66,14 @@ class _AboutPageState extends State { return ret; } + Future writeImageToStorage(Uint8List feedbackScreenshot) async { + final Directory output = await getTemporaryDirectory(); + final String screenshotFilePath = '${output.path}/sanmill-feedback.png'; + final File screenshotFile = File(screenshotFilePath); + await screenshotFile.writeAsBytes(feedbackScreenshot); + return screenshotFilePath; + } + @override Widget build(BuildContext context) { String mode = getMode(); @@ -90,12 +102,29 @@ class _AboutPageState extends State { ), ListItemDivider(), SettingsListTile( - context: context, - titleString: S.of(context).feedback, - onTap: () { - _launchFeedback(); - }, - ), + context: context, + titleString: S.of(context).feedback, + onTap: () { + if (Platform.isWindows) { + // flutter_email_sender does not support Windows. + _launchFeedback(); + } else { + BetterFeedback.of(context).show((feedback) async { + // draft an email and send to developer + final screenshotFilePath = + await writeImageToStorage(feedback.screenshot); + + final Email email = Email( + body: feedback.text, + subject: "[Mill] Sanmill " + "$_version" + " Feedback", + recipients: ['calcitem@outlook.com'], + attachmentPaths: [screenshotFilePath], + isHTML: false, + ); + await FlutterEmailSender.send(email); + }); + } + }), ListItemDivider(), SettingsListTile( context: context, diff --git a/src/ui/flutter_app/pubspec.yaml b/src/ui/flutter_app/pubspec.yaml index 9a72c610..4730d58e 100644 --- a/src/ui/flutter_app/pubspec.yaml +++ b/src/ui/flutter_app/pubspec.yaml @@ -26,6 +26,8 @@ dependencies: devicelocale: ^0.4.1 double_back_to_close_app: ^2.0.1 flutter_picker: ^2.0.1 + flutter_email_sender: ^5.0.1 + feedback: ^2.0.0 #pref: ^2.3.0 #screen_recorder: ^0.0.2