Skip to content

Commit

Permalink
fix(color_slim_widget.dart): Implement color slim widget
Browse files Browse the repository at this point in the history
  • Loading branch information
rlperez committed Apr 20, 2022
1 parent 23b0775 commit 5509ded
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 21 deletions.
46 changes: 45 additions & 1 deletion lib/traits/slim/color_slim_widget.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
import 'package:bootstrap_icons/bootstrap_icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
import 'package:yonomi_device_widgets/assets/traits/unknown_item_icon.dart';
import 'package:yonomi_device_widgets/providers/color_provider.dart';
import 'package:yonomi_device_widgets/traits/slim/base_slim_widget.dart';
import 'package:yonomi_device_widgets/ui/widget_style_constants.dart';
import 'package:yonomi_platform_sdk/third_party/yonomi_graphql_schema/schema.docs.schema.gql.dart';
import 'package:yonomi_platform_sdk/yonomi-sdk.dart';

class ColorSlimWidget extends BaseSlimWidget {
ColorSlimWidget(ColorProvider _colorTraitProvider)
: super(
provider: _colorTraitProvider,
leftIcon: UnknownItemIcon(),
headerText: Text('Color'));
headerText: Text('Color'),
rightIcon: TextButton(
onPressed: () {
final pickedColor = _colorTraitProvider.getColorState;
SlidePicker(
pickerColor: _hsbToColor(pickedColor),
onColorChanged: (color) {
final calculatedColor = HSVColor.fromColor(color);
_colorTraitProvider.setColorAction(HSBColor(
calculatedColor.hue.toInt(),
(calculatedColor.saturation * 100).toInt(),
(calculatedColor.value * 100).toInt()));
},
colorModel: ColorModel.hsv,
);
},
child: Row(
children: [
CircleAvatar(
backgroundColor:
_hsbToColor(_colorTraitProvider.getColorState),
radius: 14,
),
Icon(
BootstrapIcons.pencil,
color: WidgetStyleConstants.globalSuccessColor,
size: 14.0,
)
],
)));

static Color _hsbToColor(GHSBColorValueInput? hsbColor) {
if (hsbColor == null) {
return Colors.transparent;
} else {
return HSVColor.fromAHSV(1.0, hsbColor.h.toDouble(), hsbColor.s / 100.0,
hsbColor.b / 100.0)
.toColor();
}
}
}
57 changes: 37 additions & 20 deletions test/mixins/color_testing.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
// in yonomi_device_widgets/test/mixins/color_testing.dart.
// Do not manually edit this file.

import 'dart:async' as _i4;
import 'dart:ui' as _i7;
import 'dart:async' as _i6;
import 'dart:ui' as _i8;

import 'package:mockito/mockito.dart' as _i1;
import 'package:yonomi_device_widgets/providers/color_provider.dart' as _i2;
import 'package:yonomi_device_widgets/providers/device_provider.dart' as _i5;
import 'package:yonomi_device_widgets/providers/widget_state.dart' as _i3;
import 'package:yonomi_device_widgets/providers/color_provider.dart' as _i3;
import 'package:yonomi_device_widgets/providers/device_provider.dart' as _i4;
import 'package:yonomi_device_widgets/providers/widget_state.dart' as _i5;
import 'package:yonomi_platform_sdk/src/repository/devices_repository.dart'
as _i6;
as _i7;
import 'package:yonomi_platform_sdk/yonomi-sdk.dart' as _i2;

// ignore_for_file: avoid_redundant_argument_values
// ignore_for_file: avoid_setters_without_getters
Expand All @@ -20,22 +21,33 @@ import 'package:yonomi_platform_sdk/src/repository/devices_repository.dart'
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis

class _FakeDevice_0 extends _i1.Fake implements _i2.Device {}

/// A class which mocks [ColorProvider].
///
/// See the documentation for Mockito's code generation for more information.
class MockColorProvider extends _i1.Mock implements _i2.ColorProvider {
class MockColorProvider extends _i1.Mock implements _i3.ColorProvider {
MockColorProvider() {
_i1.throwOnMissingStub(this);
}

@override
_i4.GetDeviceDetailsMethod get getDetails =>
(super.noSuchMethod(Invocation.getter(#getDetails),
returnValue: (_i2.Request request, String id) =>
Future<_i2.Device>.value(_FakeDevice_0()))
as _i4.GetDeviceDetailsMethod);
@override
_i3.SendSetColorActionFunction get sendSetColorAction => (super.noSuchMethod(
Invocation.getter(#sendSetColorAction),
returnValue: (_i2.Request request, String id, _i2.HSBColor hsbColor) =>
Future<void>.value()) as _i3.SendSetColorActionFunction);
@override
String get displayName =>
(super.noSuchMethod(Invocation.getter(#displayName), returnValue: '')
as String);

get getColorState => null;
@override
set setState(_i3.WidgetState? newState) =>
set setState(_i5.WidgetState? newState) =>
super.noSuchMethod(Invocation.setter(#setState, newState),
returnValueForMissingStub: null);
@override
Expand Down Expand Up @@ -63,33 +75,38 @@ class MockColorProvider extends _i1.Mock implements _i2.ColorProvider {
(super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false)
as bool);
@override
_i4.Future<void> fetchData(
{_i5.GetDeviceDetailsMethod? getDetails =
_i6.DevicesRepository.getDeviceDetails}) =>
_i6.Future<void> setColorAction(_i2.HSBColor? color) =>
(super.noSuchMethod(Invocation.method(#setColorAction, [color]),
returnValue: Future<void>.value(),
returnValueForMissingStub: Future<void>.value()) as _i6.Future<void>);
@override
_i6.Future<void> fetchData(
{_i4.GetDeviceDetailsMethod? getDetails =
_i7.DevicesRepository.getDeviceDetails}) =>
(super.noSuchMethod(
Invocation.method(#fetchData, [], {#getDetails: getDetails}),
returnValue: Future<void>.value(),
returnValueForMissingStub: Future<void>.value()) as _i4.Future<void>);
returnValueForMissingStub: Future<void>.value()) as _i6.Future<void>);
@override
void setErrorState(String? errorMsg) =>
super.noSuchMethod(Invocation.method(#setErrorState, [errorMsg]),
returnValueForMissingStub: null);
@override
_i4.Future<void> performAction<T>(
_i6.Future<void> performAction<T>(
T? desiredState, Function? getState, Function? action,
{_i5.GetDeviceDetailsMethod? getDetails =
_i6.DevicesRepository.getDeviceDetails}) =>
{_i4.GetDeviceDetailsMethod? getDetails =
_i7.DevicesRepository.getDeviceDetails}) =>
(super.noSuchMethod(
Invocation.method(#performAction, [desiredState, getState, action],
{#getDetails: getDetails}),
returnValue: Future<void>.value(),
returnValueForMissingStub: Future<void>.value()) as _i4.Future<void>);
returnValueForMissingStub: Future<void>.value()) as _i6.Future<void>);
@override
void addListener(_i7.VoidCallback? listener) =>
void addListener(_i8.VoidCallback? listener) =>
super.noSuchMethod(Invocation.method(#addListener, [listener]),
returnValueForMissingStub: null);
@override
void removeListener(_i7.VoidCallback? listener) =>
void removeListener(_i8.VoidCallback? listener) =>
super.noSuchMethod(Invocation.method(#removeListener, [listener]),
returnValueForMissingStub: null);
@override
Expand Down

0 comments on commit 5509ded

Please sign in to comment.