-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Improve color display in M3 Demo #2438
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
37fa690
Add color schematic to m3_demo.
jwill b37c8df
Update scheme.dart
jwill 4e4d17b
Update color_screen_test.dart
jwill 8f388bc
Update scheme.dart
jwill 18e59e1
Update color_box.dart
jwill 49f2e3f
Merge branch 'flutter:main' into jwill_m3_demo
jwill 2332cd1
Rollback properties to stable version
jwill 2509a64
dart format per request
jwill 719ff25
remove m3 demo from master and beta CI
ericwindmill 4e0a897
Replaced vars with static types
jwill 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter/services.dart'; | ||
|
|
||
| class ColorBox extends StatefulWidget { | ||
| const ColorBox({ | ||
| super.key, | ||
| required this.label, | ||
| required this.tone, | ||
| required this.color, | ||
| required this.onColor, | ||
| required this.height, | ||
| required this.width, | ||
| this.displayPaletteInfo = false | ||
| }); | ||
|
|
||
| final String label; | ||
| final String tone; | ||
| final Color color, onColor; | ||
| final double height, width; | ||
| final bool displayPaletteInfo; | ||
|
|
||
| @override | ||
| State<ColorBox> createState() => _ColorBoxState(); | ||
| } | ||
|
|
||
| class _ColorBoxState extends State<ColorBox> { | ||
| bool hovered = false; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| final fonts = Theme.of(context).textTheme; | ||
| return MouseRegion( | ||
| onEnter: (_) { | ||
| if (mounted) setState(() => hovered = true); | ||
| }, | ||
| onExit: (_) { | ||
| if (mounted) setState(() => hovered = false); | ||
| }, | ||
| child: Container( | ||
| color: widget.color, | ||
| height: widget.height, | ||
| width: widget.width, | ||
| child: DefaultTextStyle( | ||
| style: fonts.labelSmall!.copyWith(color: widget.onColor), | ||
| child: Stack( | ||
| children: [ | ||
| Positioned( | ||
| top: 10, | ||
| left: 10, | ||
| child: Text(widget.label), | ||
| ), | ||
| Positioned( | ||
| bottom: 10, | ||
| right: 10, | ||
| child: Text(widget.displayPaletteInfo ? widget.tone : ''), | ||
| ), | ||
| if (hovered) | ||
| Positioned( | ||
| top: 0, | ||
| right: 0, | ||
| child: IconButton( | ||
| padding: EdgeInsets.zero, | ||
| color: widget.onColor, | ||
| tooltip: 'Copy hex color', | ||
| icon: const Icon(Icons.copy, size:24), | ||
| onPressed: () async { | ||
| final messenger = ScaffoldMessenger.of(context); | ||
| // Copy color as hex to clipboard | ||
| var hex = '#'; | ||
| final c = widget.color; | ||
| // Will change from int 0-255 to double 0.0-1.0 in 3.26+ | ||
| // The properties also change from red/green/blue to r/g/b | ||
| // hex += (c.[r g b] * 255.0).round().toRadixString(16).padLeft(2, '0'); | ||
| hex += c.red.toRadixString(16).padLeft(2, '0'); | ||
| hex += c.green.toRadixString(16).padLeft(2, '0'); | ||
| hex += c.blue.toRadixString(16).padLeft(2, '0'); | ||
| final data = ClipboardData(text: hex); | ||
| await Clipboard.setData(data); | ||
| messenger.hideCurrentSnackBar(); | ||
| messenger.showSnackBar( | ||
| SnackBar( | ||
| content: Text('Copied $hex to clipboard'), | ||
| ), | ||
| ); | ||
| }, | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.