Flutter Web Save Image - flutter

I was working on a flutter web app where I need to save an image created using canvas.I tried FileSaver.js library but it wasn't successful for me.
Index.html main.dart

I created simple package image_downloader_web that can easily download image from web.
final WebImageDownloader _webImageDownloader = WebImageDownloader();
const _url = "https://picsum.photos/200";
Future<void> _downloadImage() async {
await _webImageDownloader.downloadImageFromWeb(_url);
}

Related

How to share image + text both to WhatsApp from flutter app

I try to use this package
share_plus
from flutter to make user can share image + text with other apps (WhatsApp). It works fine on Android, but the problem is in IOS I can't share image and text same in one time. I searched for a long time but could not find a solution to this problem.
Code:
Future ShareImage()async{
var urls='https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Image_created_with_a_mobile_phone.png/1200px-Image_created_with_a_mobile_phone.png';
final url=Uri.parse(urls);
final res =await http.get(url);
final bytes =res.bodyBytes;
final temp = await getTemporaryDirectory();
final path ='${temp.path}/imageToShare.jpg';
File(path).writeAsBytesSync(bytes);
Share.shareFiles([path],text:'Great picture'); }
Anyone have a way to solve this problem?
I think you need these packages for your need according.
whatsapp_share2: https://pub.dev/packages/whatsapp_share2
whatsapp_share: https://pub.dev/packages/whatsapp_share
akvelon_flutter_share_plugin:
https://pub.dev/packages/akvelon_flutter_share_plugin
flutter_share: https://pub.dev/packages/flutter_share
More package available at https://pub.dev

How to Download Image from URL Instead Open in New Tab

I just want to download an image from the URL instead of open it in a new tab. I already try some code, but it didn't work as I want
1. url_launcher
launch(my_url);
2. url_launcher_web
final launcher = UrlLauncherPlugin();
launcher.launch(my_url);
3. dio
final response = await Dio().download(my_url, './xx.html');
UPDATE
Please note that I don't want to open the file in a new tab or current tab, I just want to direct download the file (something like making a stream to download).
For flutter web to download any file you can take the help of HTML library which will treat it as simply an anchor tag with download option. Note this can download any file so better check for IMAGE URL'S as well.
import 'dart:html' as html;
void downloadImage(String url){
html.AnchorElement anchorElement = new html.AnchorElement(href: url);
anchorElement.download = url;
anchorElement.click();
}

Fetch all Folders from root directories in Flutter

I want to fetch all the folder from internal and external storage same as any other video player app , how to make it done in flutter for both IOS/Android
you can use ext_storage like this,
void getRootPath() async {
var path = await ExtStorage.getExternalStorageDirectory();
print(path); // /storage/emulated/0
}
and can search iterable.

Can't remove PDF file from cache Flutter

I'm using the following library to display a pdf in my application "https://pub.dev/packages/advance_pdf_viewer".
I'm displaying the pdf from file assets like this:
loadDocument() async {
document = await PDFDocument.fromAsset('assets/res/sample.pdf');
setState(() {
_isLoading = false;
});
}
The problem is that I want to replace the file with a new version, but it keeps showing the old one.
What I tried:
1- Changing file name
2- Flutter clean
3- Pub get
4- Deleting the whole file from the project, and still showing ( which means it's somewhere in the cache )
5- Deleting the app
All previous solutions didn't work, and it's driving me crazy.
Thanks

Flutter, how to take full screenshot

i am trying to find a way to take a screenshot of entire screen. Flutter library is only allowing me to make a screenshot of a widget, but i want a screenshot of entire android.
I did find this link:
How to programmatically take a screenshot on Android?
and this is resolwing my problem, but i tried to use that java code as it is in documentation:
https://flutter.dev/docs/development/platform-integration/platform-channels?tab=android-channel-java-tab
sadly i am not able to run that code, maybie im making some kind of mistakes? i find a error, while i whas following docs instruction, after that program whas working (not exacly, java whas not able to find my battery, but code whas compiling), and then i copy first answer from that stack link and i tried to pase it in "MainActivity" folder, sadly program whas not working, my "old" java code whas comipilng, from the docs, not the new one.
If you know the solution how to make a photo of entire android screen using some kind of buttor in flutter, or how to implement code from that link into my MainActivity.java folder, please help
Try this package native_screenshot
https://pub.dev/packages/native_screenshot
You can simply run this function to take the screenshot of your phone:
Future<void> _capturePng() async {
String path = await NativeScreenshot.takeScreenshot();
print(path);
}
You can learn more about this package here
It work fine with Android and IOS
Hope it will be useful
You can use screenshot plugin:https://pub.dev/packages/screenshot to take a widget screenshot.
A screenshot is a simple plugin to capture widgets as Images. This plugin wraps your widgets inside RenderRepaintBoundary
Use this package as a library
Add this to your package's pubspec.yaml file:
dependencies:
screenshot: ^0.2.0
Now in your Dart code, Import it:
import 'package:screenshot/screenshot.dart';
This handy plugin can be used to capture any Widget including full-screen screenshots & individual widgets like Text().
Create Instance of Screenshot Controller
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
File _imageFile;
//Create an instance of ScreenshotController
ScreenshotController screenshotController = ScreenshotController();
#override
void initState() {
// TODO: implement initState
super.initState();
}
...
}
Wrap the widget that you want to capture inside Screenshot Widget. Assign the controller to screenshotController that you have created earlier
Screenshot(
controller: screenshotController,
child: Text("This text will be captured as image"),
),
Take the screenshot by calling the capture method. This will return a File
screenshotController.capture().then((File image) {
//Capture Done
setState(() {
_imageFile = image;
});
}).catchError((onError) {
print(onError);
});
Duplicate: How to take a screenshot of the current widget - Flutter