Skip to content

Commit

Permalink
added mail_to functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mendelg committed Feb 10, 2025
1 parent 6ca67b7 commit 04b34c3
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
12 changes: 12 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<!-- Add queries for URL launcher -->
<queries>
<!-- For email support -->
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
</queries>
<application
android:label="otzaria"
android:name="${applicationName}"
Expand Down
4 changes: 4 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>mailto</string>
</array>
</dict>
</plist>
51 changes: 51 additions & 0 deletions lib/screens/reading/text/text_book_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'commentators_list_screen.dart';
import 'package:flutter/services.dart';
import 'package:otzaria/models/tabs/tab.dart';
import 'package:otzaria/utils/text_manipulation.dart' as utils;
import 'package:url_launcher/url_launcher.dart';

/// A [StatefulWidget] that displays a text book.
///
Expand Down Expand Up @@ -58,6 +59,13 @@ class _TextBookViewerState extends State<TextBookViewer>
final FocusNode textSearchFocusNode = FocusNode();
late TabController tabController;

String? encodeQueryParameters(Map<String, String> params) {
return params.entries
.map((MapEntry<String, String> e) =>
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}')
.join('&');
}

@override
initState() {
super.initState();
Expand Down Expand Up @@ -285,6 +293,49 @@ class _TextBookViewerState extends State<TextBookViewer>
),
),
),
// Report bug button
IconButton(
icon: const Icon(Icons.error_outline),
tooltip: 'דווח על טעות בספר',
onPressed: () async {
final currentRef = await utils.refFromIndex(
widget.tab.positionsListener.itemPositions.value.isNotEmpty
? widget.tab.positionsListener.itemPositions.value.first
.index
: 0,
widget.tab.tableOfContents,
);

final Uri emailLaunchUri = Uri(
scheme: 'mailto',
path: '[email protected]',
query: encodeQueryParameters(<String, String>{
'subject': 'דיווח על טעות: ${widget.tab.book.title}',
'body':
'שם הספר: ${widget.tab.book.title}\nמיקום: $currentRef\n\nפירוט הטעות:\n',
}),
);

try {
if (!await launchUrl(emailLaunchUri,
mode: LaunchMode.externalApplication)) {
// ignore: use_build_context_synchronously
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('לא ניתן לפתוח את תוכנת הדואר'),
),
);
}
} catch (e) {
// ignore: use_build_context_synchronously
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('לא ניתן לפתוח את תוכנת הדואר'),
),
);
}
},
),
],
),
body: LayoutBuilder(
Expand Down

0 comments on commit 04b34c3

Please sign in to comment.