The application saves an image to the device's storage using the gallery_saver package for Flutter. The package makes it simple to save images to an Android device.
Below is the directory that the images are saved to on this project:
This tutorial uses the example by Johannes Milke linked here.
First, add the gallery_saver
package to the project. Save an image url to a String
variable and get a temporary directory. Pass in the image url to the temporary directory using the dio package. The GallerySaver
accepts this temporary file and saves it to the device's storage.
String url = 'https://picsum.photos/200/300?grayscale';
final tempDir = await getTemporaryDirectory();
print(tempDir);
final path = '${tempDir.path}/myfile.jpg';
await Dio().download(url, path);
await GallerySaver.saveImage(path);
To get the THETA image file, run the listFiles command from the THETA API. Setting the startPosition
to 0 and the entryCount
to 1 will get the last image taken.
var url = Uri.parse('http://192.168.1.1/osc/commands/execute');
var header = {'Content-Type': 'application/json;charset=utf-8'};
var bodyMap = {
'name': 'camera.listFiles',
'parameters': {
'fileType': 'image',
'startPosition': 0,
'entryCount': 1,
'maxThumbSize': 0,
'_detail': true,
}
};
Use the http
package for Flutter to execute the command and save the response to a variable.
var response =
await http.post(url, headers: header, body: bodyJson);
Then, parse out the file url from the response.
var fileUrl =
jsonDecode(response.body)['results']['entries'][0]['fileUrl'];
Once the THETA file url is parsed out, the technique between saving the network image and THETA image is the same.