Skip to content

Commit f515fac

Browse files
author
gopi2401
committed
add: share video
1 parent 0c8bd94 commit f515fac

File tree

4 files changed

+141
-7
lines changed

4 files changed

+141
-7
lines changed

lib/screens/download_queue_screen.dart

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import 'dart:convert';
2+
import 'dart:io';
23

34
import 'package:flutter/material.dart';
45
import 'package:get/get.dart';
6+
import 'package:share_plus/share_plus.dart';
57

68
import '../models/download_job.dart';
79
import '../services/analytics_service.dart';
810
import '../services/download_queue_service.dart';
911
import '../services/notification_service.dart';
12+
import '../status_saver/utils/video_play.dart';
1013

1114
class DownloadQueueScreen extends StatefulWidget {
1215
const DownloadQueueScreen({super.key});
@@ -41,6 +44,70 @@ class _DownloadQueueScreenState extends State<DownloadQueueScreen> {
4144
super.dispose();
4245
}
4346

47+
bool _isPlayableVideo(String path) {
48+
final lower = path.toLowerCase();
49+
return lower.endsWith('.mp4') ||
50+
lower.endsWith('.mov') ||
51+
lower.endsWith('.m4v') ||
52+
lower.endsWith('.webm') ||
53+
lower.endsWith('.mkv') ||
54+
lower.endsWith('.3gp');
55+
}
56+
57+
Future<void> _shareDownloadedFile(DownloadJob job) async {
58+
final path = job.filePath;
59+
if (path == null || path.isEmpty) {
60+
if (!mounted) return;
61+
ScaffoldMessenger.of(context).showSnackBar(
62+
const SnackBar(content: Text('File path unavailable for sharing.')),
63+
);
64+
return;
65+
}
66+
67+
final file = File(path);
68+
if (!await file.exists()) {
69+
if (!mounted) return;
70+
ScaffoldMessenger.of(context).showSnackBar(
71+
const SnackBar(content: Text('Downloaded file is missing.')),
72+
);
73+
return;
74+
}
75+
76+
await SharePlus.instance.share(
77+
ShareParams(
78+
files: [XFile(path)],
79+
text: job.fileName,
80+
subject: 'Shared from Insta Downloader',
81+
),
82+
);
83+
}
84+
85+
Future<void> _playDownloadedVideo(DownloadJob job) async {
86+
final path = job.filePath;
87+
if (path == null || path.isEmpty) {
88+
if (!mounted) return;
89+
ScaffoldMessenger.of(context).showSnackBar(
90+
const SnackBar(content: Text('Video path unavailable.')),
91+
);
92+
return;
93+
}
94+
95+
final file = File(path);
96+
if (!await file.exists()) {
97+
if (!mounted) return;
98+
ScaffoldMessenger.of(context).showSnackBar(
99+
const SnackBar(content: Text('Video file is missing.')),
100+
);
101+
return;
102+
}
103+
104+
if (!mounted) return;
105+
await Navigator.push(
106+
context,
107+
MaterialPageRoute(builder: (_) => PlayStatus(videoFile: path)),
108+
);
109+
}
110+
44111
@override
45112
Widget build(BuildContext context) {
46113
return DefaultTabController(
@@ -165,12 +232,30 @@ class _DownloadQueueScreenState extends State<DownloadQueueScreen> {
165232
subtitle: Text(
166233
'${NotificationService.to.getTypeLabel(job.type)} - ${job.status.name}',
167234
),
168-
trailing: job.status == DownloadStatus.failed
169-
? IconButton(
235+
trailing: Row(
236+
mainAxisSize: MainAxisSize.min,
237+
children: [
238+
if (job.status == DownloadStatus.success && job.filePath != null)
239+
IconButton(
240+
tooltip: 'Share',
241+
icon: const Icon(Icons.share),
242+
onPressed: () => _shareDownloadedFile(job),
243+
),
244+
if (job.status == DownloadStatus.success &&
245+
job.filePath != null &&
246+
_isPlayableVideo(job.filePath!))
247+
IconButton(
248+
tooltip: 'Play',
249+
icon: const Icon(Icons.play_circle),
250+
onPressed: () => _playDownloadedVideo(job),
251+
),
252+
if (job.status == DownloadStatus.failed)
253+
IconButton(
170254
icon: const Icon(Icons.refresh),
171255
onPressed: () => queue.retry(job.id),
172-
)
173-
: null,
256+
),
257+
],
258+
),
174259
);
175260
},
176261
);

lib/status_saver/utils/video_play.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:io';
22

33
import 'package:flutter/material.dart';
4+
import 'package:share_plus/share_plus.dart';
45
import 'package:video_player/video_player.dart';
56
import 'package:path/path.dart' as path;
67
import '../../utils/app_utils.dart';
@@ -122,6 +123,29 @@ class PlayStatusState extends State<PlayStatus> {
122123
}
123124
}
124125

126+
Future<void> _shareVideo() async {
127+
try {
128+
final file = File(widget.videoFile);
129+
if (!await file.exists()) {
130+
if (!mounted) return;
131+
ScaffoldMessenger.of(context).showSnackBar(
132+
const SnackBar(content: Text('Video file is missing.')),
133+
);
134+
return;
135+
}
136+
137+
await SharePlus.instance.share(
138+
ShareParams(
139+
files: [XFile(widget.videoFile)],
140+
text: path.basename(widget.videoFile),
141+
subject: 'Shared from Insta Downloader',
142+
),
143+
);
144+
} catch (e, stackTrace) {
145+
catchInfo(e, stackTrace);
146+
}
147+
}
148+
125149
@override
126150
Widget build(BuildContext context) {
127151
return Scaffold(
@@ -138,6 +162,14 @@ class PlayStatusState extends State<PlayStatus> {
138162
onPressed: () => Navigator.of(context).pop(),
139163
),
140164
actions: [
165+
IconButton(
166+
color: Colors.white,
167+
icon: const Icon(
168+
Icons.share,
169+
color: Colors.white,
170+
),
171+
onPressed: _shareVideo,
172+
),
141173
IconButton(
142174
color: Colors.white,
143175
icon: const Icon(

pubspec.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,22 @@ packages:
816816
url: "https://pub.dev"
817817
source: hosted
818818
version: "0.28.0"
819+
share_plus:
820+
dependency: "direct main"
821+
description:
822+
name: share_plus
823+
sha256: "14c8860d4de93d3a7e53af51bff479598c4e999605290756bbbe45cf65b37840"
824+
url: "https://pub.dev"
825+
source: hosted
826+
version: "12.0.1"
827+
share_plus_platform_interface:
828+
dependency: transitive
829+
description:
830+
name: share_plus_platform_interface
831+
sha256: "88023e53a13429bd65d8e85e11a9b484f49d4c190abbd96c7932b74d6927cc9a"
832+
url: "https://pub.dev"
833+
source: hosted
834+
version: "6.1.0"
819835
shared_preferences:
820836
dependency: "direct main"
821837
description:

pubspec.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ dependencies:
4545
webview_flutter: ^4.4.4
4646
encrypt: ^5.0.0
4747
url_launcher: ^6.2.4
48-
adaptive_theme: ^3.7.0
49-
shared_preferences: ^2.3.2
50-
device_info_plus: ^11.5.0
48+
adaptive_theme: ^3.7.0
49+
shared_preferences: ^2.3.2
50+
device_info_plus: ^11.5.0
5151
# video_thumbnail: ^0.5.3
5252
speed_dial_fab: ^2.2.1
5353
chewie: ^1.3.4
@@ -58,6 +58,7 @@ dependencies:
5858
path: ^1.9.0
5959
video_thumbnail: ^0.5.6
6060
intl: ^0.19.0
61+
share_plus: ^12.0.0
6162

6263
dev_dependencies:
6364
flutter_test:

0 commit comments

Comments
 (0)