Search code examples
databasedartmobile-applicationobjectbox

Set and get Image in objectbox


I want to set and get image from local storage, but I have no idea how to do this.


Solution

  • I have done with the help of http and base64String

    Future<String> getNetworkImage()async{
        final data = await _firestore.collection("[email protected]").doc("GymDetails").get();
        final imageurl = data.get("url");
        final uri = Uri.parse(imageurl);
        final response = await http.get(uri);
        final unit8listimage = response.bodyBytes;
        final base64image = base64Encode(unit8listimage);
        final object = SetImage(imageurl: base64image);
    
        if(!_objectBox.setimage.isEmpty()){
          _objectBox.setimage.remove;
        }
        
        _objectBox.setimage.put(object);
    
        final getimage = _objectBox.setimage.get(object.id);
        return getimage!.imageurl;  
    }