Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.7.0: MacosImageIcon & sidebar updates #274

Merged
merged 24 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
28b1f56
feat: MacosTabView & MacosSegmentedControl
GroovinChip Jul 4, 2022
fdba08d
chore: fixup scripts
GroovinChip Jul 4, 2022
572798e
test: tests for segmented control & tab view
GroovinChip Jul 4, 2022
101289f
chore: remove unused code
GroovinChip Jul 4, 2022
827e758
chore: run flutter format .
GroovinChip Jul 4, 2022
d28dbc1
chore: bump code metrics
GroovinChip Jul 4, 2022
477498b
docs: dartdoc updates
GroovinChip Jul 4, 2022
18ac443
docs: fix a documentation error
GroovinChip Jul 5, 2022
96a3e51
chore: run flutter format .
GroovinChip Jul 5, 2022
0114f0f
feat: MacosImageIcon & sidebar updates
GroovinChip Jul 7, 2022
f00c4cf
test: fix issues with date_picker_test
GroovinChip Jul 7, 2022
8be7e0f
Merge branch 'dev' into sidebar_items_tweaks
GroovinChip Jul 7, 2022
3f98b5f
Merge branch 'dev' into tab_view
GroovinChip Jul 7, 2022
6a63b24
Merge branch 'tab_view' into sidebar_items_tweaks
GroovinChip Jul 7, 2022
e1056ec
refactor: make active property of MacosTab optional, since it is hand…
whiplashoo Jul 9, 2022
af54b8f
chore: fix import change
whiplashoo Jul 9, 2022
e9039ee
Merge branch 'tab_view' into sidebar_items_tweaks
GroovinChip Jul 9, 2022
7969106
refactor: change colors to match default native app design
whiplashoo Jul 9, 2022
e876325
Merge branch 'tab_view' into sidebar_items_tweaks
GroovinChip Jul 9, 2022
37581e1
docs: update tab view screenshot in readme
GroovinChip Jul 9, 2022
8de5e5e
Merge branch 'tab_view' into sidebar_items_tweaks
GroovinChip Jul 9, 2022
3018620
Merge branch 'dev' into sidebar_items_tweaks
whiplashoo Jul 10, 2022
34b3b74
chore: fix README
whiplashoo Jul 10, 2022
177207f
test: fix date picker test
whiplashoo Jul 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [1.7.0]
* ✨ New
* `MacosImageIcon` widget. Identical to the `ImageIcon` from `flutter/widgets.dart` except it will obey a
`MacosIconThemeData` instead of an `IconThemeData`
* `SidebarItemSize` enum, which determines the height of sidebar items and the maximum size their `leading` widgets.
* `SidebarItem` now accepts an optional `trailing` widget.
* 🔄 Updated
* `SidebarItems` now supports `SidebarItemSize` via the `itemSize` property, which defaults to
`SidebarItemSize.medium`. The widget has been updated to manage the item's height, the maximum size of the item's
leading widget, and the font size of the item's label widget according to the given `SidebarItemSize`.
* The example app has been tweaked to use some icons from the SF Symbols 4 Beta via the new `MacosImageIcon` widget.

## [1.6.0]
* New widgets: `MacosTabView` and `MacosTabView`
* BREAKING CHANGE: `Label.yAxis` has been renamed to `Label.crossAxisAlignment`
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 49 additions & 19 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,47 +176,77 @@ class _WidgetGalleryState extends State<WidgetGallery> {
currentIndex: pageIndex,
onChanged: (i) => setState(() => pageIndex = i),
scrollController: controller,
items: const [
SidebarItem(
leading: MacosIcon(CupertinoIcons.square_on_circle),
itemSize: SidebarItemSize.large,
items: [
const SidebarItem(
// leading: MacosIcon(CupertinoIcons.square_on_circle),
leading: MacosImageIcon(
AssetImage(
'assets/sf_symbols/button_programmable_2x.png',
),
),
label: Text('Buttons'),
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.arrow_2_circlepath),
const SidebarItem(
leading: MacosImageIcon(
AssetImage(
'assets/sf_symbols/lines_measurement_horizontal_2x.png',
),
),
label: Text('Indicators'),
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.textbox),
const SidebarItem(
leading: MacosImageIcon(
AssetImage(
'assets/sf_symbols/character_cursor_ibeam_2x.png',
),
),
label: Text('Fields'),
),
SidebarItem(
leading: Icon(CupertinoIcons.folder),
label: Text('Disclosure'),
leading: const MacosIcon(CupertinoIcons.folder),
label: const Text('Disclosure'),
trailing: Text(
'2',
style: TextStyle(
color: MacosTheme.brightnessOf(context) == Brightness.dark
? MacosColors.tertiaryLabelColor.darkColor
: MacosColors.tertiaryLabelColor,
),
),
disclosureItems: [
SidebarItem(
leading: MacosIcon(CupertinoIcons.infinite),
const SidebarItem(
leading: MacosImageIcon(
AssetImage(
'assets/sf_symbols/rectangle_3_group_2x.png',
),
),
label: Text('Colors'),
),
SidebarItem(
const SidebarItem(
leading: MacosIcon(CupertinoIcons.infinite),
label: Text('Item 3'),
),
],
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.rectangle),
const SidebarItem(
leading: MacosIcon(CupertinoIcons.square_on_square),
label: Text('Dialogs & Sheets'),
),
SidebarItem(
const SidebarItem(
leading: MacosIcon(CupertinoIcons.macwindow),
label: Text('Toolbar'),
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.calendar),
const SidebarItem(
leading: MacosImageIcon(
AssetImage(
'assets/sf_symbols/filemenu_and_selection_2x.png',
),
),
label: Text('Selectors'),
),
SidebarItem(
leading: MacosIcon(CupertinoIcons.table_fill),
const SidebarItem(
leading: MacosIcon(CupertinoIcons.uiwindow_split_2x1),
label: Text('TabView'),
),
],
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ packages:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "1.0.5"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -87,7 +87,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.6.0"
version: "1.7.0"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -129,7 +129,7 @@ packages:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.2"
version: "6.0.3"
sky_engine:
dependency: transitive
description: flutter
Expand Down
8 changes: 6 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ dependencies:
flutter:
sdk: flutter

cupertino_icons: ^1.0.4
cupertino_icons: ^1.0.5
macos_ui:
path: ..
provider: ^6.0.2
provider: ^6.0.3

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.1

flutter:
assets:
- assets/sf_symbols/
1 change: 1 addition & 0 deletions lib/macos_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export 'src/buttons/toolbar/toolbar_pulldown_button.dart';
export 'src/dialogs/macos_alert_dialog.dart';
export 'src/fields/search_field.dart';
export 'src/fields/text_field.dart';
export 'src/icon/image_icon.dart';
export 'src/icon/macos_icon.dart';
export 'src/indicators/capacity_indicators.dart';
export 'src/indicators/progress_indicators.dart';
Expand Down
102 changes: 102 additions & 0 deletions lib/src/icon/image_icon.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:macos_ui/macos_ui.dart';

/// {@template macosImageIcon}
/// An icon that comes from an [ImageProvider], e.g. an [AssetImage].
///
/// The [size] and [color] default to the value given by the current [MacosIconTheme].
///
/// See also:
/// * [MacosIconButton], for interactive icons.
/// * [MacosIconTheme], which provides ambient configuration for icons.
/// * [MacosIcon], for icons based on glyphs from fonts instead of images.
/// {@endtemplate}
class MacosImageIcon extends StatelessWidget {
/// {@macro macosImageIcon}
const MacosImageIcon(
this.image, {
super.key,
this.size,
this.color,
this.semanticLabel,
});

/// The image to display as the icon.
///
/// The icon can be null, in which case the widget will render as an empty
/// space of the specified [size].
final ImageProvider? image;

/// The size of the icon in logical pixels.
///
/// Icons occupy a square with width and height equal to size.
///
/// Defaults to the current [MacosIconTheme] size, if any. If there is no
/// [MacosIconTheme], or it does not specify an explicit size, then it
/// defaults to 24.0.
final double? size;

/// The color to use when drawing the icon.
///
/// Defaults to the current [MacosIconTheme] color, if any. If there is
/// no [MacosIconTheme], then it defaults to not recolorizing the image.
///
/// The image will be additionally adjusted by the opacity of the current
/// [MacosIconTheme], if any.
final Color? color;

/// Semantic label for the icon.
///
/// Announced in accessibility modes (e.g TalkBack/VoiceOver).
/// This label does not show in the UI.
///
/// * [SemanticsProperties.label], which is set to [semanticLabel] in the
/// underlying [Semantics] widget.
final String? semanticLabel;

@override
Widget build(BuildContext context) {
final iconTheme = MacosIconTheme.of(context);
final iconSize = size ?? iconTheme.size;

if (image == null) {
return Semantics(
label: semanticLabel,
child: SizedBox(width: iconSize, height: iconSize),
);
}

final iconOpacity = iconTheme.opacity;
Color iconColor = color ?? iconTheme.color!;

if (iconOpacity != null && iconOpacity != 1.0) {
iconColor = iconColor.withOpacity(iconColor.opacity * iconOpacity);
}

return Semantics(
label: semanticLabel,
child: Image(
image: image!,
width: iconSize,
height: iconSize,
color: iconColor,
fit: BoxFit.scaleDown,
excludeFromSemantics: true,
),
);
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<ImageProvider>(
'image',
image,
ifNull: '<empty>',
showName: false,
));
properties.add(DoubleProperty('size', size, defaultValue: null));
properties.add(ColorProperty('color', color, defaultValue: null));
}
}
9 changes: 9 additions & 0 deletions lib/src/layout/sidebar/sidebar_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SidebarItem with Diagnosticable {
this.focusNode,
this.semanticLabel,
this.disclosureItems,
this.trailing,
});

/// The widget before [label].
Expand Down Expand Up @@ -57,6 +58,13 @@ class SidebarItem with Diagnosticable {
/// If non-null and [leading] is null, a local animated icon is created
final List<SidebarItem>? disclosureItems;

/// An optional trailing widget.
///
/// Typically a text indicator of a count of items, like in this
/// screenshots from the Apple Notes app:
/// {@image <img src="https://imgur.com/REpW9f9.png" height="88" width="219" />}
final Widget? trailing;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
Expand All @@ -69,5 +77,6 @@ class SidebarItem with Diagnosticable {
'disclosure items',
disclosureItems,
));
properties.add(DiagnosticsProperty<Widget?>('trailing', trailing));
}
}
Loading