Using Flutter Downloader plugin, after download app closes - flutter

**I use Flutter Downloader Package After complete download some file , my app closes automatically and disconnecte to the android studio. Any one help me to find soltutions.
final status = await Permission.storage.request();
if (status.isGranted) {
await downloadPDF();
}
downloadPDF() async {
final externalDir = await getExternalStorageDirectory();
taskId = await FlutterDownloader.enqueue(
url: pdfURL,
savedDir: externalDir.path,
fileName: "Flamingo Order Details",
showNotification: true,
openFileFromNotification: true,
);
}
Here is my console error:
I/flutter (15913): Fatal: could not find callback
F/libc (15913): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 15956 (1.raster), pid 15913 (le.order_system)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'motorola/chef/chef_sprout:10/QPTS30.61-18-16-8/03acd:user/release-keys'
Revision: 'pvt'
ABI: 'arm64'
Timestamp: 2021-04-23 16:39:38+0530
pid: 15913, tid: 15956, name: 1.raster >>> com.example.order_system <<<
uid: 10870
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
Cause: null pointer dereference
x0 000000741e5a6478 x1 00000074841cfa00 x2 0000000000000001 x3 0000000000000000
x4 0000000000000000 x5 00000000ffffffff x6 00000000ffffffff x7 0000000b96c6a75c
x8 0000000080000081 x9 658adf78f7e836ee x10 0000000000000000 x11 0000000000000000
x12 0000000000000001 x13 000000747b19fe80 x14 0000007489a0a280 x15 0000000000000000
x16 000000747b19b050 x17 0000007515c9787c x18 000000741d05e000 x19 000000741e5a6478
x20 00000074841cfa00 x21 0000000000000001 x22 0000000000000000 x23 00000074843db380
x24 000000741e5a7020 x25 000000741e5a7020 x26 0000000000000000 x27 0000000000000001
x28 0000000000000043 x29 000000741e5a6450
sp 000000741e5a6420 lr 000000747b013f84 pc 000000747b01c378
backtrace:
#00 pc 00000000001d8378 /vendor/lib64/egl/libGLESv2_adreno.so (BuildId: 22cc95e0051ae85072c405eeeeeb312d)
#01 pc 00000000001cff80 /vendor/lib64/egl/libGLESv2_adreno.so (BuildId: 22cc95e0051ae85072c405eeeeeb312d)
#02 pc 00000000000207b0 /system/lib64/libEGL.so (android::eglSwapBuffersWithDamageKHRImpl(void*, void*, int*, int)+316) (BuildId: 248ba7f2d80e7bb9952a20e1c3493c86)
#03 pc 000000000001d0a8 /system/lib64/libEGL.so (eglSwapBuffers+80) (BuildId: 248ba7f2d80e7bb9952a20e1c3493c86)
#04 pc 00000000012ec528 /data/app/com.example.order_system-8XYsushVsEZPOltQ3k8npA==/lib/arm64/libflutter.so (BuildId: e14966237eb013b063fed6484195268f7398b594)
Lost connection to device.

Maybe it is late but it may help others. Recently I faced this error and I solved it. Your UI is rendering in Main isolate and your download events come from background isolate. Because codes in callback are run in the background isolate, so you have to handle the communication between two isolates. Usually, communication needs to take place to show download progress in the main UI. Implement the below code to handle communication:
import 'dart:isolate';
import 'dart:ui'; // You need to import these 2 libraries besides another libraries to work with this code
final ReceivePort _port = ReceivePort();
#override
void initState() {
super.initState();
IsolateNameServer.registerPortWithName(_port.sendPort, 'downloader_send_port');
_port.listen((dynamic data) {
String id = data[0];
DownloadTaskStatus status = data[1];
int progress = data[2];
setState((){ });
});
FlutterDownloader.registerCallback(downloadCallback);
}
#override
void dispose() {
IsolateNameServer.removePortNameMapping('downloader_send_port');
super.dispose();
}
static void downloadCallback(String id, DownloadTaskStatus status, int progress) {
final SendPort send = IsolateNameServer.lookupPortByName('downloader_send_port')!;
send.send([id, status, progress]);
}
void _download(String url) async {
final status = await Permission.storage.request();
if(status.isGranted) {
final externalDir = await getExternalStorageDirectory();
final id = await FlutterDownloader.enqueue(
url: url,
savedDir: externalDir!.path,
showNotification: true,
openFileFromNotification: true,
);
} else {
print('Permission Denied');
}
}
Call _download(url) function in your button and you are ready to go.
N.B: I am using sound null safety in my app and for this reason I am using null aware operator in this line of code:
final SendPort send = IsolateNameServer.lookupPortByName('downloader_send_port')!;

Related

Flutter vlc player crashes app after going back

I have added flutter vlc player to my app. when i go back from vlc player page, the app suddenly crashes.
i have tried direct example from pub.dev to try it out, but it also results into same.
This is my Error
D/apitrace(22547): apitrace: warning: caught signal 6
D/apitrace(22547): call flush from exceptionCallback
F/libc (22547): Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 23200
(AWindowHandler), pid 22547 (.webyte.vidflix)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'OPPO/CPH2015/OP4C7D:9/PPR1.180610.011/1640680627:user/release-keys'
Revision: '0'
ABI: 'arm64'
pid: 22547, tid: 23200, name: AWindowHandler >>> com.webyte.vidflix <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: 'java_vm_ext.cc:542] JNI DETECTED ERROR IN APPLICATION: JNI GetJavaVM called with pending exception java.lang.RuntimeException: Error during detachFromGLContext (see logcat for details)'
here ismy code
#override
void initState() {
super.initState();
_videoPlayerController = VlcPlayerController.network(
'https://media.w3.org/2010/05/sintel/trailer.mp4',
hwAcc: HwAcc.full,
autoPlay: true,
options: VlcPlayerOptions(),
)..initialize();
}
#override
void dispose() async {
super.dispose();
await _videoPlayerController!.stopRendererScanning();
await _videoPlayerController!.dispose();
}

Flutter stripe_checkout Payment Method Exception

I'm using Flutter stripe_checkout: ^1.0.0 and saw some odd behaviour.
When the checkout button is clicked just once, the screen would turn blank with the following printout. On Stripe dashboard, it says, "Incomplete - The customer has not entered their payment method'.
I/flutter (32631): Checkout session id cs_test_a10k5Lsopaz9JupfebE9pW77ZgUpucfzCrh1WTKX9KcApdbKztnZiz1SKe
I/WebViewFactory(32631): Loading com.google.android.webview version 83.0.4103.106 (code 410410681)
I/cr_VariationsUtils(32631): Requesting new seed from IVariationsSeedServer
I/cr_LibraryLoader(32631): Loaded native library version number "83.0.4103.106"
I/cr_CachingUmaRecorder(32631): Flushed 3 samples from 3 histograms.
I/TetheringManager(32631): registerTetheringEventCallback:com.healthcare.jaaba
W/GooglePlayServicesUtil(32631): Google Play Store is missing.
W/GooglePlayServicesUtil(32631): Google Play Store is missing.
W/GooglePlayServicesUtil(32631): Google Play Store is missing.
W/GooglePlayServicesUtil(32631): Google Play Store is missing.
E/cr_PlatformSer-Internal(32631): UsageReporting query failed
W/ealthcare.jaab(32631): Accessing hidden method Landroid/media/AudioManager;->getOutputLatency(I)I (greylist, reflection, allowed)
D/HostConnection(32631): HostConnection::get() New Host Connection established 0xf4e7e280, tid 752
E/cr_PlatformSer-Internal(32631): Unable to determine Safe Browsing user opt-in preference
D/HostConnection(32631): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0
D/EGL_emulation(32631): eglCreateContext: 0xf4e7c140: maj 3 min 0 rcv 3
D/EGL_emulation(32631): eglMakeCurrent: 0xf4e7c140: ver 3 0 (tinfo 0xaf33b210) (first time)
D/EGL_emulation(32631): eglMakeCurrent: 0xf4e60d10: ver 3 0 (tinfo 0xf51b1d50) (first time)
W/Gralloc4(32631): allocator 3.x is not supported
I/VideoCapabilities(32631): Unsupported profile 4 for video/mp4v-es
W/cr_MediaCodecUtil(32631): HW encoder for video/avc is not available on this device.
D/EGL_emulation(32631): eglCreateContext: 0xf4e7f1d0: maj 3 min 0 rcv 3
I/ealthcare.jaab(32631): NativeAlloc concurrent copying GC freed 50165(3378KB) AllocSpace objects, 15(428KB) LOS objects, 49% free, 3769KB/7539KB, paused 2.245ms total 147.024ms
W/ealthcare.jaab(32631): Reducing the number of considered missed Gc histogram windows from 124 to 100
I/chromium(32631): [INFO:CONSOLE(1)] "Unrecognized feature: 'payment'.", source: https://js.stripe.com/v3/ (1)
However, when the checkout button is clicked 3 - 5 times continuously, the card form appears and the payment would be successful.
I/flutter (32631): Checkout session id cs_test_a1ZwZrvL4812TEpjFwQ649RMYjirJr9TMwQVZ29JYrjGj54gmqkCtTyfTW
I/flutter (32631): Checkout session id cs_test_a13D23W9EY1SgLBqYIZLAHTvFBcHKY1wUIiZdr3Kb6XPNsrrLEfj3KJjkj
I/ealthcare.jaab(32631): NativeAlloc concurrent copying GC freed 7125(419KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 3431KB/6863KB, paused 1.352ms total 189.441ms
I/chromium(32631): [INFO:CONSOLE(1)] "Unrecognized feature: 'payment'.", source: https://js.stripe.com/v3/ (1)
I/chromium(32631): [INFO:CONSOLE(1)] "Unrecognized feature: 'payment'.", source: https://js.stripe.com/v3/ (1)
I/flutter (32631): Checkout session id cs_test_a1QsxT2t7H68MpvgLinDukwOBzwW1W21ktnbQdqB25R6t2b0TE5mO4u9jj
I/flutter (32631): Checkout session id cs_test_a1o2VPwBSq0RRW6PlSKnGr554hoWFIOrPy1NZWnLveMqAZyLX6iVYKFr0y
I/chromium(32631): [INFO:CONSOLE(1)] "Unrecognized feature: 'payment'.", source: https://js.stripe.com/v3/ (1)
I/chromium(32631): [INFO:CONSOLE(1)] "Unrecognized feature: 'payment'.", source: https://js.stripe.com/v3/ (1)
I/flutter (32631): Checkout session id cs_test_a1uWleO9v9VAwUAra957z8uHbpOwNyp24nZYgAQ2aOLHqwt3hBcOtAg8Yf
I/chromium(32631): [INFO:CONSOLE(1)] "Unrecognized feature: 'payment'.", source: https://js.stripe.com/v3/ (1)
I/chromium(32631): [INFO:CONSOLE(1)] "Unrecognized feature: 'payment'.", source: https://js.stripe.com/v3/ (1)
I/chromium(32631): [INFO:CONSOLE(1)] "Unrecognized feature: 'payment'.", source: https://js.stripe.com/v3/fingerprinted/js/stripe-a07f9e62b0b55658b30abedf1005cae0.js (1)
I/chatty (32631): uid=10139(com.healthcare.jaaba) identical 1 line
I/chromium(32631): [INFO:CONSOLE(1)] "Unrecognized feature: 'payment'.", source: https://js.stripe.com/v3/fingerprinted/js/stripe-a07f9e62b0b55658b30abedf1005cae0.js (1)
I/Choreographer(32631): Skipped 31 frames! The application may be doing too much work on its main thread.
I/chromium(32631): [INFO:CONSOLE(265)] "Uncaught ReferenceError: PaymentRequest is not defined", source: https://pay.google.com/gp/p/js/pay.js (265)
Flutter Application: checkout_screen.dart
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:stripe_checkout/stripe_checkout.dart';
import 'package:flutter/material.dart';
import '../../../../utils/env.dart';
import '../widgets/example_scaffold.dart';
import '../../../../utils/api_endpoints.dart';
import 'platforms/stripe_checkout.dart' if (dart.library.js)
'platforms/stripe_checkout_web.dart';
class CheckoutScreenExample extends StatefulWidget {
const CheckoutScreenExample({Key? key}) : super(key: key);
#override
_CheckoutScreenExample createState() => _CheckoutScreenExample();
}
class _CheckoutScreenExample extends State<CheckoutScreenExample> {
#override
Widget build(BuildContext context) {
return ExampleScaffold(
title: 'Checkout Page',
padding: const EdgeInsets.all(16),
children: [
const SizedBox(height: 120),
Center(
child: ElevatedButton(
onPressed: checkout,
child: const Text('Open Checkout'),
),
)
],
);
}
Future<void> checkout() async {
final String sessionId = await _createCheckoutSession();
final result = await redirectToCheckout(
context: context,
sessionId: sessionId,
publishableKey: stripePublishableKey,
successUrl: 'https://checkout.stripe.dev/success',
canceledUrl: 'https://checkout.stripe.dev/cancel',
);
if (mounted) {
final text = result.when(
success: () => 'Paid successfully',
canceled: () => 'Checkout canceled',
error: (e) => 'Error $e',
redirected: () => 'Redirected successfully',
);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(text)),
);
}
}
Future<String> _createCheckoutSession() async {
final stripePayURL = Uri.parse(ApiUrl.stripePayUrl);
final response = await http.get(
stripePayURL,
headers: <String, String>{'Authorization': 'Bearer ' + token,
},
);
final Map<String, dynamic> bodyResponse = json.decode(response.body);
final id = bodyResponse['checkout_session_id'] as String;
debugPrint('Checkout session id $id');
return id;
}
}
Flask Backend: billing.py
#api_blueprint.route('/stripe_pay', methods=['GET'])
#token_auth.login_required
def stripe_pay():
cart_id = basic_auth.current_user().id
transaction = Transaction.query.filter(Transaction.cart_id==cart_id).first()
price = stripe.Price.create(
unit_amount=transaction.count_grand_total(),
currency=transaction.currency,
)
session = stripe.checkout.Session.create(
payment_method_types=['card'],
line_items=[{
'price': price,
'quantity': 1,
}],
mode='payment',
success_url=url_for('api.success', cart_id=cart_id, _external=True) + '?cart_id=cart_id' + '?session_id={CHECKOUT_SESSION_ID}',
cancel_url=url_for('home.index', _external=True),
)
return jsonify ({
'checkout_session_id': session['id'],
'checkout_public_key': checkout_public_key,
'cart_id': int(cart_id)
})
I would appreciate if someone show me how to fix this. Thank you.

My widgets tests work separately but wont work together

this is my code:
void main() {
testWidgets("Localiza os widgets na home", (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(home: HomeView()));
final Finder drawer = find.byType(IconButton);
await tester.tap(drawer);
expect(drawer, findsOneWidget);
await tester.pumpAndSettle();
final Finder listTileDrawer = find.byType(ListTile);
expect(listTileDrawer, findsNWidgets(5));
final Finder listViewDrawer = find.byType(ListView);
expect(listViewDrawer, findsOneWidget);
});
testWidgets("Valida se snackBar está sendo exibida corretamente", (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(
home: Scaffold(
body: BotaoRedirecionamentoExterno(
url: 'url invalida',
texto: 'teste',
))));
final botao = find.byType(BotaoRedirecionamentoExterno);
await tester.tap(botao);
await tester.pumpAndSettle();
final Finder snackBar = find.byType(SnackBar);
expect(snackBar, findsOneWidget);
});
}
When I run: test/view/home/home_widget_test.dart --no-sound-null-safety it works as expected:
I/flutter (11181): 00:01 +1: Valida se snackBar está sendo exibida corretamente
I/flutter (11181): 00:02 +2: All tests passed!
But when I try: flutter test --no-sound-null-safety:
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure object was thrown running a test:
Expected: exactly one matching node in the widget tree
Actual: _WidgetTypeFinder:<zero widgets with type "SnackBar" (ignoring offstage widgets)>
Which: means none were found but one was expected
When the exception was thrown, this was the stack:
#4 main.<anonymous closure> (file:///Users/macos/Desktop/portal-agro-sp-master/test/view/home/home_widget_test.dart:33:5)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)
This was caught by the test expectation on the following line:
file:///Users/macos/Desktop/portal-agro-sp-master/test/view/home/home_widget_test.dart line 33
The test description was:
Valida se snackBar está sendo exibida corretamente
════════════════════════════════════════════════════════════════════════════════════════════════════
00:26 +25 -1: /Users/macos/Desktop/portal-agro-sp-master/test/view/home/home_widget_test.dart: Valida se snackBar está sendo exibida corretamente [E]
Test failed. See exception logs above.
The test description was: Valida se snackBar está sendo exibida corretamente
I need to be able to run all my tests together due to a customer requirement. I already have more than 23 tests ready and this is the first time this has happened.
Does anyone know why this is happening and a way to solve it ?

Flutter - flutter_inappwebview - GL error: Out of memory

I use the flutter_inappwebview plugin to run a WebView (PostUrl). but I found an error when displaying my web. Here's an example of my coding:
import 'dart:async';
import 'dart:convert' show utf8;
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:smartmosque/Api/ApiServer.dart';
import 'package:smartmosque/Utils/Global.dart';
class PaymentLinkAjaPage extends StatefulWidget {
final String token;
PaymentLinkAjaPage({this.token});
#override
_PaymentLinkAjaPageState createState() => _PaymentLinkAjaPageState();
}
class _PaymentLinkAjaPageState extends State<PaymentLinkAjaPage> {
InAppWebViewController webView;
String url = "";
double progress = 0;
void actionBack() {
if (url.length > 100) {
Navigator.pop(context);
Navigator.pop(context);
Navigator.pop(context);
} else {
Navigator.pop(context);
}
}
#override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () {
actionBack();
return Future.value(true);
},
child: Scaffold(
backgroundColor: Global.primaryRed,
appBar: AppBar(
title: Text("Infak Link Aja!"),
elevation: 0,
leading: IconButton(
icon: Icon(Icons.clear),
onPressed: () {
actionBack();
}),
),
body: Container(
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 20, right: 20),
child: progress < 1.0
? LinearProgressIndicator(value: progress)
: Container()),
Expanded(
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20)),
child: InAppWebView(
initialHeaders: {},
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
debuggingEnabled: true,
useShouldOverrideUrlLoading: false)),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
var encodetext = utf8.encode("message=${widget.token}");
Uint8List postdata = Uint8List.fromList(encodetext);
webView.postUrl(url: urlWebLinkAja, postData: postdata);
},
androidOnPermissionRequest:
(InAppWebViewController controller, String origin,
List<String> resources) async {
return PermissionRequestResponse(
resources: resources,
action: PermissionRequestResponseAction.GRANT);
},
onReceivedServerTrustAuthRequest:
(controller, challenge) async {
return ServerTrustAuthResponse(
action: ServerTrustAuthResponseAction.PROCEED);
},
onLoadStart:
(InAppWebViewController controller, String url) async {
setState(() {
this.url = url;
// print("urlstart: $url");
});
},
onLoadStop: (controller, url) async {
setState(() {
this.url = url;
});
},
onProgressChanged:
(InAppWebViewController controller, int progress) {
setState(() {
this.progress = progress / 100;
});
},
),
))
],
),
),
),
);
}
}
and here's the error log:
E/OpenGLRenderer( 5918): GL error: Out of memory!
F/OpenGLRenderer( 5918): glFinish error! GL_OUT_OF_MEMORY (0x505)
W/google-breakpad( 5918): ### ### ### ### ### ### ### ### ### ### ### ### ###
W/google-breakpad( 5918): Chrome build fingerprint:
W/google-breakpad( 5918): 70.0.3538.110
W/google-breakpad( 5918): 353811052
W/google-breakpad( 5918): ### ### ### ### ### ### ### ### ### ### ### ### ###
F/libc ( 5918): Fatal signal 6 (SIGABRT), code -6 in tid 6041 (RenderThread), pid 5918 (gma.example)
Softversion: PD1731F_EX_A_1.18.3
Time: 2020-09-28 15:17:37
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'vivo/1724/1724:8.1.0/OPM1.171019.011/compil08311518:user/release-keys'
Revision: '0'
ABI: 'arm64'
pid: 5918, tid: 6041, name: RenderThread >>> com.example.test <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: 'glFinish error! GL_OUT_OF_MEMORY (0x505)'
x0 0000000000000000 x1 0000000000001799 x2 0000000000000006 x3 0000000000000008
x4 0000007b2cd44588 x5 0000007b2cd44588 x6 0000007b2cd44588 x7 0000007b2cd44588
x8 0000000000000083 x9 0000000010000000 x10 0000007b2cd43cb0 x11 8f38f30250d84677
x12 8f38f30250d84677 x13 0000000000000000 x14 ffffffffffffffdf x15 8f38f30250d84677
x16 0000005f418bffa8 x17 0000007bd2ec4134 x18 8f38f30250d84677 x19 000000000000171e
x20 0000000000001799 x21 0000000000000083 x22 0000007bd29a9a70 x23 0000000000000502
x24 0000007bd29a9b3e x25 0000000000000505 x26 0000007bd29a9b24 x27 0000007bd29a9b3e
x28 0000000000000505 x29 0000007b2cd43cf0 x30 0000007bd2e6a630
sp 0000007b2cd43cb0 pc 0000007bd2e6a658 pstate 0000000060000000
backtrace:
#00 pc 000000000001e658 /system/lib64/libc.so (abort+120)
#01 pc 00000000000083e4 /system/lib64/liblog.so (__android_log_assert+296)
#02 pc 00000000000468fc /system/lib64/libhwui.so (android::uirenderer::debug::GlesErrorCheckWrapper::assertNoErrors(char const*)+384)
#03 pc 0000000000089b00 /system/lib64/libhwui.so (android::uirenderer::Caches::flush(android::uirenderer::Caches::FlushMode)+164)
#04 pc 00000000000752fc /system/lib64/libhwui.so (android::uirenderer::renderthread::Bridge_destroyHardwareResources(android::uirenderer::renderthread::destroyHardwareResourcesArgs*)+12)
#05 pc 0000000000076934 /system/lib64/libhwui.so (android::uirenderer::renderthread::MethodInvokeRenderTask::run()+24)
#06 pc 0000000000076cc8 /system/lib64/libhwui.so (android::uirenderer::renderthread::SignalingRenderTask::run()+28)
#07 pc 0000000000077c18 /system/lib64/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+336)
#08 pc 0000000000011590 /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+276)
#09 pc 00000000000aa03c /system/lib64/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+136)
#10 pc 0000000000077968 /system/lib64/libc.so (__pthread_start(void*)+36)
#11 pc 000000000001fa30 /system/lib64/libc.so (__start_thread+68)
Lost connection to device.
Running flutter doctor:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 1.20.4, on Microsoft Windows [Version 10.0.18363.1082], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Android Studio (version 3.6)
[√] VS Code (version 1.49.2)
[√] Connected device (1 available)
• No issues found!

Sending email with attachments via flutter_email_sender is not working on Android

I'm trying to send an email with a pdf attachment using flutter_email_sender, it works fine on iOS but throws Failed to find configured root error on Android. Below is the code.
Future<void> _downloadFile(String url, String filename) async {
var request = await httpClient.getUrl(Uri.parse(url));
var response = await request.close();
var bytes = await consolidateHttpClientResponseBytes(response);
String dir = (await getApplicationDocumentsDirectory()).path;
File file = new File('$dir/$filename');
await file.writeAsBytes(bytes);
setState(() {
_file = file;
});
}
final Email email = Email(
body: 'Email body',
subject: 'Email subject',
recipients: ['email#gmail.com'],
attachmentPath: _file.path,
);
await FlutterEmailSender.send(email);
and the stack trace:
E/MethodChannel#flutter_email_sender: Failed to handle method call
java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.xxx.xx/app_flutter/account_opening.pdf at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:739)
at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:418)
at com.sidlatau.flutteremailsender.FlutterEmailSenderPlugin.sendEmail(FlutterEmailSenderPlugin.kt:95)
at com.sidlatau.flutteremailsender.FlutterEmailSenderPlugin.onMethodCall(FlutterEmailSenderPlugin.kt:38)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:643)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:326)
at android.os.Looper.loop(Looper.java:160)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2019-09-11 13:44:42.484 26003-26003/com.xxx.xx W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy#98fb11f
2019-09-11 13:44:42.505 26003-26003/com.xxx.xx D/AndroidRuntime: Shutting down VM
2019-09-11 13:44:42.512 26003-26003/com.xxx.xx E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxx.xx, PID: 26003
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.xx/com.kiwi.fluttercrashlytics.CrashActivity}: com.kiwi.fluttercrashlytics.FlutterException: PlatformException(error, Failed to find configured root that contains /data/data/com.xxx.xx/app_flutter/account_opening.pdf, null)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: com.kiwi.fluttercrashlytics.FlutterException: PlatformException(error, Failed to find configured root that contains /data/data/com.xxx.xx/app_flutter/account_opening.pdf, null)
at StandardMethodCodec.decodeEnvelope(package:flutter/src/services/message_codecs.dart:564)
at MethodChannel.invokeMethod(package:flutter/src/services/platform_channel.dart:316)
at FlutterEmailSender.send(package:flutter_email_sender/flutter_email_sender.dart:10)
at _EmailWidgetState.build.<fn>(package:gsec/shared/widgets/manualPDFWidget/email_widget.dart:136)
at OnboardingNextButtonWidget.build.<fn>(package:gsec/onboardingScreen/onboard_next_button_widget.dart:84)
at GestureRecognizer.invokeCallback(package:flutter/src/gestures/recognizer.dart:182)
at TapGestureRecognizer._checkUp(package:flutter/src/gestures/tap.dart:365)
at TapGestureRecognizer.acceptGesture(package:flutter/src/gestures/tap.dart:312)
at GestureArenaManager.sweep(package:flutter/src/gestures/arena.dart:156)
at _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent(package:flutter/src/gestures/binding.dart:222)
at _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent(package:flutter/src/gestures/binding.dart:198)
at _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent(package:flutter/src/gestures/binding.dart:156)
at _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue(package:flutter/src/gestures/binding.dart:102)
at _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket(package:flutter/src/gestures/binding.dart:86)
at ._rootRunUnary(dart:async/zone.dart:1136)
at _CustomZone.runUnary(dart:async/zone.dart:1029)
at _CustomZone.runUnaryGuarded(dart:async/zone.dart:931)
at ._invoke1(dart:ui/hooks.dart:250)
at ._dispatchPointerDataPacket(dart:ui/hooks.dart:159)
It is not possible to attach files from ApplicationDocumentsDirectory since this directory is only accessible from your app. You have to use a directory like ExternalStorageDirectory to be able to send from it. If you do so don't forget to add WRITE_EXTERNAL_STORAGE permission to your app before release.
Cheers.