diff --git a/example/lib/main.dart b/example/lib/main.dart index 24e8a0a..4ef441c 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,6 +1,6 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:io'; +import 'package:universal_io/io.dart'; import 'package:adwaita/adwaita.dart'; import 'package:collection/collection.dart'; diff --git a/example/pubspec.lock b/example/pubspec.lock index d4296d7..22874d6 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -61,10 +61,10 @@ packages: dependency: transitive description: name: collection - sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.1" + version: "1.18.0" dbus: dependency: transitive description: @@ -154,21 +154,37 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.0" - js: + leak_tracker: dependency: transitive description: - name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" url: "https://pub.dev" source: hosted - version: "0.6.7" + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" libadwaita: dependency: "direct main" description: path: ".." relative: true source: path - version: "2.0.1" + version: "2.0.2" libadwaita_core: dependency: transitive description: @@ -189,26 +205,26 @@ packages: dependency: transitive description: name: matcher - sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.15" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.2.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.11.0" package_info_plus: dependency: transitive description: @@ -229,10 +245,10 @@ packages: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" path_parsing: dependency: transitive description: @@ -298,26 +314,26 @@ packages: dependency: transitive description: name: source_span - sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" string_scanner: dependency: transitive description: @@ -338,10 +354,10 @@ packages: dependency: transitive description: name: test_api - sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.5.1" + version: "0.6.1" typed_data: dependency: transitive description: @@ -350,6 +366,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.1" + universal_io: + dependency: transitive + description: + name: universal_io + sha256: "1722b2dcc462b4b2f3ee7d188dad008b6eb4c40bbd03a3de451d82c78bba9aad" + url: "https://pub.dev" + source: hosted + version: "2.2.2" url_launcher: dependency: transitive description: @@ -454,6 +478,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.1" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" win32: dependency: transitive description: @@ -487,5 +519,5 @@ packages: source: hosted version: "6.3.0" sdks: - dart: ">=3.0.0-0 <4.0.0" + dart: ">=3.2.0-0 <4.0.0" flutter: ">=3.7.0-0" diff --git a/lib/src/widgets/adw/header_bar.dart b/lib/src/widgets/adw/header_bar.dart index d1aba4b..fee4247 100644 --- a/lib/src/widgets/adw/header_bar.dart +++ b/lib/src/widgets/adw/header_bar.dart @@ -1,5 +1,3 @@ -import 'dart:io'; - import 'package:dbus/dbus.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -7,6 +5,7 @@ import 'package:gsettings/gsettings.dart'; import 'package:libadwaita/src/utils/colors.dart'; import 'package:libadwaita/src/widgets/widgets.dart'; import 'package:libadwaita_core/libadwaita_core.dart'; +import 'package:universal_io/io.dart'; class HeaderBarStyle { const HeaderBarStyle({ @@ -53,32 +52,32 @@ class AdwHeaderBar extends StatefulWidget { this.start = const [], this.end = const [], this.style = const HeaderBarStyle(), - required AdwActions actions, + AdwActions? actions, AdwControls? controls, }) : closeBtn = controls != null - ? controls.closeBtn?.call(actions.onClose) + ? controls.closeBtn?.call(actions?.onClose) : AdwWindowButton( nativeControls: style.nativeControls, buttonType: WindowButtonType.close, - onPressed: actions.onClose, + onPressed: actions?.onClose, ), maximizeBtn = controls != null - ? controls.maximizeBtn?.call(actions.onMaximize) + ? controls.maximizeBtn?.call(actions?.onMaximize) : AdwWindowButton( nativeControls: style.nativeControls, buttonType: WindowButtonType.maximize, - onPressed: actions.onMaximize, + onPressed: actions?.onMaximize, ), minimizeBtn = controls != null - ? controls.minimizeBtn?.call(actions.onMinimize) + ? controls.minimizeBtn?.call(actions?.onMinimize) : AdwWindowButton( nativeControls: style.nativeControls, buttonType: WindowButtonType.minimize, - onPressed: actions.onMinimize, + onPressed: actions?.onMinimize, ), - onHeaderDrag = actions.onHeaderDrag, - onDoubleTap = actions.onDoubleTap, - onRightClick = actions.onRightClick; + onHeaderDrag = actions?.onHeaderDrag, + onDoubleTap = actions?.onDoubleTap, + onRightClick = actions?.onRightClick; /// The leading widget for the headerbar final List start; @@ -112,19 +111,13 @@ class AdwHeaderBar extends StatefulWidget { } class _AdwHeaderBarState extends State { - bool get hasWindowControls => - widget.closeBtn != null || - widget.minimizeBtn != null || - widget.maximizeBtn != null; + bool get hasWindowControls => widget.closeBtn != null || widget.minimizeBtn != null || widget.maximizeBtn != null; - late ValueNotifier?> separator = - !widget.style.autoPositionWindowButtons || - !kIsWeb && - (Platform.isLinux || Platform.isWindows || Platform.isMacOS) - ? ValueNotifier( - ['', 'minimize,maximize,close'], - ) - : ValueNotifier(null); + late ValueNotifier?> separator = !widget.style.autoPositionWindowButtons || !kIsWeb && (Platform.isLinux || Platform.isWindows || Platform.isMacOS) + ? ValueNotifier( + ['', 'minimize,maximize,close'], + ) + : ValueNotifier(null); @override void initState() { @@ -138,10 +131,7 @@ class _AdwHeaderBarState extends State { (e) => e .split(',') .where( - (element) => - element == 'close' || - element == 'maximize' || - element == 'minimize', + (element) => element == 'close' || element == 'maximize' || element == 'minimize', ) .join(','), ); @@ -156,8 +146,7 @@ class _AdwHeaderBarState extends State { WidgetsBinding.instance.addPostFrameCallback((_) async { try { - final buttonLayout = - await schema.get('button-layout') as DBusString?; + final buttonLayout = await schema.get('button-layout') as DBusString?; if (buttonLayout != null) { updateSep(buttonLayout.value); } @@ -187,9 +176,7 @@ class _AdwHeaderBarState extends State { alignment: Alignment.topCenter, child: Container( decoration: BoxDecoration( - color: !widget.style.isTransparent - ? Theme.of(context).appBarTheme.backgroundColor - : null, + color: !widget.style.isTransparent ? Theme.of(context).appBarTheme.backgroundColor : null, border: !widget.style.isTransparent ? Border( bottom: BorderSide(color: context.borderColor), @@ -215,15 +202,11 @@ class _AdwHeaderBarState extends State { leading: Row( mainAxisSize: MainAxisSize.min, children: [ - if (hasWindowControls && - sep != null && - sep[0].split(',').isNotEmpty) ...[ + if (hasWindowControls && sep != null && sep[0].split(',').isNotEmpty) ...[ SizedBox(width: widget.style.titlebarSpace), for (var i in sep[0].split(',')) if (windowButtons[i] != null) windowButtons[i]!, - if (!widget.style.nativeControls || - !kIsWeb && Platform.isLinux) - SizedBox(width: widget.style.titlebarSpace), + if (!widget.style.nativeControls || !kIsWeb && Platform.isLinux) SizedBox(width: widget.style.titlebarSpace), ], ...widget.start.map( (e) => Padding( @@ -243,15 +226,11 @@ class _AdwHeaderBarState extends State { child: e, ), ), - if (hasWindowControls && - sep != null && - sep[1].split(',').isNotEmpty) ...[ + if (hasWindowControls && sep != null && sep[1].split(',').isNotEmpty) ...[ SizedBox(width: widget.style.titlebarSpace), for (var i in sep[1].split(',')) if (windowButtons[i] != null) windowButtons[i]!, - if (!widget.style.nativeControls || - !kIsWeb && Platform.isLinux) - SizedBox(width: widget.style.titlebarSpace), + if (!widget.style.nativeControls || !kIsWeb && Platform.isLinux) SizedBox(width: widget.style.titlebarSpace), ], ], ), diff --git a/lib/src/widgets/adw/new/scaffold.dart b/lib/src/widgets/adw/new/scaffold.dart index 155f006..8852ed9 100644 --- a/lib/src/widgets/adw/new/scaffold.dart +++ b/lib/src/widgets/adw/new/scaffold.dart @@ -13,15 +13,14 @@ class AdwScaffold extends StatefulWidget { this.flapStyle, this.flapOptions, this.flapController, - @Deprecated('headerbar is deprecated, use the properties separately') - AdwHeaderBar? Function(Widget?)? headerbar, + @Deprecated('headerbar is deprecated, use the properties separately') AdwHeaderBar? Function(Widget?)? headerbar, this.viewSwitcher, this.viewSwitcherConstraint, this.headerBarStyle, this.start, this.title, this.end, - required this.actions, + this.actions, this.controls, }); @@ -42,7 +41,7 @@ class AdwScaffold extends StatefulWidget { final Widget? title; final List? end; - final AdwActions actions; + final AdwActions? actions; final AdwControls? controls; final Widget? viewSwitcher; @@ -63,8 +62,7 @@ class _AdwScaffoldState extends State { @override Widget build(BuildContext context) { - final isMobile = MediaQuery.of(context).size.width <= - (widget.viewSwitcherConstraint ?? 600); + final isMobile = MediaQuery.of(context).size.width <= (widget.viewSwitcherConstraint ?? 600); final isFlapVisible = widget.flap != null; final isViewSwitcherVisible = widget.viewSwitcher != null; @@ -84,9 +82,7 @@ class _AdwScaffoldState extends State { AdwHeaderBar( actions: widget.actions, controls: widget.controls, - title: isViewSwitcherVisible && !isMobile - ? widget.viewSwitcher - : widget.title, + title: isViewSwitcherVisible && !isMobile ? widget.viewSwitcher : widget.title, end: widget.end ?? [], start: widget.start ?? [], style: widget.headerBarStyle ?? const HeaderBarStyle(), @@ -94,12 +90,8 @@ class _AdwScaffoldState extends State { Expanded( child: Scaffold( key: widget.scaffoldKey, - drawerEnableOpenDragGesture: _flapController - ?.shouldEnableDrawerGesture(FlapPosition.start) ?? - false, - endDrawerEnableOpenDragGesture: _flapController - ?.shouldEnableDrawerGesture(FlapPosition.end) ?? - false, + drawerEnableOpenDragGesture: _flapController?.shouldEnableDrawerGesture(FlapPosition.start) ?? false, + endDrawerEnableOpenDragGesture: _flapController?.shouldEnableDrawerGesture(FlapPosition.end) ?? false, onDrawerChanged: _flapController?.onDrawerChanged, drawer: flap, endDrawer: flap, @@ -114,9 +106,7 @@ class _AdwScaffoldState extends State { : widget.body, bottomNavigationBar: isViewSwitcherVisible && isMobile ? Container( - height: widget.headerBarStyle != null - ? widget.headerBarStyle!.height - : 51, + height: widget.headerBarStyle != null ? widget.headerBarStyle!.height : 51, decoration: BoxDecoration( border: Border( top: BorderSide( diff --git a/lib/src/widgets/adw/new/window_button.dart b/lib/src/widgets/adw/new/window_button.dart index cacb358..b01ee1e 100644 --- a/lib/src/widgets/adw/new/window_button.dart +++ b/lib/src/widgets/adw/new/window_button.dart @@ -1,4 +1,4 @@ -import 'dart:io'; +import 'package:universal_io/io.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index fcfedc4..709bece 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,6 +26,8 @@ dependencies: package_info_plus: ">=4.0.0 <5.0.0" popover_gtk: ">=0.2.6+3 <1.0.0" url_launcher: ">=6.1.11 <7.0.0" + universal_io: ^2.2.2 + dev_dependencies: very_good_analysis: ^3.0.1