Fix bugs across app + server, optimize UI/UX, add Gitea CI
Some checks failed
CI / Test (Server, optional) (push) Failing after 2m10s
Windows Build / Build Windows (x64) (push) Failing after 29s
CI / Test (Flutter, Linux) (push) Has been cancelled
CI / Analyze (Flutter) (push) Has been cancelled

Bug fixes (Flutter):
- Wrap multi-statement DB writes (insert/update/delete note, deleteDocument,
  deletePageData, OCR FTS merge, migrations) in transactions to prevent data
  loss on interruption and a read-modify-write FTS race.
- Fix PdfDocument leaks on exception (try/finally dispose) and preserve image
  aspect ratio when stamping images onto PDF pages.
- Guard file-picker against empty selection (was .single -> crash).
- Fix eraser ConcurrentModificationError and unmodifiable-list crash on PDF
  pages; capture page synchronously on save to stop wrong-page data loss.
- Fix Riverpod DB-not-ready races, broken pull-to-refresh, settings load race,
  and search N+1; transform stored annotations on PDF page rotation.
- Normalize pen pressure for devices without a pressure range.
- PPT: single source of truth for slide strokes so ink displays and exports.

UI/UX:
- Material 3 typography, theme-aware colors (dark-mode fixes), hover cursors
  and right-click/visible actions on desktop, keyboard shortcuts (undo/redo/
  save/find), toolbar overflow handling, friendlier empty states, semantic OCR
  status badges, relative timestamps, 1-based page indicators, large-deck PPT
  navigation, and a scratchpad-scope label in split view.

Server (optional backend):
- Persist JWT secret (was per-process random), block path traversal in storage,
  fix CORS '*'+credentials, add OCR job ownership checks, last-writer-wins sync
  guard, constant-time login, and split out heavy OCR deps so the API/tests run
  without them.

CI: Gitea workflows for format+analyze+test (Linux, system sqlite) and a
Windows release build; pristine `flutter analyze`, all Flutter and server tests
green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-21 03:18:00 +08:00
commit 72428dc075
210 changed files with 18171 additions and 0 deletions

19
lib/models/bookmark.dart Normal file
View File

@@ -0,0 +1,19 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'bookmark.freezed.dart';
part 'bookmark.g.dart';
@freezed
abstract class Bookmark with _$Bookmark {
const factory Bookmark({
required String id,
required String documentId,
required int pageNumber,
@Default('') String label,
@Default(0xFF2196F3) int color,
required DateTime createdAt,
}) = _Bookmark;
factory Bookmark.fromJson(Map<String, dynamic> json) =>
_$BookmarkFromJson(json);
}

View File

@@ -0,0 +1,290 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// 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
part of 'bookmark.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(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',
);
Bookmark _$BookmarkFromJson(Map<String, dynamic> json) {
return _Bookmark.fromJson(json);
}
/// @nodoc
mixin _$Bookmark {
String get id => throw _privateConstructorUsedError;
String get documentId => throw _privateConstructorUsedError;
int get pageNumber => throw _privateConstructorUsedError;
String get label => throw _privateConstructorUsedError;
int get color => throw _privateConstructorUsedError;
DateTime get createdAt => throw _privateConstructorUsedError;
/// Serializes this Bookmark to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of Bookmark
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$BookmarkCopyWith<Bookmark> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $BookmarkCopyWith<$Res> {
factory $BookmarkCopyWith(Bookmark value, $Res Function(Bookmark) then) =
_$BookmarkCopyWithImpl<$Res, Bookmark>;
@useResult
$Res call({
String id,
String documentId,
int pageNumber,
String label,
int color,
DateTime createdAt,
});
}
/// @nodoc
class _$BookmarkCopyWithImpl<$Res, $Val extends Bookmark>
implements $BookmarkCopyWith<$Res> {
_$BookmarkCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of Bookmark
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = null,
Object? documentId = null,
Object? pageNumber = null,
Object? label = null,
Object? color = null,
Object? createdAt = null,
}) {
return _then(
_value.copyWith(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
documentId: null == documentId
? _value.documentId
: documentId // ignore: cast_nullable_to_non_nullable
as String,
pageNumber: null == pageNumber
? _value.pageNumber
: pageNumber // ignore: cast_nullable_to_non_nullable
as int,
label: null == label
? _value.label
: label // ignore: cast_nullable_to_non_nullable
as String,
color: null == color
? _value.color
: color // ignore: cast_nullable_to_non_nullable
as int,
createdAt: null == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$BookmarkImplCopyWith<$Res>
implements $BookmarkCopyWith<$Res> {
factory _$$BookmarkImplCopyWith(
_$BookmarkImpl value,
$Res Function(_$BookmarkImpl) then,
) = __$$BookmarkImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
String id,
String documentId,
int pageNumber,
String label,
int color,
DateTime createdAt,
});
}
/// @nodoc
class __$$BookmarkImplCopyWithImpl<$Res>
extends _$BookmarkCopyWithImpl<$Res, _$BookmarkImpl>
implements _$$BookmarkImplCopyWith<$Res> {
__$$BookmarkImplCopyWithImpl(
_$BookmarkImpl _value,
$Res Function(_$BookmarkImpl) _then,
) : super(_value, _then);
/// Create a copy of Bookmark
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = null,
Object? documentId = null,
Object? pageNumber = null,
Object? label = null,
Object? color = null,
Object? createdAt = null,
}) {
return _then(
_$BookmarkImpl(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
documentId: null == documentId
? _value.documentId
: documentId // ignore: cast_nullable_to_non_nullable
as String,
pageNumber: null == pageNumber
? _value.pageNumber
: pageNumber // ignore: cast_nullable_to_non_nullable
as int,
label: null == label
? _value.label
: label // ignore: cast_nullable_to_non_nullable
as String,
color: null == color
? _value.color
: color // ignore: cast_nullable_to_non_nullable
as int,
createdAt: null == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$BookmarkImpl implements _Bookmark {
const _$BookmarkImpl({
required this.id,
required this.documentId,
required this.pageNumber,
this.label = '',
this.color = 0xFF2196F3,
required this.createdAt,
});
factory _$BookmarkImpl.fromJson(Map<String, dynamic> json) =>
_$$BookmarkImplFromJson(json);
@override
final String id;
@override
final String documentId;
@override
final int pageNumber;
@override
@JsonKey()
final String label;
@override
@JsonKey()
final int color;
@override
final DateTime createdAt;
@override
String toString() {
return 'Bookmark(id: $id, documentId: $documentId, pageNumber: $pageNumber, label: $label, color: $color, createdAt: $createdAt)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$BookmarkImpl &&
(identical(other.id, id) || other.id == id) &&
(identical(other.documentId, documentId) ||
other.documentId == documentId) &&
(identical(other.pageNumber, pageNumber) ||
other.pageNumber == pageNumber) &&
(identical(other.label, label) || other.label == label) &&
(identical(other.color, color) || other.color == color) &&
(identical(other.createdAt, createdAt) ||
other.createdAt == createdAt));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
id,
documentId,
pageNumber,
label,
color,
createdAt,
);
/// Create a copy of Bookmark
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$BookmarkImplCopyWith<_$BookmarkImpl> get copyWith =>
__$$BookmarkImplCopyWithImpl<_$BookmarkImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$BookmarkImplToJson(this);
}
}
abstract class _Bookmark implements Bookmark {
const factory _Bookmark({
required final String id,
required final String documentId,
required final int pageNumber,
final String label,
final int color,
required final DateTime createdAt,
}) = _$BookmarkImpl;
factory _Bookmark.fromJson(Map<String, dynamic> json) =
_$BookmarkImpl.fromJson;
@override
String get id;
@override
String get documentId;
@override
int get pageNumber;
@override
String get label;
@override
int get color;
@override
DateTime get createdAt;
/// Create a copy of Bookmark
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$BookmarkImplCopyWith<_$BookmarkImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -0,0 +1,27 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'bookmark.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$BookmarkImpl _$$BookmarkImplFromJson(Map<String, dynamic> json) =>
_$BookmarkImpl(
id: json['id'] as String,
documentId: json['documentId'] as String,
pageNumber: (json['pageNumber'] as num).toInt(),
label: json['label'] as String? ?? '',
color: (json['color'] as num?)?.toInt() ?? 0xFF2196F3,
createdAt: DateTime.parse(json['createdAt'] as String),
);
Map<String, dynamic> _$$BookmarkImplToJson(_$BookmarkImpl instance) =>
<String, dynamic>{
'id': instance.id,
'documentId': instance.documentId,
'pageNumber': instance.pageNumber,
'label': instance.label,
'color': instance.color,
'createdAt': instance.createdAt.toIso8601String(),
};

21
lib/models/document.dart Normal file
View File

@@ -0,0 +1,21 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'document.freezed.dart';
part 'document.g.dart';
@freezed
abstract class Document with _$Document {
const factory Document({
required String id,
required String filename,
required String docType,
required String filePath,
@Default(0) int pageCount,
@Default(0) int rotation,
required DateTime createdAt,
required DateTime updatedAt,
}) = _Document;
factory Document.fromJson(Map<String, dynamic> json) =>
_$DocumentFromJson(json);
}

View File

@@ -0,0 +1,335 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// 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
part of 'document.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(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',
);
Document _$DocumentFromJson(Map<String, dynamic> json) {
return _Document.fromJson(json);
}
/// @nodoc
mixin _$Document {
String get id => throw _privateConstructorUsedError;
String get filename => throw _privateConstructorUsedError;
String get docType => throw _privateConstructorUsedError;
String get filePath => throw _privateConstructorUsedError;
int get pageCount => throw _privateConstructorUsedError;
int get rotation => throw _privateConstructorUsedError;
DateTime get createdAt => throw _privateConstructorUsedError;
DateTime get updatedAt => throw _privateConstructorUsedError;
/// Serializes this Document to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of Document
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$DocumentCopyWith<Document> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $DocumentCopyWith<$Res> {
factory $DocumentCopyWith(Document value, $Res Function(Document) then) =
_$DocumentCopyWithImpl<$Res, Document>;
@useResult
$Res call({
String id,
String filename,
String docType,
String filePath,
int pageCount,
int rotation,
DateTime createdAt,
DateTime updatedAt,
});
}
/// @nodoc
class _$DocumentCopyWithImpl<$Res, $Val extends Document>
implements $DocumentCopyWith<$Res> {
_$DocumentCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of Document
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = null,
Object? filename = null,
Object? docType = null,
Object? filePath = null,
Object? pageCount = null,
Object? rotation = null,
Object? createdAt = null,
Object? updatedAt = null,
}) {
return _then(
_value.copyWith(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
filename: null == filename
? _value.filename
: filename // ignore: cast_nullable_to_non_nullable
as String,
docType: null == docType
? _value.docType
: docType // ignore: cast_nullable_to_non_nullable
as String,
filePath: null == filePath
? _value.filePath
: filePath // ignore: cast_nullable_to_non_nullable
as String,
pageCount: null == pageCount
? _value.pageCount
: pageCount // ignore: cast_nullable_to_non_nullable
as int,
rotation: null == rotation
? _value.rotation
: rotation // ignore: cast_nullable_to_non_nullable
as int,
createdAt: null == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime,
updatedAt: null == updatedAt
? _value.updatedAt
: updatedAt // ignore: cast_nullable_to_non_nullable
as DateTime,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$DocumentImplCopyWith<$Res>
implements $DocumentCopyWith<$Res> {
factory _$$DocumentImplCopyWith(
_$DocumentImpl value,
$Res Function(_$DocumentImpl) then,
) = __$$DocumentImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
String id,
String filename,
String docType,
String filePath,
int pageCount,
int rotation,
DateTime createdAt,
DateTime updatedAt,
});
}
/// @nodoc
class __$$DocumentImplCopyWithImpl<$Res>
extends _$DocumentCopyWithImpl<$Res, _$DocumentImpl>
implements _$$DocumentImplCopyWith<$Res> {
__$$DocumentImplCopyWithImpl(
_$DocumentImpl _value,
$Res Function(_$DocumentImpl) _then,
) : super(_value, _then);
/// Create a copy of Document
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = null,
Object? filename = null,
Object? docType = null,
Object? filePath = null,
Object? pageCount = null,
Object? rotation = null,
Object? createdAt = null,
Object? updatedAt = null,
}) {
return _then(
_$DocumentImpl(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
filename: null == filename
? _value.filename
: filename // ignore: cast_nullable_to_non_nullable
as String,
docType: null == docType
? _value.docType
: docType // ignore: cast_nullable_to_non_nullable
as String,
filePath: null == filePath
? _value.filePath
: filePath // ignore: cast_nullable_to_non_nullable
as String,
pageCount: null == pageCount
? _value.pageCount
: pageCount // ignore: cast_nullable_to_non_nullable
as int,
rotation: null == rotation
? _value.rotation
: rotation // ignore: cast_nullable_to_non_nullable
as int,
createdAt: null == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime,
updatedAt: null == updatedAt
? _value.updatedAt
: updatedAt // ignore: cast_nullable_to_non_nullable
as DateTime,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$DocumentImpl implements _Document {
const _$DocumentImpl({
required this.id,
required this.filename,
required this.docType,
required this.filePath,
this.pageCount = 0,
this.rotation = 0,
required this.createdAt,
required this.updatedAt,
});
factory _$DocumentImpl.fromJson(Map<String, dynamic> json) =>
_$$DocumentImplFromJson(json);
@override
final String id;
@override
final String filename;
@override
final String docType;
@override
final String filePath;
@override
@JsonKey()
final int pageCount;
@override
@JsonKey()
final int rotation;
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
@override
String toString() {
return 'Document(id: $id, filename: $filename, docType: $docType, filePath: $filePath, pageCount: $pageCount, rotation: $rotation, createdAt: $createdAt, updatedAt: $updatedAt)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$DocumentImpl &&
(identical(other.id, id) || other.id == id) &&
(identical(other.filename, filename) ||
other.filename == filename) &&
(identical(other.docType, docType) || other.docType == docType) &&
(identical(other.filePath, filePath) ||
other.filePath == filePath) &&
(identical(other.pageCount, pageCount) ||
other.pageCount == pageCount) &&
(identical(other.rotation, rotation) ||
other.rotation == rotation) &&
(identical(other.createdAt, createdAt) ||
other.createdAt == createdAt) &&
(identical(other.updatedAt, updatedAt) ||
other.updatedAt == updatedAt));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
id,
filename,
docType,
filePath,
pageCount,
rotation,
createdAt,
updatedAt,
);
/// Create a copy of Document
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$DocumentImplCopyWith<_$DocumentImpl> get copyWith =>
__$$DocumentImplCopyWithImpl<_$DocumentImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$DocumentImplToJson(this);
}
}
abstract class _Document implements Document {
const factory _Document({
required final String id,
required final String filename,
required final String docType,
required final String filePath,
final int pageCount,
final int rotation,
required final DateTime createdAt,
required final DateTime updatedAt,
}) = _$DocumentImpl;
factory _Document.fromJson(Map<String, dynamic> json) =
_$DocumentImpl.fromJson;
@override
String get id;
@override
String get filename;
@override
String get docType;
@override
String get filePath;
@override
int get pageCount;
@override
int get rotation;
@override
DateTime get createdAt;
@override
DateTime get updatedAt;
/// Create a copy of Document
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$DocumentImplCopyWith<_$DocumentImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -0,0 +1,31 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'document.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$DocumentImpl _$$DocumentImplFromJson(Map<String, dynamic> json) =>
_$DocumentImpl(
id: json['id'] as String,
filename: json['filename'] as String,
docType: json['docType'] as String,
filePath: json['filePath'] as String,
pageCount: (json['pageCount'] as num?)?.toInt() ?? 0,
rotation: (json['rotation'] as num?)?.toInt() ?? 0,
createdAt: DateTime.parse(json['createdAt'] as String),
updatedAt: DateTime.parse(json['updatedAt'] as String),
);
Map<String, dynamic> _$$DocumentImplToJson(_$DocumentImpl instance) =>
<String, dynamic>{
'id': instance.id,
'filename': instance.filename,
'docType': instance.docType,
'filePath': instance.filePath,
'pageCount': instance.pageCount,
'rotation': instance.rotation,
'createdAt': instance.createdAt.toIso8601String(),
'updatedAt': instance.updatedAt.toIso8601String(),
};

21
lib/models/ink_point.dart Normal file
View File

@@ -0,0 +1,21 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'pointer_device_kind.dart';
part 'ink_point.freezed.dart';
part 'ink_point.g.dart';
@freezed
abstract class InkPoint with _$InkPoint {
const factory InkPoint({
required double x,
required double y,
@Default(0.5) double pressure,
@Default(0.0) double tilt,
required int timestamp,
@Default(InputDeviceKind.unknown) InputDeviceKind pointerDeviceKind,
}) = _InkPoint;
factory InkPoint.fromJson(Map<String, dynamic> json) =>
_$InkPointFromJson(json);
}

View File

@@ -0,0 +1,291 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// 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
part of 'ink_point.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(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',
);
InkPoint _$InkPointFromJson(Map<String, dynamic> json) {
return _InkPoint.fromJson(json);
}
/// @nodoc
mixin _$InkPoint {
double get x => throw _privateConstructorUsedError;
double get y => throw _privateConstructorUsedError;
double get pressure => throw _privateConstructorUsedError;
double get tilt => throw _privateConstructorUsedError;
int get timestamp => throw _privateConstructorUsedError;
InputDeviceKind get pointerDeviceKind => throw _privateConstructorUsedError;
/// Serializes this InkPoint to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of InkPoint
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$InkPointCopyWith<InkPoint> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $InkPointCopyWith<$Res> {
factory $InkPointCopyWith(InkPoint value, $Res Function(InkPoint) then) =
_$InkPointCopyWithImpl<$Res, InkPoint>;
@useResult
$Res call({
double x,
double y,
double pressure,
double tilt,
int timestamp,
InputDeviceKind pointerDeviceKind,
});
}
/// @nodoc
class _$InkPointCopyWithImpl<$Res, $Val extends InkPoint>
implements $InkPointCopyWith<$Res> {
_$InkPointCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of InkPoint
/// 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,
Object? tilt = null,
Object? timestamp = null,
Object? pointerDeviceKind = null,
}) {
return _then(
_value.copyWith(
x: null == x
? _value.x
: x // ignore: cast_nullable_to_non_nullable
as double,
y: 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,
tilt: null == tilt
? _value.tilt
: tilt // ignore: cast_nullable_to_non_nullable
as double,
timestamp: null == timestamp
? _value.timestamp
: timestamp // ignore: cast_nullable_to_non_nullable
as int,
pointerDeviceKind: null == pointerDeviceKind
? _value.pointerDeviceKind
: pointerDeviceKind // ignore: cast_nullable_to_non_nullable
as InputDeviceKind,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$InkPointImplCopyWith<$Res>
implements $InkPointCopyWith<$Res> {
factory _$$InkPointImplCopyWith(
_$InkPointImpl value,
$Res Function(_$InkPointImpl) then,
) = __$$InkPointImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
double x,
double y,
double pressure,
double tilt,
int timestamp,
InputDeviceKind pointerDeviceKind,
});
}
/// @nodoc
class __$$InkPointImplCopyWithImpl<$Res>
extends _$InkPointCopyWithImpl<$Res, _$InkPointImpl>
implements _$$InkPointImplCopyWith<$Res> {
__$$InkPointImplCopyWithImpl(
_$InkPointImpl _value,
$Res Function(_$InkPointImpl) _then,
) : super(_value, _then);
/// Create a copy of InkPoint
/// 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,
Object? tilt = null,
Object? timestamp = null,
Object? pointerDeviceKind = null,
}) {
return _then(
_$InkPointImpl(
x: null == x
? _value.x
: x // ignore: cast_nullable_to_non_nullable
as double,
y: 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,
tilt: null == tilt
? _value.tilt
: tilt // ignore: cast_nullable_to_non_nullable
as double,
timestamp: null == timestamp
? _value.timestamp
: timestamp // ignore: cast_nullable_to_non_nullable
as int,
pointerDeviceKind: null == pointerDeviceKind
? _value.pointerDeviceKind
: pointerDeviceKind // ignore: cast_nullable_to_non_nullable
as InputDeviceKind,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$InkPointImpl implements _InkPoint {
const _$InkPointImpl({
required this.x,
required this.y,
this.pressure = 0.5,
this.tilt = 0.0,
required this.timestamp,
this.pointerDeviceKind = InputDeviceKind.unknown,
});
factory _$InkPointImpl.fromJson(Map<String, dynamic> json) =>
_$$InkPointImplFromJson(json);
@override
final double x;
@override
final double y;
@override
@JsonKey()
final double pressure;
@override
@JsonKey()
final double tilt;
@override
final int timestamp;
@override
@JsonKey()
final InputDeviceKind pointerDeviceKind;
@override
String toString() {
return 'InkPoint(x: $x, y: $y, pressure: $pressure, tilt: $tilt, timestamp: $timestamp, pointerDeviceKind: $pointerDeviceKind)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$InkPointImpl &&
(identical(other.x, x) || other.x == x) &&
(identical(other.y, y) || other.y == y) &&
(identical(other.pressure, pressure) ||
other.pressure == pressure) &&
(identical(other.tilt, tilt) || other.tilt == tilt) &&
(identical(other.timestamp, timestamp) ||
other.timestamp == timestamp) &&
(identical(other.pointerDeviceKind, pointerDeviceKind) ||
other.pointerDeviceKind == pointerDeviceKind));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
x,
y,
pressure,
tilt,
timestamp,
pointerDeviceKind,
);
/// Create a copy of InkPoint
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$InkPointImplCopyWith<_$InkPointImpl> get copyWith =>
__$$InkPointImplCopyWithImpl<_$InkPointImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$InkPointImplToJson(this);
}
}
abstract class _InkPoint implements InkPoint {
const factory _InkPoint({
required final double x,
required final double y,
final double pressure,
final double tilt,
required final int timestamp,
final InputDeviceKind pointerDeviceKind,
}) = _$InkPointImpl;
factory _InkPoint.fromJson(Map<String, dynamic> json) =
_$InkPointImpl.fromJson;
@override
double get x;
@override
double get y;
@override
double get pressure;
@override
double get tilt;
@override
int get timestamp;
@override
InputDeviceKind get pointerDeviceKind;
/// Create a copy of InkPoint
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$InkPointImplCopyWith<_$InkPointImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -0,0 +1,42 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'ink_point.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$InkPointImpl _$$InkPointImplFromJson(Map<String, dynamic> json) =>
_$InkPointImpl(
x: (json['x'] as num).toDouble(),
y: (json['y'] as num).toDouble(),
pressure: (json['pressure'] as num?)?.toDouble() ?? 0.5,
tilt: (json['tilt'] as num?)?.toDouble() ?? 0.0,
timestamp: (json['timestamp'] as num).toInt(),
pointerDeviceKind:
$enumDecodeNullable(
_$InputDeviceKindEnumMap,
json['pointerDeviceKind'],
) ??
InputDeviceKind.unknown,
);
Map<String, dynamic> _$$InkPointImplToJson(
_$InkPointImpl instance,
) => <String, dynamic>{
'x': instance.x,
'y': instance.y,
'pressure': instance.pressure,
'tilt': instance.tilt,
'timestamp': instance.timestamp,
'pointerDeviceKind': _$InputDeviceKindEnumMap[instance.pointerDeviceKind]!,
};
const _$InputDeviceKindEnumMap = {
InputDeviceKind.touch: 'touch',
InputDeviceKind.mouse: 'mouse',
InputDeviceKind.stylus: 'stylus',
InputDeviceKind.invertedStylus: 'invertedStylus',
InputDeviceKind.trackpad: 'trackpad',
InputDeviceKind.unknown: 'unknown',
};

View File

@@ -0,0 +1,25 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'ink_point.dart';
import 'pen_tool.dart';
part 'ink_stroke.freezed.dart';
part 'ink_stroke.g.dart';
@freezed
abstract class InkStroke with _$InkStroke {
const factory InkStroke({
required String id,
required List<InkPoint> points,
@Default(PenTool.pen) PenTool tool,
@Default(0xFF000000) int color,
@Default(2.0) double strokeWidth,
required DateTime createdAt,
@Default(false) bool filled,
String? textContent,
@Default(14.0) double fontSize,
}) = _InkStroke;
factory InkStroke.fromJson(Map<String, dynamic> json) =>
_$InkStrokeFromJson(json);
}

View File

@@ -0,0 +1,363 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// 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
part of 'ink_stroke.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(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',
);
InkStroke _$InkStrokeFromJson(Map<String, dynamic> json) {
return _InkStroke.fromJson(json);
}
/// @nodoc
mixin _$InkStroke {
String get id => throw _privateConstructorUsedError;
List<InkPoint> get points => throw _privateConstructorUsedError;
PenTool get tool => throw _privateConstructorUsedError;
int get color => throw _privateConstructorUsedError;
double get strokeWidth => throw _privateConstructorUsedError;
DateTime get createdAt => throw _privateConstructorUsedError;
bool get filled => throw _privateConstructorUsedError;
String? get textContent => throw _privateConstructorUsedError;
double get fontSize => throw _privateConstructorUsedError;
/// Serializes this InkStroke to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of InkStroke
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$InkStrokeCopyWith<InkStroke> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $InkStrokeCopyWith<$Res> {
factory $InkStrokeCopyWith(InkStroke value, $Res Function(InkStroke) then) =
_$InkStrokeCopyWithImpl<$Res, InkStroke>;
@useResult
$Res call({
String id,
List<InkPoint> points,
PenTool tool,
int color,
double strokeWidth,
DateTime createdAt,
bool filled,
String? textContent,
double fontSize,
});
}
/// @nodoc
class _$InkStrokeCopyWithImpl<$Res, $Val extends InkStroke>
implements $InkStrokeCopyWith<$Res> {
_$InkStrokeCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of InkStroke
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = null,
Object? points = null,
Object? tool = null,
Object? color = null,
Object? strokeWidth = null,
Object? createdAt = null,
Object? filled = null,
Object? textContent = freezed,
Object? fontSize = null,
}) {
return _then(
_value.copyWith(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
points: null == points
? _value.points
: points // ignore: cast_nullable_to_non_nullable
as List<InkPoint>,
tool: null == tool
? _value.tool
: tool // ignore: cast_nullable_to_non_nullable
as PenTool,
color: null == color
? _value.color
: color // ignore: cast_nullable_to_non_nullable
as int,
strokeWidth: null == strokeWidth
? _value.strokeWidth
: strokeWidth // ignore: cast_nullable_to_non_nullable
as double,
createdAt: null == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime,
filled: null == filled
? _value.filled
: filled // ignore: cast_nullable_to_non_nullable
as bool,
textContent: freezed == textContent
? _value.textContent
: textContent // ignore: cast_nullable_to_non_nullable
as String?,
fontSize: null == fontSize
? _value.fontSize
: fontSize // ignore: cast_nullable_to_non_nullable
as double,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$InkStrokeImplCopyWith<$Res>
implements $InkStrokeCopyWith<$Res> {
factory _$$InkStrokeImplCopyWith(
_$InkStrokeImpl value,
$Res Function(_$InkStrokeImpl) then,
) = __$$InkStrokeImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
String id,
List<InkPoint> points,
PenTool tool,
int color,
double strokeWidth,
DateTime createdAt,
bool filled,
String? textContent,
double fontSize,
});
}
/// @nodoc
class __$$InkStrokeImplCopyWithImpl<$Res>
extends _$InkStrokeCopyWithImpl<$Res, _$InkStrokeImpl>
implements _$$InkStrokeImplCopyWith<$Res> {
__$$InkStrokeImplCopyWithImpl(
_$InkStrokeImpl _value,
$Res Function(_$InkStrokeImpl) _then,
) : super(_value, _then);
/// Create a copy of InkStroke
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = null,
Object? points = null,
Object? tool = null,
Object? color = null,
Object? strokeWidth = null,
Object? createdAt = null,
Object? filled = null,
Object? textContent = freezed,
Object? fontSize = null,
}) {
return _then(
_$InkStrokeImpl(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
points: null == points
? _value._points
: points // ignore: cast_nullable_to_non_nullable
as List<InkPoint>,
tool: null == tool
? _value.tool
: tool // ignore: cast_nullable_to_non_nullable
as PenTool,
color: null == color
? _value.color
: color // ignore: cast_nullable_to_non_nullable
as int,
strokeWidth: null == strokeWidth
? _value.strokeWidth
: strokeWidth // ignore: cast_nullable_to_non_nullable
as double,
createdAt: null == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime,
filled: null == filled
? _value.filled
: filled // ignore: cast_nullable_to_non_nullable
as bool,
textContent: freezed == textContent
? _value.textContent
: textContent // ignore: cast_nullable_to_non_nullable
as String?,
fontSize: null == fontSize
? _value.fontSize
: fontSize // ignore: cast_nullable_to_non_nullable
as double,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$InkStrokeImpl implements _InkStroke {
const _$InkStrokeImpl({
required this.id,
required final List<InkPoint> points,
this.tool = PenTool.pen,
this.color = 0xFF000000,
this.strokeWidth = 2.0,
required this.createdAt,
this.filled = false,
this.textContent,
this.fontSize = 14.0,
}) : _points = points;
factory _$InkStrokeImpl.fromJson(Map<String, dynamic> json) =>
_$$InkStrokeImplFromJson(json);
@override
final String id;
final List<InkPoint> _points;
@override
List<InkPoint> get points {
if (_points is EqualUnmodifiableListView) return _points;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_points);
}
@override
@JsonKey()
final PenTool tool;
@override
@JsonKey()
final int color;
@override
@JsonKey()
final double strokeWidth;
@override
final DateTime createdAt;
@override
@JsonKey()
final bool filled;
@override
final String? textContent;
@override
@JsonKey()
final double fontSize;
@override
String toString() {
return 'InkStroke(id: $id, points: $points, tool: $tool, color: $color, strokeWidth: $strokeWidth, createdAt: $createdAt, filled: $filled, textContent: $textContent, fontSize: $fontSize)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$InkStrokeImpl &&
(identical(other.id, id) || other.id == id) &&
const DeepCollectionEquality().equals(other._points, _points) &&
(identical(other.tool, tool) || other.tool == tool) &&
(identical(other.color, color) || other.color == color) &&
(identical(other.strokeWidth, strokeWidth) ||
other.strokeWidth == strokeWidth) &&
(identical(other.createdAt, createdAt) ||
other.createdAt == createdAt) &&
(identical(other.filled, filled) || other.filled == filled) &&
(identical(other.textContent, textContent) ||
other.textContent == textContent) &&
(identical(other.fontSize, fontSize) ||
other.fontSize == fontSize));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
id,
const DeepCollectionEquality().hash(_points),
tool,
color,
strokeWidth,
createdAt,
filled,
textContent,
fontSize,
);
/// Create a copy of InkStroke
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$InkStrokeImplCopyWith<_$InkStrokeImpl> get copyWith =>
__$$InkStrokeImplCopyWithImpl<_$InkStrokeImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$InkStrokeImplToJson(this);
}
}
abstract class _InkStroke implements InkStroke {
const factory _InkStroke({
required final String id,
required final List<InkPoint> points,
final PenTool tool,
final int color,
final double strokeWidth,
required final DateTime createdAt,
final bool filled,
final String? textContent,
final double fontSize,
}) = _$InkStrokeImpl;
factory _InkStroke.fromJson(Map<String, dynamic> json) =
_$InkStrokeImpl.fromJson;
@override
String get id;
@override
List<InkPoint> get points;
@override
PenTool get tool;
@override
int get color;
@override
double get strokeWidth;
@override
DateTime get createdAt;
@override
bool get filled;
@override
String? get textContent;
@override
double get fontSize;
/// Create a copy of InkStroke
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$InkStrokeImplCopyWith<_$InkStrokeImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -0,0 +1,47 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'ink_stroke.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$InkStrokeImpl _$$InkStrokeImplFromJson(Map<String, dynamic> json) =>
_$InkStrokeImpl(
id: json['id'] as String,
points: (json['points'] as List<dynamic>)
.map((e) => InkPoint.fromJson(e as Map<String, dynamic>))
.toList(),
tool: $enumDecodeNullable(_$PenToolEnumMap, json['tool']) ?? PenTool.pen,
color: (json['color'] as num?)?.toInt() ?? 0xFF000000,
strokeWidth: (json['strokeWidth'] as num?)?.toDouble() ?? 2.0,
createdAt: DateTime.parse(json['createdAt'] as String),
filled: json['filled'] as bool? ?? false,
textContent: json['textContent'] as String?,
fontSize: (json['fontSize'] as num?)?.toDouble() ?? 14.0,
);
Map<String, dynamic> _$$InkStrokeImplToJson(_$InkStrokeImpl instance) =>
<String, dynamic>{
'id': instance.id,
'points': instance.points,
'tool': _$PenToolEnumMap[instance.tool]!,
'color': instance.color,
'strokeWidth': instance.strokeWidth,
'createdAt': instance.createdAt.toIso8601String(),
'filled': instance.filled,
'textContent': instance.textContent,
'fontSize': instance.fontSize,
};
const _$PenToolEnumMap = {
PenTool.pen: 'pen',
PenTool.marker: 'marker',
PenTool.eraser: 'eraser',
PenTool.highlighter: 'highlighter',
PenTool.rectangle: 'rectangle',
PenTool.ellipse: 'ellipse',
PenTool.line: 'line',
PenTool.arrow: 'arrow',
PenTool.text: 'text',
};

20
lib/models/note.dart Normal file
View File

@@ -0,0 +1,20 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'ink_stroke.dart';
part 'note.freezed.dart';
part 'note.g.dart';
@freezed
abstract class Note with _$Note {
const factory Note({
required String id,
@Default('Untitled') String title,
@Default([]) List<InkStroke> strokes,
required DateTime createdAt,
required DateTime updatedAt,
@Default([]) List<String> tags,
}) = _Note;
factory Note.fromJson(Map<String, dynamic> json) => _$NoteFromJson(json);
}

View File

@@ -0,0 +1,297 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// 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
part of 'note.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(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',
);
Note _$NoteFromJson(Map<String, dynamic> json) {
return _Note.fromJson(json);
}
/// @nodoc
mixin _$Note {
String get id => throw _privateConstructorUsedError;
String get title => throw _privateConstructorUsedError;
List<InkStroke> get strokes => throw _privateConstructorUsedError;
DateTime get createdAt => throw _privateConstructorUsedError;
DateTime get updatedAt => throw _privateConstructorUsedError;
List<String> get tags => throw _privateConstructorUsedError;
/// Serializes this Note to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of Note
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$NoteCopyWith<Note> get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $NoteCopyWith<$Res> {
factory $NoteCopyWith(Note value, $Res Function(Note) then) =
_$NoteCopyWithImpl<$Res, Note>;
@useResult
$Res call({
String id,
String title,
List<InkStroke> strokes,
DateTime createdAt,
DateTime updatedAt,
List<String> tags,
});
}
/// @nodoc
class _$NoteCopyWithImpl<$Res, $Val extends Note>
implements $NoteCopyWith<$Res> {
_$NoteCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of Note
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = null,
Object? title = null,
Object? strokes = null,
Object? createdAt = null,
Object? updatedAt = null,
Object? tags = null,
}) {
return _then(
_value.copyWith(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
title: null == title
? _value.title
: title // ignore: cast_nullable_to_non_nullable
as String,
strokes: null == strokes
? _value.strokes
: strokes // ignore: cast_nullable_to_non_nullable
as List<InkStroke>,
createdAt: null == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime,
updatedAt: null == updatedAt
? _value.updatedAt
: updatedAt // ignore: cast_nullable_to_non_nullable
as DateTime,
tags: null == tags
? _value.tags
: tags // ignore: cast_nullable_to_non_nullable
as List<String>,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$NoteImplCopyWith<$Res> implements $NoteCopyWith<$Res> {
factory _$$NoteImplCopyWith(
_$NoteImpl value,
$Res Function(_$NoteImpl) then,
) = __$$NoteImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
String id,
String title,
List<InkStroke> strokes,
DateTime createdAt,
DateTime updatedAt,
List<String> tags,
});
}
/// @nodoc
class __$$NoteImplCopyWithImpl<$Res>
extends _$NoteCopyWithImpl<$Res, _$NoteImpl>
implements _$$NoteImplCopyWith<$Res> {
__$$NoteImplCopyWithImpl(_$NoteImpl _value, $Res Function(_$NoteImpl) _then)
: super(_value, _then);
/// Create a copy of Note
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = null,
Object? title = null,
Object? strokes = null,
Object? createdAt = null,
Object? updatedAt = null,
Object? tags = null,
}) {
return _then(
_$NoteImpl(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String,
title: null == title
? _value.title
: title // ignore: cast_nullable_to_non_nullable
as String,
strokes: null == strokes
? _value._strokes
: strokes // ignore: cast_nullable_to_non_nullable
as List<InkStroke>,
createdAt: null == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime,
updatedAt: null == updatedAt
? _value.updatedAt
: updatedAt // ignore: cast_nullable_to_non_nullable
as DateTime,
tags: null == tags
? _value._tags
: tags // ignore: cast_nullable_to_non_nullable
as List<String>,
),
);
}
}
/// @nodoc
@JsonSerializable()
class _$NoteImpl implements _Note {
const _$NoteImpl({
required this.id,
this.title = 'Untitled',
final List<InkStroke> strokes = const [],
required this.createdAt,
required this.updatedAt,
final List<String> tags = const [],
}) : _strokes = strokes,
_tags = tags;
factory _$NoteImpl.fromJson(Map<String, dynamic> json) =>
_$$NoteImplFromJson(json);
@override
final String id;
@override
@JsonKey()
final String title;
final List<InkStroke> _strokes;
@override
@JsonKey()
List<InkStroke> get strokes {
if (_strokes is EqualUnmodifiableListView) return _strokes;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_strokes);
}
@override
final DateTime createdAt;
@override
final DateTime updatedAt;
final List<String> _tags;
@override
@JsonKey()
List<String> get tags {
if (_tags is EqualUnmodifiableListView) return _tags;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_tags);
}
@override
String toString() {
return 'Note(id: $id, title: $title, strokes: $strokes, createdAt: $createdAt, updatedAt: $updatedAt, tags: $tags)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$NoteImpl &&
(identical(other.id, id) || other.id == id) &&
(identical(other.title, title) || other.title == title) &&
const DeepCollectionEquality().equals(other._strokes, _strokes) &&
(identical(other.createdAt, createdAt) ||
other.createdAt == createdAt) &&
(identical(other.updatedAt, updatedAt) ||
other.updatedAt == updatedAt) &&
const DeepCollectionEquality().equals(other._tags, _tags));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
id,
title,
const DeepCollectionEquality().hash(_strokes),
createdAt,
updatedAt,
const DeepCollectionEquality().hash(_tags),
);
/// Create a copy of Note
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$NoteImplCopyWith<_$NoteImpl> get copyWith =>
__$$NoteImplCopyWithImpl<_$NoteImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$NoteImplToJson(this);
}
}
abstract class _Note implements Note {
const factory _Note({
required final String id,
final String title,
final List<InkStroke> strokes,
required final DateTime createdAt,
required final DateTime updatedAt,
final List<String> tags,
}) = _$NoteImpl;
factory _Note.fromJson(Map<String, dynamic> json) = _$NoteImpl.fromJson;
@override
String get id;
@override
String get title;
@override
List<InkStroke> get strokes;
@override
DateTime get createdAt;
@override
DateTime get updatedAt;
@override
List<String> get tags;
/// Create a copy of Note
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$NoteImplCopyWith<_$NoteImpl> get copyWith =>
throw _privateConstructorUsedError;
}

32
lib/models/note.g.dart Normal file
View File

@@ -0,0 +1,32 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'note.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$NoteImpl _$$NoteImplFromJson(Map<String, dynamic> json) => _$NoteImpl(
id: json['id'] as String,
title: json['title'] as String? ?? 'Untitled',
strokes:
(json['strokes'] as List<dynamic>?)
?.map((e) => InkStroke.fromJson(e as Map<String, dynamic>))
.toList() ??
const [],
createdAt: DateTime.parse(json['createdAt'] as String),
updatedAt: DateTime.parse(json['updatedAt'] as String),
tags:
(json['tags'] as List<dynamic>?)?.map((e) => e as String).toList() ??
const [],
);
Map<String, dynamic> _$$NoteImplToJson(_$NoteImpl instance) =>
<String, dynamic>{
'id': instance.id,
'title': instance.title,
'strokes': instance.strokes,
'createdAt': instance.createdAt.toIso8601String(),
'updatedAt': instance.updatedAt.toIso8601String(),
'tags': instance.tags,
};

11
lib/models/pen_tool.dart Normal file
View File

@@ -0,0 +1,11 @@
enum PenTool {
pen,
marker,
eraser,
highlighter,
rectangle,
ellipse,
line,
arrow,
text,
}

View File

@@ -0,0 +1,16 @@
import 'package:json_annotation/json_annotation.dart';
enum InputDeviceKind {
@JsonValue('touch')
touch,
@JsonValue('mouse')
mouse,
@JsonValue('stylus')
stylus,
@JsonValue('invertedStylus')
invertedStylus,
@JsonValue('trackpad')
trackpad,
@JsonValue('unknown')
unknown,
}

View File

@@ -0,0 +1,62 @@
import 'dart:math';
/// Predefined pressure curve types.
enum PressureCurveType { linear, soft, hard, custom }
/// Maps raw pen pressure [0,1] to effective pressure [0,1] using a power curve.
///
/// - **Linear**: identity (p)
/// - **Soft**: `pow(p, 1.5)` — light touch produces small lines, needs more pressure
/// - **Hard**: `pow(p, 0.5)` — light touch already produces thick lines
/// - **Custom**: `pow(p, exponent)` where exponent is derived from [softness]
class PressureCurve {
final PressureCurveType type;
final double softness;
const PressureCurve({
this.type = PressureCurveType.linear,
this.softness = 0.5,
});
/// Predefined linear curve (identity).
static const linear = PressureCurve(type: PressureCurveType.linear);
/// Predefined soft curve — needs more pressure to ramp up.
static const soft = PressureCurve(
type: PressureCurveType.soft,
softness: 0.3,
);
/// Predefined hard curve — light touch already produces thick lines.
static const hard = PressureCurve(
type: PressureCurveType.hard,
softness: 0.7,
);
/// Maps raw pressure [0,1] to effective pressure [0,1].
double apply(double rawPressure) {
final p = rawPressure.clamp(0.0, 1.0);
switch (type) {
case PressureCurveType.linear:
return p;
case PressureCurveType.soft:
return pow(p, 1.5).toDouble();
case PressureCurveType.hard:
return pow(p, 0.5).toDouble();
case PressureCurveType.custom:
final exponent = softness * 2 + 0.2;
return pow(p, exponent).toDouble();
}
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is PressureCurve &&
runtimeType == other.runtimeType &&
type == other.type &&
softness == other.softness;
@override
int get hashCode => type.hashCode ^ softness.hashCode;
}