You should check out the path provider plugin on pub.dev. What you want to do is read the Xender/image directory and say map them to a list or something. See my implementation below. I am trying to show the images in a staggered view(assuming the images are in jpg format): First, add the path provider plugin to your pubspec.yaml
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
final Directory _photoDir = Directory('/storage/emulated/0/Xender/image');
class Photos extends StatefulWidget {
@override
PhotosState createState() {
return new PhotosState();
}
}
class PhotosState extends State {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
if(!Directory("${_photoDir.path}").existsSync()) {
return Scaffold(
appBar: AppBar(
title: Text("Xender Images"),
),
body: Container(
padding: EdgeInsets.only(bottom: 60.0),
child: Center(
child: Text("All Xender images should appear here", style: TextStyle(
fontSize: 18.0
),),
),
),
);
}else {
var imageList = _photoDir.listSync().map((item) => item.path).where((
item) => item.endsWith(".jpg")).toList(growable: false);
if (imageList.length > 0) {
return Scaffold(
appBar: AppBar(
title: Text("Xender Images"),
),
body: Container(
padding: EdgeInsets.only(bottom: 60.0),
child: StaggeredGridView.countBuilder(
padding: const EdgeInsets.all(8.0),
crossAxisCount: 4,
itemCount: imageList.length,
itemBuilder: (context, index) {
String imgPath = imageList[index];
return Material(
elevation: 8.0,
borderRadius: BorderRadius.all(Radius.circular(8)),
child: InkWell(
onTap: () {},
child: Hero(
tag: imgPath,
child: Image.file(
File(imgPath),
fit: BoxFit.cover,
),
),
),
);
},
staggeredTileBuilder: (i) =>
StaggeredTile.count(2, i.isEven ? 2 : 3),
mainAxisSpacing: 8.0,
crossAxisSpacing: 8.0,
),
),
);
} else {
return Scaffold(
appBar: AppBar(
title: Text("Xender images"),
),
body: Center(
child: Container(
padding: EdgeInsets.only(bottom: 60.0),
child: Text("Sorry, No Images Where Found.", style: TextStyle(
fontSize: 18.0
),),
),
),
);
}
}
}
}