main.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. //查看文件
  56. // print("response.toString()=="+response.toString());
  57. // List<FileSystemEntity> listSync = directory.listSync();
  58. // for(FileSystemEntity f in listSync){
  59. // print("====="+f.path);
  60. // }
  61. // unzipPath=directory.toString();
  62. print("unzipPath==="+unzipPath);
  63. }
  64. @override
  65. Widget build(BuildContext context) {
  66. return MaterialApp(
  67. home: Scaffold(
  68. appBar: AppBar(
  69. title: const Text('Plugin example app'),
  70. ),
  71. body: Column(
  72. children: <Widget>[
  73. Center(
  74. child: Text('Running on: $_platformVersion\n'),
  75. ),
  76. RaisedButton(
  77. onPressed: (){
  78. Flutterzip.unpack(unzipPath, outPath);
  79. Flutterzip.onProcessChange.stream.listen((event) {
  80. print("========="+event.toString());
  81. });
  82. },
  83. child: Text("解压"),
  84. ),
  85. SizedBox(height: 20,),
  86. RaisedButton(
  87. onPressed: (){
  88. viewList();
  89. },
  90. child: Text("查看目录"),
  91. ),
  92. ],
  93. ),
  94. ),
  95. );
  96. }
  97. viewList()async{
  98. //查看文件
  99. List<FileSystemEntity> listSync = directory.listSync();
  100. for(FileSystemEntity f in listSync){
  101. print("====="+f.path);
  102. }
  103. }
  104. }