Skip to main content

Full Screenshot in Webview flutter

 import 'dart:convert';

import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:path_provider/path_provider.dart';

class InAppWebViewExampleScreen extends StatefulWidget {
@override
_InAppWebViewExampleScreenState createState() =>
new _InAppWebViewExampleScreenState();
}

class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
late InAppWebViewController webView;
late Uint8List screenshotBytes;

@override
void initState() {
super.initState();
}

@override
void dispose() {
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("InAppWebView")),
body: Container(
child: Column(children: <Widget>[
Expanded(
child: InAppWebView(
initialUrlRequest:
URLRequest(url: WebUri("https://github.com/flutter")),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (InAppWebViewController controller, WebUri? url) {},
onLoadStop: (InAppWebViewController controller, WebUri? url) async {
try {
var canvasHeight = await controller.evaluateJavascript(
source:
"Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);");
await controller.setOptions(
options: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
useShouldOverrideUrlLoading: true,
mediaPlaybackRequiresUserGesture: false,
),
android: AndroidInAppWebViewOptions(
useHybridComposition: true,
),
));
screenshotBytes = (await controller.takeScreenshot(
screenshotConfiguration: ScreenshotConfiguration(
compressFormat: CompressFormat.PNG,
//androidHeight: int.parse(canvasHeight.toString())
)))!;
showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: SingleChildScrollView(
child: Image.memory(screenshotBytes),
),
);
},
);
} catch (e) {
print("Screenshot error: $e");
}
},
))
])));
}
}


class FullPageScreenshot extends StatefulWidget {
@override
_FullPageScreenshotState createState() => _FullPageScreenshotState();
}

class _FullPageScreenshotState extends State<FullPageScreenshot> {
late InAppWebViewController webViewController;

Future<void> _takeFullPageScreenshot() async {
try {
// Take screenshot of visible area only
Uint8List? imageBytes = await webViewController.takeScreenshot(
screenshotConfiguration: ScreenshotConfiguration(
compressFormat: CompressFormat.PNG,
),
);

if (imageBytes != null) {
final directory = await getApplicationDocumentsDirectory();
File imgFile = File('${directory.path}/screenshot.png');
await imgFile.writeAsBytes(imageBytes);
print('Screenshot saved to ${imgFile.path}');
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Screenshot saved!')));
}
} catch (e) {
print("Screenshot error: $e");
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Failed to take screenshot')));
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Full Page Screenshot'),
actions: [
IconButton(
icon: Icon(Icons.camera),
onPressed: _takeFullPageScreenshot,
),
],
),
body: InAppWebView(
initialUrlRequest: URLRequest(url: WebUri('https://upsoftech.com/biodata/public/templates/temp.html')),
onWebViewCreated: (controller) {
webViewController = controller;
},
// Add more configuration if needed
),
);
}
}

Comments

Popular posts from this blog

agora live streaming flutter

https://docs.agora.io/en/agora-chat/restful-api/user-system-registration?platform=flutter https://docs.agora.io/en/agora-chat/restful-api/chatroom-management/manage-chatrooms?platform=flutter https://stackoverflow.com/questions/75666504/how-to-generate-an-app-token-for-agora-chat https://stackoverflow.com/questions/61595787/flutter-how-can-i-create-an-incoming-call-notification?rq=4 https://stackoverflow.com/questions/70031266/flutter-incoming-video-audio-call-notification-using-agora https://stackoverflow.com/questions/61460809/video-call-acceptance-screen-with-agora-flutter https://stackoverflow.com/questions/70031266/flutter-incoming-video-audio-call-notification-using-agora https://www.flutterant.com/flutter-video-calling-by-agora-sdk/ https://medium.com/flutter/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124 https://medium.com/@Ayush_b58/flutter-callkit-handle-actions-in-the-killed-state-e6f296c603e6 https://stackoverflow.com/questions/61460809/vi...

method channel JavaScript flutter

 method channel JavaScript  flutter   flutter plugin :  https://pub.dev/packages/webview_flutter Step 1 - HTML CODE  <! DOCTYPE html > < html > < head >   < title > Thanks for your order! </ title >   < link rel = "stylesheet" href = "css/style.css" >   < script src = "js/client.js" defer ></ script >   < meta name = "viewport" content = "width=device-width, initial-scale=1" > </ head > < body > </ body > < script type = 'text/javascript' > function postMessage (){   var data = {         message : "Response from web" ,         sender : "user123" ,         timestamp : new Date (). toISOString ()     };     var jsonData = JSON . stringify ( data );     setTimeout ( function () {         PayResponse . postMessage ( jsonData );   ...

FFmpeg resources

FFmpeg is a set of open source libraries that allow you to record, convert digital audio and video recordings in various formats. It includes libavcodec, a library for encoding and decoding audio and video, and libavformat, a library for multiplexing and demultiplexing into a media container. The name comes from the name of the MPEG and FF expert group, meaning fast forward. FFmpeg is already built into the program and does not require downloading additional codecs. The conversion takes place directly on the device (the Internet is not required), and the conversion speed depends on the processor speed of the device. Supports: MPEG4, h265, h264, mp3, 3gp, aac, ogg (vorbis and theora), opus, vp8, vp9 and many other formats (you will find the list in the app). Requirements: Android 4.4 and the availability of the processor ARMv7, ARMv8, x86, x86_64. FFmpeg with x264, x265, ogg, vorbis, theora, opus, vp8, vp9, mp3lame, libxvid, libfdk_aac, libvo_amrwbenc, libopencore-amr, speex, libsox, li...