Flutter PDF Viewer for Linux Desktop

Flutter PDF Viewer for Linux desktop

So just to clarify how we can achive this using webkit, as example:

CMakeLists.txt:

#add webkit package reference
pkg_check_modules(WEBKIT2 REQUIRED IMPORTED_TARGET webkit2gtk-4.0)
...
#remove -Werror flag to allow compilation with warnings
target_compile_options(${TARGET} PRIVATE -Wall)
...
#link webkit libraries
target_link_libraries(${BINARY_NAME} PUBLIC PkgConfig::WEBKIT2)
#somehow this line causes 'flutter run' to crash on "Linking CXX executable" step.
#Looks like it compiles, but fails to link.
#I think there is should be other question opened for this issue.

my_application.cc:

#include "my_application.h"
#include <flutter_linux/flutter_linux.h>
#include <webkit2/webkit2.h>
#include "flutter/generated_plugin_registrant.h"

static void my_application_activate(GApplication* application) {

GtkWidget *vbox1 = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox1);

// we can insert any gtk controls in this window outside of FlView
GtkWidget *label = gtk_label_new ("Hello GNOME!");
gtk_box_pack_start (GTK_BOX (vbox1), label, TRUE, TRUE, 2);
gtk_widget_show (label);

// webkit/poppler/evince should work perfect because they gtk+
WebKitWebView *pWebKitView = WEBKIT_WEB_VIEW(webkit_web_view_new());
gtk_box_pack_start (GTK_BOX (vbox1), GTK_WIDGET(pWebKitView), TRUE, TRUE, 2);
gtk_widget_show(GTK_WIDGET(pWebKitView));

// finally add FlView
g_autoptr(FlDartProject) project = fl_dart_project_new();
FlView *view = fl_view_new(project);
gtk_box_pack_start (GTK_BOX (vbox1), GTK_WIDGET(view), TRUE, TRUE, 2);
gtk_widget_show (GTK_WIDGET (view));

GtkWindow* window =
GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
gtk_container_add (GTK_CONTAINER (window), vbox1);

fl_register_plugins(FL_PLUGIN_REGISTRY(view));
gtk_widget_grab_focus(GTK_WIDGET(view));

GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
gtk_widget_show(GTK_WIDGET(header_bar));
gtk_header_bar_set_title(header_bar, "client");
gtk_header_bar_set_show_close_button(header_bar, TRUE);
gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
gtk_window_set_default_size(window, 1280, 720);

gtk_widget_show(GTK_WIDGET(window));
}

Is there a PDF viewer for Flutter 3.3.8 version?

Use this pacakge:

https://pub.dev/packages/flutter_pdfview

flutter_pdfview: ^1.2.5

Does Flutter 3 support Webview on Desktop?

No Flutter 3 Does not support Webview on Desktop, however you can use a package -
https://pub.dev/packages/desktop_webview_window

Show PDF Inline File for iOS in Flutter

When I was implementing the functionality for PDF viewer, there was no PDF plugin.

However, funny enough a friend at work found out that there is already a PDF viewer implemented for Flutter here, which we ended up using.

Note: At the time of writing the question, 16.08 there was not yet any plugin available. The mentioned was created on 30.08.



Related Topics



Leave a reply



Submit