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

Not able to load gallery images #16

Open
Shrulabh opened this issue Oct 26, 2020 · 1 comment
Open

Not able to load gallery images #16

Shrulabh opened this issue Oct 26, 2020 · 1 comment
Labels
question Further information is requested

Comments

@Shrulabh
Copy link

`import 'dart:io';

import 'package:flutter/material.dart';
import 'package:media_gallery/media_gallery.dart';
import 'package:permission_handler/permission_handler.dart';

class ListAppScreen extends StatefulWidget {
@OverRide
_ListAppScreenState createState() => _ListAppScreenState();
}

class _ListAppScreenState extends State {
List imageList = [];
_listMedia() {
Permission.storage.request().isGranted.then(
(value) {
if (value) {
print(value);
if (imageList.length == 0) {
fetchMediaFromPhone();
}
} else {
print(imageList.length);
Permission.storage.request();
}
},
);
print(imageList.length);
return imageList.length == 0
? Container(child: Center(child: CircularProgressIndicator()))
: Container(
child: GridView.builder(
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemCount: imageList.length,
itemBuilder: (BuildContext context, index) {
return Container(
decoration: BoxDecoration(
border: Border.all(
width: 10,
color: Colors.black38,
),
),
child: Image.file(imageList[index]),
);
},
),
);
}

void fetchMediaFromPhone() {
MediaGallery.listMediaCollections(
mediaTypes: [MediaType.image],
).then((value) {
print(value);
for (MediaCollection collections in value) {
collections
.getMedias(
mediaType: MediaType.image,
take: 500,
)
.then(
(mediaPage) async {
for (var i in mediaPage.items) {
File mediaFile = await i.getFile();
if (!imageList.contains(mediaFile)) {
imageList.add(mediaFile);
}
print("item info of media type - ${mediaFile.path}");
}
setState(() {});
// break;
},
);
break;
}
});
}

void selectImage(BuildContext ctx) {
Navigator.of(ctx).pushNamed(
'/app',
);
}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: _listMedia(),
),
);
}
}`

This the above code.
I am trying to display all the images in the gallery,
when the page loads up it is able to show only 4-5 images and then the app crashes. Please help..

@aloisdeniel
Copy link
Owner

Hi !

Do you have any log ? Maybe a memory issue.

Did you try the provided sample ? Does it work ?

@aloisdeniel aloisdeniel added the question Further information is requested label Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants