/*
 * @author lsy
 * @date   2019-11-01
 **/
import 'dart:io';
import 'dart:typed_data';
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:gengmei_flutter_plugin/gengmei_flutter_plugin.dart';
import 'package:gmalpha_flutter/commonModel/GMBase.dart';
import 'package:gmalpha_flutter/commonModel/toast/toast.dart';

class AlbumPreviewModel extends BaseModel {
  var imageLive = LiveData<String>();

  final String imgPath;
  int size;

  AlbumPreviewModel(this.imgPath, this.size);

  getPreviewImage(BuildContext context) {
    print("IMAGE SIZE ===> $size");
//    if (size != 0 && size < 1024 * 1024*3 && Platform.isAndroid) {
//      imageLive.notifyView(imgPath);
//    } else {
//      int a = DateTime.now().millisecondsSinceEpoch;
//      iosItem(imgPath, context, (value) {
//        var realPath = value["realImagePath"];
//        imageLive.notifyView(realPath);
//        print("TIME ${DateTime.now().millisecondsSinceEpoch - a}");
//      });
//    }
  }

//  Future<Codec> _loadAsync(ResizeFileImage key) async {
//    assert(key == this);
//    final Uint8List bytes = await file.readAsBytes();
//    if (bytes.lengthInBytes == 0) return null;
//    return await instantiateImageCodec(bytes,
//        targetHeight: this.targetHeight, targetWidth: this.targetWidth);
//  }

//  void iosItem(String path, BuildContext context, Function fun) {
//    GengmeiFlutterPlugin.previewImage(path).then((value) {
//      if (value != null) {
//        fun(Map<String, String>.from(value));
//      }
//    }).catchError((error) {
//      Toast.debugShow(context, error.toString());
//      print(error);
//    });
//  }

  @override
  void dispose() {
    imageLive.dispost();
  }
}
