main.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import 'dart:io';
  2. import 'package:dio/dio.dart';
  3. import 'package:flutter/material.dart';
  4. import 'dart:async';
  5. import 'package:flutter/services.dart';
  6. import 'package:flutterzip/flutterzip.dart';
  7. import 'package:path_provider/path_provider.dart';
  8. void main() {
  9. runApp(MyApp());
  10. }
  11. class MyApp extends StatefulWidget {
  12. @override
  13. _MyAppState createState() => _MyAppState();
  14. }
  15. class _MyAppState extends State<MyApp> {
  16. String _platformVersion = 'Unknown';
  17. @override
  18. void initState() {
  19. super.initState();
  20. initPlatformState();
  21. if(Platform.isIOS){
  22. initPath();
  23. }
  24. }
  25. // Platform messages are asynchronous, so we initialize in an async method.
  26. Future<void> initPlatformState() async {
  27. String platformVersion;
  28. // Platform messages may fail, so we use a try/catch PlatformException.
  29. try {
  30. platformVersion = await Flutterzip.platformVersion;
  31. } on PlatformException {
  32. platformVersion = 'Failed to get platform version.';
  33. }
  34. // If the widget was removed from the tree while the asynchronous platform
  35. // message was in flight, we want to discard the reply rather than calling
  36. // setState to update our non-existent appearance.
  37. if (!mounted) return;
  38. setState(() {
  39. _platformVersion = platformVersion;
  40. });
  41. }
  42. String unzipPath="/storage/emulated/0/aa_flutter/2-05 The Go-Kart.zip";
  43. // String unzipPath="/storage/emulated/0/aa_flutter/1592808973784462.avi 2.zip";
  44. String outPath="/storage/emulated/0/aa_flutter/2-05 The Go-Kart/";
  45. var directory;
  46. initPath()async{
  47. // unzipPath=getDownloadsDirectory().toString()+"/2-05 The Go-Kart.zip";
  48. //下载到手机
  49. String s="http://139.199.153.108:8080/2-05%20The%20Go-Kart.zip";
  50. directory = await getTemporaryDirectory();
  51. var savePath=directory.path+"/2-05 The Go-Kart.zip";
  52. unzipPath=directory.path+"/2-05 The Go-Kart.zip";
  53. outPath=directory.path+"/2-05 The Go-Kart";
  54. var response = await Dio().download(s,savePath);
  55. print("download====ok");
  56. //查看文件
  57. // print("response.toString()=="+response.toString());
  58. // List<FileSystemEntity> listSync = directory.listSync();
  59. // for(FileSystemEntity f in listSync){
  60. // print("====="+f.path);
  61. // }
  62. // unzipPath=directory.toString();
  63. print("unzipPath==="+unzipPath);
  64. }
  65. @override
  66. Widget build(BuildContext context) {
  67. return MaterialApp(
  68. home: Scaffold(
  69. appBar: AppBar(
  70. title: const Text('Plugin example app'),
  71. ),
  72. body: Column(
  73. children: <Widget>[
  74. Center(
  75. child: Text('Running on: $_platformVersion\n'),
  76. ),
  77. RaisedButton(
  78. onPressed: ()async{
  79. await Flutterzip.unpack(unzipPath, outPath);
  80. print("okokoko");
  81. // Flutterzip.onProcessChange.stream.listen((event) {
  82. // print("========="+event.toString());
  83. // });
  84. },
  85. child: Text("解压"),
  86. ),
  87. SizedBox(height: 20,),
  88. RaisedButton(
  89. onPressed: (){
  90. viewList();
  91. },
  92. child: Text("查看目录"),
  93. ),
  94. ],
  95. ),
  96. ),
  97. );
  98. }
  99. viewList()async{
  100. //查看文件
  101. List<FileSystemEntity> listSync = directory.listSync();
  102. for(FileSystemEntity f in listSync){
  103. print("====="+f.path);
  104. }
  105. }
  106. }