Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Root folderName #12

Closed
ThePunisher569 opened this issue Jul 22, 2020 · 2 comments
Closed

Root folderName #12

ThePunisher569 opened this issue Jul 22, 2020 · 2 comments

Comments

@ThePunisher569
Copy link

I'm trying to access the root folder name which is '/storage/emulated/0' but the foldername field in json array for is null and the following error was thrown:

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building Builder(dirty):
A non-null String must be provided to a Text widget.
'package:flutter/src/widgets/text.dart':
Failed assertion: line 360 pos 10: 'data != null'

The relevant error-causing widget was:
Builder file:///C:/Users/Aatif/AndroidStudioProjects/gallery_app/lib/main.dart:59:32
When the exception was thrown, this was the stack:
#2 new Text (package:flutter/src/widgets/text.dart:360:10)
#3 _HomeState.build.. (package:gallery_app/main.dart:66:36)
#4 Builder.build (package:flutter/src/widgets/basic.dart:7166:48)
#5 StatelessElement.build (package:flutter/src/widgets/framework.dart:4631:28)
#6 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4557:15)
...

JSON array:
**_{files: [/storage/emulated/0/IMG_20160709_181323981.jpg]}, {files: [/storage/emulated/0/IMG_20160709_174128028.jpg]}_**, {files: [/storage/emulated/0/timetable/IMG-20200107-WA0002.jpg], folderName: timetable}, {files: [/storage/emulated/0/Fake Tweets/Image-6156.jpg, /storage/emulated/0/Fake Tweets/Image-3012.jpg, /storage/emulated/0/Fake Tweets/IMG_20180703_141329.jpg], folderName: Fake Tweets},

as you can see there's no folderName field.

@ThePunisher569 ThePunisher569 changed the title Files in root folder Root folderName Jul 22, 2020
@mohitjadav86
Copy link

Hope This one can help.
https://stackoverflow.com/a/56353311

@ThePunisher569
Copy link
Author

Hope This one can help.
https://stackoverflow.com/a/56353311

I've filtered the list of images which are in root folder and added folderName

      _imagesPath = await StoragePath.imagesPath;
      //images list with files and folder name

      var imagesList = jsonDecode(_imagesPath) as List;

      //root folderName handling********************
      Map<String,dynamic> rootObject = {'files':[],'folderName':'0'};
      for(Map<String,dynamic> a in imagesList){
        if (a['folderName']==null){
          a['folderName'] = '0';
          rootObject['files']=rootObject['files']+a['files'];
        }
      }
      imagesList.removeWhere((element) => element['folderName']=='0');
      imagesList.insert(0,rootObject);
      //***********************

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants