feat: use platform adaptive widgets and replace native title bar with Flutter TitleBar

This commit is contained in:
Kingkor Roy Tirtho 2022-12-23 12:32:11 +06:00
parent 3244f42d18
commit 8618aeab4f
16 changed files with 98 additions and 57 deletions

View File

@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart';
import 'package:tuple/tuple.dart';
import 'package:window_manager/window_manager.dart';
import 'package:window_size/window_size.dart';
import 'src/app.dart';
@ -59,6 +60,19 @@ void main() async {
// Don't forget to also change the size in linux/my_application.cc:50
setWindowMinSize(const Size(692, 580));
setWindowMaxSize(const Size(692, 580));
await windowManager.ensureInitialized();
const windowOptions = WindowOptions(
size: Size(692, 580),
center: true,
backgroundColor: Colors.transparent,
skipTaskbar: false,
titleBarStyle: TitleBarStyle.hidden,
);
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
});
final foundQuickGet = await Process.run('which', ['quickget']);
if (foundQuickGet.exitCode == 0) {
gOperatingSystems = await loadOperatingSystems(false);

View File

@ -10,6 +10,7 @@ import 'package:quickgui/src/mixins/app_version.dart';
import 'package:quickgui/src/pages/deget_not_found_page.dart';
import 'package:quickgui/src/supported_locales.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:window_manager/window_manager.dart';
import 'globals.dart';
import 'mixins/preferences_mixin.dart';
@ -23,10 +24,9 @@ class App extends StatefulWidget {
State<App> createState() => _AppState();
}
class _AppState extends State<App> with PreferencesMixin {
class _AppState extends State<App> with PreferencesMixin, WindowListener {
@override
Widget build(BuildContext context) {
platform = TargetPlatform.macOS;
return FutureBuilder<SharedPreferences>(
future: SharedPreferences.getInstance(),
builder: (context, snapshot) {
@ -57,11 +57,12 @@ class _AppState extends State<App> with PreferencesMixin {
GlobalWidgetsLocalizations.delegate,
],
windowButtonConfig: PlatformWindowButtonConfig(
isMaximized: () => false,
onClose: () {},
onMinimize: () {},
onMaximize: () {},
onRestore: () {},
isMaximized: () => windowManager.isMaximized(),
onClose: windowManager.close,
onMinimize: windowManager.minimize,
onMaximize: windowManager.maximize,
onRestore: windowManager.restore,
showMaximizeButton: false,
),
windowsTheme: fluent.ThemeData(
scaffoldBackgroundColor: fluent.Colors.grey[50],

View File

@ -1,6 +1,7 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:quickgui/src/widgets/title_bar.dart';
import 'package:url_launcher/url_launcher.dart';
class DebgetNotFoundPage extends StatelessWidget {
@ -9,11 +10,8 @@ class DebgetNotFoundPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return PlatformScaffold(
appBar: PlatformAppBar(
appBar: TitleBar(
title: PlatformText.subheading('Quickgui'),
actions: const [
PlatformWindowButtons(),
],
automaticallyImplyLeading: false,
),
body: Center(

View File

@ -6,6 +6,7 @@ import 'package:desktop_notifications/desktop_notifications.dart';
import 'package:flutter/material.dart';
import 'package:gettext_i18n/gettext_i18n.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:quickgui/src/widgets/title_bar.dart';
import '../model/operating_system.dart';
import '../model/option.dart';
@ -130,8 +131,8 @@ class _DownloaderState extends State<Downloader> {
@override
Widget build(BuildContext context) {
return PlatformScaffold(
appBar: PlatformAppBar(
title: PlatformText(
appBar: TitleBar(
title: PlatformText.subheading(
context.t('Downloading {0}', args: [
'${widget.operatingSystem.name} ${widget.version.version}' +
(widget.option!.option.isNotEmpty
@ -139,9 +140,6 @@ class _DownloaderState extends State<Downloader> {
: '')
]),
),
actions: const [
PlatformWindowButtons(),
],
automaticallyImplyLeading: false,
),
body: Center(

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:gettext_i18n/gettext_i18n.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:quickgui/src/widgets/title_bar.dart';
import '../widgets/home_page/downloader_menu.dart';
import '../widgets/home_page/logo.dart';
@ -11,11 +12,8 @@ class DownloaderPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return PlatformScaffold(
appBar: PlatformAppBar(
title: PlatformText(context.t('Downloader')),
actions: const [
PlatformWindowButtons(),
],
appBar: TitleBar(
title: PlatformText.subheading(context.t('Downloader')),
),
body: Column(
children: const [

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:gettext_i18n/gettext_i18n.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:quickgui/src/widgets/title_bar.dart';
import 'package:window_size/window_size.dart';
import '../widgets/home_page/logo.dart';
@ -25,7 +26,7 @@ class _MainPageState extends State<MainPage> {
@override
Widget build(BuildContext context) {
return PlatformScaffold(
appBar: PlatformAppBar(
appBar: TitleBar(
automaticallyImplyLeading: false,
title: PlatformText.subheading(context.t('Quickgui')),
centerTitle: true,
@ -41,7 +42,6 @@ class _MainPageState extends State<MainPage> {
);
},
),
const PlatformWindowButtons(),
],
),
body: Column(

View File

@ -9,6 +9,7 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:gettext_i18n/gettext_i18n.dart';
import 'package:path/path.dart' as path;
import 'package:platform_ui/platform_ui.dart';
import 'package:quickgui/src/widgets/title_bar.dart';
import '../globals.dart';
import '../mixins/preferences_mixin.dart';
@ -529,11 +530,8 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
@override
Widget build(BuildContext context) {
return PlatformScaffold(
appBar: PlatformAppBar(
title: PlatformText(context.t('Manager')),
actions: const [
PlatformWindowButtons(),
],
appBar: TitleBar(
title: PlatformText.subheading(context.t('Manager')),
),
body: _buildVmList(),
);

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:gettext_i18n/gettext_i18n.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:quickgui/src/widgets/title_bar.dart';
import '../model/operating_system.dart';
@ -29,11 +30,8 @@ class _OperatingSystemSelectionState extends State<OperatingSystemSelection> {
.where((os) => os.name.toLowerCase().contains(term.toLowerCase()))
.toList();
return PlatformScaffold(
appBar: PlatformAppBar(
title: PlatformText(context.t('Select operating system')),
actions: const [
PlatformWindowButtons(),
],
appBar: TitleBar(
title: PlatformText.subheading(context.t('Select operating system')),
),
body: SingleChildScrollView(
child: Column(

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:gettext_i18n/gettext_i18n.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:quickgui/src/widgets/title_bar.dart';
import 'package:tuple/tuple.dart';
import '../model/operating_system.dart';
@ -36,14 +37,11 @@ class _VersionSelectionState extends State<VersionSelection> {
.toList();
return PlatformScaffold(
appBar: PlatformAppBar(
title: PlatformText(
appBar: TitleBar(
title: PlatformText.subheading(
context
.t('Select version for {0}', args: [widget.operatingSystem.name]),
),
actions: const [
PlatformWindowButtons(),
],
),
body: SingleChildScrollView(
child: Column(

View File

@ -1,4 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:gettext_i18n/gettext_i18n.dart';
import 'package:platform_ui/platform_ui.dart';
@ -19,11 +19,8 @@ class MainMenu extends StatelessWidget {
PlatformFilledButton(
onPressed: () {
Navigator.of(context).push(
PageRouteBuilder(
fullscreenDialog: true,
pageBuilder: (context, animation1, animation2) =>
const Manager(),
transitionDuration: Duration.zero,
CupertinoPageRoute(
builder: (context) => const Manager(),
),
);
},
@ -34,11 +31,8 @@ class MainMenu extends StatelessWidget {
onPressed: () {
//Navigator.of(context).push(MaterialPageRoute(builder: (context) => const DownloaderPage()));
Navigator.of(context).push(
PageRouteBuilder(
fullscreenDialog: true,
pageBuilder: (context, animation1, animation2) =>
const DownloaderPage(),
transitionDuration: Duration.zero,
CupertinoPageRoute(
builder: (context) => const DownloaderPage(),
),
);
},

View File

@ -3,6 +3,7 @@ import 'package:gettext_i18n/gettext_i18n.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:provider/provider.dart';
import 'package:quickgui/src/supported_locales.dart';
import 'package:quickgui/src/widgets/title_bar.dart';
import '../globals.dart';
import '../mixins/app_version.dart';
@ -41,11 +42,8 @@ class _SettingsPageState extends State<SettingsPage> with PreferencesMixin {
Widget build(BuildContext context) {
var _version = AppVersion.packageInfo!.version;
return PlatformScaffold(
appBar: PlatformAppBar(
title: PlatformText(context.t('Settings')),
actions: const [
PlatformWindowButtons(),
],
appBar: TitleBar(
title: PlatformText.subheading(context.t('Settings')),
),
body: Consumer<AppSettings>(
builder: (context, appSettings, _) {

View File

@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:window_manager/window_manager.dart';
class TitleBar extends PlatformAppBar {
TitleBar({
List<Widget>? actions,
super.backgroundColor,
super.centerTitle,
super.leading,
super.leadingWidth,
super.title,
super.titleSpacing,
super.toolbarOpacity,
super.toolbarTextStyle,
super.titleTextStyle,
super.actionsIconTheme,
super.automaticallyImplyLeading,
super.foregroundColor,
super.titleWidth,
super.key,
}) : super(
actions: [
...actions ?? [],
const PlatformWindowButtons(),
],
);
@override
Widget build(BuildContext context) {
return DragToMoveArea(child: super.build(context));
}
}

View File

@ -6,13 +6,21 @@
#include "generated_plugin_registrant.h"
#include <screen_retriever/screen_retriever_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>
#include <window_size/window_size_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar);
g_autoptr(FlPluginRegistrar) window_size_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowSizePlugin");
window_size_plugin_register_with_registrar(window_size_registrar);

View File

@ -3,7 +3,9 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
url_launcher_linux
window_manager
window_size
)

View File

@ -48,7 +48,7 @@ static void my_application_activate(GApplication* application) {
}
gtk_window_set_default_size(window, 692, 580);
gtk_widget_show(GTK_WIDGET(window));
gtk_widget_realize(GTK_WIDGET(window));
g_autoptr(FlDartProject) project = fl_dart_project_new();
fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);

View File

@ -4,7 +4,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.2.8-1
environment:
sdk: ">=2.14.4 <3.0.0"
sdk: ">=2.17.0 <3.0.0"
dependencies:
flutter:
@ -30,11 +30,14 @@ dependencies:
flutter_svg: ^1.1.6
gettext_i18n: ^1.0.2
url_launcher: ^6.1.6
platform_ui: ^0.1.0
platform_ui:
git:
url: https://github.com/KRTirtho/platform_ui.git
fluent_ui: ^4.1.2
macos_ui: ^1.7.5
libadwaita: ^1.2.5
adwaita: ^0.5.2
window_manager: ^0.2.8
dev_dependencies:
flutter_test: