고원빈

[frontend] Error 해결

...@@ -84,3 +84,6 @@ appbar 관련 디자인은 추후 구현 예정 ...@@ -84,3 +84,6 @@ appbar 관련 디자인은 추후 구현 예정
84 84
85 ### 2021-05-25 85 ### 2021-05-25
86 + 로그인 권한 문제 해결 86 + 로그인 권한 문제 해결
87 +
88 +### 2021-05-26
89 ++ future buillder 변경
...\ No newline at end of file ...\ No newline at end of file
......
1 -SERVER_URL=
...\ No newline at end of file ...\ No newline at end of file
1 +SERVER_URL=http://192.168.0.3:4717/api/
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -5,39 +5,32 @@ import 'package:http/http.dart' as http; ...@@ -5,39 +5,32 @@ import 'package:http/http.dart' as http;
5 import 'package:flutter_dotenv/flutter_dotenv.dart'; 5 import 'package:flutter_dotenv/flutter_dotenv.dart';
6 import 'package:intl/intl.dart'; 6 import 'package:intl/intl.dart';
7 7
8 +import '../utils/user_secure_stoarge.dart';
8 import 'models/Bottle.dart'; 9 import 'models/Bottle.dart';
9 import 'models/Medicine.dart'; 10 import 'models/Medicine.dart';
10 import 'package:Smart_Medicine_Box/src/screens/SettingPage.dart'; 11 import 'package:Smart_Medicine_Box/src/screens/SettingPage.dart';
11 12
12 class DashBoard extends StatefulWidget { 13 class DashBoard extends StatefulWidget {
13 int pageNumber; 14 int pageNumber;
14 - Bottle bottleInformation;
15 - Medicine medicineInformation;
16 15
17 - DashBoard( 16 + DashBoard({
18 - {Key key, 17 + Key key,
19 this.pageNumber, 18 this.pageNumber,
20 - this.bottleInformation, 19 + }) : super(key: key);
21 - this.medicineInformation})
22 - : super(key: key);
23 20
24 @override 21 @override
25 _DashBoardState createState() => _DashBoardState(); 22 _DashBoardState createState() => _DashBoardState();
26 } 23 }
27 24
28 class _DashBoardState extends State<DashBoard> { 25 class _DashBoardState extends State<DashBoard> {
29 - Bottle _bottleinformation = new Bottle();
30 int _selectedIndex = 0; 26 int _selectedIndex = 0;
31 - Medicine _medicineInformation = new Medicine();
32 27
33 Widget build(BuildContext context) { 28 Widget build(BuildContext context) {
34 _selectedIndex = widget.pageNumber; 29 _selectedIndex = widget.pageNumber;
35 - _medicineInformation = widget.medicineInformation;
36 - _bottleinformation = widget.bottleInformation;
37 var _tabs = [ 30 var _tabs = [
38 - ineerInformationpage(context, _bottleinformation), 31 + ineerInformationpage(context),
39 - mainpage(context, _medicineInformation), 32 + mainpage(context),
40 - outerInformationpage(context, _bottleinformation), 33 + outerInformationpage(context),
41 ]; 34 ];
42 35
43 return Scaffold( 36 return Scaffold(
...@@ -126,12 +119,46 @@ class _DashBoardState extends State<DashBoard> { ...@@ -126,12 +119,46 @@ class _DashBoardState extends State<DashBoard> {
126 } 119 }
127 } 120 }
128 121
129 -Widget mainpage(BuildContext context, Medicine medicineInformation) { 122 +Widget mainpage(BuildContext context) {
123 + Medicine _medicineInformation = new Medicine();
124 +
125 + Future<Medicine> _getmedicine() async {
126 + String usertoken = await UserSecureStorage.getUserToken();
127 + String medicineid = await UserSecureStorage.getMedicineId();
128 + http.Response medicineresponse = await http.get(
129 + Uri.encodeFull(
130 + DotEnv().env['SERVER_URL'] + 'medicine/' + medicineid.toString()),
131 + headers: {"authorization": usertoken},
132 + );
133 +
134 + if (medicineresponse.statusCode == 200) {
135 + Map<String, dynamic> data = jsonDecode(medicineresponse.body);
136 + _medicineInformation = Medicine.fromJson(data);
137 + }
138 + print(1);
139 + print(_medicineInformation.company);
140 + return _medicineInformation;
141 + }
142 +
130 final Size size = MediaQuery.of(context).size; 143 final Size size = MediaQuery.of(context).size;
131 return Scaffold( 144 return Scaffold(
132 backgroundColor: Colors.white, 145 backgroundColor: Colors.white,
133 body: SingleChildScrollView( 146 body: SingleChildScrollView(
134 - child: Container( 147 + child: FutureBuilder(
148 + future: _getmedicine(),
149 + builder: (BuildContext context, AsyncSnapshot snapshot) {
150 + if (snapshot.hasData == false) {
151 + return CircularProgressIndicator();
152 + } else if (snapshot.hasError) {
153 + return Padding(
154 + padding: const EdgeInsets.all(8.0),
155 + child: Text(
156 + 'Error: ${snapshot.error}',
157 + style: TextStyle(fontSize: 15),
158 + ),
159 + );
160 + } else {
161 + return Container(
135 margin: EdgeInsets.fromLTRB(0, 30, 0, 0), 162 margin: EdgeInsets.fromLTRB(0, 30, 0, 0),
136 padding: EdgeInsets.fromLTRB(5, 0, 5, 5), 163 padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
137 child: Column( 164 child: Column(
...@@ -144,8 +171,8 @@ Widget mainpage(BuildContext context, Medicine medicineInformation) { ...@@ -144,8 +171,8 @@ Widget mainpage(BuildContext context, Medicine medicineInformation) {
144 margin: EdgeInsets.all(15), 171 margin: EdgeInsets.all(15),
145 decoration: BoxDecoration( 172 decoration: BoxDecoration(
146 border: Border.all(), 173 border: Border.all(),
147 - borderRadius: BorderRadius.all( 174 + borderRadius: BorderRadius.all(Radius.circular(
148 - Radius.circular(25.0) // <--- border radius here 175 + 25.0) // <--- border radius here
149 ), 176 ),
150 ), 177 ),
151 child: Column( 178 child: Column(
...@@ -154,9 +181,9 @@ Widget mainpage(BuildContext context, Medicine medicineInformation) { ...@@ -154,9 +181,9 @@ Widget mainpage(BuildContext context, Medicine medicineInformation) {
154 Container( 181 Container(
155 child: Center( 182 child: Center(
156 child: Text( 183 child: Text(
157 - medicineInformation.name == null 184 + '${snapshot.data.name}' == null
158 ? '-' 185 ? '-'
159 - : medicineInformation.name, 186 + : '${snapshot.data.name}',
160 style: TextStyle( 187 style: TextStyle(
161 color: Colors.black, 188 color: Colors.black,
162 fontSize: 24, 189 fontSize: 24,
...@@ -178,9 +205,9 @@ Widget mainpage(BuildContext context, Medicine medicineInformation) { ...@@ -178,9 +205,9 @@ Widget mainpage(BuildContext context, Medicine medicineInformation) {
178 ), 205 ),
179 ), 206 ),
180 Text( 207 Text(
181 - medicineInformation.company == null 208 + _medicineInformation.company == null
182 ? '-' 209 ? '-'
183 - : medicineInformation.company, 210 + : _medicineInformation.company,
184 style: TextStyle( 211 style: TextStyle(
185 color: Colors.grey, 212 color: Colors.grey,
186 fontSize: 14, 213 fontSize: 14,
...@@ -204,9 +231,9 @@ Widget mainpage(BuildContext context, Medicine medicineInformation) { ...@@ -204,9 +231,9 @@ Widget mainpage(BuildContext context, Medicine medicineInformation) {
204 ), 231 ),
205 ), 232 ),
206 Text( 233 Text(
207 - medicineInformation.target == null 234 + _medicineInformation.target == null
208 ? '-' 235 ? '-'
209 - : medicineInformation.target, 236 + : _medicineInformation.target,
210 style: TextStyle( 237 style: TextStyle(
211 color: Colors.grey, 238 color: Colors.grey,
212 fontSize: 14, 239 fontSize: 14,
...@@ -230,9 +257,9 @@ Widget mainpage(BuildContext context, Medicine medicineInformation) { ...@@ -230,9 +257,9 @@ Widget mainpage(BuildContext context, Medicine medicineInformation) {
230 ), 257 ),
231 ), 258 ),
232 Text( 259 Text(
233 - medicineInformation.dosage == null 260 + _medicineInformation.dosage == null
234 ? '-' 261 ? '-'
235 - : medicineInformation.dosage, 262 + : _medicineInformation.dosage,
236 style: TextStyle( 263 style: TextStyle(
237 color: Colors.grey, 264 color: Colors.grey,
238 fontSize: 14, 265 fontSize: 14,
...@@ -263,9 +290,9 @@ Widget mainpage(BuildContext context, Medicine medicineInformation) { ...@@ -263,9 +290,9 @@ Widget mainpage(BuildContext context, Medicine medicineInformation) {
263 Container( 290 Container(
264 width: size.width, 291 width: size.width,
265 child: Text( 292 child: Text(
266 - medicineInformation.warn == null 293 + _medicineInformation.warn == null
267 ? '-' 294 ? '-'
268 - : medicineInformation.warn, 295 + : _medicineInformation.warn,
269 style: TextStyle( 296 style: TextStyle(
270 color: Colors.redAccent, fontSize: 14), 297 color: Colors.redAccent, fontSize: 14),
271 ), 298 ),
...@@ -278,16 +305,51 @@ Widget mainpage(BuildContext context, Medicine medicineInformation) { ...@@ -278,16 +305,51 @@ Widget mainpage(BuildContext context, Medicine medicineInformation) {
278 ), 305 ),
279 ], 306 ],
280 ), 307 ),
308 + );
309 + }
310 + },
281 ), 311 ),
282 ), 312 ),
283 ); 313 );
284 } 314 }
285 315
286 -Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) { 316 +Widget ineerInformationpage(BuildContext context) {
317 + Bottle _bottleinformation = new Bottle();
318 + //get bottle
319 + Future<Bottle> _getbottle() async {
320 + String usertoken = await UserSecureStorage.getUserToken();
321 + String bottleid = await UserSecureStorage.getBottleId();
322 + Bottle _bottleinformation = new Bottle();
323 + http.Response response = await http.get(
324 + Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'bottle/' + bottleid),
325 + headers: {"authorization": usertoken});
326 +
327 + if (response.statusCode == 200) {
328 + Map<String, dynamic> jsonData = jsonDecode(response.body);
329 + _bottleinformation = Bottle.fromJson(jsonData);
330 + }
331 + return _bottleinformation;
332 + }
333 +
287 final Size size = MediaQuery.of(context).size; 334 final Size size = MediaQuery.of(context).size;
335 +
288 return Scaffold( 336 return Scaffold(
289 backgroundColor: Colors.white, 337 backgroundColor: Colors.white,
290 - body: Container( 338 + body: FutureBuilder(
339 + future: _getbottle(),
340 + builder: (BuildContext context, AsyncSnapshot snapshot) {
341 + if (snapshot.hasData == false) {
342 + return CircularProgressIndicator();
343 + } else if (snapshot.hasError) {
344 + return Padding(
345 + padding: const EdgeInsets.all(8.0),
346 + child: Text(
347 + 'Error: ${snapshot.error}',
348 + style: TextStyle(fontSize: 15),
349 + ),
350 + );
351 + } else {
352 + return Container(
291 height: size.height * 0.9, 353 height: size.height * 0.9,
292 margin: EdgeInsets.fromLTRB(0, 30, 0, 0), 354 margin: EdgeInsets.fromLTRB(0, 30, 0, 0),
293 padding: EdgeInsets.fromLTRB(5, 0, 5, 5), 355 padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
...@@ -354,15 +416,14 @@ Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) { ...@@ -354,15 +416,14 @@ Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) {
354 height: size.height * 0.145, 416 height: size.height * 0.145,
355 child: Center( 417 child: Center(
356 child: Row( 418 child: Row(
357 - mainAxisAlignment: MainAxisAlignment.center, 419 + mainAxisAlignment:
420 + MainAxisAlignment.center,
358 children: [ 421 children: [
359 Text( 422 Text(
360 - bottleinformation.temperature 423 + '${snapshot.data.temperature}' ==
361 - .toString() ==
362 null 424 null
363 ? '-' 425 ? '-'
364 - : bottleinformation.temperature 426 + : '${snapshot.data.temperature}',
365 - .toString(),
366 textAlign: TextAlign.center, 427 textAlign: TextAlign.center,
367 textScaleFactor: 1.0, 428 textScaleFactor: 1.0,
368 style: TextStyle( 429 style: TextStyle(
...@@ -420,13 +481,14 @@ Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) { ...@@ -420,13 +481,14 @@ Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) {
420 height: size.height * 0.14, 481 height: size.height * 0.14,
421 child: Center( 482 child: Center(
422 child: Row( 483 child: Row(
423 - mainAxisAlignment: MainAxisAlignment.center, 484 + mainAxisAlignment:
485 + MainAxisAlignment.center,
424 children: [ 486 children: [
425 Text( 487 Text(
426 - bottleinformation.humidity.toString() == 488 + snapshot.data.humidity.toString() ==
427 null 489 null
428 ? '-' 490 ? '-'
429 - : bottleinformation.humidity 491 + : snapshot.data.humidity
430 .toString(), 492 .toString(),
431 textAlign: TextAlign.center, 493 textAlign: TextAlign.center,
432 textScaleFactor: 1.0, 494 textScaleFactor: 1.0,
...@@ -502,13 +564,14 @@ Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) { ...@@ -502,13 +564,14 @@ Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) {
502 height: size.height * 0.14, 564 height: size.height * 0.14,
503 child: Center( 565 child: Center(
504 child: Row( 566 child: Row(
505 - mainAxisAlignment: MainAxisAlignment.center, 567 + mainAxisAlignment:
568 + MainAxisAlignment.center,
506 children: [ 569 children: [
507 Text( 570 Text(
508 - bottleinformation.balance.toString() == 571 + snapshot.data.balance.toString() ==
509 null 572 null
510 ? '-' 573 ? '-'
511 - : bottleinformation.balance 574 + : snapshot.data.balance
512 .toString(), 575 .toString(),
513 textAlign: TextAlign.center, 576 textAlign: TextAlign.center,
514 textScaleFactor: 1.0, 577 textScaleFactor: 1.0,
...@@ -567,10 +630,10 @@ Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) { ...@@ -567,10 +630,10 @@ Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) {
567 height: size.height * 0.14, 630 height: size.height * 0.14,
568 child: Center( 631 child: Center(
569 child: Text( 632 child: Text(
570 - bottleinformation.recentOpen == null 633 + snapshot.data.recentOpen == null
571 ? '-' 634 ? '-'
572 - : DateFormat.Hm() 635 + : DateFormat.Hm().format(
573 - .format(bottleinformation.recentOpen), 636 + snapshot.data.recentOpen),
574 textAlign: TextAlign.center, 637 textAlign: TextAlign.center,
575 textScaleFactor: 1.0, 638 textScaleFactor: 1.0,
576 style: TextStyle( 639 style: TextStyle(
...@@ -592,15 +655,54 @@ Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) { ...@@ -592,15 +655,54 @@ Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) {
592 ), 655 ),
593 ], 656 ],
594 ), 657 ),
658 + );
659 + }
660 + },
595 ), 661 ),
596 ); 662 );
597 } 663 }
598 664
599 -Widget outerInformationpage(BuildContext context, Bottle bottleinformation) { 665 +Widget outerInformationpage(BuildContext context) {
666 + Bottle _bottleinformation = new Bottle();
667 + //get bottle
668 + Future<Bottle> _getbottle() async {
669 + String usertoken = await UserSecureStorage.getUserToken();
670 + String bottleid = await UserSecureStorage.getBottleId();
671 + Bottle _bottleinformation = new Bottle();
672 + http.Response response = await http.get(
673 + Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'bottle/' + bottleid),
674 + headers: {"authorization": usertoken});
675 +
676 + if (response.statusCode == 200) {
677 + Map<String, dynamic> jsonData = jsonDecode(response.body);
678 + print(jsonData);
679 + _bottleinformation = Bottle.fromJson(jsonData);
680 + }
681 + print(1);
682 + print(_bottleinformation.toJson());
683 + return _bottleinformation;
684 + }
685 +
600 final Size size = MediaQuery.of(context).size; 686 final Size size = MediaQuery.of(context).size;
601 return Scaffold( 687 return Scaffold(
602 backgroundColor: Colors.white, 688 backgroundColor: Colors.white,
603 - body: Container( 689 + body: FutureBuilder(
690 + future: _getbottle(),
691 + builder: (BuildContext context, AsyncSnapshot snapshot) {
692 + if (snapshot.hasData == false) {
693 + return CircularProgressIndicator();
694 + } else if (snapshot.hasError) {
695 + return Padding(
696 + padding: const EdgeInsets.all(8.0),
697 + child: Text(
698 + 'Error: ${snapshot.error}',
699 + style: TextStyle(fontSize: 15),
700 + ),
701 + );
702 + } else {
703 + print(123412);
704 + print(snapshot.data.dosage);
705 + return Container(
604 height: size.height * 0.9, 706 height: size.height * 0.9,
605 margin: EdgeInsets.fromLTRB(0, 30, 0, 0), 707 margin: EdgeInsets.fromLTRB(0, 30, 0, 0),
606 padding: EdgeInsets.fromLTRB(5, 0, 5, 5), 708 padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
...@@ -665,12 +767,14 @@ Widget outerInformationpage(BuildContext context, Bottle bottleinformation) { ...@@ -665,12 +767,14 @@ Widget outerInformationpage(BuildContext context, Bottle bottleinformation) {
665 width: size.width, 767 width: size.width,
666 height: size.height * 0.12, 768 height: size.height * 0.12,
667 child: Row( 769 child: Row(
668 - mainAxisAlignment: MainAxisAlignment.center, 770 + mainAxisAlignment:
771 + MainAxisAlignment.center,
669 children: [ 772 children: [
670 Text( 773 Text(
671 - bottleinformation.dosage == null 774 + snapshot.data.dosage == null
672 ? '-' 775 ? '-'
673 - : bottleinformation.dosage.toString(), 776 + : snapshot.data.dosage
777 + .toString(),
674 textAlign: TextAlign.center, 778 textAlign: TextAlign.center,
675 textScaleFactor: 1.0, 779 textScaleFactor: 1.0,
676 style: TextStyle( 780 style: TextStyle(
...@@ -763,16 +867,8 @@ Widget outerInformationpage(BuildContext context, Bottle bottleinformation) { ...@@ -763,16 +867,8 @@ Widget outerInformationpage(BuildContext context, Bottle bottleinformation) {
763 ), 867 ),
764 ], 868 ],
765 ), 869 ),
766 - ), 870 + );
871 + }
872 + }),
767 ); 873 );
768 } 874 }
769 -
770 -/*
771 -bottom navbar로 이동
772 -appbar로는 저거 만들어서 사용
773 -설정 smartmedicine box를 app bar 로 구현
774 -이건 우선 작업 후 추후 작업
775 -
776 -
777 -
778 -*/
......
...@@ -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 }
......