I am trying to build a picture and camera screen in a page like the Instagram post screen I tried using storage path which currently only works on android and also returns an error, I want it to work on android and ios so I can easily pick multiple images no cropping or editing needed for the pictures.
class FileModel {
List<String> files;
String folder;
FileModel({this.files, this.folder});
FileModel.fromJson(Map<String, dynamic> json) {
files = json['files'].cast<String>();
folder = json['folderName'];
}
}
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:storage_path/storage_path.dart';
import 'package:rojar1/models/file_model.dart';
class PostScreen extends StatefulWidget {
static String routeName = "/postscreen";
PostScreen({Key key, this.title}) : super(key: key);
final String title;
@override
_PostScreenState createState() => _PostScreenState();
}
class _PostScreenState extends State<PostScreen> {
List<FileModel> files;
FileModel selectedModel;
String image;
@override
void initState() {
super.initState();
getImagesPath();
}
getImagesPath() async {
var imagePath = await StoragePath.imagesPath;
var images = jsonDecode(imagePath) as List;
files = images.map<FileModel>((e) => FileModel.fromJson(e)).toList();
if (files != null && files.length > 0)
setState(() {
selectedModel = files[0];
image = files[0].files[0];
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.clear),
SizedBox(width: 10),
DropdownButtonHideUnderline(
child: DropdownButton<FileModel>(
items: getItems(),
onChanged: (FileModel d) {
assert(d.files.length > 0);
image = d.files[0];
setState(() {
selectedModel = d;
});
},
value: selectedModel,
))
],
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Next',
style: TextStyle(color: Colors.blue),
),
)
],
),
Divider(),
Container(
height: MediaQuery.of(context).size.height * 0.45,
child: image != null
? Image.file(File(image),
height: MediaQuery.of(context).size.height * 0.45,
width: MediaQuery.of(context).size.width)
: Container()),
Divider(),
selectedModel == null && selectedModel.files.length < 1
? Container()
: Container(
height: MediaQuery.of(context).size.height * 0.38,
child: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
crossAxisSpacing: 4,
mainAxisSpacing: 4),
itemBuilder: (_, i) {
var file = selectedModel.files[i];
return GestureDetector(
child: Image.file(
File(file),
fit: BoxFit.cover,
),
onTap: () {
setState(() {
image = file;
});
},
);
},
itemCount: selectedModel.files.length),
)
],
),
),
);
}
List<DropdownMenuItem> getItems() {
return files
.map((e) => DropdownMenuItem(
child: Text(
e.folder,
style: TextStyle(color: Colors.black),
),
value: e,
))
.toList() ??
[];
}
}
You need to customized the album at the lower part, then you need to build your own album with this photo_manager:
get album photos by paged:
// page: The page number of the page, starting at 0.
// perPage: The number of pages per page.
final assetList = await path.getAssetListPaged(page, perPage);
once you got them, layout whatever you like, like putting images in gridview at the lower part