user.dart
3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import 'dart:core';
import 'package:flutter/material.dart';
import 'dart:convert';
User userFromJson(String str) => User.fromJson(json.decode(str));
String userToJson(User data) => json.encode(data.toJson());
class User {
String email;
String password;
String phone;
String token;
String username;
List<String> books;
List<String> favorite;
User(
this.email,
this.password,
this.phone,
this.token,
this.username,
this.books,
this.favorite
);
User.fromJson(Map<String, dynamic> json)
:
token = json["token"],
email=json["email"],
password= json["password"],
phone=json["phone"],
username= json["username"],
books=List<String>.from(json["books"].map((x) => x)),
favorite= List<String>.from(json["favorite"].map((x) => x));
Map<String, dynamic> toJson() => {
"email": email,
"password": password,
"phone": phone,
"username": username,
"books": List<dynamic>.from(books.map((x) => x)),
"favorite": List<dynamic>.from(favorite.map((x) => x))
};
void update(var user) {
// String username, List<String> address, String phone,
// List<String> pets, List<String> favorites
this.email = user["email"] ?? this.email;
this.username = user["nickname"] ?? this.username;
//수정필요
this.phone = user["phone"] ?? this.phone;
// this._pets =
// user["pets"] == null ? this._pets : List<String>.from(user["pets"]);
this.books = (user["books"] == null)
? this.books
: List<String>.from(user["books"]);
this.favorite = (user["favorite"] == null)
? this.favorite
: List<String>.from(user["favorite"]);
print("user update");
//notifyListeners();
}
}
//user provider
//pets provider
/*
class User with ChangeNotifier {
String _email;
String get email => _email;
set email(String email) => _email = email;
String _username;
String get username => _username;
set username(String username) => _username = username;
String _phone;
String get phone => _phone;
set phone(String phone) => _phone = phone;
List<String> _books = List<String>(5);
List<String> get _books => _pets;
List<String> _favorite = List<String>();
List<String> get favorite => _favorites;
void updatefavorite(String contentsID){
this._favorite.add(contentsID);
}
void deletefavorite(String contentsID){
this._favorite.remove(contentsID);
}
void update(var user) {
// String username, List<String> address, String phone,
// List<String> pets, List<String> favorites
this._email = user["email"] ?? this._email;
this._username = user["nickname"] ?? this._username;
//수정필요
this._phone = user["phone"] ?? this._phone;
// this._pets =
// user["pets"] == null ? this._pets : List<String>.from(user["pets"]);
this._books = (user["books"] == null)
? this._books
: List<String>.from(user["books"]);
this._favorite = (user["favorite"] == null)
? this._favorite
: List<String>.from(user["favorite"]);
print("user update");
//notifyListeners();
}
}*/