Skip to content

Commit

Permalink
fix: adjust mouse cursor fo various widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Nov 3, 2022
1 parent fa66ebd commit f42a3f9
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 44 deletions.
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ class _MyHomePageState extends State<MyHomePage> {
child: const PlatformText("Hover/Long-Press for Tooltip"),
),
PlatformCheckbox(
label: const PlatformText("Checkbox"),
value: checked,
onChanged: (value) {
setState(() {
Expand Down
58 changes: 46 additions & 12 deletions lib/src/platform_checkbox.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:fluent_ui/fluent_ui.dart' as FluentUI;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:platform_ui/src/specific/macos_checkbox.dart';

Expand All @@ -9,11 +10,13 @@ class PlatformCheckbox extends StatelessWidget with PlatformMixin<Widget> {
final MouseCursor? mouseCursor;
final FocusNode? focusNode;
final bool autofocus;
final Widget? label;

const PlatformCheckbox({
Key? key,
required this.value,
required this.onChanged,
this.label,
this.mouseCursor,
this.focusNode,
this.autofocus = false,
Expand All @@ -26,13 +29,28 @@ class PlatformCheckbox extends StatelessWidget with PlatformMixin<Widget> {

@override
Widget android(BuildContext context) {
return Checkbox(
value: value,
tristate: true,
onChanged: onChanged,
mouseCursor: mouseCursor,
focusNode: focusNode,
autofocus: autofocus,
return MouseRegion(
cursor: mouseCursor ?? SystemMouseCursors.click,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Checkbox(
value: value,
tristate: true,
onChanged: onChanged,
mouseCursor: mouseCursor,
focusNode: focusNode,
autofocus: autofocus,
),
if (label != null)
GestureDetector(
onTap: () {
onChanged?.call(value == null ? null : !value!);
},
child: label!,
),
],
),
);
}

Expand All @@ -52,10 +70,25 @@ class PlatformCheckbox extends StatelessWidget with PlatformMixin<Widget> {
autofocus: autofocus,
focusNode: focusNode,
child: MouseRegion(
cursor: mouseCursor ?? MouseCursor.defer,
child: MacosCheckbox(
value: value,
onChanged: onChanged,
cursor: mouseCursor ?? SystemMouseCursors.click,
child: FluentUI.Row(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.all(4),
child: MacosCheckbox(
value: value,
onChanged: onChanged,
),
),
if (label != null)
GestureDetector(
onTap: () {
onChanged?.call(value == null ? null : !value!);
},
child: label!,
),
],
),
),
);
Expand All @@ -64,12 +97,13 @@ class PlatformCheckbox extends StatelessWidget with PlatformMixin<Widget> {
@override
Widget windows(BuildContext context) {
return MouseRegion(
cursor: mouseCursor ?? MouseCursor.defer,
cursor: mouseCursor ?? SystemMouseCursors.click,
child: FluentUI.Checkbox(
checked: value,
onChanged: onChanged,
focusNode: focusNode,
autofocus: autofocus,
content: label,
),
);
}
Expand Down
50 changes: 27 additions & 23 deletions lib/src/platform_icon_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PlatformIconButton extends StatelessWidget with PlatformMixin<Widget> {
final Color? hoverColor;
final Color? disabledColor;
final VoidCallback? onPressed;
final MouseCursor? mouseCursor;
final MouseCursor mouseCursor;
final FocusNode? focusNode;
final bool autofocus;
final String? tooltip;
Expand All @@ -34,7 +34,7 @@ class PlatformIconButton extends StatelessWidget with PlatformMixin<Widget> {
this.splashRadius,
this.hoverColor,
this.disabledColor,
this.mouseCursor,
this.mouseCursor = SystemMouseCursors.click,
this.focusNode,
this.autofocus = false,
this.tooltip,
Expand Down Expand Up @@ -91,7 +91,7 @@ class PlatformIconButton extends StatelessWidget with PlatformMixin<Widget> {
autofocus: autofocus,
focusNode: focusNode,
child: MouseRegion(
cursor: mouseCursor ?? MouseCursor.defer,
cursor: mouseCursor,
child: constraints != null
? ConstrainedBox(
constraints: constraints!,
Expand Down Expand Up @@ -119,7 +119,7 @@ class PlatformIconButton extends StatelessWidget with PlatformMixin<Widget> {
hoverColor: hoverColor,
disabledColor: disabledColor,
onPressed: onPressed,
mouseCursor: mouseCursor ?? MouseCursor.defer,
mouseCursor: mouseCursor,
boxConstraints: constraints ??
const BoxConstraints(
minHeight: 20,
Expand Down Expand Up @@ -149,25 +149,29 @@ class PlatformIconButton extends StatelessWidget with PlatformMixin<Widget> {
alignment: alignment,
child: FluentUI.Tooltip(
message: tooltip ?? '',
child: FluentUI.IconButton(
icon: icon,
onPressed: onPressed,
autofocus: autofocus,
focusNode: focusNode,
iconButtonMode: windowsIconButtonMode,
style: FluentUI.ButtonStyle(
backgroundColor: backgroundColor != null
? FluentUI.ButtonState.all(backgroundColor)
: null,
iconSize:
iconSize != null ? FluentUI.ButtonState.all(iconSize) : null,
padding: FluentUI.ButtonState.all(padding),
shape: FluentUI.ButtonState.all(
shape == BoxShape.rectangle
? FluentUI.RoundedRectangleBorder(
borderRadius: borderRadius ?? BorderRadius.circular(8.0),
)
: const FluentUI.CircleBorder(),
child: MouseRegion(
cursor: mouseCursor,
child: FluentUI.IconButton(
icon: icon,
onPressed: onPressed,
autofocus: autofocus,
focusNode: focusNode,
iconButtonMode: windowsIconButtonMode,
style: FluentUI.ButtonStyle(
backgroundColor: backgroundColor != null
? FluentUI.ButtonState.all(backgroundColor)
: null,
iconSize:
iconSize != null ? FluentUI.ButtonState.all(iconSize) : null,
padding: FluentUI.ButtonState.all(padding),
shape: FluentUI.ButtonState.all(
shape == BoxShape.rectangle
? FluentUI.RoundedRectangleBorder(
borderRadius:
borderRadius ?? BorderRadius.circular(8.0),
)
: const FluentUI.CircleBorder(),
),
),
),
),
Expand Down
8 changes: 4 additions & 4 deletions lib/src/platform_slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PlatformSlider extends StatelessWidget with PlatformMixin<Widget> {
/// works only in windows, linux and android
final Color? inactiveColor;
final Color? thumbColor;
final MouseCursor? mouseCursor;
final MouseCursor mouseCursor;
final FocusNode? focusNode;
final bool autofocus;

Expand All @@ -33,7 +33,7 @@ class PlatformSlider extends StatelessWidget with PlatformMixin<Widget> {
this.max = 1.0,
this.divisions,
this.label,
this.mouseCursor,
this.mouseCursor = SystemMouseCursors.grabbing,
this.activeColor,
this.inactiveColor,
this.thumbColor,
Expand Down Expand Up @@ -72,7 +72,7 @@ class PlatformSlider extends StatelessWidget with PlatformMixin<Widget> {
autofocus: autofocus,
focusNode: focusNode,
child: MouseRegion(
cursor: mouseCursor ?? MouseCursor.defer,
cursor: mouseCursor,
child: CupertinoSlider(
value: value,
onChanged: onChanged,
Expand Down Expand Up @@ -118,7 +118,7 @@ class PlatformSlider extends StatelessWidget with PlatformMixin<Widget> {
? FluentUI.ButtonState.all(inactiveColor)
: null,
),
mouseCursor: mouseCursor ?? MouseCursor.defer,
mouseCursor: mouseCursor,
focusNode: focusNode,
autofocus: autofocus,
);
Expand Down
10 changes: 5 additions & 5 deletions lib/src/platform_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PlatformSwitch extends StatelessWidget with PlatformMixin<Widget> {

final Color? inactiveTrackColor;

final MouseCursor? mouseCursor;
final MouseCursor mouseCursor;

final FocusNode? focusNode;

Expand All @@ -31,7 +31,7 @@ class PlatformSwitch extends StatelessWidget with PlatformMixin<Widget> {
this.activeTrackColor,
this.inactiveThumbColor,
this.inactiveTrackColor,
this.mouseCursor,
this.mouseCursor = SystemMouseCursors.click,
this.focusNode,
this.autofocus = false,
}) : super(key: key);
Expand Down Expand Up @@ -62,7 +62,7 @@ class PlatformSwitch extends StatelessWidget with PlatformMixin<Widget> {
autofocus: autofocus,
focusNode: focusNode,
child: MouseRegion(
cursor: mouseCursor ?? SystemMouseCursors.click,
cursor: mouseCursor,
child: CupertinoSwitch(
value: value,
onChanged: onChanged,
Expand All @@ -85,7 +85,7 @@ class PlatformSwitch extends StatelessWidget with PlatformMixin<Widget> {
autofocus: autofocus,
focusNode: focusNode,
child: MouseRegion(
cursor: mouseCursor ?? SystemMouseCursors.click,
cursor: mouseCursor,
child: MacosSwitch(
value: value,
onChanged: onChanged,
Expand All @@ -101,7 +101,7 @@ class PlatformSwitch extends StatelessWidget with PlatformMixin<Widget> {
final toggleTheme = ToggleSwitchTheme.of(context);

return MouseRegion(
cursor: mouseCursor ?? SystemMouseCursors.click,
cursor: mouseCursor,
child: ToggleSwitch(
checked: value,
onChanged: onChanged,
Expand Down

0 comments on commit f42a3f9

Please sign in to comment.