Showing
11 changed files
with
61 additions
and
55 deletions
... | @@ -83,4 +83,7 @@ appbar 관련 디자인은 추후 구현 예정 | ... | @@ -83,4 +83,7 @@ appbar 관련 디자인은 추후 구현 예정 |
83 | 83 | ||
84 | 84 | ||
85 | ### 2021-05-25 | 85 | ### 2021-05-25 |
86 | -+ 로그인 권한 문제 해결 | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
86 | ++ 로그인 권한 문제 해결 | ||
87 | + | ||
88 | +### 2021-05-26 | ||
89 | ++ future buillder 변경 | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -10,46 +10,13 @@ import '../../utils/user_secure_stoarge.dart'; | ... | @@ -10,46 +10,13 @@ import '../../utils/user_secure_stoarge.dart'; |
10 | 10 | ||
11 | class BottleList extends StatefulWidget { | 11 | class BottleList extends StatefulWidget { |
12 | List<Bottle> bottlelist; | 12 | List<Bottle> bottlelist; |
13 | - String hubid; | 13 | + BottleList({Key key, this.bottlelist}) : super(key: key); |
14 | - BottleList({Key key, this.bottlelist, this.hubid}) : super(key: key); | ||
15 | 14 | ||
16 | @override | 15 | @override |
17 | _BottleListState createState() => _BottleListState(); | 16 | _BottleListState createState() => _BottleListState(); |
18 | } | 17 | } |
19 | 18 | ||
20 | class _BottleListState extends State<BottleList> { | 19 | class _BottleListState extends State<BottleList> { |
21 | - Bottle _bottleinformation = new Bottle(); | ||
22 | - Medicine _medicineinformation = new Medicine(); | ||
23 | - | ||
24 | - Future<Bottle> getbottle(int index) async { | ||
25 | - String usertoken = await UserSecureStorage.getUserToken(); | ||
26 | - http.Response response = await http.get( | ||
27 | - Uri.encodeFull(DotEnv().env['SERVER_URL'] + | ||
28 | - 'bottle/' + | ||
29 | - widget.bottlelist[index].bottleId.toString()), | ||
30 | - headers: {"authorization": usertoken}); | ||
31 | - | ||
32 | - if (response.statusCode == 200) { | ||
33 | - Map<String, dynamic> jsonData = jsonDecode(response.body); | ||
34 | - print(jsonData); | ||
35 | - _bottleinformation = Bottle.fromJson(jsonData); | ||
36 | - } | ||
37 | - } | ||
38 | - | ||
39 | - Future<Bottle> getmedicine(int index) async { | ||
40 | - String usertoken = await UserSecureStorage.getUserToken(); | ||
41 | - http.Response medicineresponse = await http.get( | ||
42 | - Uri.encodeFull(DotEnv().env['SERVER_URL'] + | ||
43 | - 'medicine/' + | ||
44 | - widget.bottlelist[index].medicineId.toString()), | ||
45 | - headers: {"authorization": usertoken}, | ||
46 | - ); | ||
47 | - if (medicineresponse.statusCode == 200) { | ||
48 | - Map<String, dynamic> data = jsonDecode(medicineresponse.body); | ||
49 | - _medicineinformation = Medicine.fromJson(data); | ||
50 | - } | ||
51 | - } | ||
52 | - | ||
53 | Widget build(BuildContext context) { | 20 | Widget build(BuildContext context) { |
54 | final Size size = MediaQuery.of(context).size; | 21 | final Size size = MediaQuery.of(context).size; |
55 | return Scaffold( | 22 | return Scaffold( |
... | @@ -97,15 +64,15 @@ class _BottleListState extends State<BottleList> { | ... | @@ -97,15 +64,15 @@ class _BottleListState extends State<BottleList> { |
97 | ), | 64 | ), |
98 | trailing: Icon(Icons.arrow_forward), | 65 | trailing: Icon(Icons.arrow_forward), |
99 | onTap: () async { | 66 | onTap: () async { |
100 | - await getbottle(index); | 67 | + UserSecureStorage.setBottleId( |
101 | - await getmedicine(index); | 68 | + widget.bottlelist[index].bottleId.toString()); |
69 | + UserSecureStorage.setMedicineId( | ||
70 | + widget.bottlelist[index].medicineId.toString()); | ||
102 | Navigator.push( | 71 | Navigator.push( |
103 | context, | 72 | context, |
104 | MaterialPageRoute( | 73 | MaterialPageRoute( |
105 | builder: (BuildContext context) => DashBoard( | 74 | builder: (BuildContext context) => DashBoard( |
106 | pageNumber: 1, | 75 | pageNumber: 1, |
107 | - bottleInformation: _bottleinformation, | ||
108 | - medicineInformation: _medicineinformation, | ||
109 | ), | 76 | ), |
110 | ), | 77 | ), |
111 | ); | 78 | ); | ... | ... |
... | @@ -215,7 +215,9 @@ class _DetailMedicineState extends State<DetailMedicine> { | ... | @@ -215,7 +215,9 @@ class _DetailMedicineState extends State<DetailMedicine> { |
215 | context, | 215 | context, |
216 | MaterialPageRoute( | 216 | MaterialPageRoute( |
217 | builder: (BuildContext context) => | 217 | builder: (BuildContext context) => |
218 | - HomePage(), | 218 | + DashBoard( |
219 | + pageNumber: 1, | ||
220 | + ), | ||
219 | ), | 221 | ), |
220 | ); | 222 | ); |
221 | }) | 223 | }) | ... | ... |
... | @@ -45,6 +45,7 @@ class _HubListState extends State<HubList> { | ... | @@ -45,6 +45,7 @@ class _HubListState extends State<HubList> { |
45 | } else { | 45 | } else { |
46 | return "Error"; | 46 | return "Error"; |
47 | } | 47 | } |
48 | + return "Error"; | ||
48 | } | 49 | } |
49 | 50 | ||
50 | Widget build(BuildContext context) { | 51 | Widget build(BuildContext context) { |
... | @@ -95,14 +96,15 @@ class _HubListState extends State<HubList> { | ... | @@ -95,14 +96,15 @@ class _HubListState extends State<HubList> { |
95 | var result = | 96 | var result = |
96 | await getBottleList(widget.hublist[index]); | 97 | await getBottleList(widget.hublist[index]); |
97 | if (result == "GET") { | 98 | if (result == "GET") { |
99 | + UserSecureStorage.setHubId( | ||
100 | + widget.hublist[index].toString()); | ||
98 | Navigator.push( | 101 | Navigator.push( |
99 | context, | 102 | context, |
100 | MaterialPageRoute( | 103 | MaterialPageRoute( |
101 | builder: (BuildContext context) => | 104 | builder: (BuildContext context) => |
102 | BottleList( | 105 | BottleList( |
103 | - bottlelist: _bottleList, | 106 | + bottlelist: _bottleList, |
104 | - hubid: widget.hublist[index] | 107 | + ), |
105 | - .toString()), | ||
106 | )); | 108 | )); |
107 | } else if (result == "Not Found") { | 109 | } else if (result == "Not Found") { |
108 | showDialog( | 110 | showDialog( |
... | @@ -115,15 +117,15 @@ class _HubListState extends State<HubList> { | ... | @@ -115,15 +117,15 @@ class _HubListState extends State<HubList> { |
115 | new FlatButton( | 117 | new FlatButton( |
116 | child: new Text('등록'), | 118 | child: new Text('등록'), |
117 | onPressed: () { | 119 | onPressed: () { |
120 | + UserSecureStorage.setHubId(widget | ||
121 | + .hublist[index] | ||
122 | + .toString()); | ||
118 | Navigator.push( | 123 | Navigator.push( |
119 | context, | 124 | context, |
120 | MaterialPageRoute( | 125 | MaterialPageRoute( |
121 | builder: (BuildContext | 126 | builder: (BuildContext |
122 | context) => | 127 | context) => |
123 | - RegisterBottle( | 128 | + RegisterBottle(), |
124 | - hubid: widget | ||
125 | - .hublist[index] | ||
126 | - .toString()), | ||
127 | )); | 129 | )); |
128 | }) | 130 | }) |
129 | ], | 131 | ], | ... | ... |
... | @@ -20,16 +20,16 @@ class _RegisterBottleState extends State<RegisterBottle> { | ... | @@ -20,16 +20,16 @@ class _RegisterBottleState extends State<RegisterBottle> { |
20 | 20 | ||
21 | Future<String> registerhub_Validate() async { | 21 | Future<String> registerhub_Validate() async { |
22 | String usertoken = await UserSecureStorage.getUserToken(); | 22 | String usertoken = await UserSecureStorage.getUserToken(); |
23 | + String hubid = await UserSecureStorage.getHubId(); | ||
24 | + print(hubid); | ||
23 | http.Response bottleresponse = await http.post( | 25 | http.Response bottleresponse = await http.post( |
24 | Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'bottle'), | 26 | Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'bottle'), |
25 | headers: { | 27 | headers: { |
26 | "Content-Type": "application/json", | 28 | "Content-Type": "application/json", |
27 | "authorization": usertoken | 29 | "authorization": usertoken |
28 | }, | 30 | }, |
29 | - body: jsonEncode({ | 31 | + body: jsonEncode( |
30 | - 'bottleId': medicineBottleIDController.text, | 32 | + {'bottleId': medicineBottleIDController.text, 'hubId': hubid})); |
31 | - 'hubId': widget.hubid | ||
32 | - })); | ||
33 | 33 | ||
34 | if (bottleresponse.statusCode == 201) { | 34 | if (bottleresponse.statusCode == 201) { |
35 | return "등록 완료"; | 35 | return "등록 완료"; | ... | ... |
... | @@ -120,6 +120,7 @@ class _RegisterHubState extends State<RegisterHub> { | ... | @@ -120,6 +120,7 @@ class _RegisterHubState extends State<RegisterHub> { |
120 | String saveMessage = await registerhub_Validate(); | 120 | String saveMessage = await registerhub_Validate(); |
121 | print(saveMessage); | 121 | print(saveMessage); |
122 | if (saveMessage == "허브 등록 완료") { | 122 | if (saveMessage == "허브 등록 완료") { |
123 | + UserSecureStorage.setHubId(medicineHubIDController.text); | ||
123 | Navigator.push( | 124 | Navigator.push( |
124 | context, | 125 | context, |
125 | MaterialPageRoute( | 126 | MaterialPageRoute( | ... | ... |
... | @@ -28,6 +28,7 @@ class _SignInPageState extends State<SignInPage> { | ... | @@ -28,6 +28,7 @@ class _SignInPageState extends State<SignInPage> { |
28 | 28 | ||
29 | //Login 함수 | 29 | //Login 함수 |
30 | Future<String> login(String _email, String _password) async { | 30 | Future<String> login(String _email, String _password) async { |
31 | + print(Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'auth/login')); | ||
31 | http.Response response = await http.post( | 32 | http.Response response = await http.post( |
32 | Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'auth/login'), | 33 | Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'auth/login'), |
33 | headers: {"Content-Type": "application/json"}, | 34 | headers: {"Content-Type": "application/json"}, |
... | @@ -38,6 +39,7 @@ class _SignInPageState extends State<SignInPage> { | ... | @@ -38,6 +39,7 @@ class _SignInPageState extends State<SignInPage> { |
38 | }, | 39 | }, |
39 | ), | 40 | ), |
40 | ); | 41 | ); |
42 | + print(response.statusCode); | ||
41 | 43 | ||
42 | if (response.statusCode == 200) { | 44 | if (response.statusCode == 200) { |
43 | Map<String, dynamic> data = jsonDecode(response.body); | 45 | Map<String, dynamic> data = jsonDecode(response.body); |
... | @@ -51,7 +53,7 @@ class _SignInPageState extends State<SignInPage> { | ... | @@ -51,7 +53,7 @@ class _SignInPageState extends State<SignInPage> { |
51 | } | 53 | } |
52 | } | 54 | } |
53 | 55 | ||
54 | - //Get Bottle List 함수 | 56 | + //Get Hub List 함수 |
55 | Future<String> getHubList() async { | 57 | Future<String> getHubList() async { |
56 | String usertoken = await UserSecureStorage.getUserToken(); | 58 | String usertoken = await UserSecureStorage.getUserToken(); |
57 | http.Response response = await http.get( | 59 | http.Response response = await http.get( |
... | @@ -207,6 +209,7 @@ class _SignInPageState extends State<SignInPage> { | ... | @@ -207,6 +209,7 @@ class _SignInPageState extends State<SignInPage> { |
207 | String saveMessage = await login( | 209 | String saveMessage = await login( |
208 | emailController.text, | 210 | emailController.text, |
209 | passwordController.text); | 211 | passwordController.text); |
212 | + print(saveMessage); | ||
210 | if (emailController.text.isEmpty || | 213 | if (emailController.text.isEmpty || |
211 | passwordController.text.isEmpty) { | 214 | passwordController.text.isEmpty) { |
212 | showDialog( | 215 | showDialog( |
... | @@ -227,7 +230,6 @@ class _SignInPageState extends State<SignInPage> { | ... | @@ -227,7 +230,6 @@ class _SignInPageState extends State<SignInPage> { |
227 | ); | 230 | ); |
228 | }); | 231 | }); |
229 | } else { | 232 | } else { |
230 | - saveMessage = "로그인 성공"; | ||
231 | if (saveMessage == "로그인 성공") { | 233 | if (saveMessage == "로그인 성공") { |
232 | var result = await getHubList(); | 234 | var result = await getHubList(); |
233 | print(result); | 235 | print(result); |
... | @@ -242,6 +244,9 @@ class _SignInPageState extends State<SignInPage> { | ... | @@ -242,6 +244,9 @@ class _SignInPageState extends State<SignInPage> { |
242 | } else if (result == "get완료") { | 244 | } else if (result == "get완료") { |
243 | UserSecureStorage.setUserToken( | 245 | UserSecureStorage.setUserToken( |
244 | user.token); | 246 | user.token); |
247 | + UserSecureStorage.setUserId( | ||
248 | + user.userId); | ||
249 | + print('asdg'); | ||
245 | Navigator.push( | 250 | Navigator.push( |
246 | context, | 251 | context, |
247 | MaterialPageRoute( | 252 | MaterialPageRoute( |
... | @@ -250,6 +255,8 @@ class _SignInPageState extends State<SignInPage> { | ... | @@ -250,6 +255,8 @@ class _SignInPageState extends State<SignInPage> { |
250 | HubList(hublist: _hublist), | 255 | HubList(hublist: _hublist), |
251 | )); | 256 | )); |
252 | } else {} | 257 | } else {} |
258 | + } else { | ||
259 | + print('Error'); | ||
253 | } | 260 | } |
254 | } | 261 | } |
255 | }, | 262 | }, | ... | ... |
1 | import 'dart:convert'; | 1 | import 'dart:convert'; |
2 | +import 'package:Smart_Medicine_Box/src/screens/Homepage.dart'; | ||
2 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
3 | import 'package:http/http.dart' as http; | 4 | import 'package:http/http.dart' as http; |
4 | import 'package:flutter_dotenv/flutter_dotenv.dart'; | 5 | import 'package:flutter_dotenv/flutter_dotenv.dart'; |
... | @@ -182,7 +183,7 @@ class _SignUpLocalState extends State<SignUpLocal> { | ... | @@ -182,7 +183,7 @@ class _SignUpLocalState extends State<SignUpLocal> { |
182 | context, | 183 | context, |
183 | MaterialPageRoute( | 184 | MaterialPageRoute( |
184 | builder: (BuildContext context) => | 185 | builder: (BuildContext context) => |
185 | - RegisterHub())); | 186 | + HomePage())); |
186 | }) | 187 | }) |
187 | ], | 188 | ], |
188 | ); | 189 | ); | ... | ... |
... | @@ -7,6 +7,12 @@ class UserSecureStorage { | ... | @@ -7,6 +7,12 @@ class UserSecureStorage { |
7 | 7 | ||
8 | static const _keyUserId = 'userid'; | 8 | static const _keyUserId = 'userid'; |
9 | 9 | ||
10 | + static const _keyBottleId = 'bottleid'; | ||
11 | + | ||
12 | + static const _keyMedicineId = 'medicineid'; | ||
13 | + | ||
14 | + static const _keyhubId = 'hubid'; | ||
15 | + | ||
10 | static Future setUserId(String userid) async => | 16 | static Future setUserId(String userid) async => |
11 | await _storage.write(key: _keyUserId, value: userid); | 17 | await _storage.write(key: _keyUserId, value: userid); |
12 | 18 | ||
... | @@ -18,4 +24,21 @@ class UserSecureStorage { | ... | @@ -18,4 +24,21 @@ class UserSecureStorage { |
18 | 24 | ||
19 | static Future<String> getUserToken() async => | 25 | static Future<String> getUserToken() async => |
20 | await _storage.read(key: _keyToken); | 26 | await _storage.read(key: _keyToken); |
27 | + | ||
28 | + static Future setBottleId(String bottleid) async => | ||
29 | + await _storage.write(key: _keyBottleId, value: bottleid); | ||
30 | + | ||
31 | + static Future<String> getBottleId() async => | ||
32 | + await _storage.read(key: _keyBottleId); | ||
33 | + | ||
34 | + static Future setMedicineId(String medicineid) async => | ||
35 | + await _storage.write(key: _keyMedicineId, value: medicineid); | ||
36 | + | ||
37 | + static Future<String> getMedicineId() async => | ||
38 | + await _storage.read(key: _keyMedicineId); | ||
39 | + | ||
40 | + static Future setHubId(String hubid) async => | ||
41 | + await _storage.write(key: _keyhubId, value: hubid); | ||
42 | + | ||
43 | + static Future<String> getHubId() async => await _storage.read(key: _keyhubId); | ||
21 | } | 44 | } | ... | ... |
-
Please register or login to post a comment