Skip to content

Commit

Permalink
fixed I can't download whatsapp status for my gallery #2
Browse files Browse the repository at this point in the history
  • Loading branch information
netharuM committed Apr 26, 2022
1 parent b6918e5 commit fd15f9f
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ images
- ![sharing page](./assets/sharing.png)

- settings page
- with an option to clear the rendered cache incase you forogot to clear it
- with an option to clear the rendered cache incase you forgot to clear it
- and themes
- dark theme
- ![dark theme settings page](./assets/settings_dark.png)
Expand Down
170 changes: 139 additions & 31 deletions lib/pages/status_preview_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:gallery_saver/gallery_saver.dart';
import 'package:video_player/video_player.dart';
import 'package:share_plus/share_plus.dart';
import 'package:filesystem_picker/filesystem_picker.dart';
Expand Down Expand Up @@ -41,22 +42,13 @@ class _StatusPreviewPageState extends State<StatusPreviewPage> {
),
TextButton(
onPressed: () async {
String? path = await FilesystemPicker.open(
title: 'Save to folder',
showSaveAsDialog(
context: context,
rootDirectory: Directory(
'/storage/emulated/0/',
),
fsType: FilesystemType.folder,
pickText: 'Save file to this folder',
folderIconColor: Colors.teal,
statusFile: widget.file,
statusType: StatusType.video,
);
if (path != null) {
await widget.file.copy(
'$path/${widget.file.path.split('/').last}');
}
},
child: const Icon(Icons.download),
child: const Icon(Icons.save_alt_rounded),
),
TextButton(
onPressed: () {
Expand Down Expand Up @@ -99,23 +91,13 @@ class _StatusPreviewPageState extends State<StatusPreviewPage> {
),
TextButton(
onPressed: () async {
// copying the status to another directory
String? path = await FilesystemPicker.open(
title: 'Save to folder',
showSaveAsDialog(
context: context,
rootDirectory: Directory(
'/storage/emulated/0/',
),
fsType: FilesystemType.folder,
pickText: 'Save file to this folder',
folderIconColor: Colors.teal,
statusFile: widget.file,
statusType: StatusType.image,
);
if (path != null) {
await widget.file.copy(
'$path/${widget.file.path.split('/').last}');
}
},
child: const Icon(Icons.download),
child: const Icon(Icons.save_alt_rounded),
),
TextButton(
onPressed: () {
Expand Down Expand Up @@ -235,11 +217,17 @@ class PlayerPosIndicator extends StatefulWidget {

class _PlayerPosIndicatorState extends State<PlayerPosIndicator> {
double position = 0;
double max = 0;

void _update() {
setState(() {
position = widget.controller.value.position.inMilliseconds.toDouble();
});
int val = widget.controller.value.position.inMilliseconds.toInt();
int maxVal = widget.controller.value.duration.inMilliseconds.toInt();
if (val >= 0 && val <= maxVal) {
setState(() {
position = val.toDouble();
max = maxVal.toDouble();
});
}
}

@override
Expand All @@ -261,11 +249,131 @@ class _PlayerPosIndicatorState extends State<PlayerPosIndicator> {
child: Slider(
value: position,
min: 0,
max: widget.controller.value.duration.inMilliseconds.toDouble(),
max: max,
onChanged: (double value) {
widget.controller.seekTo(Duration(milliseconds: value.toInt()));
},
),
);
}
}

enum StatusType {
image,
video,
}

Future<T> showSaveAsDialog<T>({
required BuildContext context,
required File statusFile,
required StatusType statusType,
}) async {
return await showDialog(
context: context,
builder: (BuildContext context) => SaveAsPopup(
statusFile: statusFile,
statusType: statusType,
),
);
}

class SaveAsPopup extends StatelessWidget {
final File statusFile;
final StatusType statusType;
const SaveAsPopup({
Key? key,
required this.statusFile,
required this.statusType,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
body: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
margin: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Theme.of(context).scaffoldBackgroundColor,
borderRadius: BorderRadius.circular(12),
),
child: Column(
children: [
Row(
children: const [
Text(
'Save to ',
style: TextStyle(
fontSize: 18,
),
),
Icon(Icons.save_alt),
],
),
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ElevatedButton.icon(
onPressed: () async {
Navigator.pop(context);
if (statusType == StatusType.image) {
await GallerySaver.saveImage(statusFile.path);
} else {
await GallerySaver.saveVideo(statusFile.path);
}
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Saved the statuses'),
),
);
},
icon: const Icon(Icons.photo_sharp),
label: const Text('Gallery'),
style: ElevatedButton.styleFrom(
shape: const StadiumBorder(),
),
),
ElevatedButton.icon(
onPressed: () async {
String? path = await FilesystemPicker.open(
title: 'Save to folder',
context: context,
rootDirectory: Directory(
'/storage/emulated/0/',
),
fsType: FilesystemType.folder,
pickText: 'Save file to this folder',
folderIconColor: Colors.teal,
);
if (path != null) {
Navigator.pop(context);
await statusFile.copy(
'$path/${statusFile.path.split('/').last}',
);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Saved the statuses'),
),
);
}
},
icon: const Icon(Icons.folder_sharp),
label: const Text('Folder'),
style: ElevatedButton.styleFrom(
shape: const StadiumBorder(),
),
),
],
),
],
),
),
],
),
);
}
}
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
gallery_saver:
dependency: "direct main"
description:
name: gallery_saver
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.2"
html:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.3+6
version: 1.0.3+7

environment:
sdk: ">=2.16.2 <3.0.0"
Expand Down Expand Up @@ -47,6 +47,7 @@ dependencies:
provider: ^6.0.2
shared_preferences: ^2.0.13
device_info_plus: ^3.2.3
gallery_saver: ^2.3.2

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit fd15f9f

Please sign in to comment.