Skip to content

Commit

Permalink
PAINTROID-454: Flutter: Add Layers - add image to layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenkomotive committed Oct 19, 2024
1 parent 8190c03 commit 4eec72b
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 42 deletions.
2 changes: 1 addition & 1 deletion lib/core/providers/state/layer_menu_state_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ part 'layer_menu_state_data.freezed.dart';
class LayerMenuStateData with _$LayerMenuStateData {
const factory LayerMenuStateData({
required bool isVisible,
required List<LayerStateData> layer,
required List<LayerStateData> layers,
}) = _LayerMenuStateData;
}
43 changes: 18 additions & 25 deletions lib/core/providers/state/layer_menu_state_data.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ final _privateConstructorUsedError = UnsupportedError(
/// @nodoc
mixin _$LayerMenuStateData {
bool get isVisible => throw _privateConstructorUsedError;

List<LayerStateData> get layers => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
Expand All @@ -30,9 +29,8 @@ abstract class $LayerMenuStateDataCopyWith<$Res> {
factory $LayerMenuStateDataCopyWith(
LayerMenuStateData value, $Res Function(LayerMenuStateData) then) =
_$LayerMenuStateDataCopyWithImpl<$Res, LayerMenuStateData>;

@useResult
$Res call({bool isVisible, List<LayerStateData> layer});
$Res call({bool isVisible, List<LayerStateData> layers});
}

/// @nodoc
Expand All @@ -42,24 +40,23 @@ class _$LayerMenuStateDataCopyWithImpl<$Res, $Val extends LayerMenuStateData>

// ignore: unused_field
final $Val _value;

// ignore: unused_field
final $Res Function($Val) _then;

@pragma('vm:prefer-inline')
@override
$Res call({
Object? isVisible = null,
Object? layer = null,
Object? layers = null,
}) {
return _then(_value.copyWith(
isVisible: null == isVisible
? _value.isVisible
: isVisible // ignore: cast_nullable_to_non_nullable
as bool,
layer: null == layer
layers: null == layers
? _value.layers
: layer // ignore: cast_nullable_to_non_nullable
: layers // ignore: cast_nullable_to_non_nullable
as List<LayerStateData>,
) as $Val);
}
Expand All @@ -71,10 +68,9 @@ abstract class _$$LayerMenuStateDataImplCopyWith<$Res>
factory _$$LayerMenuStateDataImplCopyWith(_$LayerMenuStateDataImpl value,
$Res Function(_$LayerMenuStateDataImpl) then) =
__$$LayerMenuStateDataImplCopyWithImpl<$Res>;

@override
@useResult
$Res call({bool isVisible, List<LayerStateData> layer});
$Res call({bool isVisible, List<LayerStateData> layers});
}

/// @nodoc
Expand All @@ -89,16 +85,16 @@ class __$$LayerMenuStateDataImplCopyWithImpl<$Res>
@override
$Res call({
Object? isVisible = null,
Object? layer = null,
Object? layers = null,
}) {
return _then(_$LayerMenuStateDataImpl(
isVisible: null == isVisible
? _value.isVisible
: isVisible // ignore: cast_nullable_to_non_nullable
as bool,
layer: null == layer
? _value._layer
: layer // ignore: cast_nullable_to_non_nullable
layers: null == layers
? _value._layers
: layers // ignore: cast_nullable_to_non_nullable
as List<LayerStateData>,
));
}
Expand All @@ -108,23 +104,22 @@ class __$$LayerMenuStateDataImplCopyWithImpl<$Res>
class _$LayerMenuStateDataImpl implements _LayerMenuStateData {
const _$LayerMenuStateDataImpl(
{required this.isVisible, required final List<LayerStateData> layer})
: _layer = layer;
{required this.isVisible, required final List<LayerStateData> layers})
: _layers = layers;

@override
final bool isVisible;
final List<LayerStateData> _layer;

final List<LayerStateData> _layers;
@override
List<LayerStateData> get layers {
if (_layer is EqualUnmodifiableListView) return _layer;
if (_layers is EqualUnmodifiableListView) return _layers;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_layer);
return EqualUnmodifiableListView(_layers);
}

@override
String toString() {
return 'LayerMenuStateData(isVisible: $isVisible, layer: $layers)';
return 'LayerMenuStateData(isVisible: $isVisible, layers: $layers)';
}

@override
Expand All @@ -134,12 +129,12 @@ class _$LayerMenuStateDataImpl implements _LayerMenuStateData {
other is _$LayerMenuStateDataImpl &&
(identical(other.isVisible, isVisible) ||
other.isVisible == isVisible) &&
const DeepCollectionEquality().equals(other._layer, _layer));
const DeepCollectionEquality().equals(other._layers, _layers));
}

@override
int get hashCode => Object.hash(
runtimeType, isVisible, const DeepCollectionEquality().hash(_layer));
runtimeType, isVisible, const DeepCollectionEquality().hash(_layers));

@JsonKey(ignore: true)
@override
Expand All @@ -152,14 +147,12 @@ class _$LayerMenuStateDataImpl implements _LayerMenuStateData {
abstract class _LayerMenuStateData implements LayerMenuStateData {
const factory _LayerMenuStateData(
{required final bool isVisible,
required final List<LayerStateData> layer}) = _$LayerMenuStateDataImpl;
required final List<LayerStateData> layers}) = _$LayerMenuStateDataImpl;

@override
bool get isVisible;

@override
List<LayerStateData> get layers;

@override
@JsonKey(ignore: true)
_$$LayerMenuStateDataImplCopyWith<_$LayerMenuStateDataImpl> get copyWith =>
Expand Down
14 changes: 7 additions & 7 deletions lib/core/providers/state/layer_menu_state_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LayerMenuStateProvider extends _$LayerMenuStateProvider {
LayerMenuStateData build() {
return LayerMenuStateData(
isVisible: false,
layer: [
layers: [
LayerStateData(
key: ValueKey(uuid.v4()),
isSelected: true,
Expand All @@ -37,7 +37,7 @@ class LayerMenuStateProvider extends _$LayerMenuStateProvider {
}
final movedLayer = layerList.removeAt(oldIndex);
layerList.insert(newIndex, movedLayer);
state = state.copyWith(layer: layerList);
state = state.copyWith(layers: layerList);
}

void toggleSelection(Key? layerKey) {
Expand All @@ -48,7 +48,7 @@ class LayerMenuStateProvider extends _$LayerMenuStateProvider {
return layer.copyWith(isSelected: false);
}).toList();

state = state.copyWith(layer: updatedLayerList);
state = state.copyWith(layers: updatedLayerList);
}

void toggleLayerVisibility(Key? layerKey) {
Expand All @@ -58,7 +58,7 @@ class LayerMenuStateProvider extends _$LayerMenuStateProvider {
}
return layer;
}).toList();
state = state.copyWith(layer: updatedLayerList);
state = state.copyWith(layers: updatedLayerList);
}

void updateLayerOpacity(Key? layerKey, double opacity) {
Expand All @@ -68,7 +68,7 @@ class LayerMenuStateProvider extends _$LayerMenuStateProvider {
}
return layer;
}).toList();
state = state.copyWith(layer: updatedLayerList);
state = state.copyWith(layers: updatedLayerList);
}

void addLayer() {
Expand All @@ -83,7 +83,7 @@ class LayerMenuStateProvider extends _$LayerMenuStateProvider {
opacity: 1.0,
);
updatedLayerList.add(newLayer);
state = state.copyWith(layer: updatedLayerList);
state = state.copyWith(layers: updatedLayerList);
}

void deleteLayer() {
Expand All @@ -94,6 +94,6 @@ class LayerMenuStateProvider extends _$LayerMenuStateProvider {
updatedLayerList[lastIndex] =
updatedLayerList[lastIndex].copyWith(isSelected: true);

state = state.copyWith(layer: updatedLayerList);
state = state.copyWith(layers: updatedLayerList);
}
}
2 changes: 1 addition & 1 deletion lib/core/providers/state/layer_menu_state_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/core/providers/state/layer_state_data.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:ui' as ui;

import 'package:flutter/cupertino.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

Expand All @@ -11,5 +13,6 @@ class LayerStateData with _$LayerStateData {
required bool isSelected,
required bool isVisible,
required double opacity,
ui.Image? image,
}) = _LayerStateData;
}
40 changes: 33 additions & 7 deletions lib/core/providers/state/layer_state_data.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mixin _$LayerStateData {
bool get isSelected => throw _privateConstructorUsedError;
bool get isVisible => throw _privateConstructorUsedError;
double get opacity => throw _privateConstructorUsedError;
ui.Image? get image => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
$LayerStateDataCopyWith<LayerStateData> get copyWith =>
Expand All @@ -33,7 +34,11 @@ abstract class $LayerStateDataCopyWith<$Res> {
_$LayerStateDataCopyWithImpl<$Res, LayerStateData>;
@useResult
$Res call(
{ValueKey<dynamic> key, bool isSelected, bool isVisible, double opacity});
{ValueKey<dynamic> key,
bool isSelected,
bool isVisible,
double opacity,
ui.Image? image});
}

/// @nodoc
Expand All @@ -53,6 +58,7 @@ class _$LayerStateDataCopyWithImpl<$Res, $Val extends LayerStateData>
Object? isSelected = null,
Object? isVisible = null,
Object? opacity = null,
Object? image = freezed,
}) {
return _then(_value.copyWith(
key: null == key
Expand All @@ -71,6 +77,10 @@ class _$LayerStateDataCopyWithImpl<$Res, $Val extends LayerStateData>
? _value.opacity
: opacity // ignore: cast_nullable_to_non_nullable
as double,
image: freezed == image
? _value.image
: image // ignore: cast_nullable_to_non_nullable
as ui.Image?,
) as $Val);
}
}
Expand All @@ -84,7 +94,11 @@ abstract class _$$LayerStateDataImplCopyWith<$Res>
@override
@useResult
$Res call(
{ValueKey<dynamic> key, bool isSelected, bool isVisible, double opacity});
{ValueKey<dynamic> key,
bool isSelected,
bool isVisible,
double opacity,
ui.Image? image});
}

/// @nodoc
Expand All @@ -102,6 +116,7 @@ class __$$LayerStateDataImplCopyWithImpl<$Res>
Object? isSelected = null,
Object? isVisible = null,
Object? opacity = null,
Object? image = freezed,
}) {
return _then(_$LayerStateDataImpl(
key: null == key
Expand All @@ -120,6 +135,10 @@ class __$$LayerStateDataImplCopyWithImpl<$Res>
? _value.opacity
: opacity // ignore: cast_nullable_to_non_nullable
as double,
image: freezed == image
? _value.image
: image // ignore: cast_nullable_to_non_nullable
as ui.Image?,
));
}
}
Expand All @@ -131,7 +150,8 @@ class _$LayerStateDataImpl implements _LayerStateData {
{required this.key,
required this.isSelected,
required this.isVisible,
required this.opacity});
required this.opacity,
this.image});

@override
final ValueKey<dynamic> key;
Expand All @@ -141,10 +161,12 @@ class _$LayerStateDataImpl implements _LayerStateData {
final bool isVisible;
@override
final double opacity;
@override
final ui.Image? image;

@override
String toString() {
return 'LayerStateData(key: $key, isSelected: $isSelected, isVisible: $isVisible, opacity: $opacity)';
return 'LayerStateData(key: $key, isSelected: $isSelected, isVisible: $isVisible, opacity: $opacity, image: $image)';
}

@override
Expand All @@ -157,12 +179,13 @@ class _$LayerStateDataImpl implements _LayerStateData {
other.isSelected == isSelected) &&
(identical(other.isVisible, isVisible) ||
other.isVisible == isVisible) &&
(identical(other.opacity, opacity) || other.opacity == opacity));
(identical(other.opacity, opacity) || other.opacity == opacity) &&
(identical(other.image, image) || other.image == image));
}

@override
int get hashCode =>
Object.hash(runtimeType, key, isSelected, isVisible, opacity);
Object.hash(runtimeType, key, isSelected, isVisible, opacity, image);

@JsonKey(ignore: true)
@override
Expand All @@ -177,7 +200,8 @@ abstract class _LayerStateData implements LayerStateData {
{required final ValueKey<dynamic> key,
required final bool isSelected,
required final bool isVisible,
required final double opacity}) = _$LayerStateDataImpl;
required final double opacity,
final ui.Image? image}) = _$LayerStateDataImpl;

@override
ValueKey<dynamic> get key;
Expand All @@ -188,6 +212,8 @@ abstract class _LayerStateData implements LayerStateData {
@override
double get opacity;
@override
ui.Image? get image;
@override
@JsonKey(ignore: true)
_$$LayerStateDataImplCopyWith<_$LayerStateDataImpl> get copyWith =>
throw _privateConstructorUsedError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Layer extends ConsumerWidget {
child: Text(
key.toString(),
textAlign: TextAlign.center,
style: TextStyle(
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
Expand Down

0 comments on commit 4eec72b

Please sign in to comment.