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

Inertia on Camera first pass, file cleanup #8

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 11 additions & 5 deletions example/flutter_colorpicker-1.1.0/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ class _MyAppState extends State<MyApp> {
List<Color> colorHistory = [];

void changeColor(Color color) => setState(() => currentColor = color);
void changeColors(List<Color> colors) => setState(() => currentColors = colors);
void changeColors(List<Color> colors) =>
setState(() => currentColors = colors);

@override
Widget build(BuildContext context) {
final foregroundColor = useWhiteForeground(currentColor) ? Colors.white : Colors.black;
final foregroundColor =
useWhiteForeground(currentColor) ? Colors.white : Colors.black;
return AnimatedTheme(
data: lightTheme ? ThemeData.light() : ThemeData.dark(),
child: Builder(builder: (context) {
Expand All @@ -33,7 +35,9 @@ class _MyAppState extends State<MyApp> {
child: Scaffold(
floatingActionButton: FloatingActionButton.extended(
onPressed: () => setState(() => lightTheme = !lightTheme),
icon: Icon(lightTheme ? Icons.dark_mode_rounded : Icons.light_mode_rounded),
icon: Icon(lightTheme
? Icons.dark_mode_rounded
: Icons.light_mode_rounded),
label: Text(lightTheme ? 'Night' : ' Day '),
backgroundColor: currentColor,
foregroundColor: foregroundColor,
Expand All @@ -58,9 +62,11 @@ class _MyAppState extends State<MyApp> {
pickerColor: currentColor,
onColorChanged: changeColor,
colorHistory: colorHistory,
onHistoryChanged: (List<Color> colors) => colorHistory = colors,
onHistoryChanged: (List<Color> colors) =>
colorHistory = colors,
),
MaterialColorPickerExample(pickerColor: currentColor, onColorChanged: changeColor),
MaterialColorPickerExample(
pickerColor: currentColor, onColorChanged: changeColor),
BlockColorPickerExample(
pickerColor: currentColor,
onColorChanged: changeColor,
Expand Down
41 changes: 30 additions & 11 deletions example/flutter_colorpicker-1.1.0/lib/src/block_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import 'utils.dart';
typedef PickerItem = Widget Function(Color color);

/// Customize the layout.
typedef PickerLayoutBuilder = Widget Function(BuildContext context, List<Color> colors, PickerItem child);
typedef PickerLayoutBuilder = Widget Function(
BuildContext context, List<Color> colors, PickerItem child);

/// Customize the item shape.
typedef PickerItemBuilder = Widget Function(Color color, bool isCurrentColor, void Function() changeColor);
typedef PickerItemBuilder = Widget Function(
Color color, bool isCurrentColor, void Function() changeColor);

// Provide a list of colors for block color picker.
const List<Color> _defaultColors = [
Expand All @@ -39,7 +41,8 @@ const List<Color> _defaultColors = [
];

// Provide a layout for [BlockPicker].
Widget _defaultLayoutBuilder(BuildContext context, List<Color> colors, PickerItem child) {
Widget _defaultLayoutBuilder(
BuildContext context, List<Color> colors, PickerItem child) {
Orientation orientation = MediaQuery.of(context).orientation;

return SizedBox(
Expand All @@ -55,13 +58,19 @@ Widget _defaultLayoutBuilder(BuildContext context, List<Color> colors, PickerIte
}

// Provide a shape for [BlockPicker].
Widget _defaultItemBuilder(Color color, bool isCurrentColor, void Function() changeColor) {
Widget _defaultItemBuilder(
Color color, bool isCurrentColor, void Function() changeColor) {
return Container(
margin: const EdgeInsets.all(7),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: color,
boxShadow: [BoxShadow(color: color.withOpacity(0.8), offset: const Offset(1, 2), blurRadius: 5)],
boxShadow: [
BoxShadow(
color: color.withOpacity(0.8),
offset: const Offset(1, 2),
blurRadius: 5)
],
),
child: Material(
color: Colors.transparent,
Expand All @@ -71,7 +80,8 @@ Widget _defaultItemBuilder(Color color, bool isCurrentColor, void Function() cha
child: AnimatedOpacity(
duration: const Duration(milliseconds: 210),
opacity: isCurrentColor ? 1 : 0,
child: Icon(Icons.done, color: useWhiteForeground(color) ? Colors.white : Colors.black),
child: Icon(Icons.done,
color: useWhiteForeground(color) ? Colors.white : Colors.black),
),
),
),
Expand Down Expand Up @@ -122,9 +132,12 @@ class _BlockPickerState extends State<BlockPicker> {
widget.availableColors,
(Color color) => widget.itemBuilder(
color,
(_currentColor != null && (widget.useInShowDialog ? true : widget.pickerColor != null))
(_currentColor != null &&
(widget.useInShowDialog ? true : widget.pickerColor != null))
? (_currentColor?.value == color.value) &&
(widget.useInShowDialog ? true : widget.pickerColor?.value == color.value)
(widget.useInShowDialog
? true
: widget.pickerColor?.value == color.value)
: false,
() => changeColor(color),
),
Expand Down Expand Up @@ -167,7 +180,9 @@ class _MultipleChoiceBlockPickerState extends State<MultipleChoiceBlockPicker> {
void toggleColor(Color color) {
setState(() {
if (_currentColors != null) {
_currentColors!.contains(color) ? _currentColors!.remove(color) : _currentColors!.add(color);
_currentColors!.contains(color)
? _currentColors!.remove(color)
: _currentColors!.add(color);
}
});
widget.onColorsChanged(_currentColors ?? []);
Expand All @@ -180,8 +195,12 @@ class _MultipleChoiceBlockPickerState extends State<MultipleChoiceBlockPicker> {
widget.availableColors,
(Color color) => widget.itemBuilder(
color,
(_currentColors != null && (widget.useInShowDialog ? true : widget.pickerColors != null))
? _currentColors!.contains(color) && (widget.useInShowDialog ? true : widget.pickerColors!.contains(color))
(_currentColors != null &&
(widget.useInShowDialog ? true : widget.pickerColors != null))
? _currentColors!.contains(color) &&
(widget.useInShowDialog
? true
: widget.pickerColors!.contains(color))
: false,
() => toggleColor(color),
),
Expand Down
Loading