flutterdartuint8arrayuint8list

Save a memory image (such as Uint8list) as image file in flutter


I have some Uint8lists and I want to save them as jpg files. Can anyone help?


Solution

  • By 'storage', do you mean write to a file? You don't really need "flutter" to do this. Just use the libraries provided by dart. Here is an example of downloading my gravatar which you can get as Uin8List and then saving it to a file.

    import 'dart:io';
    import 'dart:typed_data';
    
    import 'package:http/http.dart' as http;
    
    void main() {
      http.get('https://www.gravatar.com/avatar/e944138e1114aefe4b08848a46465589').then((response) {
        Uint8List bodyBytes = response.bodyBytes;
        File('my_image.jpg').writeAsBytes(bodyBytes);
      });
    }