Flutter Dart - MacOS Channel For Image Metadata

Опубликовано: 22 Май 2026
на канале: Lawrence Tsang
95
0

Experimental, Released with MIT License.

https://1drv.ms/u/s!ApN1U-GH6AeInjWcX...


CPM from my old iOS channel test app.

Get Metadata as a String (SemiColumn delimited)
getMetaData(String path) async

Get MetaData as a Dictionary (convert to Map)
getMapFromDictionary(String path) async

Get Image as Bytes (Scaled) for Raw Image,
(Flutter, no support for Raw Images)
getAssetBinary(String path, int width) async

Invoke Apple Map with Latitude and Longitude
invokeAppleMap(double lat, double long) async

Add the FOLDER to the Plugins-Folder, as before.

reference examples (this_test_app):
import 'package:imagedata/imagedata.dart';
import 'package:color_panel/color_panel.dart';
import 'package:window_size/window_size.dart' as window_size;
import 'package:file_chooser/file_chooser.dart' as FileChooser;
import 'dart:io' as IO;
import 'package:path/path.dart' as PATH;


Folder Structure

MyAPPs
this_test_app
plugins


Released with MIT License.

https://1drv.ms/u/s!ApN1U-GH6AeInjWcX...




=============================
Notes:

Channel async method, will block UI update,
Raw File Bytes, will take a long time to load.

To allow, Popup view to complete the initial display,
I used the tick, as in UWP, added my delay.

// Widget build(BuildContext context)


Widget cellImage;


bool isRaw = [".cr2",".nef", ".dng", ".orf", ".sr2"].contains(extension);
if (isRaw)
{
// Channel method to get the byte
// future builder (return Image Element, snapshot.data['image'] )
future: getTnFromChannel(widget.photo.pathFileOrHttp, 8192),
//.....

}
else
{
// Flutter Image From File, to build the CellImage....
}



// return Image Element (Angle bracket replaced by *)
// Where Imagedata is the reference to ny channel method

Future*Map*String, dynamic** getTnFromChannel(String path, int width) async
{
await myDelay(200); // Allow Large Image View UI updete

Map*String,dynamic* retMap = Map();

IO.File file = IO.File(path);
String basename = PATH.basename(file.path);
String ext = PATH.extension(basename).toLowerCase();

if (ext != ".gif")
{
final Uint8List ui8l = await Imagedata.getAssetBinary(path, width);
final ret = new Image.memory
(
ui8l,
width: double.infinity,
height: double.infinity,
fit: BoxFit.contain,
);

retMap['image'] = ret; // Dictionary Map
return retMap;
}
else
{
// gif as is
Image img = new Image.file(file, fit: BoxFit.contain);
retMap['image'] = img;
return retMap;
}
}


// D e l a y

Future*void* myDelay(int ms) async
{
final duration = Duration(milliseconds: ms);
await new Future.delayed(duration);
}

// Dictionary (no direct return)

Map currentImageMetaData;
Future*void* getDictionaryAsMap() async
{
// Channel Method
final Map mapData = await Imagedata.getMapFromDictionary(widget.photo.pathFileOrHttp);
if (mapData == null)
{
//print("method channel return nil");
currentImageMetaData = Map();
largeImageAR = 1.0;
return;
}

final metedataAsMap = Map.from(mapData);


if (metedataAsMap == null)
{
currentImageMetaData = Map();
largeImageAR = 1.0;
return;
}

double w = double.parse( metedataAsMap['pixelWidth'] );
double h = double.parse( metedataAsMap['pixelHeight'] );
if (w != null && h != null)
{
double largeImageAR = w / h;
}
else { largeImageAR = 1.0; }

currentImageMetaData = metedataAsMap;

}


// Init

void initState()
{
super.initState();


// test channel method
getDictionaryAsMap();

}



// Apple Map, return, the invoke string, not used


Future*String* invokeAppleMap(double lat, double long) async
{
String strDesc;
strDesc = await Imagedata.invokeAppleMap(lat, long);

return strDesc;
}



===============================================
// Resoureces

Test Images from Pexels and Pixaby
Xcode 11.5
Android Studio 4
Flutter 1.19.0
Dart: 2.9.0