import 'dart:convert'; import 'package:flutter_passvault/modelclasses/jsomdata.dart'; MyCredentialList myCredentialListFromJson(String str) => MyCredentialList.fromJson(json.decode(str)); String myCredentialListToJson(MyCredentialList data) => json.encode(data.toJson()); class MyCredentialList { bool success; String message; List data; MyCredentialList({ required this.success, required this.message, required this.data, }); factory MyCredentialList.fromJson(Map json) => MyCredentialList( success: json["success"], message: json["message"], data: List.from( json["data"].map((x) => CredentialList.fromJson(x))), ); Map toJson() => { "success": success, "message": message, "data": List.from(data.map((x) => x.toJson())), }; } class CredentialList implements JsonData { @override int id; @override String name; @override String username; @override String password; @override late String detail; @override late int createdBy; @override late int modifiedBy; @override late DateTime createdAt; @override late DateTime updatedAt; late Pivot? pivot; CredentialList({ required this.id, required this.name, required this.username, required this.password, detail, createdBy, modifiedBy, createdAt, updatedAt, this.pivot, }) { this.detail = detail ?? ''; this.createdBy = createdBy ?? 0; this.modifiedBy = modifiedBy ?? 0; this.createdAt = createdAt ?? DateTime.now(); this.updatedAt = updatedAt ?? DateTime.now(); // Initialize pivot normally } factory CredentialList.fromJson(Map json) => CredentialList( id: json["id"], name: json["name"], username: json["username"], password: json["password"], detail: json["detail"], createdBy: json["created_by"], modifiedBy: json["modified_by"], createdAt: DateTime.parse(json["created_at"]), updatedAt: DateTime.parse(json["updated_at"]), pivot: Pivot.fromJson(json["pivot"]), ); Map toJson() => { "id": id, "name": name, "username": username, "password": password, "detail": detail, "created_by": createdBy, "modified_by": modifiedBy, "created_at": createdAt.toIso8601String(), "updated_at": updatedAt.toIso8601String(), "pivot": pivot?.toJson(), }; @override String toString() { return 'MyCredentialList{id: $id, name: $name, username: $username, password: $password,detail: $detail,created_by: $createdBy,modified_by: $modifiedBy,created_at: $createdAt.toIso8601String(), updated_at: $updatedAt.toIso8601String(),pivot: $pivot?.toJson(),}'; } } class Pivot { int userId; int credId; DateTime createdAt; DateTime updatedAt; Pivot({ required this.userId, required this.credId, required this.createdAt, required this.updatedAt, }); factory Pivot.fromJson(Map json) => Pivot( userId: json["user_id"], credId: json["cred_id"], createdAt: DateTime.parse(json["created_at"]), updatedAt: DateTime.parse(json["updated_at"]), ); Map toJson() => { "user_id": userId, "cred_id": credId, "created_at": createdAt.toIso8601String(), "updated_at": updatedAt.toIso8601String(), }; }