From fc4458f5cc994b3bdee84bf74d29f634bcd524d9 Mon Sep 17 00:00:00 2001 From: Johann Schramm <43448334+JohannSchramm@users.noreply.github.com> Date: Wed, 25 Feb 2026 15:50:30 +0100 Subject: [PATCH 1/3] chore: Update packages --- pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 08ef6a8..4e7e248 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ environment: dependencies: flutter: sdk: flutter - freezed_annotation: ">=2.4.1 <3.0.0" + freezed_annotation: ^3.1.0 perfect_freehand: ^2.3.2 simpli: ^0.1.1 value_notifier_tools: ^0.1.2 @@ -21,7 +21,7 @@ dev_dependencies: build_runner: ^2.4.9 flutter_test: sdk: flutter - freezed: ^2.4.7 + freezed: ^3.2.5 json_serializable: ^6.9.5 lintervention: ^0.3.1 melos: ^6.3.3 From 336a19d8c290152818dcfb06b53fbaeb415ae726 Mon Sep 17 00:00:00 2001 From: Johann Schramm <43448334+JohannSchramm@users.noreply.github.com> Date: Wed, 25 Feb 2026 15:51:24 +0100 Subject: [PATCH 2/3] chore: Update freezed models for freezed 3 --- lib/src/domain/model/point/point.dart | 2 +- lib/src/domain/model/point/point.freezed.dart | 350 +++-- lib/src/domain/model/point/point.g.dart | 5 +- lib/src/domain/model/sketch/sketch.dart | 2 +- .../domain/model/sketch/sketch.freezed.dart | 314 +++-- lib/src/domain/model/sketch/sketch.g.dart | 5 +- .../domain/model/sketch_line/sketch_line.dart | 2 +- .../sketch_line/sketch_line.freezed.dart | 358 +++-- .../model/sketch_line/sketch_line.g.dart | 5 +- .../view/state/scribble.state.freezed.dart | 1183 ++++++++--------- lib/src/view/state/scribble.state.g.dart | 12 +- 11 files changed, 1268 insertions(+), 970 deletions(-) diff --git a/lib/src/domain/model/point/point.dart b/lib/src/domain/model/point/point.dart index 0f323ed..c59644c 100644 --- a/lib/src/domain/model/point/point.dart +++ b/lib/src/domain/model/point/point.dart @@ -8,7 +8,7 @@ part 'point.g.dart'; /// pressure value. /// {@endtemplate} @Freezed() -class Point with _$Point { +abstract class Point with _$Point { /// {@macro point} const factory Point( double x, diff --git a/lib/src/domain/model/point/point.freezed.dart b/lib/src/domain/model/point/point.freezed.dart index 7b25d0b..f347544 100644 --- a/lib/src/domain/model/point/point.freezed.dart +++ b/lib/src/domain/model/point/point.freezed.dart @@ -1,5 +1,5 @@ -// coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND +// coverage:ignore-file // ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark @@ -9,47 +9,60 @@ part of 'point.dart'; // FreezedGenerator // ************************************************************************** +// dart format off T _$identity(T value) => value; -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -Point _$PointFromJson(Map json) { - return _Point.fromJson(json); -} - /// @nodoc mixin _$Point { - double get x => throw _privateConstructorUsedError; - double get y => throw _privateConstructorUsedError; - double get pressure => throw _privateConstructorUsedError; - - /// Serializes this Point to a JSON map. - Map toJson() => throw _privateConstructorUsedError; + double get x; + double get y; + double get pressure; /// Create a copy of Point /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) - $PointCopyWith get copyWith => throw _privateConstructorUsedError; + @pragma('vm:prefer-inline') + $PointCopyWith get copyWith => + _$PointCopyWithImpl(this as Point, _$identity); + + /// Serializes this Point to a JSON map. + Map toJson(); + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is Point && + (identical(other.x, x) || other.x == x) && + (identical(other.y, y) || other.y == y) && + (identical(other.pressure, pressure) || + other.pressure == pressure)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, x, y, pressure); + + @override + String toString() { + return 'Point(x: $x, y: $y, pressure: $pressure)'; + } } /// @nodoc -abstract class $PointCopyWith<$Res> { - factory $PointCopyWith(Point value, $Res Function(Point) then) = - _$PointCopyWithImpl<$Res, Point>; +abstract mixin class $PointCopyWith<$Res> { + factory $PointCopyWith(Point value, $Res Function(Point) _then) = + _$PointCopyWithImpl; @useResult $Res call({double x, double y, double pressure}); } /// @nodoc -class _$PointCopyWithImpl<$Res, $Val extends Point> - implements $PointCopyWith<$Res> { - _$PointCopyWithImpl(this._value, this._then); +class _$PointCopyWithImpl<$Res> implements $PointCopyWith<$Res> { + _$PointCopyWithImpl(this._self, this._then); - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; + final Point _self; + final $Res Function(Point) _then; /// Create a copy of Point /// with the given fields replaced by the non-null parameter values. @@ -60,74 +73,185 @@ class _$PointCopyWithImpl<$Res, $Val extends Point> Object? y = null, Object? pressure = null, }) { - return _then(_value.copyWith( + return _then(_self.copyWith( x: null == x - ? _value.x + ? _self.x : x // ignore: cast_nullable_to_non_nullable as double, y: null == y - ? _value.y + ? _self.y : y // ignore: cast_nullable_to_non_nullable as double, pressure: null == pressure - ? _value.pressure + ? _self.pressure : pressure // ignore: cast_nullable_to_non_nullable as double, - ) as $Val); + )); } } -/// @nodoc -abstract class _$$PointImplCopyWith<$Res> implements $PointCopyWith<$Res> { - factory _$$PointImplCopyWith( - _$PointImpl value, $Res Function(_$PointImpl) then) = - __$$PointImplCopyWithImpl<$Res>; - @override - @useResult - $Res call({double x, double y, double pressure}); -} +/// Adds pattern-matching-related methods to [Point]. +extension PointPatterns on Point { + /// A variant of `map` that fallback to returning `orElse`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` -/// @nodoc -class __$$PointImplCopyWithImpl<$Res> - extends _$PointCopyWithImpl<$Res, _$PointImpl> - implements _$$PointImplCopyWith<$Res> { - __$$PointImplCopyWithImpl( - _$PointImpl _value, $Res Function(_$PointImpl) _then) - : super(_value, _then); + @optionalTypeArgs + TResult maybeMap( + TResult Function(_Point value)? $default, { + required TResult orElse(), + }) { + final _that = this; + switch (_that) { + case _Point() when $default != null: + return $default(_that); + case _: + return orElse(); + } + } - /// Create a copy of Point - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? x = null, - Object? y = null, - Object? pressure = null, + /// A `switch`-like method, using callbacks. + /// + /// Callbacks receives the raw object, upcasted. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case final Subclass2 value: + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult map( + TResult Function(_Point value) $default, + ) { + final _that = this; + switch (_that) { + case _Point(): + return $default(_that); + case _: + throw StateError('Unexpected subclass'); + } + } + + /// A variant of `map` that fallback to returning `null`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(_Point value)? $default, + ) { + final _that = this; + switch (_that) { + case _Point() when $default != null: + return $default(_that); + case _: + return null; + } + } + + /// A variant of `when` that fallback to an `orElse` callback. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeWhen( + TResult Function(double x, double y, double pressure)? $default, { + required TResult orElse(), }) { - return _then(_$PointImpl( - null == x - ? _value.x - : x // ignore: cast_nullable_to_non_nullable - as double, - null == y - ? _value.y - : y // ignore: cast_nullable_to_non_nullable - as double, - pressure: null == pressure - ? _value.pressure - : pressure // ignore: cast_nullable_to_non_nullable - as double, - )); + final _that = this; + switch (_that) { + case _Point() when $default != null: + return $default(_that.x, _that.y, _that.pressure); + case _: + return orElse(); + } + } + + /// A `switch`-like method, using callbacks. + /// + /// As opposed to `map`, this offers destructuring. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case Subclass2(:final field2): + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult when( + TResult Function(double x, double y, double pressure) $default, + ) { + final _that = this; + switch (_that) { + case _Point(): + return $default(_that.x, _that.y, _that.pressure); + case _: + throw StateError('Unexpected subclass'); + } + } + + /// A variant of `when` that fallback to returning `null` + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function(double x, double y, double pressure)? $default, + ) { + final _that = this; + switch (_that) { + case _Point() when $default != null: + return $default(_that.x, _that.y, _that.pressure); + case _: + return null; + } } } /// @nodoc @JsonSerializable() -class _$PointImpl extends _Point { - const _$PointImpl(this.x, this.y, {this.pressure = 0.5}) : super._(); - - factory _$PointImpl.fromJson(Map json) => - _$$PointImplFromJson(json); +class _Point extends Point { + const _Point(this.x, this.y, {this.pressure = 0.5}) : super._(); + factory _Point.fromJson(Map json) => _$PointFromJson(json); @override final double x; @@ -137,16 +261,26 @@ class _$PointImpl extends _Point { @JsonKey() final double pressure; + /// Create a copy of Point + /// with the given fields replaced by the non-null parameter values. @override - String toString() { - return 'Point(x: $x, y: $y, pressure: $pressure)'; + @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') + _$PointCopyWith<_Point> get copyWith => + __$PointCopyWithImpl<_Point>(this, _$identity); + + @override + Map toJson() { + return _$PointToJson( + this, + ); } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$PointImpl && + other is _Point && (identical(other.x, x) || other.x == x) && (identical(other.y, y) || other.y == y) && (identical(other.pressure, pressure) || @@ -157,40 +291,52 @@ class _$PointImpl extends _Point { @override int get hashCode => Object.hash(runtimeType, x, y, pressure); - /// Create a copy of Point - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$PointImplCopyWith<_$PointImpl> get copyWith => - __$$PointImplCopyWithImpl<_$PointImpl>(this, _$identity); - @override - Map toJson() { - return _$$PointImplToJson( - this, - ); + String toString() { + return 'Point(x: $x, y: $y, pressure: $pressure)'; } } -abstract class _Point extends Point { - const factory _Point(final double x, final double y, - {final double pressure}) = _$PointImpl; - const _Point._() : super._(); +/// @nodoc +abstract mixin class _$PointCopyWith<$Res> implements $PointCopyWith<$Res> { + factory _$PointCopyWith(_Point value, $Res Function(_Point) _then) = + __$PointCopyWithImpl; + @override + @useResult + $Res call({double x, double y, double pressure}); +} - factory _Point.fromJson(Map json) = _$PointImpl.fromJson; +/// @nodoc +class __$PointCopyWithImpl<$Res> implements _$PointCopyWith<$Res> { + __$PointCopyWithImpl(this._self, this._then); - @override - double get x; - @override - double get y; - @override - double get pressure; + final _Point _self; + final $Res Function(_Point) _then; /// Create a copy of Point /// with the given fields replaced by the non-null parameter values. @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$PointImplCopyWith<_$PointImpl> get copyWith => - throw _privateConstructorUsedError; + @pragma('vm:prefer-inline') + $Res call({ + Object? x = null, + Object? y = null, + Object? pressure = null, + }) { + return _then(_Point( + null == x + ? _self.x + : x // ignore: cast_nullable_to_non_nullable + as double, + null == y + ? _self.y + : y // ignore: cast_nullable_to_non_nullable + as double, + pressure: null == pressure + ? _self.pressure + : pressure // ignore: cast_nullable_to_non_nullable + as double, + )); + } } + +// dart format on diff --git a/lib/src/domain/model/point/point.g.dart b/lib/src/domain/model/point/point.g.dart index 2b06066..29c9097 100644 --- a/lib/src/domain/model/point/point.g.dart +++ b/lib/src/domain/model/point/point.g.dart @@ -6,14 +6,13 @@ part of 'point.dart'; // JsonSerializableGenerator // ************************************************************************** -_$PointImpl _$$PointImplFromJson(Map json) => _$PointImpl( +_Point _$PointFromJson(Map json) => _Point( (json['x'] as num).toDouble(), (json['y'] as num).toDouble(), pressure: (json['pressure'] as num?)?.toDouble() ?? 0.5, ); -Map _$$PointImplToJson(_$PointImpl instance) => - { +Map _$PointToJson(_Point instance) => { 'x': instance.x, 'y': instance.y, 'pressure': instance.pressure, diff --git a/lib/src/domain/model/sketch/sketch.dart b/lib/src/domain/model/sketch/sketch.dart index b20f9fa..c1edd91 100644 --- a/lib/src/domain/model/sketch/sketch.dart +++ b/lib/src/domain/model/sketch/sketch.dart @@ -9,7 +9,7 @@ part 'sketch.g.dart'; /// Represents a sketch with a list of [SketchLine]s. @freezed -class Sketch with _$Sketch { +abstract class Sketch with _$Sketch { /// Represents a sketch with a list of [SketchLine]s. const factory Sketch({ required List lines, diff --git a/lib/src/domain/model/sketch/sketch.freezed.dart b/lib/src/domain/model/sketch/sketch.freezed.dart index 787e53b..3d6fd01 100644 --- a/lib/src/domain/model/sketch/sketch.freezed.dart +++ b/lib/src/domain/model/sketch/sketch.freezed.dart @@ -1,5 +1,5 @@ -// coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND +// coverage:ignore-file // ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark @@ -9,79 +9,56 @@ part of 'sketch.dart'; // FreezedGenerator // ************************************************************************** +// dart format off T _$identity(T value) => value; -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -Sketch _$SketchFromJson(Map json) { - return _Sketch.fromJson(json); -} - /// @nodoc mixin _$Sketch { - List get lines => throw _privateConstructorUsedError; - - /// Serializes this Sketch to a JSON map. - Map toJson() => throw _privateConstructorUsedError; + List get lines; /// Create a copy of Sketch /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) - $SketchCopyWith get copyWith => throw _privateConstructorUsedError; -} + @pragma('vm:prefer-inline') + $SketchCopyWith get copyWith => + _$SketchCopyWithImpl(this as Sketch, _$identity); -/// @nodoc -abstract class $SketchCopyWith<$Res> { - factory $SketchCopyWith(Sketch value, $Res Function(Sketch) then) = - _$SketchCopyWithImpl<$Res, Sketch>; - @useResult - $Res call({List lines}); -} + /// Serializes this Sketch to a JSON map. + Map toJson(); -/// @nodoc -class _$SketchCopyWithImpl<$Res, $Val extends Sketch> - implements $SketchCopyWith<$Res> { - _$SketchCopyWithImpl(this._value, this._then); + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is Sketch && + const DeepCollectionEquality().equals(other.lines, lines)); + } - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => + Object.hash(runtimeType, const DeepCollectionEquality().hash(lines)); - /// Create a copy of Sketch - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') @override - $Res call({ - Object? lines = null, - }) { - return _then(_value.copyWith( - lines: null == lines - ? _value.lines - : lines // ignore: cast_nullable_to_non_nullable - as List, - ) as $Val); + String toString() { + return 'Sketch(lines: $lines)'; } } /// @nodoc -abstract class _$$SketchImplCopyWith<$Res> implements $SketchCopyWith<$Res> { - factory _$$SketchImplCopyWith( - _$SketchImpl value, $Res Function(_$SketchImpl) then) = - __$$SketchImplCopyWithImpl<$Res>; - @override +abstract mixin class $SketchCopyWith<$Res> { + factory $SketchCopyWith(Sketch value, $Res Function(Sketch) _then) = + _$SketchCopyWithImpl; @useResult $Res call({List lines}); } /// @nodoc -class __$$SketchImplCopyWithImpl<$Res> - extends _$SketchCopyWithImpl<$Res, _$SketchImpl> - implements _$$SketchImplCopyWith<$Res> { - __$$SketchImplCopyWithImpl( - _$SketchImpl _value, $Res Function(_$SketchImpl) _then) - : super(_value, _then); +class _$SketchCopyWithImpl<$Res> implements $SketchCopyWith<$Res> { + _$SketchCopyWithImpl(this._self, this._then); + + final Sketch _self; + final $Res Function(Sketch) _then; /// Create a copy of Sketch /// with the given fields replaced by the non-null parameter values. @@ -90,22 +67,177 @@ class __$$SketchImplCopyWithImpl<$Res> $Res call({ Object? lines = null, }) { - return _then(_$SketchImpl( + return _then(_self.copyWith( lines: null == lines - ? _value._lines + ? _self.lines : lines // ignore: cast_nullable_to_non_nullable as List, )); } } +/// Adds pattern-matching-related methods to [Sketch]. +extension SketchPatterns on Sketch { + /// A variant of `map` that fallback to returning `orElse`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeMap( + TResult Function(_Sketch value)? $default, { + required TResult orElse(), + }) { + final _that = this; + switch (_that) { + case _Sketch() when $default != null: + return $default(_that); + case _: + return orElse(); + } + } + + /// A `switch`-like method, using callbacks. + /// + /// Callbacks receives the raw object, upcasted. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case final Subclass2 value: + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult map( + TResult Function(_Sketch value) $default, + ) { + final _that = this; + switch (_that) { + case _Sketch(): + return $default(_that); + case _: + throw StateError('Unexpected subclass'); + } + } + + /// A variant of `map` that fallback to returning `null`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(_Sketch value)? $default, + ) { + final _that = this; + switch (_that) { + case _Sketch() when $default != null: + return $default(_that); + case _: + return null; + } + } + + /// A variant of `when` that fallback to an `orElse` callback. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeWhen( + TResult Function(List lines)? $default, { + required TResult orElse(), + }) { + final _that = this; + switch (_that) { + case _Sketch() when $default != null: + return $default(_that.lines); + case _: + return orElse(); + } + } + + /// A `switch`-like method, using callbacks. + /// + /// As opposed to `map`, this offers destructuring. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case Subclass2(:final field2): + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult when( + TResult Function(List lines) $default, + ) { + final _that = this; + switch (_that) { + case _Sketch(): + return $default(_that.lines); + case _: + throw StateError('Unexpected subclass'); + } + } + + /// A variant of `when` that fallback to returning `null` + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function(List lines)? $default, + ) { + final _that = this; + switch (_that) { + case _Sketch() when $default != null: + return $default(_that.lines); + case _: + return null; + } + } +} + /// @nodoc @JsonSerializable() -class _$SketchImpl implements _Sketch { - const _$SketchImpl({required final List lines}) : _lines = lines; - - factory _$SketchImpl.fromJson(Map json) => - _$$SketchImplFromJson(json); +class _Sketch implements Sketch { + const _Sketch({required final List lines}) : _lines = lines; + factory _Sketch.fromJson(Map json) => _$SketchFromJson(json); final List _lines; @override @@ -115,16 +247,26 @@ class _$SketchImpl implements _Sketch { return EqualUnmodifiableListView(_lines); } + /// Create a copy of Sketch + /// with the given fields replaced by the non-null parameter values. @override - String toString() { - return 'Sketch(lines: $lines)'; + @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') + _$SketchCopyWith<_Sketch> get copyWith => + __$SketchCopyWithImpl<_Sketch>(this, _$identity); + + @override + Map toJson() { + return _$SketchToJson( + this, + ); } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$SketchImpl && + other is _Sketch && const DeepCollectionEquality().equals(other._lines, _lines)); } @@ -133,34 +275,42 @@ class _$SketchImpl implements _Sketch { int get hashCode => Object.hash(runtimeType, const DeepCollectionEquality().hash(_lines)); - /// Create a copy of Sketch - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$SketchImplCopyWith<_$SketchImpl> get copyWith => - __$$SketchImplCopyWithImpl<_$SketchImpl>(this, _$identity); - @override - Map toJson() { - return _$$SketchImplToJson( - this, - ); + String toString() { + return 'Sketch(lines: $lines)'; } } -abstract class _Sketch implements Sketch { - const factory _Sketch({required final List lines}) = _$SketchImpl; +/// @nodoc +abstract mixin class _$SketchCopyWith<$Res> implements $SketchCopyWith<$Res> { + factory _$SketchCopyWith(_Sketch value, $Res Function(_Sketch) _then) = + __$SketchCopyWithImpl; + @override + @useResult + $Res call({List lines}); +} - factory _Sketch.fromJson(Map json) = _$SketchImpl.fromJson; +/// @nodoc +class __$SketchCopyWithImpl<$Res> implements _$SketchCopyWith<$Res> { + __$SketchCopyWithImpl(this._self, this._then); - @override - List get lines; + final _Sketch _self; + final $Res Function(_Sketch) _then; /// Create a copy of Sketch /// with the given fields replaced by the non-null parameter values. @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$SketchImplCopyWith<_$SketchImpl> get copyWith => - throw _privateConstructorUsedError; + @pragma('vm:prefer-inline') + $Res call({ + Object? lines = null, + }) { + return _then(_Sketch( + lines: null == lines + ? _self._lines + : lines // ignore: cast_nullable_to_non_nullable + as List, + )); + } } + +// dart format on diff --git a/lib/src/domain/model/sketch/sketch.g.dart b/lib/src/domain/model/sketch/sketch.g.dart index 3bdcbcd..820615d 100644 --- a/lib/src/domain/model/sketch/sketch.g.dart +++ b/lib/src/domain/model/sketch/sketch.g.dart @@ -6,13 +6,12 @@ part of 'sketch.dart'; // JsonSerializableGenerator // ************************************************************************** -_$SketchImpl _$$SketchImplFromJson(Map json) => _$SketchImpl( +_Sketch _$SketchFromJson(Map json) => _Sketch( lines: (json['lines'] as List) .map((e) => SketchLine.fromJson(e as Map)) .toList(), ); -Map _$$SketchImplToJson(_$SketchImpl instance) => - { +Map _$SketchToJson(_Sketch instance) => { 'lines': instance.lines.map((e) => e.toJson()).toList(), }; diff --git a/lib/src/domain/model/sketch_line/sketch_line.dart b/lib/src/domain/model/sketch_line/sketch_line.dart index 20d6787..ad476b3 100644 --- a/lib/src/domain/model/sketch_line/sketch_line.dart +++ b/lib/src/domain/model/sketch_line/sketch_line.dart @@ -8,7 +8,7 @@ part 'sketch_line.g.dart'; /// Represents a line in a sketch. /// {@endtemplate} @freezed -class SketchLine with _$SketchLine { +abstract class SketchLine with _$SketchLine { /// {@macro sketch_line} const factory SketchLine({ /// The points that make up the line diff --git a/lib/src/domain/model/sketch_line/sketch_line.freezed.dart b/lib/src/domain/model/sketch_line/sketch_line.freezed.dart index 1d8315b..e520e16 100644 --- a/lib/src/domain/model/sketch_line/sketch_line.freezed.dart +++ b/lib/src/domain/model/sketch_line/sketch_line.freezed.dart @@ -1,5 +1,5 @@ -// coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND +// coverage:ignore-file // ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark @@ -9,54 +9,66 @@ part of 'sketch_line.dart'; // FreezedGenerator // ************************************************************************** +// dart format off T _$identity(T value) => value; -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -SketchLine _$SketchLineFromJson(Map json) { - return _SketchLine.fromJson(json); -} - /// @nodoc mixin _$SketchLine { /// The points that make up the line - List get points => throw _privateConstructorUsedError; + List get points; /// The color of the line in hexadecimal format (ARGB) - int get color => throw _privateConstructorUsedError; + int get color; /// The width of the line - double get width => throw _privateConstructorUsedError; - - /// Serializes this SketchLine to a JSON map. - Map toJson() => throw _privateConstructorUsedError; + double get width; /// Create a copy of SketchLine /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') $SketchLineCopyWith get copyWith => - throw _privateConstructorUsedError; + _$SketchLineCopyWithImpl(this as SketchLine, _$identity); + + /// Serializes this SketchLine to a JSON map. + Map toJson(); + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is SketchLine && + const DeepCollectionEquality().equals(other.points, points) && + (identical(other.color, color) || other.color == color) && + (identical(other.width, width) || other.width == width)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash( + runtimeType, const DeepCollectionEquality().hash(points), color, width); + + @override + String toString() { + return 'SketchLine(points: $points, color: $color, width: $width)'; + } } /// @nodoc -abstract class $SketchLineCopyWith<$Res> { +abstract mixin class $SketchLineCopyWith<$Res> { factory $SketchLineCopyWith( - SketchLine value, $Res Function(SketchLine) then) = - _$SketchLineCopyWithImpl<$Res, SketchLine>; + SketchLine value, $Res Function(SketchLine) _then) = + _$SketchLineCopyWithImpl; @useResult $Res call({List points, int color, double width}); } /// @nodoc -class _$SketchLineCopyWithImpl<$Res, $Val extends SketchLine> - implements $SketchLineCopyWith<$Res> { - _$SketchLineCopyWithImpl(this._value, this._then); +class _$SketchLineCopyWithImpl<$Res> implements $SketchLineCopyWith<$Res> { + _$SketchLineCopyWithImpl(this._self, this._then); - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; + final SketchLine _self; + final $Res Function(SketchLine) _then; /// Create a copy of SketchLine /// with the given fields replaced by the non-null parameter values. @@ -67,79 +79,190 @@ class _$SketchLineCopyWithImpl<$Res, $Val extends SketchLine> Object? color = null, Object? width = null, }) { - return _then(_value.copyWith( + return _then(_self.copyWith( points: null == points - ? _value.points + ? _self.points : points // ignore: cast_nullable_to_non_nullable as List, color: null == color - ? _value.color + ? _self.color : color // ignore: cast_nullable_to_non_nullable as int, width: null == width - ? _value.width + ? _self.width : width // ignore: cast_nullable_to_non_nullable as double, - ) as $Val); + )); } } -/// @nodoc -abstract class _$$SketchLineImplCopyWith<$Res> - implements $SketchLineCopyWith<$Res> { - factory _$$SketchLineImplCopyWith( - _$SketchLineImpl value, $Res Function(_$SketchLineImpl) then) = - __$$SketchLineImplCopyWithImpl<$Res>; - @override - @useResult - $Res call({List points, int color, double width}); -} +/// Adds pattern-matching-related methods to [SketchLine]. +extension SketchLinePatterns on SketchLine { + /// A variant of `map` that fallback to returning `orElse`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeMap( + TResult Function(_SketchLine value)? $default, { + required TResult orElse(), + }) { + final _that = this; + switch (_that) { + case _SketchLine() when $default != null: + return $default(_that); + case _: + return orElse(); + } + } -/// @nodoc -class __$$SketchLineImplCopyWithImpl<$Res> - extends _$SketchLineCopyWithImpl<$Res, _$SketchLineImpl> - implements _$$SketchLineImplCopyWith<$Res> { - __$$SketchLineImplCopyWithImpl( - _$SketchLineImpl _value, $Res Function(_$SketchLineImpl) _then) - : super(_value, _then); + /// A `switch`-like method, using callbacks. + /// + /// Callbacks receives the raw object, upcasted. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case final Subclass2 value: + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult map( + TResult Function(_SketchLine value) $default, + ) { + final _that = this; + switch (_that) { + case _SketchLine(): + return $default(_that); + case _: + throw StateError('Unexpected subclass'); + } + } - /// Create a copy of SketchLine - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? points = null, - Object? color = null, - Object? width = null, + /// A variant of `map` that fallback to returning `null`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? mapOrNull( + TResult? Function(_SketchLine value)? $default, + ) { + final _that = this; + switch (_that) { + case _SketchLine() when $default != null: + return $default(_that); + case _: + return null; + } + } + + /// A variant of `when` that fallback to an `orElse` callback. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeWhen( + TResult Function(List points, int color, double width)? $default, { + required TResult orElse(), }) { - return _then(_$SketchLineImpl( - points: null == points - ? _value._points - : points // ignore: cast_nullable_to_non_nullable - as List, - color: null == color - ? _value.color - : color // ignore: cast_nullable_to_non_nullable - as int, - width: null == width - ? _value.width - : width // ignore: cast_nullable_to_non_nullable - as double, - )); + final _that = this; + switch (_that) { + case _SketchLine() when $default != null: + return $default(_that.points, _that.color, _that.width); + case _: + return orElse(); + } + } + + /// A `switch`-like method, using callbacks. + /// + /// As opposed to `map`, this offers destructuring. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case Subclass2(:final field2): + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult when( + TResult Function(List points, int color, double width) $default, + ) { + final _that = this; + switch (_that) { + case _SketchLine(): + return $default(_that.points, _that.color, _that.width); + case _: + throw StateError('Unexpected subclass'); + } + } + + /// A variant of `when` that fallback to returning `null` + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? whenOrNull( + TResult? Function(List points, int color, double width)? $default, + ) { + final _that = this; + switch (_that) { + case _SketchLine() when $default != null: + return $default(_that.points, _that.color, _that.width); + case _: + return null; + } } } /// @nodoc @JsonSerializable() -class _$SketchLineImpl implements _SketchLine { - const _$SketchLineImpl( +class _SketchLine implements SketchLine { + const _SketchLine( {required final List points, required this.color, required this.width}) : _points = points; - - factory _$SketchLineImpl.fromJson(Map json) => - _$$SketchLineImplFromJson(json); + factory _SketchLine.fromJson(Map json) => + _$SketchLineFromJson(json); /// The points that make up the line final List _points; @@ -160,16 +283,26 @@ class _$SketchLineImpl implements _SketchLine { @override final double width; + /// Create a copy of SketchLine + /// with the given fields replaced by the non-null parameter values. @override - String toString() { - return 'SketchLine(points: $points, color: $color, width: $width)'; + @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') + _$SketchLineCopyWith<_SketchLine> get copyWith => + __$SketchLineCopyWithImpl<_SketchLine>(this, _$identity); + + @override + Map toJson() { + return _$SketchLineToJson( + this, + ); } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$SketchLineImpl && + other is _SketchLine && const DeepCollectionEquality().equals(other._points, _points) && (identical(other.color, color) || other.color == color) && (identical(other.width, width) || other.width == width)); @@ -180,47 +313,54 @@ class _$SketchLineImpl implements _SketchLine { int get hashCode => Object.hash( runtimeType, const DeepCollectionEquality().hash(_points), color, width); - /// Create a copy of SketchLine - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$SketchLineImplCopyWith<_$SketchLineImpl> get copyWith => - __$$SketchLineImplCopyWithImpl<_$SketchLineImpl>(this, _$identity); - @override - Map toJson() { - return _$$SketchLineImplToJson( - this, - ); + String toString() { + return 'SketchLine(points: $points, color: $color, width: $width)'; } } -abstract class _SketchLine implements SketchLine { - const factory _SketchLine( - {required final List points, - required final int color, - required final double width}) = _$SketchLineImpl; - - factory _SketchLine.fromJson(Map json) = - _$SketchLineImpl.fromJson; - - /// The points that make up the line +/// @nodoc +abstract mixin class _$SketchLineCopyWith<$Res> + implements $SketchLineCopyWith<$Res> { + factory _$SketchLineCopyWith( + _SketchLine value, $Res Function(_SketchLine) _then) = + __$SketchLineCopyWithImpl; @override - List get points; + @useResult + $Res call({List points, int color, double width}); +} - /// The color of the line in hexadecimal format (ARGB) - @override - int get color; +/// @nodoc +class __$SketchLineCopyWithImpl<$Res> implements _$SketchLineCopyWith<$Res> { + __$SketchLineCopyWithImpl(this._self, this._then); - /// The width of the line - @override - double get width; + final _SketchLine _self; + final $Res Function(_SketchLine) _then; /// Create a copy of SketchLine /// with the given fields replaced by the non-null parameter values. @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$SketchLineImplCopyWith<_$SketchLineImpl> get copyWith => - throw _privateConstructorUsedError; + @pragma('vm:prefer-inline') + $Res call({ + Object? points = null, + Object? color = null, + Object? width = null, + }) { + return _then(_SketchLine( + points: null == points + ? _self._points + : points // ignore: cast_nullable_to_non_nullable + as List, + color: null == color + ? _self.color + : color // ignore: cast_nullable_to_non_nullable + as int, + width: null == width + ? _self.width + : width // ignore: cast_nullable_to_non_nullable + as double, + )); + } } + +// dart format on diff --git a/lib/src/domain/model/sketch_line/sketch_line.g.dart b/lib/src/domain/model/sketch_line/sketch_line.g.dart index f7c00ba..efd0b73 100644 --- a/lib/src/domain/model/sketch_line/sketch_line.g.dart +++ b/lib/src/domain/model/sketch_line/sketch_line.g.dart @@ -6,8 +6,7 @@ part of 'sketch_line.dart'; // JsonSerializableGenerator // ************************************************************************** -_$SketchLineImpl _$$SketchLineImplFromJson(Map json) => - _$SketchLineImpl( +_SketchLine _$SketchLineFromJson(Map json) => _SketchLine( points: (json['points'] as List) .map((e) => Point.fromJson(e as Map)) .toList(), @@ -15,7 +14,7 @@ _$SketchLineImpl _$$SketchLineImplFromJson(Map json) => width: (json['width'] as num).toDouble(), ); -Map _$$SketchLineImplToJson(_$SketchLineImpl instance) => +Map _$SketchLineToJson(_SketchLine instance) => { 'points': instance.points.map((e) => e.toJson()).toList(), 'color': instance.color, diff --git a/lib/src/view/state/scribble.state.freezed.dart b/lib/src/view/state/scribble.state.freezed.dart index ea1774c..953c93f 100644 --- a/lib/src/view/state/scribble.state.freezed.dart +++ b/lib/src/view/state/scribble.state.freezed.dart @@ -1,5 +1,5 @@ -// coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND +// coverage:ignore-file // ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark @@ -9,11 +9,8 @@ part of 'scribble.state.dart'; // FreezedGenerator // ************************************************************************** +// dart format off T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - ScribbleState _$ScribbleStateFromJson(Map json) { switch (json['runtimeType']) { case 'drawing': @@ -30,22 +27,21 @@ ScribbleState _$ScribbleStateFromJson(Map json) { /// @nodoc mixin _$ScribbleState { /// The current state of the sketch - Sketch get sketch => throw _privateConstructorUsedError; + Sketch get sketch; /// Which pointers are allowed for drawing and will be captured by the /// scribble widget. - ScribblePointerMode get allowedPointersMode => - throw _privateConstructorUsedError; + ScribblePointerMode get allowedPointersMode; /// The ids of all supported pointers that are currently interacting with /// the widget. - List get activePointerIds => throw _privateConstructorUsedError; + List get activePointerIds; /// The current position of the pointer - Point? get pointerPosition => throw _privateConstructorUsedError; + Point? get pointerPosition; /// The current width of the pen - double get selectedWidth => throw _privateConstructorUsedError; + double get selectedWidth; /// {@template view.state.scribble_state.scale_factor} /// How much the widget is scaled at the moment. @@ -53,7 +49,7 @@ mixin _$ScribbleState { /// Can be used if zoom functionality is needed /// (e.g. through InteractiveViewer) so that the pen width remains the same. /// {@endtemplate} - double get scaleFactor => throw _privateConstructorUsedError; + double get scaleFactor; /// {@template view.state.scribble_state.simplification_tolerance} /// The current tolerance of simplification, in pixels. @@ -61,115 +57,63 @@ mixin _$ScribbleState { /// Lines will be simplified when they are finished. A value of 0 (default) /// will mean no simplification. /// {@endtemplate} - double get simplificationTolerance => throw _privateConstructorUsedError; - @optionalTypeArgs - TResult when({ - required TResult Function( - Sketch sketch, - SketchLine? activeLine, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - int selectedColor, - double selectedWidth, - double scaleFactor, - double simplificationTolerance) - drawing, - required TResult Function( - Sketch sketch, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - double selectedWidth, - double scaleFactor, - double simplificationTolerance) - erasing, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function( - Sketch sketch, - SketchLine? activeLine, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - int selectedColor, - double selectedWidth, - double scaleFactor, - double simplificationTolerance)? - drawing, - TResult? Function( - Sketch sketch, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - double selectedWidth, - double scaleFactor, - double simplificationTolerance)? - erasing, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function( - Sketch sketch, - SketchLine? activeLine, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - int selectedColor, - double selectedWidth, - double scaleFactor, - double simplificationTolerance)? - drawing, - TResult Function( - Sketch sketch, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - double selectedWidth, - double scaleFactor, - double simplificationTolerance)? - erasing, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(Drawing value) drawing, - required TResult Function(Erasing value) erasing, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(Drawing value)? drawing, - TResult? Function(Erasing value)? erasing, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(Drawing value)? drawing, - TResult Function(Erasing value)? erasing, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - - /// Serializes this ScribbleState to a JSON map. - Map toJson() => throw _privateConstructorUsedError; + double get simplificationTolerance; /// Create a copy of ScribbleState /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') $ScribbleStateCopyWith get copyWith => - throw _privateConstructorUsedError; + _$ScribbleStateCopyWithImpl( + this as ScribbleState, _$identity); + + /// Serializes this ScribbleState to a JSON map. + Map toJson(); + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is ScribbleState && + (identical(other.sketch, sketch) || other.sketch == sketch) && + (identical(other.allowedPointersMode, allowedPointersMode) || + other.allowedPointersMode == allowedPointersMode) && + const DeepCollectionEquality() + .equals(other.activePointerIds, activePointerIds) && + (identical(other.pointerPosition, pointerPosition) || + other.pointerPosition == pointerPosition) && + (identical(other.selectedWidth, selectedWidth) || + other.selectedWidth == selectedWidth) && + (identical(other.scaleFactor, scaleFactor) || + other.scaleFactor == scaleFactor) && + (identical( + other.simplificationTolerance, simplificationTolerance) || + other.simplificationTolerance == simplificationTolerance)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash( + runtimeType, + sketch, + allowedPointersMode, + const DeepCollectionEquality().hash(activePointerIds), + pointerPosition, + selectedWidth, + scaleFactor, + simplificationTolerance); + + @override + String toString() { + return 'ScribbleState(sketch: $sketch, allowedPointersMode: $allowedPointersMode, activePointerIds: $activePointerIds, pointerPosition: $pointerPosition, selectedWidth: $selectedWidth, scaleFactor: $scaleFactor, simplificationTolerance: $simplificationTolerance)'; + } } /// @nodoc -abstract class $ScribbleStateCopyWith<$Res> { +abstract mixin class $ScribbleStateCopyWith<$Res> { factory $ScribbleStateCopyWith( - ScribbleState value, $Res Function(ScribbleState) then) = - _$ScribbleStateCopyWithImpl<$Res, ScribbleState>; + ScribbleState value, $Res Function(ScribbleState) _then) = + _$ScribbleStateCopyWithImpl; @useResult $Res call( {Sketch sketch, @@ -185,14 +129,12 @@ abstract class $ScribbleStateCopyWith<$Res> { } /// @nodoc -class _$ScribbleStateCopyWithImpl<$Res, $Val extends ScribbleState> +class _$ScribbleStateCopyWithImpl<$Res> implements $ScribbleStateCopyWith<$Res> { - _$ScribbleStateCopyWithImpl(this._value, this._then); + _$ScribbleStateCopyWithImpl(this._self, this._then); - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; + final ScribbleState _self; + final $Res Function(ScribbleState) _then; /// Create a copy of ScribbleState /// with the given fields replaced by the non-null parameter values. @@ -207,36 +149,36 @@ class _$ScribbleStateCopyWithImpl<$Res, $Val extends ScribbleState> Object? scaleFactor = null, Object? simplificationTolerance = null, }) { - return _then(_value.copyWith( + return _then(_self.copyWith( sketch: null == sketch - ? _value.sketch + ? _self.sketch : sketch // ignore: cast_nullable_to_non_nullable as Sketch, allowedPointersMode: null == allowedPointersMode - ? _value.allowedPointersMode + ? _self.allowedPointersMode : allowedPointersMode // ignore: cast_nullable_to_non_nullable as ScribblePointerMode, activePointerIds: null == activePointerIds - ? _value.activePointerIds + ? _self.activePointerIds : activePointerIds // ignore: cast_nullable_to_non_nullable as List, pointerPosition: freezed == pointerPosition - ? _value.pointerPosition + ? _self.pointerPosition : pointerPosition // ignore: cast_nullable_to_non_nullable as Point?, selectedWidth: null == selectedWidth - ? _value.selectedWidth + ? _self.selectedWidth : selectedWidth // ignore: cast_nullable_to_non_nullable as double, scaleFactor: null == scaleFactor - ? _value.scaleFactor + ? _self.scaleFactor : scaleFactor // ignore: cast_nullable_to_non_nullable as double, simplificationTolerance: null == simplificationTolerance - ? _value.simplificationTolerance + ? _self.simplificationTolerance : simplificationTolerance // ignore: cast_nullable_to_non_nullable as double, - ) as $Val); + )); } /// Create a copy of ScribbleState @@ -244,8 +186,8 @@ class _$ScribbleStateCopyWithImpl<$Res, $Val extends ScribbleState> @override @pragma('vm:prefer-inline') $SketchCopyWith<$Res> get sketch { - return $SketchCopyWith<$Res>(_value.sketch, (value) { - return _then(_value.copyWith(sketch: value) as $Val); + return $SketchCopyWith<$Res>(_self.sketch, (value) { + return _then(_self.copyWith(sketch: value)); }); } @@ -254,124 +196,293 @@ class _$ScribbleStateCopyWithImpl<$Res, $Val extends ScribbleState> @override @pragma('vm:prefer-inline') $PointCopyWith<$Res>? get pointerPosition { - if (_value.pointerPosition == null) { + if (_self.pointerPosition == null) { return null; } - return $PointCopyWith<$Res>(_value.pointerPosition!, (value) { - return _then(_value.copyWith(pointerPosition: value) as $Val); + return $PointCopyWith<$Res>(_self.pointerPosition!, (value) { + return _then(_self.copyWith(pointerPosition: value)); }); } } -/// @nodoc -abstract class _$$DrawingImplCopyWith<$Res> - implements $ScribbleStateCopyWith<$Res> { - factory _$$DrawingImplCopyWith( - _$DrawingImpl value, $Res Function(_$DrawingImpl) then) = - __$$DrawingImplCopyWithImpl<$Res>; - @override - @useResult - $Res call( - {Sketch sketch, - SketchLine? activeLine, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - int selectedColor, - double selectedWidth, - double scaleFactor, - double simplificationTolerance}); +/// Adds pattern-matching-related methods to [ScribbleState]. +extension ScribbleStatePatterns on ScribbleState { + /// A variant of `map` that fallback to returning `orElse`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` - @override - $SketchCopyWith<$Res> get sketch; - $SketchLineCopyWith<$Res>? get activeLine; - @override - $PointCopyWith<$Res>? get pointerPosition; -} + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Drawing value)? drawing, + TResult Function(Erasing value)? erasing, + required TResult orElse(), + }) { + final _that = this; + switch (_that) { + case Drawing() when drawing != null: + return drawing(_that); + case Erasing() when erasing != null: + return erasing(_that); + case _: + return orElse(); + } + } -/// @nodoc -class __$$DrawingImplCopyWithImpl<$Res> - extends _$ScribbleStateCopyWithImpl<$Res, _$DrawingImpl> - implements _$$DrawingImplCopyWith<$Res> { - __$$DrawingImplCopyWithImpl( - _$DrawingImpl _value, $Res Function(_$DrawingImpl) _then) - : super(_value, _then); + /// A `switch`-like method, using callbacks. + /// + /// Callbacks receives the raw object, upcasted. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case final Subclass2 value: + /// return ...; + /// } + /// ``` - /// Create a copy of ScribbleState - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? sketch = null, - Object? activeLine = freezed, - Object? allowedPointersMode = null, - Object? activePointerIds = null, - Object? pointerPosition = freezed, - Object? selectedColor = null, - Object? selectedWidth = null, - Object? scaleFactor = null, - Object? simplificationTolerance = null, + @optionalTypeArgs + TResult map({ + required TResult Function(Drawing value) drawing, + required TResult Function(Erasing value) erasing, }) { - return _then(_$DrawingImpl( - sketch: null == sketch - ? _value.sketch - : sketch // ignore: cast_nullable_to_non_nullable - as Sketch, - activeLine: freezed == activeLine - ? _value.activeLine - : activeLine // ignore: cast_nullable_to_non_nullable - as SketchLine?, - allowedPointersMode: null == allowedPointersMode - ? _value.allowedPointersMode - : allowedPointersMode // ignore: cast_nullable_to_non_nullable - as ScribblePointerMode, - activePointerIds: null == activePointerIds - ? _value._activePointerIds - : activePointerIds // ignore: cast_nullable_to_non_nullable - as List, - pointerPosition: freezed == pointerPosition - ? _value.pointerPosition - : pointerPosition // ignore: cast_nullable_to_non_nullable - as Point?, - selectedColor: null == selectedColor - ? _value.selectedColor - : selectedColor // ignore: cast_nullable_to_non_nullable - as int, - selectedWidth: null == selectedWidth - ? _value.selectedWidth - : selectedWidth // ignore: cast_nullable_to_non_nullable - as double, - scaleFactor: null == scaleFactor - ? _value.scaleFactor - : scaleFactor // ignore: cast_nullable_to_non_nullable - as double, - simplificationTolerance: null == simplificationTolerance - ? _value.simplificationTolerance - : simplificationTolerance // ignore: cast_nullable_to_non_nullable - as double, - )); + final _that = this; + switch (_that) { + case Drawing(): + return drawing(_that); + case Erasing(): + return erasing(_that); + } } - /// Create a copy of ScribbleState - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $SketchLineCopyWith<$Res>? get activeLine { - if (_value.activeLine == null) { - return null; + /// A variant of `map` that fallback to returning `null`. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case final Subclass value: + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(Drawing value)? drawing, + TResult? Function(Erasing value)? erasing, + }) { + final _that = this; + switch (_that) { + case Drawing() when drawing != null: + return drawing(_that); + case Erasing() when erasing != null: + return erasing(_that); + case _: + return null; } + } - return $SketchLineCopyWith<$Res>(_value.activeLine!, (value) { - return _then(_value.copyWith(activeLine: value)); - }); + /// A variant of `when` that fallback to an `orElse` callback. + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return orElse(); + /// } + /// ``` + + @optionalTypeArgs + TResult maybeWhen({ + TResult Function( + Sketch sketch, + SketchLine? activeLine, + ScribblePointerMode allowedPointersMode, + List activePointerIds, + Point? pointerPosition, + int selectedColor, + double selectedWidth, + double scaleFactor, + double simplificationTolerance)? + drawing, + TResult Function( + Sketch sketch, + ScribblePointerMode allowedPointersMode, + List activePointerIds, + Point? pointerPosition, + double selectedWidth, + double scaleFactor, + double simplificationTolerance)? + erasing, + required TResult orElse(), + }) { + final _that = this; + switch (_that) { + case Drawing() when drawing != null: + return drawing( + _that.sketch, + _that.activeLine, + _that.allowedPointersMode, + _that.activePointerIds, + _that.pointerPosition, + _that.selectedColor, + _that.selectedWidth, + _that.scaleFactor, + _that.simplificationTolerance); + case Erasing() when erasing != null: + return erasing( + _that.sketch, + _that.allowedPointersMode, + _that.activePointerIds, + _that.pointerPosition, + _that.selectedWidth, + _that.scaleFactor, + _that.simplificationTolerance); + case _: + return orElse(); + } + } + + /// A `switch`-like method, using callbacks. + /// + /// As opposed to `map`, this offers destructuring. + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case Subclass2(:final field2): + /// return ...; + /// } + /// ``` + + @optionalTypeArgs + TResult when({ + required TResult Function( + Sketch sketch, + SketchLine? activeLine, + ScribblePointerMode allowedPointersMode, + List activePointerIds, + Point? pointerPosition, + int selectedColor, + double selectedWidth, + double scaleFactor, + double simplificationTolerance) + drawing, + required TResult Function( + Sketch sketch, + ScribblePointerMode allowedPointersMode, + List activePointerIds, + Point? pointerPosition, + double selectedWidth, + double scaleFactor, + double simplificationTolerance) + erasing, + }) { + final _that = this; + switch (_that) { + case Drawing(): + return drawing( + _that.sketch, + _that.activeLine, + _that.allowedPointersMode, + _that.activePointerIds, + _that.pointerPosition, + _that.selectedColor, + _that.selectedWidth, + _that.scaleFactor, + _that.simplificationTolerance); + case Erasing(): + return erasing( + _that.sketch, + _that.allowedPointersMode, + _that.activePointerIds, + _that.pointerPosition, + _that.selectedWidth, + _that.scaleFactor, + _that.simplificationTolerance); + } + } + + /// A variant of `when` that fallback to returning `null` + /// + /// It is equivalent to doing: + /// ```dart + /// switch (sealedClass) { + /// case Subclass(:final field): + /// return ...; + /// case _: + /// return null; + /// } + /// ``` + + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function( + Sketch sketch, + SketchLine? activeLine, + ScribblePointerMode allowedPointersMode, + List activePointerIds, + Point? pointerPosition, + int selectedColor, + double selectedWidth, + double scaleFactor, + double simplificationTolerance)? + drawing, + TResult? Function( + Sketch sketch, + ScribblePointerMode allowedPointersMode, + List activePointerIds, + Point? pointerPosition, + double selectedWidth, + double scaleFactor, + double simplificationTolerance)? + erasing, + }) { + final _that = this; + switch (_that) { + case Drawing() when drawing != null: + return drawing( + _that.sketch, + _that.activeLine, + _that.allowedPointersMode, + _that.activePointerIds, + _that.pointerPosition, + _that.selectedColor, + _that.selectedWidth, + _that.scaleFactor, + _that.simplificationTolerance); + case Erasing() when erasing != null: + return erasing( + _that.sketch, + _that.allowedPointersMode, + _that.activePointerIds, + _that.pointerPosition, + _that.selectedWidth, + _that.scaleFactor, + _that.simplificationTolerance); + case _: + return null; + } } } /// @nodoc @JsonSerializable() -class _$DrawingImpl extends Drawing { - const _$DrawingImpl( +class Drawing extends ScribbleState { + const Drawing( {required this.sketch, this.activeLine, this.allowedPointersMode = ScribblePointerMode.all, @@ -385,16 +496,14 @@ class _$DrawingImpl extends Drawing { : _activePointerIds = activePointerIds, $type = $type ?? 'drawing', super._(); - - factory _$DrawingImpl.fromJson(Map json) => - _$$DrawingImplFromJson(json); + factory Drawing.fromJson(Map json) => + _$DrawingFromJson(json); /// The current state of the sketch @override final Sketch sketch; /// The line that is currently being drawn - @override final SketchLine? activeLine; /// Which pointers are allowed for drawing and will be captured by the @@ -423,7 +532,6 @@ class _$DrawingImpl extends Drawing { final Point? pointerPosition; /// The color that is currently being drawn with - @override @JsonKey() final int selectedColor; @@ -455,16 +563,26 @@ class _$DrawingImpl extends Drawing { @JsonKey(name: 'runtimeType') final String $type; + /// Create a copy of ScribbleState + /// with the given fields replaced by the non-null parameter values. @override - String toString() { - return 'ScribbleState.drawing(sketch: $sketch, activeLine: $activeLine, allowedPointersMode: $allowedPointersMode, activePointerIds: $activePointerIds, pointerPosition: $pointerPosition, selectedColor: $selectedColor, selectedWidth: $selectedWidth, scaleFactor: $scaleFactor, simplificationTolerance: $simplificationTolerance)'; + @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') + $DrawingCopyWith get copyWith => + _$DrawingCopyWithImpl(this, _$identity); + + @override + Map toJson() { + return _$DrawingToJson( + this, + ); } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$DrawingImpl && + other is Drawing && (identical(other.sketch, sketch) || other.sketch == sketch) && (identical(other.activeLine, activeLine) || other.activeLine == activeLine) && @@ -499,315 +617,142 @@ class _$DrawingImpl extends Drawing { scaleFactor, simplificationTolerance); - /// Create a copy of ScribbleState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$DrawingImplCopyWith<_$DrawingImpl> get copyWith => - __$$DrawingImplCopyWithImpl<_$DrawingImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function( - Sketch sketch, - SketchLine? activeLine, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - int selectedColor, - double selectedWidth, - double scaleFactor, - double simplificationTolerance) - drawing, - required TResult Function( - Sketch sketch, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - double selectedWidth, - double scaleFactor, - double simplificationTolerance) - erasing, - }) { - return drawing( - sketch, - activeLine, - allowedPointersMode, - activePointerIds, - pointerPosition, - selectedColor, - selectedWidth, - scaleFactor, - simplificationTolerance); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function( - Sketch sketch, - SketchLine? activeLine, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - int selectedColor, - double selectedWidth, - double scaleFactor, - double simplificationTolerance)? - drawing, - TResult? Function( - Sketch sketch, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - double selectedWidth, - double scaleFactor, - double simplificationTolerance)? - erasing, - }) { - return drawing?.call( - sketch, - activeLine, - allowedPointersMode, - activePointerIds, - pointerPosition, - selectedColor, - selectedWidth, - scaleFactor, - simplificationTolerance); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function( - Sketch sketch, - SketchLine? activeLine, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - int selectedColor, - double selectedWidth, - double scaleFactor, - double simplificationTolerance)? - drawing, - TResult Function( - Sketch sketch, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - double selectedWidth, - double scaleFactor, - double simplificationTolerance)? - erasing, - required TResult orElse(), - }) { - if (drawing != null) { - return drawing( - sketch, - activeLine, - allowedPointersMode, - activePointerIds, - pointerPosition, - selectedColor, - selectedWidth, - scaleFactor, - simplificationTolerance); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(Drawing value) drawing, - required TResult Function(Erasing value) erasing, - }) { - return drawing(this); - } - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(Drawing value)? drawing, - TResult? Function(Erasing value)? erasing, - }) { - return drawing?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(Drawing value)? drawing, - TResult Function(Erasing value)? erasing, - required TResult orElse(), - }) { - if (drawing != null) { - return drawing(this); - } - return orElse(); - } - - @override - Map toJson() { - return _$$DrawingImplToJson( - this, - ); + String toString() { + return 'ScribbleState.drawing(sketch: $sketch, activeLine: $activeLine, allowedPointersMode: $allowedPointersMode, activePointerIds: $activePointerIds, pointerPosition: $pointerPosition, selectedColor: $selectedColor, selectedWidth: $selectedWidth, scaleFactor: $scaleFactor, simplificationTolerance: $simplificationTolerance)'; } } -abstract class Drawing extends ScribbleState { - const factory Drawing( - {required final Sketch sketch, - final SketchLine? activeLine, - final ScribblePointerMode allowedPointersMode, - final List activePointerIds, - final Point? pointerPosition, - final int selectedColor, - final double selectedWidth, - final double scaleFactor, - final double simplificationTolerance}) = _$DrawingImpl; - const Drawing._() : super._(); - - factory Drawing.fromJson(Map json) = _$DrawingImpl.fromJson; - - /// The current state of the sketch - @override - Sketch get sketch; - - /// The line that is currently being drawn - SketchLine? get activeLine; - - /// Which pointers are allowed for drawing and will be captured by the - /// scribble widget. - @override - ScribblePointerMode get allowedPointersMode; - - /// The ids of all supported pointers that are currently interacting with - /// the widget. - @override - List get activePointerIds; - - /// The current position of the pointer - @override - Point? get pointerPosition; - - /// The color that is currently being drawn with - int get selectedColor; - - /// The current width of the pen - @override - double get selectedWidth; - - /// {@template view.state.scribble_state.scale_factor} - /// How much the widget is scaled at the moment. - /// - /// Can be used if zoom functionality is needed - /// (e.g. through InteractiveViewer) so that the pen width remains the same. - /// {@endtemplate} - @override - double get scaleFactor; - - /// {@template view.state.scribble_state.simplification_tolerance} - /// The current tolerance of simplification, in pixels. - /// - /// Lines will be simplified when they are finished. A value of 0 (default) - /// will mean no simplification. - /// {@endtemplate} - @override - double get simplificationTolerance; - - /// Create a copy of ScribbleState - /// with the given fields replaced by the non-null parameter values. - @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$DrawingImplCopyWith<_$DrawingImpl> get copyWith => - throw _privateConstructorUsedError; -} - /// @nodoc -abstract class _$$ErasingImplCopyWith<$Res> +abstract mixin class $DrawingCopyWith<$Res> implements $ScribbleStateCopyWith<$Res> { - factory _$$ErasingImplCopyWith( - _$ErasingImpl value, $Res Function(_$ErasingImpl) then) = - __$$ErasingImplCopyWithImpl<$Res>; + factory $DrawingCopyWith(Drawing value, $Res Function(Drawing) _then) = + _$DrawingCopyWithImpl; @override @useResult $Res call( {Sketch sketch, + SketchLine? activeLine, ScribblePointerMode allowedPointersMode, List activePointerIds, Point? pointerPosition, + int selectedColor, double selectedWidth, double scaleFactor, double simplificationTolerance}); @override $SketchCopyWith<$Res> get sketch; + $SketchLineCopyWith<$Res>? get activeLine; @override $PointCopyWith<$Res>? get pointerPosition; } /// @nodoc -class __$$ErasingImplCopyWithImpl<$Res> - extends _$ScribbleStateCopyWithImpl<$Res, _$ErasingImpl> - implements _$$ErasingImplCopyWith<$Res> { - __$$ErasingImplCopyWithImpl( - _$ErasingImpl _value, $Res Function(_$ErasingImpl) _then) - : super(_value, _then); +class _$DrawingCopyWithImpl<$Res> implements $DrawingCopyWith<$Res> { + _$DrawingCopyWithImpl(this._self, this._then); + + final Drawing _self; + final $Res Function(Drawing) _then; /// Create a copy of ScribbleState /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') @override + @pragma('vm:prefer-inline') $Res call({ Object? sketch = null, + Object? activeLine = freezed, Object? allowedPointersMode = null, Object? activePointerIds = null, Object? pointerPosition = freezed, + Object? selectedColor = null, Object? selectedWidth = null, Object? scaleFactor = null, Object? simplificationTolerance = null, }) { - return _then(_$ErasingImpl( + return _then(Drawing( sketch: null == sketch - ? _value.sketch + ? _self.sketch : sketch // ignore: cast_nullable_to_non_nullable as Sketch, + activeLine: freezed == activeLine + ? _self.activeLine + : activeLine // ignore: cast_nullable_to_non_nullable + as SketchLine?, allowedPointersMode: null == allowedPointersMode - ? _value.allowedPointersMode + ? _self.allowedPointersMode : allowedPointersMode // ignore: cast_nullable_to_non_nullable as ScribblePointerMode, activePointerIds: null == activePointerIds - ? _value._activePointerIds + ? _self._activePointerIds : activePointerIds // ignore: cast_nullable_to_non_nullable as List, pointerPosition: freezed == pointerPosition - ? _value.pointerPosition + ? _self.pointerPosition : pointerPosition // ignore: cast_nullable_to_non_nullable as Point?, + selectedColor: null == selectedColor + ? _self.selectedColor + : selectedColor // ignore: cast_nullable_to_non_nullable + as int, selectedWidth: null == selectedWidth - ? _value.selectedWidth + ? _self.selectedWidth : selectedWidth // ignore: cast_nullable_to_non_nullable as double, scaleFactor: null == scaleFactor - ? _value.scaleFactor + ? _self.scaleFactor : scaleFactor // ignore: cast_nullable_to_non_nullable as double, simplificationTolerance: null == simplificationTolerance - ? _value.simplificationTolerance + ? _self.simplificationTolerance : simplificationTolerance // ignore: cast_nullable_to_non_nullable as double, )); } + + /// Create a copy of ScribbleState + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $SketchCopyWith<$Res> get sketch { + return $SketchCopyWith<$Res>(_self.sketch, (value) { + return _then(_self.copyWith(sketch: value)); + }); + } + + /// Create a copy of ScribbleState + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $SketchLineCopyWith<$Res>? get activeLine { + if (_self.activeLine == null) { + return null; + } + + return $SketchLineCopyWith<$Res>(_self.activeLine!, (value) { + return _then(_self.copyWith(activeLine: value)); + }); + } + + /// Create a copy of ScribbleState + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $PointCopyWith<$Res>? get pointerPosition { + if (_self.pointerPosition == null) { + return null; + } + + return $PointCopyWith<$Res>(_self.pointerPosition!, (value) { + return _then(_self.copyWith(pointerPosition: value)); + }); + } } /// @nodoc @JsonSerializable() -class _$ErasingImpl extends Erasing { - const _$ErasingImpl( +class Erasing extends ScribbleState { + const Erasing( {required this.sketch, this.allowedPointersMode = ScribblePointerMode.all, final List activePointerIds = const [], @@ -819,9 +764,8 @@ class _$ErasingImpl extends Erasing { : _activePointerIds = activePointerIds, $type = $type ?? 'erasing', super._(); - - factory _$ErasingImpl.fromJson(Map json) => - _$$ErasingImplFromJson(json); + factory Erasing.fromJson(Map json) => + _$ErasingFromJson(json); /// The current state of the sketch @override @@ -876,16 +820,26 @@ class _$ErasingImpl extends Erasing { @JsonKey(name: 'runtimeType') final String $type; + /// Create a copy of ScribbleState + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') + $ErasingCopyWith get copyWith => + _$ErasingCopyWithImpl(this, _$identity); + @override - String toString() { - return 'ScribbleState.erasing(sketch: $sketch, allowedPointersMode: $allowedPointersMode, activePointerIds: $activePointerIds, pointerPosition: $pointerPosition, selectedWidth: $selectedWidth, scaleFactor: $scaleFactor, simplificationTolerance: $simplificationTolerance)'; + Map toJson() { + return _$ErasingToJson( + this, + ); } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$ErasingImpl && + other is Erasing && (identical(other.sketch, sketch) || other.sketch == sketch) && (identical(other.allowedPointersMode, allowedPointersMode) || other.allowedPointersMode == allowedPointersMode) && @@ -914,194 +868,109 @@ class _$ErasingImpl extends Erasing { scaleFactor, simplificationTolerance); - /// Create a copy of ScribbleState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$ErasingImplCopyWith<_$ErasingImpl> get copyWith => - __$$ErasingImplCopyWithImpl<_$ErasingImpl>(this, _$identity); - @override - @optionalTypeArgs - TResult when({ - required TResult Function( - Sketch sketch, - SketchLine? activeLine, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - int selectedColor, - double selectedWidth, - double scaleFactor, - double simplificationTolerance) - drawing, - required TResult Function( - Sketch sketch, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - double selectedWidth, - double scaleFactor, - double simplificationTolerance) - erasing, - }) { - return erasing(sketch, allowedPointersMode, activePointerIds, - pointerPosition, selectedWidth, scaleFactor, simplificationTolerance); + String toString() { + return 'ScribbleState.erasing(sketch: $sketch, allowedPointersMode: $allowedPointersMode, activePointerIds: $activePointerIds, pointerPosition: $pointerPosition, selectedWidth: $selectedWidth, scaleFactor: $scaleFactor, simplificationTolerance: $simplificationTolerance)'; } +} +/// @nodoc +abstract mixin class $ErasingCopyWith<$Res> + implements $ScribbleStateCopyWith<$Res> { + factory $ErasingCopyWith(Erasing value, $Res Function(Erasing) _then) = + _$ErasingCopyWithImpl; @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function( - Sketch sketch, - SketchLine? activeLine, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - int selectedColor, - double selectedWidth, - double scaleFactor, - double simplificationTolerance)? - drawing, - TResult? Function( - Sketch sketch, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - double selectedWidth, - double scaleFactor, - double simplificationTolerance)? - erasing, - }) { - return erasing?.call(sketch, allowedPointersMode, activePointerIds, - pointerPosition, selectedWidth, scaleFactor, simplificationTolerance); - } + @useResult + $Res call( + {Sketch sketch, + ScribblePointerMode allowedPointersMode, + List activePointerIds, + Point? pointerPosition, + double selectedWidth, + double scaleFactor, + double simplificationTolerance}); @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function( - Sketch sketch, - SketchLine? activeLine, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - int selectedColor, - double selectedWidth, - double scaleFactor, - double simplificationTolerance)? - drawing, - TResult Function( - Sketch sketch, - ScribblePointerMode allowedPointersMode, - List activePointerIds, - Point? pointerPosition, - double selectedWidth, - double scaleFactor, - double simplificationTolerance)? - erasing, - required TResult orElse(), - }) { - if (erasing != null) { - return erasing(sketch, allowedPointersMode, activePointerIds, - pointerPosition, selectedWidth, scaleFactor, simplificationTolerance); - } - return orElse(); - } - + $SketchCopyWith<$Res> get sketch; @override - @optionalTypeArgs - TResult map({ - required TResult Function(Drawing value) drawing, - required TResult Function(Erasing value) erasing, - }) { - return erasing(this); - } + $PointCopyWith<$Res>? get pointerPosition; +} - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(Drawing value)? drawing, - TResult? Function(Erasing value)? erasing, - }) { - return erasing?.call(this); - } +/// @nodoc +class _$ErasingCopyWithImpl<$Res> implements $ErasingCopyWith<$Res> { + _$ErasingCopyWithImpl(this._self, this._then); + final Erasing _self; + final $Res Function(Erasing) _then; + + /// Create a copy of ScribbleState + /// with the given fields replaced by the non-null parameter values. @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(Drawing value)? drawing, - TResult Function(Erasing value)? erasing, - required TResult orElse(), + @pragma('vm:prefer-inline') + $Res call({ + Object? sketch = null, + Object? allowedPointersMode = null, + Object? activePointerIds = null, + Object? pointerPosition = freezed, + Object? selectedWidth = null, + Object? scaleFactor = null, + Object? simplificationTolerance = null, }) { - if (erasing != null) { - return erasing(this); - } - return orElse(); + return _then(Erasing( + sketch: null == sketch + ? _self.sketch + : sketch // ignore: cast_nullable_to_non_nullable + as Sketch, + allowedPointersMode: null == allowedPointersMode + ? _self.allowedPointersMode + : allowedPointersMode // ignore: cast_nullable_to_non_nullable + as ScribblePointerMode, + activePointerIds: null == activePointerIds + ? _self._activePointerIds + : activePointerIds // ignore: cast_nullable_to_non_nullable + as List, + pointerPosition: freezed == pointerPosition + ? _self.pointerPosition + : pointerPosition // ignore: cast_nullable_to_non_nullable + as Point?, + selectedWidth: null == selectedWidth + ? _self.selectedWidth + : selectedWidth // ignore: cast_nullable_to_non_nullable + as double, + scaleFactor: null == scaleFactor + ? _self.scaleFactor + : scaleFactor // ignore: cast_nullable_to_non_nullable + as double, + simplificationTolerance: null == simplificationTolerance + ? _self.simplificationTolerance + : simplificationTolerance // ignore: cast_nullable_to_non_nullable + as double, + )); } + /// Create a copy of ScribbleState + /// with the given fields replaced by the non-null parameter values. @override - Map toJson() { - return _$$ErasingImplToJson( - this, - ); + @pragma('vm:prefer-inline') + $SketchCopyWith<$Res> get sketch { + return $SketchCopyWith<$Res>(_self.sketch, (value) { + return _then(_self.copyWith(sketch: value)); + }); } -} - -abstract class Erasing extends ScribbleState { - const factory Erasing( - {required final Sketch sketch, - final ScribblePointerMode allowedPointersMode, - final List activePointerIds, - final Point? pointerPosition, - final double selectedWidth, - final double scaleFactor, - final double simplificationTolerance}) = _$ErasingImpl; - const Erasing._() : super._(); - - factory Erasing.fromJson(Map json) = _$ErasingImpl.fromJson; - - /// The current state of the sketch - @override - Sketch get sketch; - - /// Which pointers are allowed for drawing and will be captured by the - /// scribble widget. - @override - ScribblePointerMode get allowedPointersMode; - - /// The ids of all supported pointers that are currently interacting with - /// the widget. - @override - List get activePointerIds; - - /// The current position of the pointer - @override - Point? get pointerPosition; - - /// The current width of the pen - @override - double get selectedWidth; - - /// How much the widget is scaled at the moment. - /// - /// Can be used if zoom functionality is needed - /// (e.g. through InteractiveViewer) so that the pen width remains the same. - @override - double get scaleFactor; - - /// The current tolerance of simplification, in pixels. - /// - /// Lines will be simplified when they are finished. A value of 0 (default) - /// will mean no simplification. - @override - double get simplificationTolerance; /// Create a copy of ScribbleState /// with the given fields replaced by the non-null parameter values. @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$ErasingImplCopyWith<_$ErasingImpl> get copyWith => - throw _privateConstructorUsedError; + @pragma('vm:prefer-inline') + $PointCopyWith<$Res>? get pointerPosition { + if (_self.pointerPosition == null) { + return null; + } + + return $PointCopyWith<$Res>(_self.pointerPosition!, (value) { + return _then(_self.copyWith(pointerPosition: value)); + }); + } } + +// dart format on diff --git a/lib/src/view/state/scribble.state.g.dart b/lib/src/view/state/scribble.state.g.dart index a76c097..ac4989d 100644 --- a/lib/src/view/state/scribble.state.g.dart +++ b/lib/src/view/state/scribble.state.g.dart @@ -6,8 +6,7 @@ part of 'scribble.state.dart'; // JsonSerializableGenerator // ************************************************************************** -_$DrawingImpl _$$DrawingImplFromJson(Map json) => - _$DrawingImpl( +Drawing _$DrawingFromJson(Map json) => Drawing( sketch: Sketch.fromJson(json['sketch'] as Map), activeLine: json['activeLine'] == null ? null @@ -30,8 +29,7 @@ _$DrawingImpl _$$DrawingImplFromJson(Map json) => $type: json['runtimeType'] as String?, ); -Map _$$DrawingImplToJson(_$DrawingImpl instance) => - { +Map _$DrawingToJson(Drawing instance) => { 'sketch': instance.sketch.toJson(), 'activeLine': instance.activeLine?.toJson(), 'allowedPointersMode': @@ -52,8 +50,7 @@ const _$ScribblePointerModeEnumMap = { ScribblePointerMode.mouseAndPen: 'mouseAndPen', }; -_$ErasingImpl _$$ErasingImplFromJson(Map json) => - _$ErasingImpl( +Erasing _$ErasingFromJson(Map json) => Erasing( sketch: Sketch.fromJson(json['sketch'] as Map), allowedPointersMode: $enumDecodeNullable( _$ScribblePointerModeEnumMap, json['allowedPointersMode']) ?? @@ -72,8 +69,7 @@ _$ErasingImpl _$$ErasingImplFromJson(Map json) => $type: json['runtimeType'] as String?, ); -Map _$$ErasingImplToJson(_$ErasingImpl instance) => - { +Map _$ErasingToJson(Erasing instance) => { 'sketch': instance.sketch.toJson(), 'allowedPointersMode': _$ScribblePointerModeEnumMap[instance.allowedPointersMode]!, From c562bfd6dd1373a7bb81a1e03731d0900f7a3b54 Mon Sep 17 00:00:00 2001 From: Johann Schramm <43448334+JohannSchramm@users.noreply.github.com> Date: Fri, 27 Feb 2026 10:40:23 +0100 Subject: [PATCH 3/3] chore: Update freezed version constraints --- pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 4e7e248..b45c978 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ environment: dependencies: flutter: sdk: flutter - freezed_annotation: ^3.1.0 + freezed_annotation: ">=2.4.1 <4.0.0" perfect_freehand: ^2.3.2 simpli: ^0.1.1 value_notifier_tools: ^0.1.2 @@ -21,7 +21,7 @@ dev_dependencies: build_runner: ^2.4.9 flutter_test: sdk: flutter - freezed: ^3.2.5 + freezed: ">=2.4.7 <4.0.0" json_serializable: ^6.9.5 lintervention: ^0.3.1 melos: ^6.3.3