Coder Social home page Coder Social logo

Comments (3)

xqqlv avatar xqqlv commented on September 17, 2024

Can you post how you use it?

from image_gallery_saver.

marcuslma avatar marcuslma commented on September 17, 2024

Hello,
There is my code below:

class Photos extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          IconButton(
            icon: Icon(Icons.camera_alt),
            onPressed: () => _onConfirmImage(ImageSource.camera),
          ),
          IconButton(
            icon: Icon(Icons.filter),
            onPressed: () => _onConfirmImage(ImageSource.gallery),
          ),
        ],
      ),
    );
  }

  void _onConfirmImage(ImageSource source) async {
    if (Platform.isAndroid && source == ImageSource.camera) {
      final status = await PermissionHandler().checkPermissionStatus(PermissionGroup.storage);

      if (status != PermissionStatus.granted) {
        await PermissionHandler().requestPermissions([PermissionGroup.storage]);
      }
    }

    File file = await ImagePicker.pickImage(source: source);

    if (file != null) {
      _uploadImage(file, source);
    }
  }

  Future<Null> _uploadImage(File imageFile, ImageSource source) async {
    try {
      String imageId = "${DateTime.now().millisecondsSinceEpoch}_${path.basename(imageFile.path)}";
      List<int> imageBytes = imageFile.readAsBytesSync();

      /// Save to phones gallery
      if (source != ImageSource.gallery) {
        _saveToGallery(imageBytes);
      }

      /// Save to app directory
      Directory directory = await getApplicationDocumentsDirectory();
      File imageCopy = File("${directory.path}/imagens_auditorias/$imageId");
      imageCopy.createSync(recursive: true);
      imageCopy.writeAsBytesSync(imageBytes);
    } catch (error) {
      debugPrint(error.toString());
    }
  }
}

/// Out of the widget
void _saveToGallery(List<int> imageBytes) {
  try {
    ImageSaver.saveFile(fileData: Uint8List.fromList(imageBytes));
  } catch (error) {
    debugPrint(error.toString());
  }
}

from image_gallery_saver.

xqqlv avatar xqqlv commented on September 17, 2024

I can't see you You can calling my method and print the time before and after calling my method to verify if it is caused by my method. Do you use my plugin?

from image_gallery_saver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.