Viewing version 2.0.0-beta.1. Open the latest package page.

gtk

2.0.0-beta.1

GTK+ utilities for Flutter Linux applications.

Download archive

Readme

GTK+ utilities for Flutter Linux applications

license: MPL CI codecov

GtkSettings

GtkSettings provide a mechanism to share global settings between applications on Linux.

screenshot

GtkApplication

GtkApplication allows the primary Flutter GTK application instance to listen to remote application instances' command-line arguments and file open requests.

NOTE: linux/my_application.cc must be modified for this package to be able to function. See "Getting Started" below for details.

gtk-application.webm

Getting Started

Apply the following changes to linux/my_application.cc:

diff --git a/example/linux/my_application.cc b/example/linux/my_application.cc
index 5cd43c6..94e7215 100644
--- a/linux/my_application.cc
+++ b/linux/my_application.cc
@@ -20,6 +20,12 @@ static void my_application_activate(GApplication* application) {
   GtkWindow* window =
       GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
 
+  GList* windows = gtk_application_get_windows(GTK_APPLICATION(application));
+  if (windows) {
+    gtk_window_present(GTK_WINDOW(windows->data));
+    return;
+  }
+
   // Use a header bar when running in GNOME as this is the common style used
   // by applications and is the setup most users will be using (e.g. Ubuntu
   // desktop).
--- a/linux/my_application.cc
+++ b/linux/my_application.cc
@@ -81,7 +81,7 @@ static gboolean my_application_local_command_line(GApplication* application,
   g_application_activate(application);
   *exit_status = 0;
 
-  return TRUE;
+  return FALSE;
 }
 
 // Implements GObject::dispose.

--- a/linux/my_application.cc
+++ b/linux/my_application.cc
@@ -101,7 +101,8 @@ static void my_application_class_init(MyApplicationClass* klass) {
 static void my_application_init(MyApplication* self) {}
 
 MyApplication* my_application_new() {
-  return MY_APPLICATION(g_object_new(my_application_get_type(),
-                                     "application-id", APPLICATION_ID, "flags",
-                                     G_APPLICATION_NON_UNIQUE, nullptr));
+  return MY_APPLICATION(g_object_new(
+      my_application_get_type(), "application-id", APPLICATION_ID, "flags",
+      G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_HANDLES_OPEN,
+      nullptr));
 }

Examples

The GtkApplication widget allows listening to remote application instances' command-line arguments and file open requests from within the widget tree.

import 'package:flutter/material.dart';
import 'package:gtk_application/gtk_application.dart';

void main() {
  runApp(
    MaterialApp(
      home: GtkApplication(
        onCommandLine: (args) => print('command-line: $args'),
        onOpen: (files, hint) => print('open ($hint): $files'),
        child: // ...
      ),
    ),
  );
}

The GtkApplicationNotifier object allows listening to remote application instances' command-line arguments and file open requests outside the widget tree.

import 'package:flutter/widgets.dart';
import 'package:gtk_application/gtk_application.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  final notifier = GtkApplicationNotifier();
  notifier.addCommandLineListener((args) {
    print('command-line: $args');
  });
  notifier.addOpenListener((files, hint) {
    print('open ($hint): $files');
  });

  // ...
  // notifier.dispose();
}
Changelog

2.0.0-beta.1

  • Made GtkSettings mockable.

2.0.0-beta.0

  • Re-purpose this package to be a collection of non-visual GTK+ utilities for Flutter applications.
  • Add GtkApplication handling remote command-line arguments and file open requests.
  • Add GtkSettings for accessing desktop and application settings.

1.0.0-rc.9

  • Change adwaitaLight and adwaitaDark type to getters instead of Function

1.0.0-rc.8

  • Fix canvasColor not working

1.0.0-rc.7

  • Add documentation for colors in libadwaita_theme
  • Add adwaitaLight and adwaitaDark for LibAdwaita Theme

1.0.0-rc.6

  • GnomeTheme is now deprecated, use Theme.of(context).[color] to get whatever color you want.

1.0.0-rc.5

  • Get native window button placement by using gsetting schema

1.0.0-rc.4

  • Made width nullable and fix defaults for GtkContainer
  • Update Screenshot

1.0.0-rc.3

  • Fix ViewSwitcher color
  • Add GtkContainer custom widget
  • Add new example app
  • Fix gtk sidebar item bg color

1.0.0-rc.2

  • Fix error when no leading icon was provided for the sidebar
  • Rename gtk_colors.dart to gtk_theme.dart and moved it to the widgets directory
  • Fix imports in the files

1.0.0-rc.1

  • Remove gnomeTheme parameter requirement for gtk_sidebar
  • Add details about paramters of GnomeTheme.of(context)

1.0.0-rc.0

  • Use color schemes from libadwaita

0.9.8+1

  • Remove dead code

0.9.8

  • Add riverpod example
  • Fix selected and unselected color for gtk sidebar
  • Fix initial color parsing

0.9.5

  • Fix instructions on how to use window decoration
  • Update README and screenshot

0.9.0

  • Update gsettings to latest version
  • Fix native theme picker by @MalcolmMielle
  • Made Window Decorations a seperate package to keep this package lightweight

0.8.5

  • Use NavigationToolbar instead of Stack to center widget.

0.8.0

  • Update example
  • Add expanded and height property to GtkViewSwitcher

0.7.0+1

  • Fix Padding of Icons with Gtk header button
  • Update titlebarSpace and padding for GtkHeaderBar

0.7.0

  • Add GtkViewSwitcher from flutter_gtk package
  • Fix Double tap on header buttons doesn't work.
  • Change default padding for header

0.6.0

  • Remove adwaita_icons from dependency of example
  • Revamp code for GtkSidebar.

0.5.5

  • Remove adwaita_icons from dependency
  • Add default values for onClose, onMinimize and onMaximize for GtkHeaderBar.bitsdojo and .nativeshell.
  • Add titlebarSpace property to adjust the space b/w titlebar and trailing items.

0.5.0+1

  • Rename beignDrag to performDrag for nativeshell Gtk Header.

0.5.0

  • Add onDoubleTap and onHeaderDrag method for GtkHeaderBar
  • Add padding and height parameter to GtkHeaderBar
  • Add GtkHeaderBar.bitsdojo and GtkHeaderBar.nativeshell to integerate well with these plugins

0.4.0+1

  • Update Screenshot

0.4.0

  • Add auto detect gtk theme using GtkColorType.system by @MalcolmMielle
  • Update Window Decorations plugin
  • Add isActive parameter to Gtk popup button

0.2.3

  • Change children to body for GtkPopupMenu
  • Update Documentation and comments
  • Update get Gtk color logic
  • Update example by adding bitsdojo_window
  • Update Screenshot

0.2.0+2

  • Fix typo in README
  • Add Screenshot in README

0.2.0+1

  • Update github homepage

0.2.0

  • Remove bitsdojo_window dependency

0.1.0+1

  • Fix Readme

0.1.0

  • initial release.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add 'gtk:2.0.0-beta.1'
pubspec.yaml
name: gtk
description: GTK+ utilities for Flutter Linux applications.
homepage: https://github.com/ubuntu-flutter-community/gtk.dart
repository: https://github.com/ubuntu-flutter-community/gtk.dart
issue_tracker: https://github.com/ubuntu-flutter-community/gtk.dart/issues
version: 2.0.0-beta.1

environment:
  sdk: '>=2.17.0 <3.0.0'
  flutter: ">=3.0.0"

dependencies:
  ffi: ^2.0.1
  flutter:
    sdk: flutter
  meta: ^1.8.0

dev_dependencies:
  ffigen: 7.1.0
  flutter_lints: ^2.0.0
  flutter_test:
    sdk: flutter
  mockito: ^5.3.2

flutter:
  plugin:
    platforms:
      linux:
        pluginClass: GtkPlugin

Version history

VersionPublishedArchiveSHA-256
0.1.0Cached · Upstream SHA-256 matchedDownloadef9b882f…1b26b5
0.1.0+1Cached · Upstream SHA-256 matchedDownloadca70f6c3…d794a3
0.2.0Cached · Upstream SHA-256 matchedDownload8045cff8…7ff973
0.2.0+1Cached · Upstream SHA-256 matchedDownloadb38fde1b…72f4d7
0.2.0+2Cached · Upstream SHA-256 matchedDownload9a333a93…de735c
0.2.3Cached · Upstream SHA-256 matchedDownload79a5c345…eb6800
0.4.0Cached · Upstream SHA-256 matchedDownload396a38f0…03acbd
0.4.0+1Cached · Upstream SHA-256 matchedDownload5b4921bb…f62e08
0.5.0Cached · Upstream SHA-256 matchedDownloadf1de0c93…5c7475
0.5.0+1Cached · Upstream SHA-256 matchedDownload5a6b4cf3…c39329
0.5.5Cached · Upstream SHA-256 matchedDownload3f7ae581…14d771
0.6.0Cached · Upstream SHA-256 matchedDownload03bf5785…4792b5
0.7.0Cached · Upstream SHA-256 matchedDownload32b68ce0…5c69c8
0.7.0+1Cached · Upstream SHA-256 matchedDownload17067a52…62d9b2
0.8.0Cached · Upstream SHA-256 matchedDownload3b802bc6…f6581d
0.8.5Cached · Upstream SHA-256 matchedDownload201e5323…8af9a4
0.9.0Cached · Upstream SHA-256 matchedDownloadc50ba547…857b5d
0.9.5Cached · Upstream SHA-256 matchedDownload4e386c43…a7555b
0.9.8Cached · Upstream SHA-256 matchedDownloadd66096f7…5a58eb
0.9.8+1Cached · Upstream SHA-256 matchedDownload4d1be563…7e6288
1.0.0-rc.0Cached · Upstream SHA-256 matchedDownload8771c670…bb2b81
1.0.0-rc.1Cached · Upstream SHA-256 matchedDownloada88f7144…1e5a5d
1.0.0-rc.2Cached · Upstream SHA-256 matchedDownloadb8c40027…6f6189
1.0.0-rc.3Cached · Upstream SHA-256 matchedDownload5b240b07…6435ce
1.0.0-rc.4Cached · Upstream SHA-256 matchedDownload4ce226e7…3b905c
1.0.0-rc.5Cached · Upstream SHA-256 matchedDownloadb2c42722…92e88c
1.0.0-rc.6Cached · Upstream SHA-256 matchedDownloaddec60264…d57f6c
1.0.0-rc.7Cached · Upstream SHA-256 matchedDownload6b85ca1c…b14540
1.0.0-rc.8Cached · Upstream SHA-256 matchedDownloadb5970922…3db33b
1.0.0-rc.9Cached · Upstream SHA-256 matchedDownloadef4792e1…213551
1.0.0Cached · Upstream SHA-256 matchedDownload53def554…859450
2.0.0-beta.0Cached · Upstream SHA-256 matchedDownload56607b30…5badcb
2.0.0-beta.1Cached · Upstream SHA-256 matchedDownload47f78712…8fad91
2.0.0Cached · Upstream SHA-256 matchedDownload517560d6…e7a3f5
2.1.0Cached · Upstream SHA-256 matchedDownloade8ce9ca4…ffa42c
2.2.0Cached · Upstream SHA-256 matchedDownload4ff85b2a…879cf5

Dependencies

ffi "^2.0.1"

flutter { "sdk": "flutter" }

meta "^1.8.0"