fix: resolve flutter analyze errors - remove leaked code, fix method calls, cleanup imports

This commit is contained in:
2026-03-23 16:55:54 +07:00
parent 4f202936fa
commit 71f1feaf98
33 changed files with 2851 additions and 224 deletions
+38
View File
@@ -0,0 +1,38 @@
import 'package:equatable/equatable.dart';
import 'novel_model.dart';
class BookmarkModel extends Equatable {
const BookmarkModel({
required this.id,
required this.novelId,
this.lastChapterId,
this.lastChapterNumber,
this.readChapters = const [],
this.novel,
});
final String id;
final String novelId;
final String? lastChapterId;
final int? lastChapterNumber;
final List<int> readChapters;
final NovelModel? novel;
factory BookmarkModel.fromJson(Map<String, dynamic> json) => BookmarkModel(
id: json['id'] as String,
novelId: json['novelId'] as String,
lastChapterId: json['lastChapterId'] as String?,
lastChapterNumber: json['lastChapterNumber'] as int?,
readChapters: (json['readChapters'] as List<dynamic>?)
?.map((e) => (e as num).toInt())
.toList() ??
[],
novel: json['novel'] != null
? NovelModel.fromJson(json['novel'] as Map<String, dynamic>)
: null,
);
@override
List<Object?> get props => [id, novelId];
}
+88
View File
@@ -0,0 +1,88 @@
import 'package:equatable/equatable.dart';
class ChapterModel extends Equatable {
const ChapterModel({
required this.id,
required this.novelId,
required this.number,
required this.title,
required this.content,
this.views = 0,
this.volumeNumber,
this.volumeTitle,
this.volumeChapterNumber,
this.prevChapterId,
this.prevChapterNumber,
this.nextChapterId,
this.nextChapterNumber,
required this.createdAt,
});
final String id;
final String novelId;
final int number;
final String title;
final String content;
final int views;
final int? volumeNumber;
final String? volumeTitle;
final int? volumeChapterNumber;
final String? prevChapterId;
final int? prevChapterNumber;
final String? nextChapterId;
final int? nextChapterNumber;
final DateTime createdAt;
factory ChapterModel.fromJson(Map<String, dynamic> json) => ChapterModel(
id: json['id'] as String,
novelId: json['novelId'] as String,
number: (json['number'] as num).toInt(),
title: json['title'] as String,
content: json['content'] as String,
views: (json['views'] as num?)?.toInt() ?? 0,
volumeNumber: json['volumeNumber'] as int?,
volumeTitle: json['volumeTitle'] as String?,
volumeChapterNumber: json['volumeChapterNumber'] as int?,
prevChapterId: json['prevChapterId'] as String?,
prevChapterNumber: json['prevChapterNumber'] as int?,
nextChapterId: json['nextChapterId'] as String?,
nextChapterNumber: json['nextChapterNumber'] as int?,
createdAt: DateTime.parse(json['createdAt'] as String),
);
@override
List<Object?> get props => [id, number];
}
class ChapterListItem extends Equatable {
const ChapterListItem({
required this.id,
required this.number,
required this.title,
this.volumeNumber,
this.volumeTitle,
this.volumeChapterNumber,
required this.createdAt,
});
final String id;
final int number;
final String title;
final int? volumeNumber;
final String? volumeTitle;
final int? volumeChapterNumber;
final DateTime createdAt;
factory ChapterListItem.fromJson(Map<String, dynamic> json) => ChapterListItem(
id: json['id'] as String,
number: (json['number'] as num).toInt(),
title: json['title'] as String,
volumeNumber: json['volumeNumber'] as int?,
volumeTitle: json['volumeTitle'] as String?,
volumeChapterNumber: json['volumeChapterNumber'] as int?,
createdAt: DateTime.parse(json['createdAt'] as String),
);
@override
List<Object?> get props => [id, number];
}
+37
View File
@@ -0,0 +1,37 @@
import 'package:equatable/equatable.dart';
class CommentModel extends Equatable {
const CommentModel({
required this.id,
required this.userId,
required this.username,
required this.novelId,
required this.content,
required this.createdAt,
this.avatarUrl,
this.chapterId,
});
final String id;
final String userId;
final String username;
final String novelId;
final String content;
final DateTime createdAt;
final String? avatarUrl;
final String? chapterId;
factory CommentModel.fromJson(Map<String, dynamic> json) => CommentModel(
id: json['id'] as String,
userId: json['userId'] as String,
username: json['username'] as String? ?? 'User',
novelId: json['novelId'] as String,
content: json['content'] as String,
createdAt: DateTime.parse(json['createdAt'] as String),
avatarUrl: json['avatarUrl'] as String?,
chapterId: json['chapterId'] as String?,
);
@override
List<Object?> get props => [id];
}
+134
View File
@@ -0,0 +1,134 @@
import 'package:equatable/equatable.dart';
class NovelModel extends Equatable {
const NovelModel({
required this.id,
required this.title,
required this.slug,
required this.authorName,
required this.status,
required this.totalChapters,
this.originalTitle,
this.description,
this.coverUrl,
this.coverColor,
this.views = 0,
this.rating = 0,
this.ratingCount = 0,
this.bookmarkCount = 0,
this.genres = const [],
this.seriesId,
this.series,
this.latestChapter,
});
final String id;
final String title;
final String slug;
final String authorName;
final String status;
final int totalChapters;
final String? originalTitle;
final String? description;
final String? coverUrl;
final String? coverColor;
final int views;
final double rating;
final int ratingCount;
final int bookmarkCount;
final List<GenreModel> genres;
final String? seriesId;
final SeriesModel? series;
final LatestChapterInfo? latestChapter;
factory NovelModel.fromJson(Map<String, dynamic> json) => NovelModel(
id: json['id'] as String,
title: json['title'] as String,
slug: json['slug'] as String,
authorName: json['authorName'] as String,
status: json['status'] as String,
totalChapters: (json['totalChapters'] as num).toInt(),
originalTitle: json['originalTitle'] as String?,
description: json['description'] as String?,
coverUrl: json['coverUrl'] as String?,
coverColor: json['coverColor'] as String?,
views: (json['views'] as num?)?.toInt() ?? 0,
rating: (json['rating'] as num?)?.toDouble() ?? 0,
ratingCount: (json['ratingCount'] as num?)?.toInt() ?? 0,
bookmarkCount: (json['bookmarkCount'] as num?)?.toInt() ?? 0,
genres: (json['genres'] as List<dynamic>?)
?.map((g) => GenreModel.fromJson(g as Map<String, dynamic>))
.toList() ??
[],
seriesId: json['seriesId'] as String?,
series: json['series'] != null
? SeriesModel.fromJson(json['series'] as Map<String, dynamic>)
: null,
latestChapter: json['latestChapter'] != null
? LatestChapterInfo.fromJson(
json['latestChapter'] as Map<String, dynamic>)
: null,
);
@override
List<Object?> get props => [id, slug];
}
class GenreModel extends Equatable {
const GenreModel({required this.id, required this.name, required this.slug, this.description, this.icon, this.novelCount = 0});
final String id;
final String name;
final String slug;
final String? description;
final String? icon;
final int novelCount;
factory GenreModel.fromJson(Map<String, dynamic> json) => GenreModel(
id: json['id'] as String,
name: json['name'] as String,
slug: json['slug'] as String,
description: json['description'] as String?,
icon: json['icon'] as String?,
novelCount: (json['novelCount'] as num?)?.toInt() ?? 0,
);
@override
List<Object?> get props => [id, slug];
}
class SeriesModel extends Equatable {
const SeriesModel({required this.id, required this.name, required this.slug, this.novels = const []});
final String id;
final String name;
final String slug;
final List<NovelModel> novels;
factory SeriesModel.fromJson(Map<String, dynamic> json) => SeriesModel(
id: json['id'] as String,
name: json['name'] as String,
slug: json['slug'] as String,
novels: (json['novels'] as List<dynamic>?)
?.map((n) => NovelModel.fromJson(n as Map<String, dynamic>))
.toList() ??
[],
);
@override
List<Object?> get props => [id, slug];
}
class LatestChapterInfo extends Equatable {
const LatestChapterInfo({required this.number, required this.title, required this.createdAt});
final int number;
final String title;
final DateTime createdAt;
factory LatestChapterInfo.fromJson(Map<String, dynamic> json) => LatestChapterInfo(
number: (json['number'] as num).toInt(),
title: json['title'] as String,
createdAt: DateTime.parse(json['createdAt'] as String),
);
@override
List<Object?> get props => [number];
}
+40
View File
@@ -0,0 +1,40 @@
class ReadingSettings {
const ReadingSettings({
this.fontSize = 18,
this.lineHeight = 1.8,
this.letterSpacing = 0,
this.fontFamily = 'serif',
});
final double fontSize;
final double lineHeight;
final double letterSpacing;
final String fontFamily;
ReadingSettings copyWith({
double? fontSize,
double? lineHeight,
double? letterSpacing,
String? fontFamily,
}) =>
ReadingSettings(
fontSize: fontSize ?? this.fontSize,
lineHeight: lineHeight ?? this.lineHeight,
letterSpacing: letterSpacing ?? this.letterSpacing,
fontFamily: fontFamily ?? this.fontFamily,
);
factory ReadingSettings.fromJson(Map<String, dynamic> json) => ReadingSettings(
fontSize: (json['fontSize'] as num?)?.toDouble() ?? 18,
lineHeight: (json['lineHeight'] as num?)?.toDouble() ?? 1.8,
letterSpacing: (json['letterSpacing'] as num?)?.toDouble() ?? 0,
fontFamily: json['fontFamily'] as String? ?? 'serif',
);
Map<String, dynamic> toJson() => {
'fontSize': fontSize,
'lineHeight': lineHeight,
'letterSpacing': letterSpacing,
'fontFamily': fontFamily,
};
}
+36
View File
@@ -0,0 +1,36 @@
import 'package:equatable/equatable.dart';
class UserModel extends Equatable {
const UserModel({
required this.id,
required this.email,
this.name,
this.image,
this.role = 'USER',
});
final String id;
final String email;
final String? name;
final String? image;
final String role;
factory UserModel.fromJson(Map<String, dynamic> json) => UserModel(
id: json['id'] as String,
email: json['email'] as String,
name: json['name'] as String?,
image: json['image'] as String?,
role: json['role'] as String? ?? 'USER',
);
Map<String, dynamic> toJson() => {
'id': id,
'email': email,
'name': name,
'image': image,
'role': role,
};
@override
List<Object?> get props => [id, email];
}