Skip to content

Instantly share code, notes, and snippets.

@stiffsteve
Created May 30, 2018 18:51
Show Gist options
  • Save stiffsteve/71430a4a7e600cb4a531ec885ce3669c to your computer and use it in GitHub Desktop.
Save stiffsteve/71430a4a7e600cb4a531ec885ce3669c to your computer and use it in GitHub Desktop.
Flutter app that loads images from the camera roll and displays them in a ListView
import 'dart:io';
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new ImageList(),
);
}
}
class ImageList extends StatelessWidget {
static final Directory _photoDir =
new Directory('/storage/emulated/0/DCIM/Camera');
@override
Widget build(BuildContext context) {
List<FileSystemEntity> _photoList;
Widget buildPhoto(int index) {
if (index >= _photoList.length) {
return null;
}
print('Loading photo[${index}]: ${_photoList[index]}... done');
return new Container(
margin: EdgeInsets.all(8.0),
child: new Image.file(
_photoList[index],
// Use small images to fit more on the screen at once
// Shows the loading speed more clearly
width: 96.0,
height: 96.0,
scale: 16.0,
fit: BoxFit.contain,
),
);
}
Widget buildPhotoList() {
_photoList = _photoDir.listSync();
return new ListView.builder(
itemBuilder: (BuildContext context, int index) => buildPhoto(index),
);
}
return new Scaffold(
appBar: new AppBar(
title: new Text("Image list"),
),
body: new Center(
child: new Align(
alignment: Alignment.topCenter,
child: buildPhotoList(),
),
),
);
}
}
@Melbourneandrew
Copy link

FileSystemException: Directory listing failed, path = '/storage/emulated/0/DCIM/Camera/'

Appears this isn't the right path for my build. Do you know how I could find the right path?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment