고원빈

[frontend] Error 해결

......@@ -83,4 +83,7 @@ appbar 관련 디자인은 추후 구현 예정
### 2021-05-25
+ 로그인 권한 문제 해결
\ No newline at end of file
+ 로그인 권한 문제 해결
### 2021-05-26
+ future buillder 변경
\ No newline at end of file
......
SERVER_URL=
\ No newline at end of file
SERVER_URL=http://192.168.0.3:4717/api/
\ No newline at end of file
......
......@@ -10,46 +10,13 @@ import '../../utils/user_secure_stoarge.dart';
class BottleList extends StatefulWidget {
List<Bottle> bottlelist;
String hubid;
BottleList({Key key, this.bottlelist, this.hubid}) : super(key: key);
BottleList({Key key, this.bottlelist}) : super(key: key);
@override
_BottleListState createState() => _BottleListState();
}
class _BottleListState extends State<BottleList> {
Bottle _bottleinformation = new Bottle();
Medicine _medicineinformation = new Medicine();
Future<Bottle> getbottle(int index) async {
String usertoken = await UserSecureStorage.getUserToken();
http.Response response = await http.get(
Uri.encodeFull(DotEnv().env['SERVER_URL'] +
'bottle/' +
widget.bottlelist[index].bottleId.toString()),
headers: {"authorization": usertoken});
if (response.statusCode == 200) {
Map<String, dynamic> jsonData = jsonDecode(response.body);
print(jsonData);
_bottleinformation = Bottle.fromJson(jsonData);
}
}
Future<Bottle> getmedicine(int index) async {
String usertoken = await UserSecureStorage.getUserToken();
http.Response medicineresponse = await http.get(
Uri.encodeFull(DotEnv().env['SERVER_URL'] +
'medicine/' +
widget.bottlelist[index].medicineId.toString()),
headers: {"authorization": usertoken},
);
if (medicineresponse.statusCode == 200) {
Map<String, dynamic> data = jsonDecode(medicineresponse.body);
_medicineinformation = Medicine.fromJson(data);
}
}
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return Scaffold(
......@@ -97,15 +64,15 @@ class _BottleListState extends State<BottleList> {
),
trailing: Icon(Icons.arrow_forward),
onTap: () async {
await getbottle(index);
await getmedicine(index);
UserSecureStorage.setBottleId(
widget.bottlelist[index].bottleId.toString());
UserSecureStorage.setMedicineId(
widget.bottlelist[index].medicineId.toString());
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => DashBoard(
pageNumber: 1,
bottleInformation: _bottleinformation,
medicineInformation: _medicineinformation,
),
),
);
......
......@@ -215,7 +215,9 @@ class _DetailMedicineState extends State<DetailMedicine> {
context,
MaterialPageRoute(
builder: (BuildContext context) =>
HomePage(),
DashBoard(
pageNumber: 1,
),
),
);
})
......
......@@ -45,6 +45,7 @@ class _HubListState extends State<HubList> {
} else {
return "Error";
}
return "Error";
}
Widget build(BuildContext context) {
......@@ -95,14 +96,15 @@ class _HubListState extends State<HubList> {
var result =
await getBottleList(widget.hublist[index]);
if (result == "GET") {
UserSecureStorage.setHubId(
widget.hublist[index].toString());
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
BottleList(
bottlelist: _bottleList,
hubid: widget.hublist[index]
.toString()),
bottlelist: _bottleList,
),
));
} else if (result == "Not Found") {
showDialog(
......@@ -115,15 +117,15 @@ class _HubListState extends State<HubList> {
new FlatButton(
child: new Text('등록'),
onPressed: () {
UserSecureStorage.setHubId(widget
.hublist[index]
.toString());
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext
context) =>
RegisterBottle(
hubid: widget
.hublist[index]
.toString()),
RegisterBottle(),
));
})
],
......
......@@ -20,16 +20,16 @@ class _RegisterBottleState extends State<RegisterBottle> {
Future<String> registerhub_Validate() async {
String usertoken = await UserSecureStorage.getUserToken();
String hubid = await UserSecureStorage.getHubId();
print(hubid);
http.Response bottleresponse = await http.post(
Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'bottle'),
headers: {
"Content-Type": "application/json",
"authorization": usertoken
},
body: jsonEncode({
'bottleId': medicineBottleIDController.text,
'hubId': widget.hubid
}));
body: jsonEncode(
{'bottleId': medicineBottleIDController.text, 'hubId': hubid}));
if (bottleresponse.statusCode == 201) {
return "등록 완료";
......
......@@ -120,6 +120,7 @@ class _RegisterHubState extends State<RegisterHub> {
String saveMessage = await registerhub_Validate();
print(saveMessage);
if (saveMessage == "허브 등록 완료") {
UserSecureStorage.setHubId(medicineHubIDController.text);
Navigator.push(
context,
MaterialPageRoute(
......
......@@ -28,6 +28,7 @@ class _SignInPageState extends State<SignInPage> {
//Login 함수
Future<String> login(String _email, String _password) async {
print(Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'auth/login'));
http.Response response = await http.post(
Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'auth/login'),
headers: {"Content-Type": "application/json"},
......@@ -38,6 +39,7 @@ class _SignInPageState extends State<SignInPage> {
},
),
);
print(response.statusCode);
if (response.statusCode == 200) {
Map<String, dynamic> data = jsonDecode(response.body);
......@@ -51,7 +53,7 @@ class _SignInPageState extends State<SignInPage> {
}
}
//Get Bottle List 함수
//Get Hub List 함수
Future<String> getHubList() async {
String usertoken = await UserSecureStorage.getUserToken();
http.Response response = await http.get(
......@@ -207,6 +209,7 @@ class _SignInPageState extends State<SignInPage> {
String saveMessage = await login(
emailController.text,
passwordController.text);
print(saveMessage);
if (emailController.text.isEmpty ||
passwordController.text.isEmpty) {
showDialog(
......@@ -227,7 +230,6 @@ class _SignInPageState extends State<SignInPage> {
);
});
} else {
saveMessage = "로그인 성공";
if (saveMessage == "로그인 성공") {
var result = await getHubList();
print(result);
......@@ -242,6 +244,9 @@ class _SignInPageState extends State<SignInPage> {
} else if (result == "get완료") {
UserSecureStorage.setUserToken(
user.token);
UserSecureStorage.setUserId(
user.userId);
print('asdg');
Navigator.push(
context,
MaterialPageRoute(
......@@ -250,6 +255,8 @@ class _SignInPageState extends State<SignInPage> {
HubList(hublist: _hublist),
));
} else {}
} else {
print('Error');
}
}
},
......
import 'dart:convert';
import 'package:Smart_Medicine_Box/src/screens/Homepage.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:flutter_dotenv/flutter_dotenv.dart';
......@@ -182,7 +183,7 @@ class _SignUpLocalState extends State<SignUpLocal> {
context,
MaterialPageRoute(
builder: (BuildContext context) =>
RegisterHub()));
HomePage()));
})
],
);
......
......@@ -7,6 +7,12 @@ class UserSecureStorage {
static const _keyUserId = 'userid';
static const _keyBottleId = 'bottleid';
static const _keyMedicineId = 'medicineid';
static const _keyhubId = 'hubid';
static Future setUserId(String userid) async =>
await _storage.write(key: _keyUserId, value: userid);
......@@ -18,4 +24,21 @@ class UserSecureStorage {
static Future<String> getUserToken() async =>
await _storage.read(key: _keyToken);
static Future setBottleId(String bottleid) async =>
await _storage.write(key: _keyBottleId, value: bottleid);
static Future<String> getBottleId() async =>
await _storage.read(key: _keyBottleId);
static Future setMedicineId(String medicineid) async =>
await _storage.write(key: _keyMedicineId, value: medicineid);
static Future<String> getMedicineId() async =>
await _storage.read(key: _keyMedicineId);
static Future setHubId(String hubid) async =>
await _storage.write(key: _keyhubId, value: hubid);
static Future<String> getHubId() async => await _storage.read(key: _keyhubId);
}
......