thumbnail_creator 0.0.9

  • Readme
  • Changelog
  • Example
  • Installing
  • 44

thumbnail_creator #

A plugin, which converts images by filepath to thumbnails on the fly in a really fast manner. The image dimensions are choosable. At this moment, only working on android!

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

0.0.1 #

  • TODO: Describe initial release.

0.0.2 #

  • Fixed some bugs

0.0.3 #

  • Fixed some bugs

0.0.4 #

  • Fixed some bugs

0.0.5 #

  • Fixed some bugs

0.0.6 #

  • Now working like expected!

0.0.7 #

  • Failed build

0.0.8 #

  • Failed build

0.0.9 #

  • Now compresses bitmap to the right input image format (png to png, jpg to jpg, etc.)
  • If the input image format is not png, jpg or jpeg, it defaults to jpg

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:thumbnail_creator/thumbnail_creator.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<String> list;
  ThumbnailCreator _creator;
  Resourcer _resourcer;

  @override
  void initState() {
    super.initState();
    _creator = ThumbnailCreator();
    _resourcer = Resourcer();

    _resourcer.initLists().then((_) {
      setState(() {
        
      });
    });

    //initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    try {
      list = List();

       for(int i = 0; i < 300; i++) {
         list.addAll([
           "/storage/emulated/0/locally/image/a137fa270841cb039862774b69d8481081308567.jpg",
           "/storage/emulated/0/locally/image/68bc5ef349b264072ef39a159d8230f7c57acce6.jpg",
           "/storage/emulated/0/locally/image/b7cdf933f7b467f22d84105e6a3cf21c08203ea6.jpg",
           "/storage/emulated/0/locally/image/81cf706c66aea1d96dffa701f56cd495b127882f.jpg",
           "/storage/emulated/0/locally/image/6364f829d8492784141c37e3109053122cd0d97d.jpg",
           "/storage/emulated/0/locally/image/bea0274c42dc4b6684c491b025876810294a9b02.jpg",
           "/storage/emulated/0/locally/image/03b7f051ba4f77720e385e758e24e2e6d2492e81.jpg",
           "/storage/emulated/0/locally/image/465521787e62c4ab8e1cdd063988ec24f6c0d22f.jpg",
           "/storage/emulated/0/locally/image/9c2ca95465a35e05bdc6c74940a3be07b74e809f.jpg",
           "/storage/emulated/0/locally/image/1c846c6ca6bca5d62a3d4e499aaab29b6dcea381.jpg",
           "/storage/emulated/0/locally/image/36e54ca387679c5dd0e9b951713c065dec6c70c8.jpg",
           "/storage/emulated/0/locally/image/e5b6c7e9888c1ab72a28cb476bb179d2500c4566.jpg",
           "/storage/emulated/0/locally/image/30e245b1c74dae622631f97f38d22075484c6ea5.jpg",
           "/storage/emulated/0/locally/image/0b4552dfc2c0e0fa917a0b1642220282500272d3.jpg",
           "/storage/emulated/0/locally/image/56ee55ac00cfb5852789a05d11c1f289d272396f.jpg",
           "/storage/emulated/0/locally/image/b05028e0239dcbc7396c7c328ad43c45a6314729.jpg",
           "/storage/emulated/0/locally/image/d6c515f7594d5dec9d14a05b17942b3853186380.jpg",
           "/storage/emulated/0/locally/image/be8847b00bb13a275dcac03ca78fcd15123641fc.jpg",
           "/storage/emulated/0/locally/image/84ecb92fad1c95127f95a96f82dd7c356a3b9161.jpg",
           "/storage/emulated/0/locally/image/893309d79142ea46badca700a9a563bb10a60a78.jpg",
           "/storage/emulated/0/locally/image/e2d25e2fe2fd411bdda7b915d3f38c9861ed4103.jpg",
           "/storage/emulated/0/locally/image/05168ef82b4a1e494b8c60b83792a2fccf12caab.jpg",
           "/storage/emulated/0/locally/image/e38b216d1c933cc6f451141df315bb00a1cd57eb.jpg",
           "/storage/emulated/0/locally/image/1c444b4ed919e850c729e60e3852b9f9e6edca6a.png",
           "/storage/emulated/0/locally/image/84ecb92fad1c95127f95a96f82dd7c356a3b9161.jpg",
           "/storage/emulated/0/locally/image/893309d79142ea46badca700a9a563bb10a60a78.jpg",
           "/storage/emulated/0/locally/image/e2d25e2fe2fd411bdda7b915d3f38c9861ed4103.jpg",
           "/storage/emulated/0/locally/image/05168ef82b4a1e494b8c60b83792a2fccf12caab.jpg",
           "/storage/emulated/0/locally/image/e38b216d1c933cc6f451141df315bb00a1cd57eb.jpg",
           "/storage/emulated/0/locally/image/1c444b4ed919e850c729e60e3852b9f9e6edca6a.png",
           "/storage/emulated/0/locally/image/98bf443a84820e4f22bbca4c5c009da52dee532e.png",
           "/storage/emulated/0/locally/image/ecffbb87e773a5e09596e398cbcb05e2fd451706.jpg",
           "/storage/emulated/0/locally/image/0a83fc2f99a2eb5060346811290d3ae00efe20c0.jpg",
           "/storage/emulated/0/locally/image/c7d2650b14dd75f77928f57b2b380ba0dfcae3ee.jpg",
           "/storage/emulated/0/locally/image/4ae7f7136682e43f25bb4a58a53652a36bfa0d8d.jpg",
           "/storage/emulated/0/locally/image/c6833bf5b021ff71a940a39d5d4c47d77c139b7f.jpg",
           "/storage/emulated/0/locally/image/a2f47ea0037ca5d843980969827bcc77949ed9df.jpg",
           "/storage/emulated/0/locally/image/a086700a723cd82a48e2779422ae3e4446c60038.jpg",
           "/storage/emulated/0/locally/image/a137fa270841cb039862774b69d8481081308567.jpg",
           "/storage/emulated/0/locally/image/68bc5ef349b264072ef39a159d8230f7c57acce6.jpg",
           "/storage/emulated/0/locally/image/b7cdf933f7b467f22d84105e6a3cf21c08203ea6.jpg",
           "/storage/emulated/0/locally/image/591b6a36cb31472082056095c141c28acab5225c.jpg",
           "/storage/emulated/0/locally/image/6517b869959366db8703b62f51123ca38c681933.jpg",
           "/storage/emulated/0/locally/image/023c249708c1f3a854117612cc2ae2306cb59d7d.jpg",
           "/storage/emulated/0/locally/image/0d4a4f61c8453531a6a2a476102fa48ba0be0ffe.jpg"
         ]);
       }

      if (this.mounted) {
        setState((){});
      }
    } on PlatformException {

    }

    // 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.
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: GridView.builder(
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 4,
              crossAxisSpacing: 1,
              mainAxisSpacing: 1,
            ),
            cacheExtent: 1200,
            itemBuilder: (_, __) {
              return FutureBuilder(
                future: _creator.getThumbnail(
                  _resourcer.imageList[__].path,
                  reqHeight: 100,
                  reqWidth: 100,
                ),
                builder: (BuildContext context, AsyncSnapshot image) {
                  if(image.hasData) {
                    return image.data is String ? Image.file(
                      File(image.data),
                      fit: BoxFit.cover,
                      width: 100,
                      height: 100,
                      gaplessPlayback: true,
                    ) : Image.memory(
                      image.data,
                      fit: BoxFit.cover,
                      width: 100,
                      height: 100,
                      gaplessPlayback: true,
                    );
                  } else {
                    print(image.data);
                    return Container(
                      width: 10,
                      height: 10,
                      child: Center(
                        child: CircularProgressIndicator(
                          valueColor: AlwaysStoppedAnimation(Colors.black),
                        ),
                      ),
                    );
                  }
                }
              );
            },
          itemCount: _resourcer.imageList != null ? _resourcer.imageList.length : 0,
        ),
      ),
    );
  }
}


class Resourcer {
  StreamController _streamController;
  Stream _stream;
  Directory _externalDocumentsDirectory;
  List<File> imageList = List();

  Stream get loadingStatusStream => _stream;

  List<String> _imageFormats = [
    'jpg',
    'jpeg',
    'png',
    'gif',
    'bmp',
    'webp',
    'wbmp',
  ];


  Future initLists() async {
    _externalDocumentsDirectory = Directory('/storage/emulated/0');

    imageList.clear();

    await _getDirectoryContent(_externalDocumentsDirectory.uri);
  }

  void dispose() {
    imageList.clear();
  }

  Future _getDirectoryContent(Uri uri) async {
    try {
      Stream<FileSystemEntity> stream = Directory.fromUri(uri).list();

      await for (FileSystemEntity entity in stream) {
        if (entity is File) {
          _determineDestination(entity);
        } else if (entity is Directory) {
          await _getDirectoryContent(entity.uri);
        }
      }
    } catch(err) {

    }
  }

  void _determineDestination(FileSystemEntity entity) {
    if (entity is File) {
      try {
        int lastIndex = entity.path.lastIndexOf('.') + 1;
        String extension = entity.path.substring(lastIndex, entity.path.length).toLowerCase();

        if (_imageFormats.indexOf(extension) != -1) {
          //print(extension);
          imageList.add(entity);
        }
      } catch (err) {
        
      }
    }
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  thumbnail_creator: ^0.0.9

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:thumbnail_creator/thumbnail_creator.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
44
Learn more about scoring.

We analyzed this package on Apr 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

4 out of 4 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/thumbnail_creator.dart.

Run flutter format to format lib/thumbnail_creator.dart.

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field http://127.0.0.1.com was unreachable.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test