-
-
Notifications
You must be signed in to change notification settings - Fork 200
Implemented checkbox #24
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,3 +44,5 @@ app.*.map.json | |
| /android/app/debug | ||
| /android/app/profile | ||
| /android/app/release | ||
|
|
||
| /windows/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,5 +18,3 @@ dependencies: | |
| dev_dependencies: | ||
| flutter_test: | ||
| sdk: flutter | ||
|
|
||
| flutter: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.