Merge pull request #26 from yaso-meth/native-file-downloading
Native-file-downloading
This commit is contained in:
@@ -1,9 +1,14 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.CAMERA" />
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
|
||||||
|
android:maxSdkVersion="32"
|
||||||
|
tools:replace="android:maxSdkVersion" />
|
||||||
<uses-feature android:name="android.hardware.camera" />
|
<uses-feature android:name="android.hardware.camera" />
|
||||||
<uses-permission android:name="android.permission.FLASHLIGHT" />
|
<uses-permission android:name="android.permission.FLASHLIGHT" />
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>LSSupportsOpeningDocumentsInPlace</key>
|
||||||
|
<true/>
|
||||||
|
<key>UIFileSharingEnabled</key>
|
||||||
|
<true/>
|
||||||
<key>LSApplicationQueriesSchemes</key>
|
<key>LSApplicationQueriesSchemes</key>
|
||||||
<array>
|
<array>
|
||||||
<string>sms</string>
|
<string>sms</string>
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:Mzansi_Innovation_Hub/main.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:syncfusion_flutter_core/theme.dart';
|
import 'package:syncfusion_flutter_core/theme.dart';
|
||||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||||
import "package:universal_html/html.dart" as html;
|
import "package:universal_html/html.dart" as html;
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:fl_downloader/fl_downloader.dart';
|
||||||
|
|
||||||
import '../../../main.dart';
|
|
||||||
import '../../../mih_objects/arguments.dart';
|
import '../../../mih_objects/arguments.dart';
|
||||||
|
|
||||||
class BuildFileView extends StatefulWidget {
|
class BuildFileView extends StatefulWidget {
|
||||||
final String link;
|
final String link;
|
||||||
final String path;
|
final String path;
|
||||||
|
|
||||||
const BuildFileView({
|
const BuildFileView({
|
||||||
super.key,
|
super.key,
|
||||||
required this.link,
|
required this.link,
|
||||||
@@ -25,6 +30,18 @@ class _BuildFileViewState extends State<BuildFileView> {
|
|||||||
//late TextEditingController currentPageController = TextEditingController();
|
//late TextEditingController currentPageController = TextEditingController();
|
||||||
double startZoomLevel = 1;
|
double startZoomLevel = 1;
|
||||||
|
|
||||||
|
int progress = 0;
|
||||||
|
late StreamSubscription progressStream;
|
||||||
|
|
||||||
|
void mihLoadingPopUp() {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return const Mihloadingcircle();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
String getExtType(String path) {
|
String getExtType(String path) {
|
||||||
//print(pdfLink.split(".")[1]);
|
//print(pdfLink.split(".")[1]);
|
||||||
return path.split(".").last;
|
return path.split(".").last;
|
||||||
@@ -50,18 +67,55 @@ class _BuildFileViewState extends State<BuildFileView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nativeFileDownload(String fileLink) async {
|
||||||
|
var permission = await FlDownloader.requestPermission();
|
||||||
|
if (permission == StoragePermissionStatus.granted) {
|
||||||
|
try {
|
||||||
|
mihLoadingPopUp();
|
||||||
|
await FlDownloader.download(fileLink);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
} on Exception catch (error) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
print(error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print("denied");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
pdfViewerController.dispose();
|
pdfViewerController.dispose();
|
||||||
|
progressStream.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
FlDownloader.initialize();
|
||||||
|
progressStream = FlDownloader.progressStream.listen((event) {
|
||||||
|
if (event.status == DownloadStatus.successful) {
|
||||||
|
setState(() {
|
||||||
|
progress = event.progress;
|
||||||
|
});
|
||||||
|
//Navigator.of(context).pop();
|
||||||
|
print("Progress $progress%: Success Downloading");
|
||||||
|
FlDownloader.openFile(filePath: event.filePath);
|
||||||
|
} else if (event.status == DownloadStatus.failed) {
|
||||||
|
print("Progress $progress%: Error Downloading");
|
||||||
|
} else if (event.status == DownloadStatus.running) {
|
||||||
|
print("Progress $progress%: Download Running");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// double width = MediaQuery.sizeOf(context).width;
|
// double width = MediaQuery.sizeOf(context).width;
|
||||||
//double height = MediaQuery.sizeOf(context).height;
|
//double height = MediaQuery.sizeOf(context).height;
|
||||||
|
debugPrint(widget.link);
|
||||||
if (getExtType(widget.path).toLowerCase() == "pdf") {
|
if (getExtType(widget.path).toLowerCase() == "pdf") {
|
||||||
//print(widget.pdfLink);
|
|
||||||
return Expanded(
|
return Expanded(
|
||||||
child: Stack(
|
child: Stack(
|
||||||
fit: StackFit.expand,
|
fit: StackFit.expand,
|
||||||
@@ -102,14 +156,25 @@ class _BuildFileViewState extends State<BuildFileView> {
|
|||||||
child: IconButton.filled(
|
child: IconButton.filled(
|
||||||
iconSize: 35,
|
iconSize: 35,
|
||||||
padding: const EdgeInsets.all(0),
|
padding: const EdgeInsets.all(0),
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
|
// debugPrint(
|
||||||
|
// "I'm here ${MzanziInnovationHub.of(context)!.theme.getPlatform()}");
|
||||||
if (MzanziInnovationHub.of(context)!.theme.getPlatform() ==
|
if (MzanziInnovationHub.of(context)!.theme.getPlatform() ==
|
||||||
"Web") {
|
"Web") {
|
||||||
html.window.open(
|
html.window.open(
|
||||||
widget.link,
|
widget.link,
|
||||||
// '${AppEnviroment.baseFileUrl}/mih/$filePath',
|
// '${AppEnviroment.baseFileUrl}/mih/$filePath',
|
||||||
'download');
|
'download');
|
||||||
} else {}
|
} else {
|
||||||
|
// print("Here");
|
||||||
|
// var permission = await FlDownloader.requestPermission();
|
||||||
|
// if (permission == StoragePermissionStatus.granted) {
|
||||||
|
// await FlDownloader.download(widget.link);
|
||||||
|
// } else {
|
||||||
|
// print("denied");
|
||||||
|
// }
|
||||||
|
nativeFileDownload(widget.link);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.download,
|
Icons.download,
|
||||||
@@ -166,18 +231,26 @@ class _BuildFileViewState extends State<BuildFileView> {
|
|||||||
child: IconButton.filled(
|
child: IconButton.filled(
|
||||||
iconSize: 35,
|
iconSize: 35,
|
||||||
padding: const EdgeInsets.all(0),
|
padding: const EdgeInsets.all(0),
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
|
// debugPrint("I'm here ");
|
||||||
|
// debugPrint(
|
||||||
|
// "I'm here ${MzanziInnovationHub.of(context)!.theme.getPlatform()}");
|
||||||
if (MzanziInnovationHub.of(context)!.theme.getPlatform() ==
|
if (MzanziInnovationHub.of(context)!.theme.getPlatform() ==
|
||||||
"Web") {
|
"Web") {
|
||||||
html.window.open(
|
html.window.open(
|
||||||
widget.link,
|
widget.link,
|
||||||
// '${AppEnviroment.baseFileUrl}/mih/$filePath',
|
// '${AppEnviroment.baseFileUrl}/mih/$filePath',
|
||||||
'download');
|
'download');
|
||||||
} else {}
|
} else {
|
||||||
// html.window.open(
|
//print("Here");
|
||||||
// widget.link,
|
// var permission = await FlDownloader.requestPermission();
|
||||||
// // '${AppEnviroment.baseFileUrl}/mih/$filePath',
|
// if (permission == StoragePermissionStatus.granted) {
|
||||||
// 'download');
|
// await FlDownloader.download(widget.link);
|
||||||
|
// } else {
|
||||||
|
// print("denied");
|
||||||
|
// }
|
||||||
|
nativeFileDownload(widget.link);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.download,
|
Icons.download,
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../../main.dart';
|
import '../../main.dart';
|
||||||
import 'package:syncfusion_flutter_core/theme.dart';
|
import 'package:syncfusion_flutter_core/theme.dart';
|
||||||
@@ -6,6 +9,7 @@ import "package:universal_html/html.dart" as html;
|
|||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
import 'package:printing/printing.dart';
|
import 'package:printing/printing.dart';
|
||||||
|
import 'package:fl_downloader/fl_downloader.dart';
|
||||||
|
|
||||||
import '../../mih_components/mih_layout/mih_action.dart';
|
import '../../mih_components/mih_layout/mih_action.dart';
|
||||||
import '../../mih_components/mih_layout/mih_body.dart';
|
import '../../mih_components/mih_layout/mih_body.dart';
|
||||||
@@ -31,6 +35,9 @@ class _FullScreenFileViewerState extends State<FullScreenFileViewer> {
|
|||||||
double startZoomLevel = 1.0;
|
double startZoomLevel = 1.0;
|
||||||
double zoomOut = 0;
|
double zoomOut = 0;
|
||||||
|
|
||||||
|
int progress = 0;
|
||||||
|
late StreamSubscription progressStream;
|
||||||
|
|
||||||
String getExtType(String path) {
|
String getExtType(String path) {
|
||||||
//print(pdfLink.split(".")[1]);
|
//print(pdfLink.split(".")[1]);
|
||||||
return path.split(".").last;
|
return path.split(".").last;
|
||||||
@@ -215,7 +222,11 @@ class _FullScreenFileViewerState extends State<FullScreenFileViewer> {
|
|||||||
widget.arguments.link,
|
widget.arguments.link,
|
||||||
// '${AppEnviroment.baseFileUrl}/mih/$filePath',
|
// '${AppEnviroment.baseFileUrl}/mih/$filePath',
|
||||||
'download');
|
'download');
|
||||||
} else {}
|
} else {
|
||||||
|
nativeFileDownload(
|
||||||
|
widget.arguments.link,
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.download,
|
Icons.download,
|
||||||
@@ -272,9 +283,35 @@ class _FullScreenFileViewerState extends State<FullScreenFileViewer> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mihLoadingPopUp() {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return const Mihloadingcircle();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nativeFileDownload(String fileLink) async {
|
||||||
|
var permission = await FlDownloader.requestPermission();
|
||||||
|
if (permission == StoragePermissionStatus.granted) {
|
||||||
|
try {
|
||||||
|
mihLoadingPopUp();
|
||||||
|
await FlDownloader.download(fileLink);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
} on Exception catch (error) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
print(error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print("denied");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
pdfViewerController.dispose();
|
pdfViewerController.dispose();
|
||||||
|
progressStream.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,6 +319,21 @@ class _FullScreenFileViewerState extends State<FullScreenFileViewer> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
//pdfViewerController = widget.arguments.pdfViewerController!;
|
//pdfViewerController = widget.arguments.pdfViewerController!;
|
||||||
pdfViewerController.addListener(onPageSelect);
|
pdfViewerController.addListener(onPageSelect);
|
||||||
|
FlDownloader.initialize();
|
||||||
|
progressStream = FlDownloader.progressStream.listen((event) {
|
||||||
|
if (event.status == DownloadStatus.successful) {
|
||||||
|
setState(() {
|
||||||
|
progress = event.progress;
|
||||||
|
});
|
||||||
|
//Navigator.of(context).pop();
|
||||||
|
print("Progress $progress%: Success Downloading");
|
||||||
|
FlDownloader.openFile(filePath: event.filePath);
|
||||||
|
} else if (event.status == DownloadStatus.failed) {
|
||||||
|
print("Progress $progress%: Error Downloading");
|
||||||
|
} else if (event.status == DownloadStatus.running) {
|
||||||
|
print("Progress $progress%: Download Running");
|
||||||
|
}
|
||||||
|
});
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,13 +76,14 @@ class MyTheme {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String getPlatform() {
|
String getPlatform() {
|
||||||
if (isPwa()) {
|
// if (isPwa()) {
|
||||||
if (platform == TargetPlatform.android) {
|
// if (platform == TargetPlatform.android) {
|
||||||
return "Android";
|
// return "Android";
|
||||||
} else if (platform == TargetPlatform.iOS) {
|
// } else if (platform == TargetPlatform.iOS) {
|
||||||
return "iOS";
|
// return "iOS";
|
||||||
}
|
// }
|
||||||
} else if (kIsWeb) {
|
// } else
|
||||||
|
if (kIsWeb) {
|
||||||
return "Web";
|
return "Web";
|
||||||
} else if (!kIsWeb) {
|
} else if (!kIsWeb) {
|
||||||
if (platform == TargetPlatform.android) {
|
if (platform == TargetPlatform.android) {
|
||||||
|
|||||||
@@ -382,6 +382,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.1"
|
version: "1.1.1"
|
||||||
|
fl_downloader:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: fl_downloader
|
||||||
|
sha256: e3f0696f7b22933baeae3c99d806c3a6f11507ab6c2bf74b4c580abf8e036f80
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.2"
|
||||||
flutter:
|
flutter:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ dependencies:
|
|||||||
syncfusion_flutter_core: ^26.2.10
|
syncfusion_flutter_core: ^26.2.10
|
||||||
syncfusion_flutter_pdfviewer: ^26.1.39
|
syncfusion_flutter_pdfviewer: ^26.1.39
|
||||||
universal_html: ^2.2.4
|
universal_html: ^2.2.4
|
||||||
file_picker: ^8.0.5
|
file_picker: ^8.1.4
|
||||||
supertokens_flutter: ^0.6.0
|
supertokens_flutter: ^0.6.0
|
||||||
http: ^1.2.1
|
http: ^1.2.1
|
||||||
google_nav_bar: ^5.0.6
|
google_nav_bar: ^5.0.6
|
||||||
@@ -66,6 +66,7 @@ dependencies:
|
|||||||
# flutter_barcode_scanner: ^2.0.0
|
# flutter_barcode_scanner: ^2.0.0
|
||||||
barcode_widget: ^2.0.4
|
barcode_widget: ^2.0.4
|
||||||
url_launcher: ^6.3.1
|
url_launcher: ^6.3.1
|
||||||
|
fl_downloader: ^2.0.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "generated_plugin_registrant.h"
|
#include "generated_plugin_registrant.h"
|
||||||
|
|
||||||
#include <firebase_core/firebase_core_plugin_c_api.h>
|
#include <firebase_core/firebase_core_plugin_c_api.h>
|
||||||
|
#include <fl_downloader/fl_downloader_plugin_c_api.h>
|
||||||
#include <geolocator_windows/geolocator_windows.h>
|
#include <geolocator_windows/geolocator_windows.h>
|
||||||
#include <permission_handler_windows/permission_handler_windows_plugin.h>
|
#include <permission_handler_windows/permission_handler_windows_plugin.h>
|
||||||
#include <printing/printing_plugin.h>
|
#include <printing/printing_plugin.h>
|
||||||
@@ -17,6 +18,8 @@
|
|||||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||||
FirebaseCorePluginCApiRegisterWithRegistrar(
|
FirebaseCorePluginCApiRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("FirebaseCorePluginCApi"));
|
registry->GetRegistrarForPlugin("FirebaseCorePluginCApi"));
|
||||||
|
FlDownloaderPluginCApiRegisterWithRegistrar(
|
||||||
|
registry->GetRegistrarForPlugin("FlDownloaderPluginCApi"));
|
||||||
GeolocatorWindowsRegisterWithRegistrar(
|
GeolocatorWindowsRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("GeolocatorWindows"));
|
registry->GetRegistrarForPlugin("GeolocatorWindows"));
|
||||||
PermissionHandlerWindowsPluginRegisterWithRegistrar(
|
PermissionHandlerWindowsPluginRegisterWithRegistrar(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
list(APPEND FLUTTER_PLUGIN_LIST
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
firebase_core
|
firebase_core
|
||||||
|
fl_downloader
|
||||||
geolocator_windows
|
geolocator_windows
|
||||||
permission_handler_windows
|
permission_handler_windows
|
||||||
printing
|
printing
|
||||||
|
|||||||
Reference in New Issue
Block a user