album_saver 0.0.1 copy "album_saver: ^0.0.1" to clipboard
album_saver: ^0.0.1 copied to clipboard

outdated

help create and save images to album

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:album_saver/album_saver.dart';
import 'package:image_picker/image_picker.dart';

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

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

class _MyAppState extends State<MyApp> {
  File _image;
  String _dcimPath;
  bool _isSaving;

  void _getDcimPath()async{
    _dcimPath = await AlbumSaver.getDcimPath();
    setState(() {
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: _isSaving == true
        ? Center(child: CircularProgressIndicator())
        : ListView(
          children: <Widget>[
            _buildPickedImage(),
            _dcimPath != null
            ? Container(
              padding: const EdgeInsets.all(16),
              child: Text("DCIM path: $_dcimPath")
            )
            : Container(),
            _buildImagePickerButton(),
            _buildSaveToAlbumButton(),
            _buildCreateAlbumButton(),
            Platform.isAndroid==true
            ? _builGetDcimPathButton()
            : Container(),
          ],
        ),
      ),
    );
  }

  Widget _buildPickedImage(){
    return Container(
      margin: EdgeInsets.all(16),
      height: 300.0,
      child: _image!=null
        ? null
        : Center(
          child: Container(
            child: Text("No selected image"),
          ),
        ),
      decoration: _image!=null
        ? BoxDecoration(
          border: Border.all(width: 1),
          image: DecorationImage(
            image: FileImage(_image),
          )
        )
        : BoxDecoration(
          border: Border.all(width: 1)
        ),
    );
  }

  Widget _buildImagePickerButton(){
    return Container(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          IconButton(
            icon: Icon(Icons.camera_alt),
            onPressed: ()async{
              var image = await ImagePicker.pickImage(source: ImageSource.camera);
              setState(() {
                _image = image;
              });
            },
          ),
          IconButton(
            icon: Icon(Icons.folder),
            onPressed: ()async{
              var image = await ImagePicker.pickImage(source: ImageSource.gallery);
              setState(() {
                _image = image;
              });
            },
          )
        ],
      ),
    );
  }

  Widget _buildSaveToAlbumButton(){
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 16.0),
      child: RaisedButton(
        color: Colors.blue,
        textColor: Colors.white,
        child: Text("Save to album"),
        onPressed: ()async{
          setState(() {
            _isSaving = true;
          });
          if(_image!=null){
            await AlbumSaver.saveToAlbum(filePath: _image.path, albumName: "test_album_saver2");
            setState(() {
              _isSaving = false;
            });
          } else {
            setState(() {
              _isSaving = false;
            });
          }
        },
      ),
    );
  }

  Widget _buildCreateAlbumButton(){
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 16.0),
      child: RaisedButton(
        color: Colors.blue,
        textColor: Colors.white,
        child: Text("Create a album named MyTestAlbum"),
        onPressed: ()async{
          setState(() {
            _isSaving = true;
          });
          await AlbumSaver.createAlbum(albumName: "MyTestAlbum");
          setState(() {
            _isSaving = false;
          });
        },
      ),
    );
  }

  Widget _builGetDcimPathButton(){
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 16.0),
      child: RaisedButton(
                color: Colors.blue,
        textColor: Colors.white,
        child: Text("Get Dcim path"),
        onPressed: ()async{
          setState(() {
            _isSaving = true;
          });
          await _getDcimPath();
          setState(() {
            _isSaving = false;
          });
        },
      ),
    );
  }
}
5
likes
30
pub points
27%
popularity

Publisher

unverified uploader

help create and save images to album

Homepage

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on album_saver