Skip to content

Commit

Permalink
Implements ColorPicker (#1152)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa authored Dec 13, 2024
2 parents a5d30f9 + 970a7e5 commit 61c3fa0
Show file tree
Hide file tree
Showing 10 changed files with 3,030 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [next]

- feat: Add `ColorPicker` ([#1001](https://github.com/bdlukaa/fluent_ui/issues/1001)
- fix: Add missing properties (`closeIconSize`, `closeButtonStyle`) in `debugFillProperties` and `InfoBarThemeData.merge` ([#1128](https://github.com/bdlukaa/fluent_ui/issues/1128)
- feat: Add `TabView.reservedStripWidth`, which adds a minimum empty area between the tabs and the tab view footer ([#1106](https://github.com/bdlukaa/fluent_ui/issues/1106))]
- fix: Correctly unfocus `NumberBox` when user taps outside ([#1135](https://github.com/bdlukaa/fluent_ui/issues/1135))
Expand Down
15 changes: 15 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ class _MyHomePageState extends State<MyHomePage> with WindowListener {
title: const Text('DatePicker'),
body: const SizedBox.shrink(),
),
PaneItem(
key: const ValueKey('/forms/color_picker'),
icon: const Icon(FluentIcons.color),
title: const Text('ColorPicker'),
body: const SizedBox.shrink(),
),
PaneItemHeader(header: const Text('Navigation')),
PaneItem(
key: const ValueKey('/navigation/navigation_view'),
Expand Down Expand Up @@ -818,6 +824,15 @@ final router = GoRouter(navigatorKey: rootNavigatorKey, routes: [
),
),

/// ColorPicker
GoRoute(
path: '/forms/color_picker',
builder: (context, state) => DeferredWidget(
forms.loadLibrary,
() => forms.ColorPickerPage(),
),
),

/// /// Navigation
/// NavigationView
GoRoute(
Expand Down
1 change: 1 addition & 0 deletions example/lib/routes/forms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export '../screens/forms/password_box.dart';
export '../screens/forms/date_picker.dart';
export '../screens/forms/text_box.dart';
export '../screens/forms/time_picker.dart';
export '../screens/forms/color_picker.dart';
222 changes: 222 additions & 0 deletions example/lib/screens/forms/color_picker.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
import 'package:example/widgets/card_highlight.dart';
import 'package:example/widgets/page.dart';
import 'package:fluent_ui/fluent_ui.dart';

class ColorPickerPage extends StatefulWidget {
const ColorPickerPage({super.key});

@override
State<ColorPickerPage> createState() => _ColorPickerPageState();
}

class _ColorPickerPageState extends State<ColorPickerPage> with PageMixin {
Color _selectedColor = Colors.blue;
bool _isMoreButtonVisible = false;
bool _isColorSliderVisible = true;
bool _isColorChannelTextInputVisible = true;
bool _isHexInputVisible = true;
bool _isAlphaEnabled = false;
bool _isAlphaSliderVisible = false;
bool _isAlphaTextInputVisible = false;
bool _isColorPreviewVisible = true;
ColorSpectrumShape _spectrumShape = ColorSpectrumShape.box;
Axis _orientation = Axis.vertical;

@override
Widget build(BuildContext context) {
return ScaffoldPage.scrollable(
header: PageHeader(
title: const Text('ColorPicker'),
commandBar: Button(
onPressed: () => setState(() {
_selectedColor = Colors.red;
_isMoreButtonVisible = false;
_isColorSliderVisible = true;
_isColorChannelTextInputVisible = true;
_isHexInputVisible = true;
_isAlphaEnabled = false;
_isAlphaSliderVisible = false;
_isAlphaTextInputVisible = false;
_isColorPreviewVisible = true;
_spectrumShape = ColorSpectrumShape.box;
_orientation = Axis.vertical;
}),
child: const Text('Reset'),
),
),
children: [
const Text(
'A ColorPicker control lets users select a color using a color spectrum, '
'sliders, and text input. It includes RGB (Red, Green, Blue) and HSV '
'(Hue, Saturation, Value) color representations.\n\n'
'The ColorPicker includes two spectrum shapes (box and ring) and several '
'optional components that can be shown or hidden.',
),
const SizedBox(height: 20),
// Options
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Spectrum Shape:',
style: FluentTheme.of(context).typography.bodyStrong),
const SizedBox(height: 8),
Row(children: [
RadioButton(
checked: _spectrumShape == ColorSpectrumShape.box,
onChanged: (v) {
if (v) {
setState(() => _spectrumShape = ColorSpectrumShape.box);
}
},
content: const Text('Box'),
),
const SizedBox(width: 20),
RadioButton(
checked: _spectrumShape == ColorSpectrumShape.ring,
onChanged: (v) {
if (v) {
setState(() => _spectrumShape = ColorSpectrumShape.ring);
}
},
content: const Text('Ring'),
),
]),
const SizedBox(height: 20),
Text('Layout:',
style: FluentTheme.of(context).typography.bodyStrong),
const SizedBox(height: 8),
Row(children: [
RadioButton(
checked: _orientation == Axis.vertical,
onChanged: (v) {
if (v) setState(() => _orientation = Axis.vertical);
},
content: const Text('Vertical'),
),
const SizedBox(width: 20),
RadioButton(
checked: _orientation == Axis.horizontal,
onChanged: (v) {
if (v) setState(() => _orientation = Axis.horizontal);
},
content: const Text('Horizontal'),
),
]),
const SizedBox(height: 20),
Text('Options:',
style: FluentTheme.of(context).typography.bodyStrong),
const SizedBox(height: 8),
Wrap(
spacing: 10,
runSpacing: 10,
children: [
Checkbox(
checked: _isColorPreviewVisible,
onChanged: (v) => setState(() => _isColorPreviewVisible = v!),
content: const Text('Color Preview'),
),
Checkbox(
checked: _isColorSliderVisible,
onChanged: (v) => setState(() => _isColorSliderVisible = v!),
content: const Text('Color Slider'),
),
if (_orientation == Axis.vertical) ...[
Checkbox(
checked: _isMoreButtonVisible,
onChanged: (v) => setState(() => _isMoreButtonVisible = v!),
content: const Text('More Button'),
),
],
Checkbox(
checked: _isColorChannelTextInputVisible,
onChanged: (v) =>
setState(() => _isColorChannelTextInputVisible = v!),
content: const Text('Channel Text Input'),
),
Checkbox(
checked: _isHexInputVisible,
onChanged: (v) => setState(() => _isHexInputVisible = v!),
content: const Text('Hex Input'),
),
],
),
const SizedBox(height: 12),
Wrap(
spacing: 10,
runSpacing: 10,
children: [
Checkbox(
checked: _isAlphaEnabled,
onChanged: (v) => setState(() {
_isAlphaEnabled = v!;
if (!v) {
_isAlphaSliderVisible = false;
_isAlphaTextInputVisible = false;
}
}),
content: const Text('Alpha Enabled'),
),
if (_isAlphaEnabled) ...[
Checkbox(
checked: _isAlphaSliderVisible,
onChanged: (v) =>
setState(() => _isAlphaSliderVisible = v!),
content: const Text('Alpha Slider'),
),
Checkbox(
checked: _isAlphaTextInputVisible,
onChanged: (v) =>
setState(() => _isAlphaTextInputVisible = v!),
content: const Text('Alpha Text Input'),
),
],
],
),
const SizedBox(height: 20),
Text('Selected Color:',
style: FluentTheme.of(context).typography.bodyStrong),
const SizedBox(height: 8),
Container(
color: _selectedColor,
width: 200,
height: 50,
),
],
),
const SizedBox(height: 20),
subtitle(content: const Text('ColorPicker Demo')),
CardHighlight(
codeSnippet: '''Color selectedColor = Colors.blue;
ColorSpectrumShape spectrumShape = ColorSpectrumShape.box;
ColorPicker(
color: selectedColor,
onChanged: (color) => setState(() => selectedColor = color),
colorSpectrumShape: spectrumShape,
isMoreButtonVisible: true,
isColorSliderVisible: true,
isColorChannelTextInputVisible: true,
isHexInputVisible: true,
isAlphaEnabled: false,
),''',
child: Row(children: [
ColorPicker(
color: _selectedColor,
onChanged: (color) => setState(() => _selectedColor = color),
colorSpectrumShape: _spectrumShape,
orientation: _orientation,
isMoreButtonVisible: _isMoreButtonVisible,
isColorSliderVisible: _isColorSliderVisible,
isColorChannelTextInputVisible: _isColorChannelTextInputVisible,
isHexInputVisible: _isHexInputVisible,
isColorPreviewVisible: _isColorPreviewVisible,
isAlphaEnabled: _isAlphaEnabled,
isAlphaSliderVisible: _isAlphaSliderVisible,
isAlphaTextInputVisible: _isAlphaTextInputVisible,
),
]),
),
],
);
}
}
1 change: 1 addition & 0 deletions lib/fluent_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export 'src/controls/form/number_box.dart';
export 'src/controls/form/password_box.dart';
export 'src/controls/form/pickers/date_picker.dart';
export 'src/controls/form/pickers/time_picker.dart';
export 'src/controls/form/color_picker/color_picker.dart';
export 'src/controls/form/selection_controls.dart';
export 'src/controls/form/text_box.dart';
export 'src/controls/form/text_form_box.dart';
Expand Down
Loading

0 comments on commit 61c3fa0

Please sign in to comment.