Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'dart:async';
- import 'package:flutter/services.dart';
- import 'package:multi_image_picker/multi_image_picker.dart';
- import 'dart:typed_data';
- import 'dart:io';
- import 'package:image/image.dart' as v3;
- import 'dart:ui' as v2;
- //import 'package:flutter/widgets.dart' as v2;
- void main() => runApp(new MyApp());
- class MyApp extends StatefulWidget {
- @override
- _MyAppState createState() => new _MyAppState();
- }
- class _MyAppState extends State<MyApp> {
- List<Asset> images = List<Asset>();
- @override
- void initState() {
- super.initState();
- }
- // image.File()
- Widget buildGridView() {
- return GridView.count(
- crossAxisCount: 3, //images.length
- children: List.generate(images.length, (index) {
- Asset asset1 = images[index];
- var x = asset1.identifier;
- print("The asset's name is $x");
- //print("The string rep is $grayScaleImage(asset1).toString()");
- return AssetThumb(
- asset: asset1,
- width: 300,
- height: 300,
- );
- }), // displays the selected images in a grid view
- );
- }
- // Future<AssetThumb> assetThumbMaker(Asset asset1) async {
- //// await saveImage(asset1);
- //// return await assetThumbMaker2(asset1);
- ////
- //// }
- ////
- //// Future<AssetThumb> assetThumbMaker2(Asset asset1) async {
- //// await Future.delayed(const Duration(seconds: 5), (){});
- //// print("got here 3");
- //// return AssetThumb(
- //// asset: asset1,
- //// width: 300,
- //// height: 300,
- //// );
- //// }
- // Future<void> saveImage(Asset asset1) async {
- // var z = await grayScaleImage(asset1);
- // v3.Image image1 = v3.decodeJpg(z);
- // v3.Image thumbnail = v3.copyResize(image1, width: 120);
- // File('assets/thumbnail-test.jpeg').writeAsBytesSync(v3.encodeJpg(thumbnail));
- // print("got here");
- // //Image.memory(z);
- // }
- Future<void> deleteAssets() async {
- await MultiImagePicker.deleteImages(assets: images);
- setState(() {
- images = List<Asset>();
- });
- }
- Future<Widget> grayScaleImage(Asset asset, int index) async {
- print("here 1");
- ByteData bd = await asset.requestThumbnail(
- asset.originalWidth, asset.originalHeight,
- quality: 100); // width and height
- var a2 = bd.buffer.asUint8List();
- var input1 =
- v3.Image.fromBytes(asset.originalWidth, asset.originalHeight, a2);
- v3.Image grayImage = v3.grayscale(input1);
- print("here 2");
- return Image.memory(Uint8List.fromList(v3.encodeJpg(grayImage)));
- //Uint8List.fromList(v3.encodeJpg(grayImage));
- //return v3.encodeJpg(grayImage);
- // Image(image: MemoryImage(listaU8L[0]));
- }
- Future<void> loadAssets() async {
- List<Asset> resultList = List<Asset>();
- String error = 'No Error Dectected';
- try {
- resultList = await MultiImagePicker.pickImages(
- maxImages: 300,
- enableCamera: true,
- selectedAssets: images,
- cupertinoOptions: CupertinoOptions(takePhotoIcon: "chat"),
- materialOptions: MaterialOptions(
- allViewTitle: "All Photos",
- ));
- } on PlatformException catch (e) {
- error = e.message;
- print(error);
- }
- // If the widget was removed from the tree while the asynchronous platform
- // message was in flight, we want to discard the reply rather than calling
- // setState to update our non-existent appearance.
- if (!mounted) return;
- setState(() {
- images = resultList;
- print(error);
- });
- }
- @override
- Widget build(BuildContext context) {
- return new MaterialApp(
- debugShowCheckedModeBanner: false,
- home: new Scaffold(
- appBar: new AppBar(
- title: const Text('GrayScale Maker'),
- centerTitle: true,
- backgroundColor: Colors.deepOrangeAccent,
- ),
- body: Stack(
- children: <Widget>[
- new Container(
- decoration: new BoxDecoration(
- image: new DecorationImage(
- image: new AssetImage("assets/background.jpg"),
- fit: BoxFit.cover,
- ), // adds background image
- ),
- ),
- Column(
- children: <Widget>[
- RaisedButton(
- child: Text("Pick images"),
- onPressed: loadAssets,
- ),
- images.length > 0
- ? RaisedButton(
- child: Text("Remove All Images"),
- onPressed: deleteAssets,
- )
- : Container(),
- Expanded(
- child: await grayScaleImage(asset, index),
- )
- ],
- ),
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement