Showing
15 changed files
with
163 additions
and
78 deletions
File mode changed
| ... | @@ -3,6 +3,7 @@ import 'dart:convert'; | ... | @@ -3,6 +3,7 @@ import 'dart:convert'; |
| 3 | import 'package:shared_preferences/shared_preferences.dart'; | 3 | import 'package:shared_preferences/shared_preferences.dart'; |
| 4 | import 'package:http/http.dart' as http; | 4 | 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 | 7 | ||
| 7 | import 'models/Bottle.dart'; | 8 | import 'models/Bottle.dart'; |
| 8 | import 'models/Medicine.dart'; | 9 | import 'models/Medicine.dart'; |
| ... | @@ -28,6 +29,7 @@ class _DashBoardState extends State<DashBoard> { | ... | @@ -28,6 +29,7 @@ class _DashBoardState extends State<DashBoard> { |
| 28 | Bottle _bottleinformation = new Bottle(); | 29 | Bottle _bottleinformation = new Bottle(); |
| 29 | int _selectedIndex = 0; | 30 | int _selectedIndex = 0; |
| 30 | Medicine _medicineInformation = new Medicine(); | 31 | Medicine _medicineInformation = new Medicine(); |
| 32 | + | ||
| 31 | Widget build(BuildContext context) { | 33 | Widget build(BuildContext context) { |
| 32 | _selectedIndex = widget.pageNumber; | 34 | _selectedIndex = widget.pageNumber; |
| 33 | _medicineInformation = widget.medicineInformation; | 35 | _medicineInformation = widget.medicineInformation; |
| ... | @@ -125,17 +127,6 @@ class _DashBoardState extends State<DashBoard> { | ... | @@ -125,17 +127,6 @@ class _DashBoardState extends State<DashBoard> { |
| 125 | } | 127 | } |
| 126 | 128 | ||
| 127 | Widget mainpage(BuildContext context, Medicine medicineInformation) { | 129 | Widget mainpage(BuildContext context, Medicine medicineInformation) { |
| 128 | - Future<String> getHubList() async { | ||
| 129 | - SharedPreferences prefs = await SharedPreferences.getInstance(); | ||
| 130 | - | ||
| 131 | - http.Response response = | ||
| 132 | - await http.get(Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'hub')); | ||
| 133 | - | ||
| 134 | - print(response.statusCode); | ||
| 135 | - } | ||
| 136 | - | ||
| 137 | - //현재 접속 중인 허브 리스트 id와 약병 리스트 id 출력 | ||
| 138 | - //약 상세 정보 가져오기 --> 이건 Detail Medicine에서 가져 오면 됨 | ||
| 139 | final Size size = MediaQuery.of(context).size; | 130 | final Size size = MediaQuery.of(context).size; |
| 140 | return Scaffold( | 131 | return Scaffold( |
| 141 | backgroundColor: Colors.white, | 132 | backgroundColor: Colors.white, |
| ... | @@ -578,7 +569,8 @@ Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) { | ... | @@ -578,7 +569,8 @@ Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) { |
| 578 | child: Text( | 569 | child: Text( |
| 579 | bottleinformation.recentOpen == null | 570 | bottleinformation.recentOpen == null |
| 580 | ? '-' | 571 | ? '-' |
| 581 | - : bottleinformation.recentOpen, | 572 | + : DateFormat.Hm() |
| 573 | + .format(bottleinformation.recentOpen), | ||
| 582 | textAlign: TextAlign.center, | 574 | textAlign: TextAlign.center, |
| 583 | textScaleFactor: 1.0, | 575 | textScaleFactor: 1.0, |
| 584 | style: TextStyle( | 576 | style: TextStyle( |
| ... | @@ -676,9 +668,9 @@ Widget outerInformationpage(BuildContext context, Bottle bottleinformation) { | ... | @@ -676,9 +668,9 @@ Widget outerInformationpage(BuildContext context, Bottle bottleinformation) { |
| 676 | mainAxisAlignment: MainAxisAlignment.center, | 668 | mainAxisAlignment: MainAxisAlignment.center, |
| 677 | children: [ | 669 | children: [ |
| 678 | Text( | 670 | Text( |
| 679 | - bottleinformation.toString() == null | 671 | + bottleinformation.dosage == null |
| 680 | ? '-' | 672 | ? '-' |
| 681 | - : bottleinformation.toString(), | 673 | + : bottleinformation.dosage.toString(), |
| 682 | textAlign: TextAlign.center, | 674 | textAlign: TextAlign.center, |
| 683 | textScaleFactor: 1.0, | 675 | textScaleFactor: 1.0, |
| 684 | style: TextStyle( | 676 | style: TextStyle( | ... | ... |
| ... | @@ -6,6 +6,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; | ... | @@ -6,6 +6,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; |
| 6 | import '../models/Bottle.dart'; | 6 | import '../models/Bottle.dart'; |
| 7 | import '../DashBoard.dart'; | 7 | import '../DashBoard.dart'; |
| 8 | import '../models/Medicine.dart'; | 8 | import '../models/Medicine.dart'; |
| 9 | +import '../../utils/user_secure_stoarge.dart'; | ||
| 9 | 10 | ||
| 10 | class BottleList extends StatefulWidget { | 11 | class BottleList extends StatefulWidget { |
| 11 | List<Bottle> bottlelist; | 12 | List<Bottle> bottlelist; |
| ... | @@ -21,10 +22,12 @@ class _BottleListState extends State<BottleList> { | ... | @@ -21,10 +22,12 @@ class _BottleListState extends State<BottleList> { |
| 21 | Medicine _medicineinformation = new Medicine(); | 22 | Medicine _medicineinformation = new Medicine(); |
| 22 | 23 | ||
| 23 | Future<Bottle> getbottle(int index) async { | 24 | Future<Bottle> getbottle(int index) async { |
| 24 | - http.Response response = await http.get(Uri.encodeFull( | 25 | + String usertoken = await UserSecureStorage.getUserToken(); |
| 25 | - DotEnv().env['SERVER_URL'] + | 26 | + http.Response response = await http.get( |
| 27 | + Uri.encodeFull(DotEnv().env['SERVER_URL'] + | ||
| 26 | 'bottle/' + | 28 | 'bottle/' + |
| 27 | - widget.bottlelist[index].bottleId.toString())); | 29 | + widget.bottlelist[index].bottleId.toString()), |
| 30 | + headers: {"authorization": usertoken}); | ||
| 28 | 31 | ||
| 29 | if (response.statusCode == 200) { | 32 | if (response.statusCode == 200) { |
| 30 | Map<String, dynamic> jsonData = jsonDecode(response.body); | 33 | Map<String, dynamic> jsonData = jsonDecode(response.body); |
| ... | @@ -34,10 +37,13 @@ class _BottleListState extends State<BottleList> { | ... | @@ -34,10 +37,13 @@ class _BottleListState extends State<BottleList> { |
| 34 | } | 37 | } |
| 35 | 38 | ||
| 36 | Future<Bottle> getmedicine(int index) async { | 39 | Future<Bottle> getmedicine(int index) async { |
| 37 | - http.Response medicineresponse = await http.get(Uri.encodeFull( | 40 | + String usertoken = await UserSecureStorage.getUserToken(); |
| 38 | - DotEnv().env['SERVER_URL'] + | 41 | + http.Response medicineresponse = await http.get( |
| 39 | - 'medicine/' + | 42 | + Uri.encodeFull(DotEnv().env['SERVER_URL'] + |
| 40 | - widget.bottlelist[index].medicineId.toString())); | 43 | + 'medicine/' + |
| 44 | + widget.bottlelist[index].medicineId.toString()), | ||
| 45 | + headers: {"authorization": usertoken}, | ||
| 46 | + ); | ||
| 41 | if (medicineresponse.statusCode == 200) { | 47 | if (medicineresponse.statusCode == 200) { |
| 42 | Map<String, dynamic> data = jsonDecode(medicineresponse.body); | 48 | Map<String, dynamic> data = jsonDecode(medicineresponse.body); |
| 43 | _medicineinformation = Medicine.fromJson(data); | 49 | _medicineinformation = Medicine.fromJson(data); |
| ... | @@ -80,32 +86,31 @@ class _BottleListState extends State<BottleList> { | ... | @@ -80,32 +86,31 @@ class _BottleListState extends State<BottleList> { |
| 80 | padding: EdgeInsets.all(8.0), | 86 | padding: EdgeInsets.all(8.0), |
| 81 | decoration: BoxDecoration(border: Border.all()), | 87 | decoration: BoxDecoration(border: Border.all()), |
| 82 | child: ListTile( | 88 | child: ListTile( |
| 83 | - title: Text( | 89 | + title: Text( |
| 84 | - 'BOTTLE ID : ' + | 90 | + 'BOTTLE ID : ' + |
| 85 | - '${widget.bottlelist[index].bottleId}', | 91 | + '${widget.bottlelist[index].bottleId}', |
| 86 | - style: TextStyle( | 92 | + style: TextStyle( |
| 87 | - color: Colors.black, | 93 | + color: Colors.black, |
| 88 | - fontSize: 20, | 94 | + fontSize: 20, |
| 89 | - fontFamily: 'Noto', | 95 | + fontFamily: 'Noto', |
| 90 | - fontWeight: FontWeight.bold), | 96 | + fontWeight: FontWeight.bold), |
| 91 | - ), | 97 | + ), |
| 92 | - trailing: Icon(Icons.arrow_forward), | 98 | + trailing: Icon(Icons.arrow_forward), |
| 93 | - onTap: () async { | 99 | + onTap: () async { |
| 94 | - getbottle(index); | 100 | + await getbottle(index); |
| 95 | - getmedicine(index); | 101 | + await getmedicine(index); |
| 96 | - print(_bottleinformation); | 102 | + Navigator.push( |
| 97 | - print(_medicineinformation); | 103 | + context, |
| 98 | - | 104 | + MaterialPageRoute( |
| 99 | - Navigator.push( | 105 | + builder: (BuildContext context) => DashBoard( |
| 100 | - context, | 106 | + pageNumber: 1, |
| 101 | - MaterialPageRoute( | 107 | + bottleInformation: _bottleinformation, |
| 102 | - builder: (BuildContext context) => DashBoard( | 108 | + medicineInformation: _medicineinformation, |
| 103 | - pageNumber: 1, | 109 | + ), |
| 104 | - bottleInformation: _bottleinformation, | 110 | + ), |
| 105 | - medicineInformation: _medicineinformation, | 111 | + ); |
| 106 | - ), | 112 | + }, |
| 107 | - )); | 113 | + ), |
| 108 | - }), | ||
| 109 | ); | 114 | ); |
| 110 | }, | 115 | }, |
| 111 | separatorBuilder: (BuildContext contetx, int index) => | 116 | separatorBuilder: (BuildContext contetx, int index) => | ... | ... |
| ... | @@ -6,6 +6,7 @@ import 'dart:convert'; | ... | @@ -6,6 +6,7 @@ import 'dart:convert'; |
| 6 | import 'package:http/http.dart' as http; | 6 | import 'package:http/http.dart' as http; |
| 7 | import 'package:flutter_dotenv/flutter_dotenv.dart'; | 7 | import 'package:flutter_dotenv/flutter_dotenv.dart'; |
| 8 | import '../models/Medicine.dart'; | 8 | import '../models/Medicine.dart'; |
| 9 | +import '../../utils/user_secure_stoarge.dart'; | ||
| 9 | 10 | ||
| 10 | class DetailMedicine extends StatefulWidget { | 11 | class DetailMedicine extends StatefulWidget { |
| 11 | Medicine searchMedicine; | 12 | Medicine searchMedicine; |
| ... | @@ -20,10 +21,14 @@ class _DetailMedicineState extends State<DetailMedicine> { | ... | @@ -20,10 +21,14 @@ class _DetailMedicineState extends State<DetailMedicine> { |
| 20 | final medicineDosageController = TextEditingController(); | 21 | final medicineDosageController = TextEditingController(); |
| 21 | //약 등록 | 22 | //약 등록 |
| 22 | Future<String> patchMedcine() async { | 23 | Future<String> patchMedcine() async { |
| 24 | + String usertoken = await UserSecureStorage.getUserToken(); | ||
| 23 | http.Response response = await http.patch( | 25 | http.Response response = await http.patch( |
| 24 | Uri.encodeFull( | 26 | Uri.encodeFull( |
| 25 | DotEnv().env['SERVER_URL'] + 'bottle/' + widget.bottleId), | 27 | DotEnv().env['SERVER_URL'] + 'bottle/' + widget.bottleId), |
| 26 | - headers: {"Content-Type": "application/json"}, | 28 | + headers: { |
| 29 | + "Content-Type": "application/json", | ||
| 30 | + "authorization": usertoken | ||
| 31 | + }, | ||
| 27 | body: jsonEncode({ | 32 | body: jsonEncode({ |
| 28 | 'medicineId': widget.searchMedicine.medicineId, | 33 | 'medicineId': widget.searchMedicine.medicineId, |
| 29 | 'dosage': medicineDosageController.text | 34 | 'dosage': medicineDosageController.text | ... | ... |
| ... | @@ -7,6 +7,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; | ... | @@ -7,6 +7,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; |
| 7 | import 'RegisterBottle.dart'; | 7 | import 'RegisterBottle.dart'; |
| 8 | import '../models/Bottle.dart'; | 8 | import '../models/Bottle.dart'; |
| 9 | import 'BottleList.dart'; | 9 | import 'BottleList.dart'; |
| 10 | +import '../../utils/user_secure_stoarge.dart'; | ||
| 10 | 11 | ||
| 11 | class HubList extends StatefulWidget { | 12 | class HubList extends StatefulWidget { |
| 12 | List<int> hublist; | 13 | List<int> hublist; |
| ... | @@ -20,8 +21,13 @@ class _HubListState extends State<HubList> { | ... | @@ -20,8 +21,13 @@ class _HubListState extends State<HubList> { |
| 20 | List<Bottle> _bottleList = new List<Bottle>(); | 21 | List<Bottle> _bottleList = new List<Bottle>(); |
| 21 | //Get BottleList | 22 | //Get BottleList |
| 22 | Future<String> getBottleList(int hubid) async { | 23 | Future<String> getBottleList(int hubid) async { |
| 23 | - http.Response response = await http.get(Uri.encodeFull( | 24 | + String usertoken = await UserSecureStorage.getUserToken(); |
| 24 | - DotEnv().env['SERVER_URL'] + 'bottle/hub/' + hubid.toString())); | 25 | + http.Response response = await http.get( |
| 26 | + Uri.encodeFull( | ||
| 27 | + DotEnv().env['SERVER_URL'] + 'bottle/hub/' + hubid.toString()), | ||
| 28 | + headers: {"authorization": usertoken}, | ||
| 29 | + ); | ||
| 30 | + print(response.body); | ||
| 25 | if (_bottleList.length != 0) { | 31 | if (_bottleList.length != 0) { |
| 26 | _bottleList.clear(); | 32 | _bottleList.clear(); |
| 27 | } | 33 | } | ... | ... |
| ... | @@ -6,6 +6,7 @@ import 'package:http/http.dart' as http; | ... | @@ -6,6 +6,7 @@ import 'package:http/http.dart' as http; |
| 6 | import 'package:flutter_dotenv/flutter_dotenv.dart'; | 6 | import 'package:flutter_dotenv/flutter_dotenv.dart'; |
| 7 | 7 | ||
| 8 | import 'SearchMedicine.dart'; | 8 | import 'SearchMedicine.dart'; |
| 9 | +import '../../utils/user_secure_stoarge.dart'; | ||
| 9 | 10 | ||
| 10 | class RegisterBottle extends StatefulWidget { | 11 | class RegisterBottle extends StatefulWidget { |
| 11 | final String hubid; | 12 | final String hubid; |
| ... | @@ -18,9 +19,13 @@ class _RegisterBottleState extends State<RegisterBottle> { | ... | @@ -18,9 +19,13 @@ class _RegisterBottleState extends State<RegisterBottle> { |
| 18 | final medicineBottleIDController = TextEditingController(); | 19 | final medicineBottleIDController = TextEditingController(); |
| 19 | 20 | ||
| 20 | Future<String> registerhub_Validate() async { | 21 | Future<String> registerhub_Validate() async { |
| 22 | + String usertoken = await UserSecureStorage.getUserToken(); | ||
| 21 | http.Response bottleresponse = await http.post( | 23 | http.Response bottleresponse = await http.post( |
| 22 | Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'bottle'), | 24 | Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'bottle'), |
| 23 | - headers: {"Content-Type": "application/json"}, | 25 | + headers: { |
| 26 | + "Content-Type": "application/json", | ||
| 27 | + "authorization": usertoken | ||
| 28 | + }, | ||
| 24 | body: jsonEncode({ | 29 | body: jsonEncode({ |
| 25 | 'bottleId': medicineBottleIDController.text, | 30 | 'bottleId': medicineBottleIDController.text, |
| 26 | 'hubId': widget.hubid | 31 | 'hubId': widget.hubid | ... | ... |
| ... | @@ -5,6 +5,7 @@ import 'package:http/http.dart' as http; | ... | @@ -5,6 +5,7 @@ import 'package:http/http.dart' as http; |
| 5 | import 'package:flutter_dotenv/flutter_dotenv.dart'; | 5 | import 'package:flutter_dotenv/flutter_dotenv.dart'; |
| 6 | 6 | ||
| 7 | import 'RegisterBottle.dart'; | 7 | import 'RegisterBottle.dart'; |
| 8 | +import '../../utils/user_secure_stoarge.dart'; | ||
| 8 | 9 | ||
| 9 | class RegisterHub extends StatefulWidget { | 10 | class RegisterHub extends StatefulWidget { |
| 10 | @override | 11 | @override |
| ... | @@ -18,14 +19,18 @@ class _RegisterHubState extends State<RegisterHub> { | ... | @@ -18,14 +19,18 @@ class _RegisterHubState extends State<RegisterHub> { |
| 18 | final medicineHubHostController = TextEditingController(); | 19 | final medicineHubHostController = TextEditingController(); |
| 19 | 20 | ||
| 20 | Future<String> registerhub_Validate() async { | 21 | Future<String> registerhub_Validate() async { |
| 21 | - http.Response hubresponse = | 22 | + String usertoken = await UserSecureStorage.getUserToken(); |
| 22 | - await http.post(Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'hub'), | 23 | + http.Response hubresponse = await http.post( |
| 23 | - headers: {"Content-Type": "application/json"}, | 24 | + Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'hub'), |
| 24 | - body: jsonEncode({ | 25 | + headers: { |
| 25 | - 'hubId': medicineHubIDController.text, | 26 | + "Content-Type": "application/json", |
| 26 | - 'host': medicineHubHostController.text, | 27 | + "authorization": usertoken |
| 27 | - 'port': medicineHubPortController.text, | 28 | + }, |
| 28 | - })); | 29 | + body: jsonEncode({ |
| 30 | + 'hubId': medicineHubIDController.text, | ||
| 31 | + 'host': medicineHubHostController.text, | ||
| 32 | + 'port': medicineHubPortController.text, | ||
| 33 | + })); | ||
| 29 | 34 | ||
| 30 | if (hubresponse.statusCode == 201) { | 35 | if (hubresponse.statusCode == 201) { |
| 31 | return "허브 등록 완료"; | 36 | return "허브 등록 완료"; | ... | ... |
| ... | @@ -5,6 +5,7 @@ import 'package:http/http.dart' as http; | ... | @@ -5,6 +5,7 @@ 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 '../models/Medicine.dart'; | 6 | import '../models/Medicine.dart'; |
| 7 | import 'DetailMedicine.dart'; | 7 | import 'DetailMedicine.dart'; |
| 8 | +import '../../utils/user_secure_stoarge.dart'; | ||
| 8 | 9 | ||
| 9 | class SearchMedicine extends StatefulWidget { | 10 | class SearchMedicine extends StatefulWidget { |
| 10 | String bottleId; | 11 | String bottleId; |
| ... | @@ -19,13 +20,17 @@ class _SearchMedicineState extends State<SearchMedicine> { | ... | @@ -19,13 +20,17 @@ class _SearchMedicineState extends State<SearchMedicine> { |
| 19 | final medicineCompanyController = TextEditingController(); | 20 | final medicineCompanyController = TextEditingController(); |
| 20 | 21 | ||
| 21 | Future<String> postMeicineList() async { | 22 | Future<String> postMeicineList() async { |
| 22 | - http.Response response = | 23 | + String usertoken = await UserSecureStorage.getUserToken(); |
| 23 | - await http.post(Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'medicine'), | 24 | + http.Response response = await http.post( |
| 24 | - headers: {"Content-Type": "application/json"}, | 25 | + Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'medicine'), |
| 25 | - body: jsonEncode({ | 26 | + headers: { |
| 26 | - 'name': medicineNameController.text, | 27 | + "Content-Type": "application/json", |
| 27 | - 'company': medicineCompanyController.text, | 28 | + "authorization": usertoken |
| 28 | - })); | 29 | + }, |
| 30 | + body: jsonEncode({ | ||
| 31 | + 'name': medicineNameController.text, | ||
| 32 | + 'company': medicineCompanyController.text, | ||
| 33 | + })); | ||
| 29 | 34 | ||
| 30 | if (_medicineList.length != 0) { | 35 | if (_medicineList.length != 0) { |
| 31 | _medicineList.clear(); | 36 | _medicineList.clear(); | ... | ... |
| ... | @@ -3,10 +3,11 @@ import 'package:flutter/material.dart'; | ... | @@ -3,10 +3,11 @@ import 'package:flutter/material.dart'; |
| 3 | import 'package:flutter/services.dart'; | 3 | import 'package:flutter/services.dart'; |
| 4 | import 'package:http/http.dart' as http; | 4 | 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:shared_preferences/shared_preferences.dart'; | 6 | + |
| 7 | -import '../DashBoard.dart'; | 7 | +import '../../utils/user_secure_stoarge.dart'; |
| 8 | import 'HubList.dart'; | 8 | import 'HubList.dart'; |
| 9 | import 'RegsiterHub.dart'; | 9 | import 'RegsiterHub.dart'; |
| 10 | +import '../models/User.dart'; | ||
| 10 | 11 | ||
| 11 | class SignInPage extends StatefulWidget { | 12 | class SignInPage extends StatefulWidget { |
| 12 | @override | 13 | @override |
| ... | @@ -18,22 +19,30 @@ class _SignInPageState extends State<SignInPage> { | ... | @@ -18,22 +19,30 @@ class _SignInPageState extends State<SignInPage> { |
| 18 | bool passwordVisible = false; | 19 | bool passwordVisible = false; |
| 19 | bool _validateEmail = false; | 20 | bool _validateEmail = false; |
| 20 | bool _validatePassword = false; | 21 | bool _validatePassword = false; |
| 22 | + | ||
| 21 | final emailController = TextEditingController(); | 23 | final emailController = TextEditingController(); |
| 22 | final passwordController = TextEditingController(); | 24 | final passwordController = TextEditingController(); |
| 23 | 25 | ||
| 26 | + User user; | ||
| 24 | List<int> _hublist = new List<int>(); //허브이름을 만들어야 할 것 같은데 임시로 허브 id만 고르게 함 | 27 | List<int> _hublist = new List<int>(); //허브이름을 만들어야 할 것 같은데 임시로 허브 id만 고르게 함 |
| 25 | 28 | ||
| 26 | //Login 함수 | 29 | //Login 함수 |
| 27 | Future<String> login(String _email, String _password) async { | 30 | Future<String> login(String _email, String _password) async { |
| 28 | http.Response response = await http.post( | 31 | http.Response response = await http.post( |
| 29 | - Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'auth/login'), | 32 | + Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'auth/login'), |
| 30 | - headers: {"Content-Type": "application/json"}, | 33 | + headers: {"Content-Type": "application/json"}, |
| 31 | - body: jsonEncode({ | 34 | + body: jsonEncode( |
| 35 | + { | ||
| 32 | 'userId': _email, | 36 | 'userId': _email, |
| 33 | 'password': _password, | 37 | 'password': _password, |
| 34 | - })); | 38 | + }, |
| 39 | + ), | ||
| 40 | + ); | ||
| 35 | 41 | ||
| 36 | if (response.statusCode == 200) { | 42 | if (response.statusCode == 200) { |
| 43 | + Map<String, dynamic> data = jsonDecode(response.body); | ||
| 44 | + user = User.fromJson(data); | ||
| 45 | + print(user); | ||
| 37 | return "로그인 성공"; | 46 | return "로그인 성공"; |
| 38 | } else if (response.statusCode == 400) { | 47 | } else if (response.statusCode == 400) { |
| 39 | return "올바르지 않은 아이디 및 패스워드"; | 48 | return "올바르지 않은 아이디 및 패스워드"; |
| ... | @@ -44,11 +53,14 @@ class _SignInPageState extends State<SignInPage> { | ... | @@ -44,11 +53,14 @@ class _SignInPageState extends State<SignInPage> { |
| 44 | 53 | ||
| 45 | //Get Bottle List 함수 | 54 | //Get Bottle List 함수 |
| 46 | Future<String> getHubList() async { | 55 | Future<String> getHubList() async { |
| 47 | - http.Response response = | 56 | + String usertoken = await UserSecureStorage.getUserToken(); |
| 48 | - await http.get(Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'hub')); | 57 | + http.Response response = await http.get( |
| 58 | + Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'hub'), | ||
| 59 | + headers: {"authorization": usertoken}, | ||
| 60 | + ); | ||
| 49 | 61 | ||
| 50 | List<dynamic> values = new List<dynamic>(); | 62 | List<dynamic> values = new List<dynamic>(); |
| 51 | - | 63 | + print(values); |
| 52 | if (_hublist.length != 0) { | 64 | if (_hublist.length != 0) { |
| 53 | _hublist.clear(); | 65 | _hublist.clear(); |
| 54 | } | 66 | } |
| ... | @@ -228,6 +240,8 @@ class _SignInPageState extends State<SignInPage> { | ... | @@ -228,6 +240,8 @@ class _SignInPageState extends State<SignInPage> { |
| 228 | RegisterHub(), | 240 | RegisterHub(), |
| 229 | )); | 241 | )); |
| 230 | } else if (result == "get완료") { | 242 | } else if (result == "get완료") { |
| 243 | + UserSecureStorage.setUserToken( | ||
| 244 | + user.token); | ||
| 231 | Navigator.push( | 245 | Navigator.push( |
| 232 | context, | 246 | context, |
| 233 | MaterialPageRoute( | 247 | MaterialPageRoute( | ... | ... |
| ... | @@ -3,7 +3,7 @@ class Bottle { | ... | @@ -3,7 +3,7 @@ class Bottle { |
| 3 | final int temperature; | 3 | final int temperature; |
| 4 | final int humidity; | 4 | final int humidity; |
| 5 | final int balance; | 5 | final int balance; |
| 6 | - final String recentOpen; | 6 | + final DateTime recentOpen; |
| 7 | final int medicineId; | 7 | final int medicineId; |
| 8 | final int hubId; | 8 | final int hubId; |
| 9 | final int dosage; | 9 | final int dosage; |
| ... | @@ -24,7 +24,7 @@ class Bottle { | ... | @@ -24,7 +24,7 @@ class Bottle { |
| 24 | temperature: parsedJson['temperature'], | 24 | temperature: parsedJson['temperature'], |
| 25 | humidity: parsedJson['humidity'], | 25 | humidity: parsedJson['humidity'], |
| 26 | balance: parsedJson['balance'], | 26 | balance: parsedJson['balance'], |
| 27 | - recentOpen: parsedJson['recentOpen'], | 27 | + recentOpen: DateTime.parse(parsedJson['recentOpen']), |
| 28 | medicineId: parsedJson['medicineId'], | 28 | medicineId: parsedJson['medicineId'], |
| 29 | hubId: parsedJson['hubId'], | 29 | hubId: parsedJson['hubId'], |
| 30 | dosage: parsedJson['dosage'], | 30 | dosage: parsedJson['dosage'], | ... | ... |
| 1 | +class User { | ||
| 2 | + final String userId; | ||
| 3 | + final String token; | ||
| 4 | + | ||
| 5 | + User({this.userId, this.token}); | ||
| 6 | + | ||
| 7 | + factory User.fromJson(Map<String, dynamic> parsedJson) { | ||
| 8 | + return User( | ||
| 9 | + userId: parsedJson['userId'], | ||
| 10 | + token: parsedJson['token'], | ||
| 11 | + ); | ||
| 12 | + } | ||
| 13 | + Map<String, dynamic> toJson() => { | ||
| 14 | + "userId": userId, | ||
| 15 | + "token": token, | ||
| 16 | + }; | ||
| 17 | +} |
| 1 | +import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | ||
| 2 | + | ||
| 3 | +class UserSecureStorage { | ||
| 4 | + static final _storage = FlutterSecureStorage(); | ||
| 5 | + | ||
| 6 | + static const _keyToken = 'usertoken'; | ||
| 7 | + | ||
| 8 | + static const _keyUserId = 'userid'; | ||
| 9 | + | ||
| 10 | + static Future setUserId(String userid) async => | ||
| 11 | + await _storage.write(key: _keyUserId, value: userid); | ||
| 12 | + | ||
| 13 | + static Future<String> getUserID() async => | ||
| 14 | + await _storage.read(key: _keyUserId); | ||
| 15 | + | ||
| 16 | + static Future setUserToken(String userToken) async => | ||
| 17 | + await _storage.write(key: _keyToken, value: userToken); | ||
| 18 | + | ||
| 19 | + static Future<String> getUserToken() async => | ||
| 20 | + await _storage.read(key: _keyToken); | ||
| 21 | +} |
| ... | @@ -132,6 +132,13 @@ packages: | ... | @@ -132,6 +132,13 @@ packages: |
| 132 | url: "https://pub.dartlang.org" | 132 | url: "https://pub.dartlang.org" |
| 133 | source: hosted | 133 | source: hosted |
| 134 | version: "0.7.0" | 134 | version: "0.7.0" |
| 135 | + flutter_secure_storage: | ||
| 136 | + dependency: "direct main" | ||
| 137 | + description: | ||
| 138 | + name: flutter_secure_storage | ||
| 139 | + url: "https://pub.dartlang.org" | ||
| 140 | + source: hosted | ||
| 141 | + version: "3.3.5" | ||
| 135 | flutter_test: | 142 | flutter_test: |
| 136 | dependency: "direct dev" | 143 | dependency: "direct dev" |
| 137 | description: flutter | 144 | description: flutter |
| ... | @@ -415,4 +422,4 @@ packages: | ... | @@ -415,4 +422,4 @@ packages: |
| 415 | version: "0.1.2" | 422 | version: "0.1.2" |
| 416 | sdks: | 423 | sdks: |
| 417 | dart: ">=2.10.0-110 <2.11.0" | 424 | dart: ">=2.10.0-110 <2.11.0" |
| 418 | - flutter: ">=1.12.13+hotfix.6 <2.0.0" | 425 | + flutter: ">=1.20.0 <2.0.0" | ... | ... |
| ... | @@ -38,6 +38,7 @@ dependencies: | ... | @@ -38,6 +38,7 @@ dependencies: |
| 38 | http: ^0.12.0+4 | 38 | http: ^0.12.0+4 |
| 39 | flutter_dotenv: ^2.1.0 | 39 | flutter_dotenv: ^2.1.0 |
| 40 | numberpicker: ^1.3.0 | 40 | numberpicker: ^1.3.0 |
| 41 | + flutter_secure_storage: ^3.3.5 | ||
| 41 | 42 | ||
| 42 | dev_dependencies: | 43 | dev_dependencies: |
| 43 | flutter_test: | 44 | flutter_test: | ... | ... |
-
Please register or login to post a comment