From fd15f9f2e89f981dba7034a4cefdc9056a001e9f Mon Sep 17 00:00:00 2001 From: netharu methmitha Date: Wed, 27 Apr 2022 03:25:46 +0530 Subject: [PATCH] fixed I can't download whatsapp status for my gallery #2 --- docs/README.md | 2 +- lib/pages/status_preview_page.dart | 170 +++++++++++++++++++++++------ pubspec.lock | 7 ++ pubspec.yaml | 3 +- 4 files changed, 149 insertions(+), 33 deletions(-) diff --git a/docs/README.md b/docs/README.md index 6bbd361..0bef500 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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) diff --git a/lib/pages/status_preview_page.dart b/lib/pages/status_preview_page.dart index 79c80e9..9f89351 100644 --- a/lib/pages/status_preview_page.dart +++ b/lib/pages/status_preview_page.dart @@ -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'; @@ -41,22 +42,13 @@ class _StatusPreviewPageState extends State { ), 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: () { @@ -99,23 +91,13 @@ class _StatusPreviewPageState extends State { ), 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: () { @@ -235,11 +217,17 @@ class PlayerPosIndicator extends StatefulWidget { class _PlayerPosIndicatorState extends State { 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 @@ -261,7 +249,7 @@ class _PlayerPosIndicatorState extends State { 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())); }, @@ -269,3 +257,123 @@ class _PlayerPosIndicatorState extends State { ); } } + +enum StatusType { + image, + video, +} + +Future showSaveAsDialog({ + 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(), + ), + ), + ], + ), + ], + ), + ), + ], + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 3a3ed74..e0d4673 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index acb36f3..9595e08 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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" @@ -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: