고원빈

[frontend] 2021-06-02

......@@ -99,4 +99,7 @@ appbar 관련 디자인은 추후 구현 예정
+ Sqlite 생성
### 2021-06-01
+ datetime 형식 한국 시간으로 변경
\ No newline at end of file
+ datetime 형식 한국 시간으로 변경
### 2021-06-02
+ 약병 , 허브 추가 제거 관리 페이지 구현
......
import 'package:Smart_Medicine_Box/src/screens/DashBoard.dart';
import 'package:Smart_Medicine_Box/src/screens/Register/BottleList.dart';
import 'package:flutter/cupertino.dart';
import 'dart:convert';
import 'package:flutter/material.dart';
......@@ -10,7 +11,8 @@ import '../../utils/user_secure_stoarge.dart';
class RegisterBottle extends StatefulWidget {
final String hubid;
RegisterBottle({Key key, this.hubid}) : super(key: key);
final bool modify_bottle;
RegisterBottle({Key key, this.hubid, this.modify_bottle}) : super(key: key);
@override
_RegisterBottleState createState() => _RegisterBottleState();
}
......@@ -106,49 +108,74 @@ class _RegisterBottleState extends State<RegisterBottle> {
onPressed: () async {
String saveMessage = await registerhub_Validate();
print(saveMessage);
if (saveMessage == "등록 완료") {
print(widget.modify_bottle);
if (saveMessage == "등록 완료" && widget.modify_bottle == false) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text('약병 등록'),
content: new Text('약병 등록이 완료 되었습니다.'),
actions: <Widget>[
new FlatButton(
child: new Text('Close'),
onPressed: () {
UserSecureStorage.setBottleId(
medicineBottleIDController.text);
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
SearchMedicine(
bottleId: medicineBottleIDController.text,
),
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text('약병 등록'),
content: new Text('약병 등록이 완료 되었습니다.'),
actions: <Widget>[
new FlatButton(
child: new Text('Close'),
onPressed: () {
UserSecureStorage.setBottleId(
medicineBottleIDController.text);
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
SearchMedicine(
bottleId: medicineBottleIDController.text,
),
);
},
),
],
);
});
),
);
},
),
],
);
},
);
} else if (saveMessage == "등록 완료" &&
widget.modify_bottle == true) {
print('asdg');
await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text('약병 등록'),
content: new Text('약병 등록이 완료 되었습니다.'),
actions: <Widget>[
new FlatButton(
child: new Text('Close'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
Navigator.of(context).pop();
} else {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text('오류'),
content: new Text(saveMessage),
actions: <Widget>[
new FlatButton(
child: new Text('Close'),
onPressed: () {
Navigator.of(context).pop();
})
],
);
});
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text('오류'),
content: new Text(saveMessage),
actions: <Widget>[
new FlatButton(
child: new Text('Close'),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
},
);
}
},
shape: RoundedRectangleBorder(
......@@ -167,25 +194,6 @@ class _RegisterBottleState extends State<RegisterBottle> {
)
],
),
bottomNavigationBar: BottomAppBar(
elevation: 0,
child: Container(
height: 70,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(70, 0, 70, 0),
child: Text(
'회원 가입시, 이용 약관 및 개인정보 처리 방침에 동의하는 것으로 간주합니다..',
style: TextStyle(fontSize: 12, color: Color(0xff747474)),
textAlign: TextAlign.center,
),
)
],
),
),
),
);
}
}
......
import 'package:Smart_Medicine_Box/src/screens/SettingPage/HubModifyList.dart';
import 'package:flutter/cupertino.dart';
import 'dart:convert';
import 'package:flutter/material.dart';
......@@ -8,6 +9,9 @@ import 'RegisterBottle.dart';
import '../../utils/user_secure_stoarge.dart';
class RegisterHub extends StatefulWidget {
final int modify_hub;
RegisterHub({Key key, this.modify_hub}) : super(key: key);
@override
_RegisterHubState createState() => _RegisterHubState();
}
......@@ -31,7 +35,7 @@ class _RegisterHubState extends State<RegisterHub> {
'host': medicineHubHostController.text,
'port': medicineHubPortController.text,
}));
print(hubresponse.statusCode);
if (hubresponse.statusCode == 201) {
return "허브 등록 완료";
} else if (hubresponse.statusCode == 409) {
......@@ -118,14 +122,40 @@ class _RegisterHubState extends State<RegisterHub> {
child: RaisedButton(
onPressed: () async {
String saveMessage = await registerhub_Validate();
if (saveMessage == "허브 등록 완료") {
print(saveMessage);
print(widget.modify_hub);
if (saveMessage == "허브 등록 완료" && widget.modify_hub == 0) {
UserSecureStorage.setHubId(medicineHubIDController.text);
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
RegisterBottle(hubid: medicineHubIDController.text),
));
context,
MaterialPageRoute(
builder: (BuildContext context) => RegisterBottle(
hubid: medicineHubIDController.text,
modify_bottle: false,
),
),
);
} else if (saveMessage == "허브 등록 완료" &&
widget.modify_hub == 1) {
Navigator.of(context).pop();
} else {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text('오류'),
content: new Text(saveMessage),
actions: <Widget>[
new FlatButton(
child: new Text('close'),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
},
);
}
},
shape: RoundedRectangleBorder(
......@@ -133,7 +163,7 @@ class _RegisterHubState extends State<RegisterHub> {
side: BorderSide(color: Colors.blue)),
color: Color(0xff1674f6),
child: Text(
' 허브 등록 ',
'허브 등록 ',
textScaleFactor: 1.0,
style: TextStyle(
fontSize: 16,
......@@ -144,25 +174,6 @@ class _RegisterHubState extends State<RegisterHub> {
)
],
),
bottomNavigationBar: BottomAppBar(
elevation: 0,
child: Container(
height: 70,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(70, 0, 70, 0),
child: Text(
'회원 가입시, 이용 약관 및 개인정보 처리 방침에 동의하는 것으로 간주합니다..',
style: TextStyle(fontSize: 12, color: Color(0xff747474)),
textAlign: TextAlign.center,
),
)
],
),
),
),
);
}
}
......
......@@ -235,9 +235,9 @@ class _SignInPageState extends State<SignInPage> {
Navigator.push(
context,
MaterialPageRoute(
builder:
(BuildContext context) =>
RegisterHub(),
builder: (BuildContext
context) =>
RegisterHub(modify_hub: 0),
));
} else if (result == "get완료") {
UserSecureStorage.setUserId(
......
......@@ -3,8 +3,7 @@ import 'package:flutter/material.dart';
import 'package:Smart_Medicine_Box/src/screens/DashBoard.dart';
import 'package:Smart_Medicine_Box/src/screens/SettingPage/Alarm.dart';
import 'package:Smart_Medicine_Box/src/screens/SettingPage/DEVInformation.dart';
import 'package:Smart_Medicine_Box/src/screens/SettingPage/InformationModify.dart';
import '../screens/Register/HubList.dart';
import 'package:Smart_Medicine_Box/src/screens/SettingPage/BottleModifyList.dart';
class SettingPage extends StatefulWidget {
@override
......@@ -134,7 +133,7 @@ class _SettingPageState extends State<SettingPage> {
));
},
child: Text(
'허브 등록',
'허브 관리',
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
......@@ -159,11 +158,11 @@ class _SettingPageState extends State<SettingPage> {
context,
MaterialPageRoute(
builder: (BuildContext context) =>
InformationModify(),
BottleModifyList(),
));
},
child: Text(
'회원 정보 수정',
'약병 관리',
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
......
import 'dart:convert';
import 'package:Smart_Medicine_Box/src/screens/Register/RegisterBottle.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:flutter_dotenv/flutter_dotenv.dart';
import '../models/Bottle.dart';
import '../DashBoard.dart';
import '../../utils/user_secure_stoarge.dart';
import '../../utils/DBHelper.dart';
import '../models/UserBottle.dart';
class BottleModifyList extends StatefulWidget {
BottleModifyList({Key key}) : super(key: key);
@override
_BottleModifyListState createState() => _BottleModifyListState();
}
class _BottleModifyListState extends State<BottleModifyList> {
List<Bottle> _bottleList = new List<Bottle>();
Future<String> getBottleList() async {
String hubid = await UserSecureStorage.getHubId();
String usertoken = await UserSecureStorage.getUserToken();
var provider = DBHelper();
http.Response response = await http.get(
Uri.encodeFull(
DotEnv().env['SERVER_URL'] + 'bottle/hub/' + hubid.toString()),
headers: {"authorization": usertoken},
);
if (_bottleList.length != 0) {
_bottleList.clear();
}
if (response.statusCode == 200) {
List<dynamic> values = new List<dynamic>();
values = json.decode(response.body);
for (int i = 0; i < values.length; i++) {
Map<String, dynamic> map = values[i];
_bottleList.add(Bottle.fromJson(map));
}
for (int i = 0; i < _bottleList.length; i++) {
UserBottle temp = new UserBottle();
temp.bottleId = _bottleList[i].bottleId;
temp.bottleName = _bottleList[i].bottleId.toString();
provider.createData(temp);
}
List<UserBottle> _userbottleList = new List<UserBottle>();
_userbottleList = await provider.getAllBottle();
for (int i = 0; i < _userbottleList.length; i++) {
print(_userbottleList[i].bottleId);
}
print(provider.getAllBottle());
return "GET";
} else if (response.statusCode == 404) {
return "Not Found";
} else {
return "Error";
}
}
Future<String> deleteBottle(int index) async {
String usertoken = await UserSecureStorage.getUserToken();
http.Response response = await http.delete(
Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'bottle/' + index.toString()),
headers: {"authorization": usertoken},
);
print('asdgasdga');
print(response.statusCode);
if (response.statusCode == 204) {
return "Delete";
} else {
return "Error";
}
}
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
leading: new Icon(Icons.medical_services_rounded,
color: Colors.black, size: 45.0),
title: Text(
'Smart Medicine Box',
style: TextStyle(
color: Colors.black,
fontSize: 23,
fontFamily: 'Noto',
fontWeight: FontWeight.bold),
),
),
body: FutureBuilder(
future: getBottleList(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData == false) {
return CircularProgressIndicator();
} else if (snapshot.hasError) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Error: ${snapshot.error}',
style: TextStyle(fontSize: 15),
),
);
} else {
return Container(
height: size.height,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 10),
Container(
height: size.height * 0.07,
width: size.width,
child: Center(
child: Text(
'등록된 약병 리스트',
textScaleFactor: 1.0,
style: TextStyle(
fontSize: 28,
fontFamily: 'Noto',
fontWeight: FontWeight.bold),
),
),
),
SizedBox(height: 10),
Expanded(
child: GridView.builder(
padding: const EdgeInsets.all(30),
itemCount:
_bottleList.length == null ? 0 : _bottleList.length,
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
itemBuilder: (BuildContext context, int index) {
return InkResponse(
splashColor: Colors.transparent,
child: Container(
height: 140,
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.all(
Radius.circular(16.0),
),
),
child: Column(
children: [
Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.black,
width: 1,
style: BorderStyle.solid),
),
),
height: 40,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Container(
height: 40,
child: Center(
child: Text(
'${_bottleList[index].bottleId}',
style: TextStyle(
color: Colors.black,
fontSize: 20,
fontFamily: 'Noto',
fontWeight: FontWeight.bold),
),
),
),
Container(
child: IconButton(
alignment: Alignment(0.9, 0),
icon: Icon(
Icons.create_sharp,
color: Colors.black,
),
onPressed: () {},
),
),
],
),
),
SizedBox(height: 10),
Container(
height: 90,
child: Icon(
Icons.medical_services_outlined,
size: 100,
),
)
],
),
),
onTap: () {
if (_bottleList.length == 1) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text('약병 삭제'),
content:
new Text('등록된 약병이 하나이므로 해제가 불가능 합니다.'),
actions: <Widget>[
new FlatButton(
child: new Text('Cloes'),
onPressed: () {
Navigator.of(context).pop();
}),
],
);
},
);
} else {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text('허브 삭제'),
content: new Text(
_bottleList[index].bottleId.toString() +
'을 삭제 하시겠습니까?'),
actions: <Widget>[
new FlatButton(
child: new Text('삭제'),
onPressed: () async {
print('dfg');
await deleteBottle(
_bottleList[index].bottleId);
setState(() {});
Navigator.of(context).pop();
},
),
new FlatButton(
child: new Text('취소'),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
},
);
}
},
);
},
),
),
Container(
padding: EdgeInsets.fromLTRB(0, 20, 0, 20),
width: size.width * 0.8,
height: size.height * 0.13,
margin: EdgeInsets.only(bottom: 0),
child: FlatButton(
height: size.height * 0.06,
onPressed: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
RegisterBottle(modify_bottle: true),
),
);
setState(() {});
},
child: Text(
'약병 추가',
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontFamily: 'Noto',
fontWeight: FontWeight.bold),
),
color: Color(0xff0B1E33),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50)),
),
),
],
),
);
}
},
),
);
}
}
import 'package:Smart_Medicine_Box/src/screens/Register/RegsiterHub.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutter_dotenv/flutter_dotenv.dart';
// Screen import
import '../models/Bottle.dart';
import '../../utils/user_secure_stoarge.dart';
class HubModifyList extends StatefulWidget {
......@@ -42,6 +42,19 @@ class _HubModifyListState extends State<HubModifyList> {
}
}
Future<String> deleteHub(int index) async {
String usertoken = await UserSecureStorage.getUserToken();
http.Response response = await http.delete(
Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'hub/' + index.toString()),
headers: {"authorization": usertoken},
);
if (response.statusCode == 204) {
return "Delete";
} else {
return "Error";
}
}
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return Scaffold(
......@@ -107,18 +120,65 @@ class _HubModifyListState extends State<HubModifyList> {
BorderRadius.all(Radius.circular(25.0)),
),
child: ListTile(
title: Text(
'HUB ID: ' + '${_hublist[index]}',
style: TextStyle(
color: Colors.black,
fontSize: 20,
fontFamily: 'Noto',
fontWeight: FontWeight.bold),
),
trailing: Icon(Icons.highlight_remove),
onTap: () async {
print('삭제 할거임');
}),
title: Text(
'HUB ID: ' + '${_hublist[index]}',
style: TextStyle(
color: Colors.black,
fontSize: 20,
fontFamily: 'Noto',
fontWeight: FontWeight.bold),
),
trailing: Icon(Icons.highlight_remove),
onTap: () async {
if (_hublist.length == 1) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text('허브 삭제'),
content: new Text(
'등록된 허브가 하나이므로 해제가 불가능 합니다.'),
actions: <Widget>[
new FlatButton(
child: new Text('Cloes'),
onPressed: () {
Navigator.of(context).pop();
}),
],
);
},
);
} else {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text('허브 삭제'),
content: new Text(
_hublist[index].toString() +
'을 삭제 하시겠습니까?'),
actions: <Widget>[
new FlatButton(
child: new Text('삭제'),
onPressed: () async {
await deleteHub(_hublist[index]);
setState(() {});
Navigator.of(context).pop();
},
),
new FlatButton(
child: new Text('취소'),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
},
);
}
},
),
);
},
separatorBuilder: (BuildContext contetx, int index) =>
......@@ -132,7 +192,16 @@ class _HubModifyListState extends State<HubModifyList> {
margin: EdgeInsets.only(bottom: 0),
child: FlatButton(
height: size.height * 0.07,
onPressed: () {},
onPressed: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
RegisterHub(modify_hub: 1),
),
);
setState(() {});
},
child: Text(
'허브 추가',
textScaleFactor: 1.0,
......