skip to Main Content

I’m developing a Flutter app that requires storage access on Android devices. The app functions properly on Android versions up to 12, but I’m encountering storage permission issues specifically on Android 13 devices. I’ve followed the standard implementation for requesting storage permissions and have included the necessary permission declarations in the app’s AndroidManifest.xml file. However, on Android 13 devices, the app fails to access external storage and encounters permission errors.

this is my error stack:

handleAppVisibility mAppVisible = true visible = false  
I/SurfaceView@7e0b0f2( 6281): onWindowVisibilityChanged(8) false
io.flutter.embedding.android.FlutterSurfaceView{7e0b0f2 V.E......
........ 0,0-720,1510} of ViewRootImpl@c959469[MainActivity]
I/SurfaceView@7e0b0f2( 6281): Changes: creating=false format=false
size=false visible=true alpha=false hint=false mUseAlpha=false
visible=true left=false top=false I/SurfaceView@7e0b0f2( 6281):
132165874 Cur surface: Surface(name=null)/@0x99a7f5a
I/SurfaceView@7e0b0f2( 6281): applyTransactionOnVriDraw: vri =
ViewRootImpl@c959469[MainActivity] fRS = false t = 0xb40000784e81cc00
android.view.SurfaceView.performSurfaceTransaction:959
android.view.SurfaceView.updateSurface:1105
android.view.SurfaceView.onWindowVisibilityChanged:371
I/ViewRootImpl@c959469[MainActivity]( 6281): applyTransactionOnDraw:
mRemoved = false isHardwareEnabled = true t =
0xb40000784e81cc00android.view.SurfaceView.applyTransactionOnVriDraw:2048
android.view.SurfaceView.performSurfaceTransaction:959
android.view.SurfaceView.updateSurface:1105
android.view.SurfaceView.onWindowVisibilityChanged:371
android.view.View.dispatchWindowVisibilityChanged:15943
I/SurfaceView@7e0b0f2( 6281): surfaceDestroyed I/SurfaceView@7e0b0f2(
6281): surfaceDestroyed callback.size 1 #2
io.flutter.embedding.android.FlutterSurfaceView{7e0b0f2 V.E......
........ 0,0-720,1510} D/BufferQueueProducer( 6281):
[SurfaceView[com.a.....gini.MainActivity]@0#3(BLAST
Consumer)3](id:188900000003,api:1,p:6281,c:6281) disconnect: api 1
D/BufferQueueProducer( 6281):
[SurfaceView[com.......ini.MainActivity]@0#3(BLAST
Consumer)3](id:188900000003,api:0,p:-1,c:6281) disconnect: api -1
I/SurfaceView@7e0b0f2( 6281): updateSurface: mVisible = false
mSurface.isValid() = true D/BLASTBufferQueue( 6281):
[SurfaceView[com.at..ni.MainActivity]@0#3](f:0,a:1) destructor()
D/BufferQueueConsumer( 6281):
[SurfaceView[com.ini.MainActivity]@0#3(BLAST
Consumer)3](id:188900000003,api:0,p:-1,c:6281) disconnect
I/SurfaceView@7e0b0f2( 6281): releaseSurfaces: viewRoot =
ViewRootImpl@c959469[MainActivity] I/SurfaceView@7e0b0f2( 6281):
applyTransactionOnVriDraw: vri = ViewRootImpl@c959469[MainActivity]
fRS = true t = 0xb400007886617400
android.view.SurfaceView.releaseSurfaces:858
android.view.SurfaceView.updateSurface:1172
android.view.SurfaceView.onWindowVisibilityChanged:371
I/SurfaceView@7e0b0f2( 6281): applyTransactionOnVriDraw:
viewRoot.applyTransactionOnDrawFromReleaseSurfaces
I/ViewRootImpl@c959469[MainActivity]( 6281): from releaseSurfaces
t.apply t = 0xb400007886617400 V/SurfaceView@7e0b0f2( 6281): Layout:
x=0 y=0 w=720 h=1510, frame=Rect(0, 0 - 720, 1510)
D/SurfaceView@7e0b0f2( 6281): windowPositionLost, frameNr = 0
D/OpenGLRenderer( 6281): setSurface called with nullptr
D/OpenGLRenderer( 6281): setSurface() destroyed EGLSurface
D/OpenGLRenderer( 6281): destroyEglSurface D/BufferQueueProducer(
6281): [ViewRootImpl@c959469[MainActivity]#2(BLAST
Consumer)2](id:188900000002,api:1,p:6281,c:6281) disconnect: api 1
I/ViewRootImpl@c959469[MainActivity]( 6281): performTraversals
mFirst=false windowShouldResize=false viewVisibilityChanged=true
mForceNextWindowRelayout=false params=null D/BLASTBufferQueue( 6281):
[ViewRootImpl@c959469[MainActivity]#2](f:0,a:1) destructor()
D/BufferQueueConsumer( 6281):
[ViewRootImpl@c959469[MainActivity]#2(BLAST
Consumer)2](id:188900000002,api:0,p:-1,c:6281) disconnect
I/ViewRootImpl@c959469[MainActivity]( 6281): Relayout returned:
old=(0,0,720,1600) new=(0,0,720,1600) req=(720,1600)8 dur=10 res=0x2
s={false 0x0} ch=true seqId=0 I/SurfaceView@7e0b0f2( 6281):
windowStopped(true) false
io.flutter.embedding.android.FlutterSurfaceView{7e0b0f2 V.E......
........ 0,0-720,1510} of ViewRootImpl@c959469[MainActivity]
D/SurfaceView@7e0b0f2( 6281): updateSurface: surface is not valid
I/SurfaceView@7e0b0f2( 6281): releaseSurfaces: viewRoot =
ViewRootImpl@c959469[MainActivity] I/SurfaceView@7e0b0f2( 6281):
applyTransactionOnVriDraw: vri = ViewRootImpl@c959469[MainActivity]
fRS = true t = 0xb4000078878b8100
android.view.SurfaceView.releaseSurfaces:858
android.view.SurfaceView.updateSurface:998
android.view.SurfaceView.setWindowStopped:335 I/SurfaceView@7e0b0f2(
6281): applyTransactionOnVriDraw:
viewRoot.applyTransactionOnDrawFromReleaseSurfaces
I/ViewRootImpl@c959469[MainActivity]( 6281): from releaseSurfaces
t.apply t = 0xb4000078878b8100 D/SurfaceView@7e0b0f2( 6281):
updateSurface: surface is not valid I/SurfaceView@7e0b0f2( 6281):
releaseSurfaces: viewRoot = ViewRootImpl@c959469[MainActivity]
I/SurfaceView@7e0b0f2( 6281): applyTransactionOnVriDraw: vri =
ViewRootImpl@c959469[MainActivity] fRS = true t = 0xb4000078fc386700
android.view.SurfaceView.releaseSurfaces:858
android.view.SurfaceView.updateSurface:998
android.view.SurfaceView.lambda$new$0$android-view-SurfaceView:200
I/SurfaceView@7e0b0f2( 6281): applyTransactionOnVriDraw:
viewRoot.applyTransactionOnDrawFromReleaseSurfaces
I/ViewRootImpl@c959469[MainActivity]( 6281): from releaseSurfaces
t.apply t = 0xb4000078fc386700 I/ViewRootImpl@c959469[MainActivity](
6281): stopped(true) old = false I/ViewRootImpl@c959469[MainActivity](
6281): WindowStopped on com.....ni/com.i.MainActivity set to true
I/MSHandlerLifeCycle( 6281): removeMultiSplitHandler: no exist.
decor=DecorView@a75d7bb[MainActivity] D/SurfaceView@7e0b0f2( 6281):
updateSurface: surface is not valid I/SurfaceView@7e0b0f2( 6281):
releaseSurfaces: viewRoot = ViewRootImpl@c959469[MainActivity]
I/SurfaceView@7e0b0f2( 6281): applyTransactionOnVriDraw: vri =
ViewRootImpl@c959469[MainActivity] fRS = true t = 0xb4000078fc386800
android.view.SurfaceView.releaseSurfaces:858
android.view.SurfaceView.updateSurface:998
android.view.SurfaceView.lambda$new$0$android-view-SurfaceView:200
I/SurfaceView@7e0b0f2( 6281): applyTransactionOnVriDraw:
viewRoot.applyTransactionOnDrawFromReleaseSurfaces
I/ViewRootImpl@c959469[MainActivity]( 6281): from releaseSurfaces
t.apply t = 0xb4000078fc386800 I/ViewRootImpl@c959469[MainActivity](
6281): MSG_WINDOW_FOCUS_CHANGED 0 0 D/FlutterBluePlugin( 6281):
mDevices size: 0 I/FA      ( 6281): Application backgrounded at:
timestamp_millis: 1694781560148 D/FlutterBluePlugin( 6281): mDevices
size: 0 I/ViewRootImpl@c959469[MainActivity]( 6281):
handleAppVisibility mAppVisible = false visible = true
D/InsetsController( 6281): onStateChanged: InsetsState:
{mDisplayFrame=Rect(0, 0 - 720, 1600),
mDisplayCutout=DisplayCutout{insets=Rect(0, 45 - 0, 0)
waterfall=Insets{left=0, top=0, right=0, bottom=0}
boundingRect={Bounds=[Rect(0, 0 - 0, 0), Rect(272, 0 - 448, 45),
Rect(0, 0 - 0, 0), Rect(0, 0 - 0, 0)]}
cutoutPathParserInfo={CutoutPathParserInfo{displayWidth=720
displayHeight=1600 physicalDisplayWidth=720 physicalDisplayHeight=1600
density={1.875} cutoutSpec={M 0,0 H -46.93333333333333 V 24 H
46.93333333333333 V 0 H 0 Z @dp} rotation={0} scale={1.0} physicalPixelDisplaySizeRatio={1.0}}}},
mRoundedCorners=RoundedCorners{[RoundedCorner{position=TopLeft,
radius=60, center=Point(60, 60)}, RoundedCorner{position=TopRight,
radius=60, center=Point(660, 60)}, RoundedCorner{position=BottomRight,
radius=60, center=Point(660, 1540)},
RoundedCorner{position=BottomLeft, radius=60, center=Point(60,
1540)}]}  mRoundedCornerFrame=Rect(0, 0 - 720, 1600),
mPrivacyIndicatorBounds=PrivacyIndicatorBounds {static
bounds=Rect(637, 0 - 720, 45) rotation=0}, mSources= { InsetsSource:
{mType=ITYPE_STATUS_BAR, mFrame=[0,0][720,45], mVisible=true,
mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_NAVIGATION_BAR, mFrame=[0,1510][720,1600],
mVisible=false, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_LEFT_GESTURES, mFrame=[0,0][0,1600], mVisible=true,
mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_RIGHT_GESTURES, mFrame=[720,0][720,1600], mVisible=true,
mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_TOP_MANDATORY_GESTURES, mFrame=[0,0][720,68],
mVisible=true, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_BOTTOM_MANDATORY_GESTURES, mFrame=[0,1510][720,1600],
mVisible=true, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_LEFT_DISPLAY_CUTOUT, mFrame=[0,0][-100000,1600],
mVisible=true, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_TOP_DISPLAY_CUTOUT, mFrame=[0,0][720,45], mVisible=true,
mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_RIGHT_DISPLAY_CUTOUT, mFrame=[100000,0][720,1600],
mVisible=true, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_BOTTOM_DISPLAY_CUTOUT, mFrame=[0,100000][720,1600],
mVisible=true, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_TOP_TAPPABLE_ELEMENT, mFrame=[0,0][720,45],
mVisible=true, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_BOTTOM_TAPPABLE_ELEMENT, mFrame=[0,1510][720,1600],
mVisible=true, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_IME, mFrame=[0,0][0,0], mVisibleFrame=[0,928][720,1600],
mVisible=false, mInsetsRoundedCornerFrame=false} }
host=cni/com.ai.MainActivity
from=android.view.ViewRootImpl$ViewRootHandler.handleMessageImpl:6740
I/SurfaceView@7e0b0f2( 6281): onWindowVisibilityChanged(4) false
io.flutter.embedding.android.FlutterSurfaceView{7e0b0f2 V.E......
........ 0,0-720,1510} of ViewRootImpl@c959469[MainActivity]
D/SurfaceView@7e0b0f2( 6281): updateSurface: surface is not valid
I/SurfaceView@7e0b0f2( 6281): releaseSurfaces: viewRoot =
ViewRootImpl@c959469[MainActivity] I/SurfaceView@7e0b0f2( 6281):
applyTransactionOnVriDraw: vri = ViewRootImpl@c959469[MainActivity]
fRS = true t = 0xb40000790a71fb00
android.view.SurfaceView.releaseSurfaces:858
android.view.SurfaceView.updateSurface:998
android.view.SurfaceView.onWindowVisibilityChanged:371
I/SurfaceView@7e0b0f2( 6281): applyTransactionOnVriDraw:
viewRoot.applyTransactionOnDrawFromReleaseSurfaces
I/ViewRootImpl@c959469[MainActivity]( 6281): applyTransactionOnDraw:
mRemoved = false isHardwareEnabled = false t =
0xb40000790a71fb00android.view.ViewRootImpl.applyTransactionOnDrawFromReleaseSurfaces:12850
android.view.SurfaceView.applyTransactionOnVriDraw:2046
android.view.SurfaceView.releaseSurfaces:858
android.view.SurfaceView.updateSurface:998
android.view.SurfaceView.onWindowVisibilityChanged:371
D/OpenGLRenderer( 6281): setSurface called with nullptr
I/ViewRootImpl@c959469[MainActivity]( 6281): performTraversals
mFirst=false windowShouldResize=false viewVisibilityChanged=true
mForceNextWindowRelayout=false params=null D/InsetsController( 6281):
onStateChanged: InsetsState: {mDisplayFrame=Rect(0, 0 - 720, 1600),
mDisplayCutout=DisplayCutout{insets=Rect(0, 45 - 0, 0)
waterfall=Insets{left=0, top=0, right=0, bottom=0}
boundingRect={Bounds=[Rect(0, 0 - 0, 0), Rect(272, 0 - 448, 45),
Rect(0, 0 - 0, 0), Rect(0, 0 - 0, 0)]}
cutoutPathParserInfo={CutoutPathParserInfo{displayWidth=720
displayHeight=1600 physicalDisplayWidth=720 physicalDisplayHeight=1600
density={1.875} cutoutSpec={M 0,0 H -46.93333333333333 V 24 H
46.93333333333333 V 0 H 0 Z @dp} rotation={0} scale={1.0} physicalPixelDisplaySizeRatio={1.0}}}},
mRoundedCorners=RoundedCorners{[RoundedCorner{position=TopLeft,
radius=60, center=Point(60, 60)}, RoundedCorner{position=TopRight,
radius=60, center=Point(660, 60)}, RoundedCorner{position=BottomRight,
radius=60, center=Point(660, 1540)},
RoundedCorner{position=BottomLeft, radius=60, center=Point(60,
1540)}]}  mRoundedCornerFrame=Rect(0, 0 - 720, 1600),
mPrivacyIndicatorBounds=PrivacyIndicatorBounds {static
bounds=Rect(637, 0 - 720, 45) rotation=0}, mSources= { InsetsSource:
{mType=ITYPE_STATUS_BAR, mFrame=[0,0][720,45], mVisible=true,
mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_NAVIGATION_BAR, mFrame=[0,1510][720,1600],
mVisible=false, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_LEFT_GESTURES, mFrame=[0,0][0,1600], mVisible=true,
mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_RIGHT_GESTURES, mFrame=[720,0][720,1600], mVisible=true,
mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_TOP_MANDATORY_GESTURES, mFrame=[0,0][720,68],
mVisible=true, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_BOTTOM_MANDATORY_GESTURES, mFrame=[0,1510][720,1600],
mVisible=true, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_LEFT_DISPLAY_CUTOUT, mFrame=[0,0][-100000,1600],
mVisible=true, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_TOP_DISPLAY_CUTOUT, mFrame=[0,0][720,45], mVisible=true,
mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_RIGHT_DISPLAY_CUTOUT, mFrame=[100000,0][720,1600],
mVisible=true, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_BOTTOM_DISPLAY_CUTOUT, mFrame=[0,100000][720,1600],
mVisible=true, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_TOP_TAPPABLE_ELEMENT, mFrame=[0,0][720,45],
mVisible=true, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_BOTTOM_TAPPABLE_ELEMENT, mFrame=[0,1510][720,1600],
mVisible=true, mInsetsRoundedCornerFrame=false}, InsetsSource:
{mType=ITYPE_IME, mFrame=[0,0][0,0], mVisibleFrame=[0,928][720,1600],
mVisible=false, mInsetsRoundedCornerFrame=false} }
host=com.a/com.ini.MainActivity
from=android.view.ViewRootImpl.relayoutWindow:9802
I/ViewRootImpl@c959469[MainActivity]( 6281): Relayout returned:
old=(0,0,720,1600) new=(0,0,720,1600) req=(720,1600)4 dur=17 res=0x0
s={false 0x0} ch=false seqId=0 D/SurfaceView@7e0b0f2( 6281):
updateSurface: surface is not valid I/SurfaceView@7e0b0f2( 6281):
releaseSurfaces: viewRoot = ViewRootImpl@c959469[MainActivity]
I/SurfaceView@7e0b0f2( 6281): applyTransactionOnVriDraw: vri =
ViewRootImpl@c959469[MainActivity] fRS = true t = 0xb40000790a71fd00
android.view.SurfaceView.releaseSurfaces:858
android.view.SurfaceView.updateSurface:998
android.view.SurfaceView.lambda$new$0$android-view-SurfaceView:200
I/SurfaceView@7e0b0f2( 6281): applyTransactionOnVriDraw:
viewRoot.applyTransactionOnDrawFromReleaseSurfaces
I/ViewRootImpl@c959469[MainActivity]( 6281): applyTransactionOnDraw:
mRemoved = false isHardwareEnabled = false t =
0xb40000790a71fd00android.view.ViewRootImpl.applyTransactionOnDrawFromReleaseSurfaces:12850
android.view.SurfaceView.applyTransactionOnVriDraw:2046
android.view.SurfaceView.releaseSurfaces:858
android.view.SurfaceView.updateSurface:998
android.view.SurfaceView.lambda$new$0$android-view-SurfaceView:200
I/ViewRootImpl@c959469[MainActivity]( 6281): stopped(false) old = true
I/ViewRootImpl@c959469[MainActivity]( 6281): WindowStopped on
com.i.MainActivity set to false I/MSHandlerLifeCycle( 6281):
removeMultiSplitHandler: no exist.
decor=DecorView@a75d7bb[MainActivity]
I/ViewRootImpl@c959469[MainActivity]( 6281): stopped(false) old =
false I/DecorView( 6281): notifyKeepScreenOnChanged:
keepScreenOn=false I/MSHandlerLifeCycle( 6281):
removeMultiSplitHandler: no exist.
decor=DecorView@a75d7bb[MainActivity]
I/ViewRootImpl@c959469[MainActivity]( 6281): Resizing
android.view.ViewRootImpl@8157bfa: frame = [0,0][720,1600] reportDraw
= false forceLayout = false syncSeqId = 0 I/SurfaceView@7e0b0f2( 6281): onWindowVisibilityChanged(0) false
io.flutter.embedding.android.FlutterSurfaceView{7e0b0f2 V.E......
........ 0,0-720,1510} of ViewRootImpl@c959469[MainActivity]
D/SurfaceView@7e0b0f2( 6281): updateSurface: surface is not valid
I/SurfaceView@7e0b0f2( 6281): releaseSurfaces: viewRoot =
ViewRootImpl@c959469[MainActivity] I/SurfaceView@7e0b0f2( 6281):
applyTransactionOnVriDraw: vri = ViewRootImpl@c959469[MainActivity]
fRS = true t = 0xb40000790a71fe00
android.view.SurfaceView.releaseSurfaces:858
android.view.SurfaceView.updateSurface:998
android.view.SurfaceView.onWindowVisibilityChanged:371
I/SurfaceView@7e0b0f2( 6281): applyTransactionOnVriDraw:
viewRoot.applyTransactionOnDrawFromReleaseSurfaces
I/ViewRootImpl@c959469[MainActivity]( 6281): applyTransactionOnDraw:
mRemoved = false isHardwareEnabled = false t =
0xb40000790a71fe00android.view.ViewRootImpl.applyTransactionOnDrawFromReleaseSurfaces:12850
android.view.SurfaceView.applyTransactionOnVriDraw:2046
android.view.SurfaceView.releaseSurfaces:858
android.view.SurfaceView.updateSurface:998
android.view.SurfaceView.onWindowVisibilityChanged:371
I/ViewRootImpl@c959469[MainActivity]( 6281): performTraversals
params={(0,0)(fillxfill) sim={adjust=resize forwardNavigation}
ty=BASE_APPLICATION fmt=TRANSLUCENT wanim=0x1030001

here is my button when i clicked this error throw:

    onPressed: () async {
                            stopButtonPressed = true;
                            if (device != null) device!.disconnect();
                            if (timer != null) timer!.cancel();
                            if (sub != null) sub!.cancel();
                            stopReading();

this my stopReading()

       stopReading() async {
/* To Do: Check if BLE setnotify needs to be disabled here or only after successful di analysis*/
progressDialog!.show(
    msg: "Your di is being analyzed will take a while, Please wait");

try {
  Future.delayed(const Duration(seconds: 1), () async {
    String path = (await getApplicationDocumentsDirectory()).path;
    diDataFile = File("$path/diData.txt");

    // sensor 1 = v
    // sensor 2 = p
    // sensor 3 = k

    // 10 15 25 20 100

    // 10 5 10 -5 80
    var diJson = <String, List<int>>{};
    diJson["v_input"] = [];
    diJson["p_input"] = [];
    diJson["k_input"] = [];

    await diDataFile!.writeAsString(jsonEncode(diJson));
    getCsvFile(
        cat1: categoryList1, cat2: categoryList2, cat3: categoryList3);
    if (progressDialog!.isOpen()) {
      if (timer != null) timer!.cancel();
      if (sub != null) await sub.cancel();
      // if (characteristic != null) await 
characteristic.setNotifyValue(false);
      if (device != null) await device!.disconnect();
      progressDialog!.close();
    }
    progressDialog!.close();
  });
} catch (e) {
  print(e);
}
progressDialog!.close();

}
this is how i gave permissions

 var deviceStoragePermission = await Permission.storage.request();
if (deviceStoragePermission.isGranted) {
        String dir = "${(await getExternalStorageDirectory())!.absolute.path}/";
        String file = dir;

        ///doctorId_medicalId.csv
        File newFile = File("$file$fileNameOfNadiToUpload.csv");
        String csv = const ListToCsvConverter().convert(rows);
        File createdCsvFile = await newFile.writeAsString(csv);
        print(createdCsvFile);

        ///creating zip file
        ///Create archive file
        final bytes = await File(createdCsvFile.path).readAsBytes();
        final archiveFile = ArchiveFile(createdCsvFile.path, bytes.length, bytes);

        ///Create instance of archive
        final archive = Archive();
        archive.addFile(archiveFile);

        ///Fetching static nadi file
        var staticFile = await getImageFileFromAssets("nadi_static_file", "${fileNameOfNadiToUpload}_A.csv");
        final staticNadiFileBytes = await File(staticFile.path).readAsBytes();
        archive.addFile(ArchiveFile(staticFile.path, staticNadiFileBytes.length, staticNadiFileBytes));
        print(staticFile.path);

        final zipEncoder = ZipEncoder();

        ///Encode zip file
        final encodedArchiveFile = zipEncoder.encode(archive);
        if (encodedArchiveFile == null) return;

        ///Final zip file
        final archivedZipFile = await File("${(await getExternalStorageDirectory())!.absolute.path}/$fileNameOfNadiToUpload.zip").writeAsBytes(encodedArchiveFile);
        StreamedResponse response = await ApiProvider().sendNadiData(patientId: patientDetails.id!, medicalId: medicalId!, file: archivedZipFile, context: context);
        NadiDataResponseModel nadiResponseData = NadiDataResponseModel();
        if (response.statusCode == 200) {
          // ignore: await_only_futures
          await response.stream.transform(utf8.decoder).listen((value) {
            nadiResponseData = NadiDataResponseModel.fromJson(jsonDecode(value));
          });
          print(nadiResponseData);
          if (nadiResponseData.cCodeError == "0") {
            showDialog(
              barrierDismissible: false,
              context: context,
              builder: (_) => CustomAlertDialog(
                title: "Please restart your .",
                showOkButton: true,
                onOkButtonPressed: () {
                  progressDialog.close();
                  Navigator.pop(context);
                  Navigator.pop(context);
                  //, "/NadiCaptureScreen", arguments: {'patientDetails': patientDetails, 'medicalId': medicalId});
                },
              ),
            );
          } else {
            visitDetails.id = medicalId!;
            progressDialog.close();
            myTimer!.cancel();
            await fetchDoctorDetails();
            String languageCode = await fetchDefauldReportLanguage();
            String doctorId = (await MySharedPreferences().getStringValue(key: LocalStorageStringConstants().userId))!;
            String clinicId = (await MySharedPreferences().getStringValue(key: LocalStorageStringConstants().clinicId))!;
            String authToken = (await MySharedPreferences().getStringValue(key: LocalStorageStringConstants().authToken))!;
            String urlString =
                ("t1=PRINT");
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) => ReportWebviewScreen(
                  typeOfReport: Report",
                  medicalId: medicalId!,
                  shouldDisplayBackwardArrow: false,
                  displayForwardArrow: true,
                  urlString: urlString,
                  patient: patientDetails,
                ),
              ),
            );
            // Navigator.push(
            //   context,
            //   MaterialPageRoute(builder: (context) => ReportScreen(reportDetails: visitDetails, patient: patientDetails)),
            // );
          }
        }
      }

2

Answers


  1. Add these permissions to AndroidManifest.xml:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" 
    android:maxSdkVersion="32" />
    
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
    

    And set compileSdkVersion to 33.

    android {
        compileSdkVersion 33
        ...
    }
    

    https://stackoverflow.com/a/76514629/9455518

    Login or Signup to reply.
  2. You have to also add this permission in Androidmanifest.xml

    <usespermissionandroid:name="android.permission.
    MANAGE_EXTERNAL_STORAGE"/>

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search