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

Implemented checkbox #24

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

## [0.0.3]

* Implemented `Checkbox`
* Implemented `ProgressCircle` and `ProgressBar`
* Implemented the `Switch` widget

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ dragging left or right. See the documentation for all customization options.

# Buttons

## Checkbox

| off | on | mixed |
| --- | -- | ----- |
| ![](https://developer.apple.com/design/human-interface-guidelines/macos/images/CheckBoxes_Deselected.svg) | ![](https://developer.apple.com/design/human-interface-guidelines/macos/images/CheckBoxes_Selected.svg) | ![](https://developer.apple.com/design/human-interface-guidelines/macos/images/CheckBoxes_Mixed.svg) |

## PushButton

<img src="https://imgur.com/v99ekWA.jpg"/>
Expand Down
2 changes: 2 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

/windows/
8 changes: 6 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MyApp extends StatelessWidget {
title: 'macos_ui example',
theme: MacosThemeData.light(),
darkTheme: MacosThemeData.dark(),
themeMode: ThemeMode.dark,
// themeMode: ThemeMode.dark,
debugShowCheckedModeBanner: false,
home: Demo(),
);
Expand All @@ -42,13 +42,17 @@ class _DemoState extends State<Demo> {
child: Text('Sidebar'),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
PushButton(
buttonSize: ButtonSize.small,
child: Text('Button'),
onPressed: () {},
),
Checkbox(
value: value,
onChanged: (v) => setState(() => value = v),
),
],
),
);
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ packages:
name: split_view
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1+1"
version: "2.0.1+2"
stack_trace:
dependency: transitive
description:
Expand Down
2 changes: 0 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter

flutter:
4 changes: 3 additions & 1 deletion lib/macos_ui.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
library macos_ui;

bdlukaa marked this conversation as resolved.
Show resolved Hide resolved
/// todo: package-level docs
export 'package:flutter/widgets.dart';
export 'package:flutter/cupertino.dart'
show CupertinoColors, CupertinoDynamicColor;
show CupertinoColors, CupertinoDynamicColor, CupertinoIcons;
export 'package:flutter/material.dart'
show
Brightness,
Expand Down Expand Up @@ -30,6 +31,7 @@ export 'src/macos_app.dart';
export 'src/styles/macos_theme.dart';
export 'src/styles/macos_theme_data.dart';
export 'src/styles/typography.dart';
export 'src/buttons/checkbox.dart';
export 'src/styles/typography.dart';
export 'src/util.dart';
export 'src/util.dart';
106 changes: 106 additions & 0 deletions lib/src/buttons/checkbox.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import 'package:macos_ui/macos_ui.dart';
bdlukaa marked this conversation as resolved.
Show resolved Hide resolved

/// A checkbox is a type of button that lets the user choose between
/// two opposite states, actions, or values. A selected checkbox is
/// considered on when it contains a checkmark and off when it's empty.
/// A checkbox is almost always followed by a title unless it appears in
/// a checklist.
class Checkbox extends StatelessWidget {
/// Creates a checkbox.
///
/// [size] must be non-negative
const Checkbox({
Key? key,
required this.value,
required this.onChanged,
this.size = 16.0,
this.activeColor,
this.disabledColor = CupertinoColors.quaternaryLabel,
this.offBorderColor = CupertinoColors.tertiaryLabel,
}) : assert(size >= 0),
super(key: key);

/// Whether the checkbox is checked or not. If null, it'll be considered
/// mixed.
final bool? value;

/// Called whenever the state of the checkbox changes. If null, the checkbox
/// will be considered disabled
final ValueChanged<bool>? onChanged;

/// The size of the checkbox. It must be non-negative.
final double size;

/// The background color when the checkbox is on or mixed. If null,
/// [Style.activeColor] is used
final Color? activeColor;

/// The background color when the checkbox is disabled. [CupertinoColors.quaternaryLabel]
/// is used by default
final Color disabledColor;

/// The color of the border when the checkbox is off. [CupertinoColors.tertiaryLabel]
/// is used by default
final Color offBorderColor;

/// Whether the checkbox is mixed or not.
bool get isMixed => value == null;

/// Whether the checkbox is disabled or not.
bool get isDisabled => onChanged == null;

@override
Widget build(BuildContext context) {
assert(debugCheckHasMacosTheme(context));
bool isLight = context.macosTheme.brightness != Brightness.dark;
return GestureDetector(
onTap: () {
if (value == null || value == false) {
onChanged?.call(true);
} else {
onChanged?.call(false);
}
},
child: Container(
height: size,
width: size,
alignment: Alignment.center,
decoration: isDisabled || value == null || value == true
? BoxDecoration(
color: CupertinoDynamicColor.resolve(
isDisabled
? disabledColor
: activeColor ??
context.macosTheme.primaryColor ??
CupertinoColors.activeBlue,
context,
),
borderRadius: BorderRadius.circular(4.0),
)
: BoxDecoration(
color: isLight ? null : CupertinoColors.tertiaryLabel,
border: Border.all(
style: isLight ? BorderStyle.solid : BorderStyle.none,
width: 0.5,
color: CupertinoDynamicColor.resolve(
offBorderColor,
context,
),
),
borderRadius: BorderRadius.circular(4.0),
),
child: Icon(
isDisabled
? null
: isMixed
? CupertinoIcons.minus
: value == false
? null
: CupertinoIcons.check_mark,
color: CupertinoColors.white,
size: (size - 3).clamp(0, size),
),
),
);
}
}