flutterzip.dart 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import 'dart:async';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/services.dart';
  4. typedef StringCallBack =Function(String);
  5. class Flutterzip {
  6. static StreamController onProcessChange = new StreamController<Map>.broadcast();
  7. static const MethodChannel _channel = const MethodChannel('flutterzip');
  8. static Future<String> get platformVersion async {
  9. final String version = await _channel.invokeMethod('getPlatformVersion');
  10. return version;
  11. }
  12. static Future<String> unpack(String unzipPath, String outPath) async {
  13. _channel.setMethodCallHandler(platformCallHandler);
  14. return await _channel.invokeMethod(
  15. 'unpack', {"unzipPath": unzipPath, "outPath": outPath});
  16. }
  17. static Future<dynamic> platformCallHandler(MethodCall call) async {
  18. switch (call.method) {
  19. case "process":
  20. Map arguments = call.arguments;
  21. onProcessChange.add(arguments);
  22. break;
  23. }
  24. }
  25. /// 关闭stream
  26. void closeStream() {
  27. _channel.setMethodCallHandler(null);
  28. onProcessChange.close();
  29. }
  30. }