You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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..
The text was updated successfully, but these errors were encountered:
`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..
The text was updated successfully, but these errors were encountered: