고원빈

[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
......
......@@ -5,39 +5,32 @@ import 'package:http/http.dart' as http;
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:intl/intl.dart';
import '../utils/user_secure_stoarge.dart';
import 'models/Bottle.dart';
import 'models/Medicine.dart';
import 'package:Smart_Medicine_Box/src/screens/SettingPage.dart';
class DashBoard extends StatefulWidget {
int pageNumber;
Bottle bottleInformation;
Medicine medicineInformation;
DashBoard(
{Key key,
this.pageNumber,
this.bottleInformation,
this.medicineInformation})
: super(key: key);
DashBoard({
Key key,
this.pageNumber,
}) : super(key: key);
@override
_DashBoardState createState() => _DashBoardState();
}
class _DashBoardState extends State<DashBoard> {
Bottle _bottleinformation = new Bottle();
int _selectedIndex = 0;
Medicine _medicineInformation = new Medicine();
Widget build(BuildContext context) {
_selectedIndex = widget.pageNumber;
_medicineInformation = widget.medicineInformation;
_bottleinformation = widget.bottleInformation;
var _tabs = [
ineerInformationpage(context, _bottleinformation),
mainpage(context, _medicineInformation),
outerInformationpage(context, _bottleinformation),
ineerInformationpage(context),
mainpage(context),
outerInformationpage(context),
];
return Scaffold(
......@@ -126,148 +119,185 @@ class _DashBoardState extends State<DashBoard> {
}
}
Widget mainpage(BuildContext context, Medicine medicineInformation) {
Widget mainpage(BuildContext context) {
Medicine _medicineInformation = new Medicine();
Future<Medicine> _getmedicine() async {
String usertoken = await UserSecureStorage.getUserToken();
String medicineid = await UserSecureStorage.getMedicineId();
http.Response medicineresponse = await http.get(
Uri.encodeFull(
DotEnv().env['SERVER_URL'] + 'medicine/' + medicineid.toString()),
headers: {"authorization": usertoken},
);
if (medicineresponse.statusCode == 200) {
Map<String, dynamic> data = jsonDecode(medicineresponse.body);
_medicineInformation = Medicine.fromJson(data);
}
print(1);
print(_medicineInformation.company);
return _medicineInformation;
}
final Size size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Colors.white,
body: SingleChildScrollView(
child: Container(
margin: EdgeInsets.fromLTRB(0, 30, 0, 0),
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(height: 20),
Container(
width: size.width,
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
margin: EdgeInsets.all(15),
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.all(
Radius.circular(25.0) // <--- border radius here
),
child: FutureBuilder(
future: _getmedicine(),
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(
margin: EdgeInsets.fromLTRB(0, 30, 0, 0),
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
child: Column(
children: [
SizedBox(height: 30),
Container(
child: Center(
child: Text(
medicineInformation.name == null
? '-'
: medicineInformation.name,
style: TextStyle(
color: Colors.black,
fontSize: 24,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w700)),
),
),
SizedBox(height: 30),
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(height: 20),
Container(
width: size.width,
alignment: Alignment(0.9, 0),
child: Wrap(
children: [
Text(
'제조사: ',
style: TextStyle(
color: Colors.grey,
fontSize: 14,
),
),
Text(
medicineInformation.company == null
? '-'
: medicineInformation.company,
style: TextStyle(
color: Colors.grey,
fontSize: 14,
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
margin: EdgeInsets.all(15),
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.all(Radius.circular(
25.0) // <--- border radius here
),
),
],
),
),
SizedBox(height: 30),
Container(
width: size.width,
padding: EdgeInsets.fromLTRB(5, 0, 5, 0),
alignment: Alignment(-1, 0),
child: Wrap(
child: Column(
children: [
Text(
'타겟 층 : ',
style: TextStyle(
color: Colors.grey,
fontSize: 14,
),
),
Text(
medicineInformation.target == null
? '-'
: medicineInformation.target,
style: TextStyle(
color: Colors.grey,
fontSize: 14,
SizedBox(height: 30),
Container(
child: Center(
child: Text(
'${snapshot.data.name}' == null
? '-'
: '${snapshot.data.name}',
style: TextStyle(
color: Colors.black,
fontSize: 24,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w700)),
),
),
],
),
),
SizedBox(height: 15),
Container(
width: size.width,
padding: EdgeInsets.fromLTRB(5, 0, 5, 0),
alignment: Alignment(-1, 0),
child: Wrap(
children: [
Text(
'복약 정보 : ',
style: TextStyle(
color: Colors.grey,
fontSize: 14,
SizedBox(height: 30),
Container(
width: size.width,
alignment: Alignment(0.9, 0),
child: Wrap(
children: [
Text(
'제조사: ',
style: TextStyle(
color: Colors.grey,
fontSize: 14,
),
),
Text(
_medicineInformation.company == null
? '-'
: _medicineInformation.company,
style: TextStyle(
color: Colors.grey,
fontSize: 14,
),
),
],
),
),
Text(
medicineInformation.dosage == null
? '-'
: medicineInformation.dosage,
style: TextStyle(
color: Colors.grey,
fontSize: 14,
SizedBox(height: 30),
Container(
width: size.width,
padding: EdgeInsets.fromLTRB(5, 0, 5, 0),
alignment: Alignment(-1, 0),
child: Wrap(
children: [
Text(
'타겟 층 : ',
style: TextStyle(
color: Colors.grey,
fontSize: 14,
),
),
Text(
_medicineInformation.target == null
? '-'
: _medicineInformation.target,
style: TextStyle(
color: Colors.grey,
fontSize: 14,
),
),
],
),
),
],
),
),
SizedBox(height: 10),
Container(
width: size.width,
padding: EdgeInsets.fromLTRB(5, 10, 5, 10),
alignment: Alignment(-1, 0),
child: Column(
children: [
SizedBox(
height: 12,
),
SizedBox(height: 15),
Container(
width: size.width,
child: Text(
'경고',
style: TextStyle(
color: Colors.redAccent, fontSize: 14),
padding: EdgeInsets.fromLTRB(5, 0, 5, 0),
alignment: Alignment(-1, 0),
child: Wrap(
children: [
Text(
'복약 정보 : ',
style: TextStyle(
color: Colors.grey,
fontSize: 14,
),
),
Text(
_medicineInformation.dosage == null
? '-'
: _medicineInformation.dosage,
style: TextStyle(
color: Colors.grey,
fontSize: 14,
),
),
],
),
),
SizedBox(height: 12),
SizedBox(height: 10),
Container(
width: size.width,
child: Text(
medicineInformation.warn == null
? '-'
: medicineInformation.warn,
style: TextStyle(
color: Colors.redAccent, fontSize: 14),
padding: EdgeInsets.fromLTRB(5, 10, 5, 10),
alignment: Alignment(-1, 0),
child: Column(
children: [
SizedBox(
height: 12,
),
Container(
width: size.width,
child: Text(
'경고',
style: TextStyle(
color: Colors.redAccent, fontSize: 14),
),
),
SizedBox(height: 12),
Container(
width: size.width,
child: Text(
_medicineInformation.warn == null
? '-'
: _medicineInformation.warn,
style: TextStyle(
color: Colors.redAccent, fontSize: 14),
),
),
],
),
),
],
......@@ -275,179 +305,214 @@ Widget mainpage(BuildContext context, Medicine medicineInformation) {
),
],
),
),
],
),
);
}
},
),
),
);
}
Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) {
Widget ineerInformationpage(BuildContext context) {
Bottle _bottleinformation = new Bottle();
//get bottle
Future<Bottle> _getbottle() async {
String usertoken = await UserSecureStorage.getUserToken();
String bottleid = await UserSecureStorage.getBottleId();
Bottle _bottleinformation = new Bottle();
http.Response response = await http.get(
Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'bottle/' + bottleid),
headers: {"authorization": usertoken});
if (response.statusCode == 200) {
Map<String, dynamic> jsonData = jsonDecode(response.body);
_bottleinformation = Bottle.fromJson(jsonData);
}
return _bottleinformation;
}
final Size size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Colors.white,
body: Container(
height: size.height * 0.9,
margin: EdgeInsets.fromLTRB(0, 30, 0, 0),
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
height: size.height * 0.08,
width: size.width,
child: Center(
child: Text(
'Inside Information',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.black,
fontSize: 32,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w700),
),
body: FutureBuilder(
future: _getbottle(),
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),
),
),
Container(
);
} else {
return Container(
height: size.height * 0.9,
margin: EdgeInsets.fromLTRB(0, 30, 0, 0),
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
height: size.height * 0.25,
width: size.width,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Flexible(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
Container(
padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
height: size.height * 0.08,
width: size.width,
child: Center(
child: Text(
'Inside Information',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.black,
fontSize: 32,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w700),
),
),
),
Container(
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
height: size.height * 0.25,
width: size.width,
child: Column(
children: <Widget>[
Container(
width: size.width * 0.43,
height: size.width * 0.45,
margin: const EdgeInsets.all(5.0),
padding: const EdgeInsets.fromLTRB(10, 5, 10, 10),
decoration: BoxDecoration(
color: Color(0xff8E97FD),
borderRadius: BorderRadius.circular(10.0),
),
child: Column(
children: [
Flexible(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: size.width,
height: size.height * 0.05,
child: Center(
child: Text(
'약병 내부 온도',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
width: size.width * 0.43,
height: size.width * 0.45,
margin: const EdgeInsets.all(5.0),
padding: const EdgeInsets.fromLTRB(10, 5, 10, 10),
decoration: BoxDecoration(
color: Color(0xff8E97FD),
borderRadius: BorderRadius.circular(10.0),
),
),
Container(
width: size.width,
height: size.height * 0.145,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
bottleinformation.temperature
.toString() ==
null
? '-'
: bottleinformation.temperature
.toString(),
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 76,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
child: Column(
children: [
Container(
width: size.width,
height: size.height * 0.05,
child: Center(
child: Text(
'약병 내부 온도',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
),
Text(
'℃',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 60,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
)
],
),
),
Container(
width: size.width,
height: size.height * 0.145,
child: Center(
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Text(
'${snapshot.data.temperature}' ==
null
? '-'
: '${snapshot.data.temperature}',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 76,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
Text(
'℃',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 60,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
)
],
),
),
),
],
),
),
],
),
),
Container(
width: size.width * 0.43,
height: size.width * 0.45,
margin: const EdgeInsets.all(5.0),
padding: const EdgeInsets.fromLTRB(10, 5, 10, 10),
decoration: BoxDecoration(
color: Color(0xff8E97FD),
borderRadius: BorderRadius.circular(10.0),
),
child: Column(
children: [
Container(
width: size.width,
height: size.height * 0.05,
child: Center(
child: Text(
'약병 내부 습도',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
width: size.width * 0.43,
height: size.width * 0.45,
margin: const EdgeInsets.all(5.0),
padding: const EdgeInsets.fromLTRB(10, 5, 10, 10),
decoration: BoxDecoration(
color: Color(0xff8E97FD),
borderRadius: BorderRadius.circular(10.0),
),
),
Container(
width: size.width,
height: size.height * 0.14,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
bottleinformation.humidity.toString() ==
null
? '-'
: bottleinformation.humidity
.toString(),
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 80,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
child: Column(
children: [
Container(
width: size.width,
height: size.height * 0.05,
child: Center(
child: Text(
'약병 내부 습도',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
),
Text(
'%',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 60,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
)
],
),
),
Container(
width: size.width,
height: size.height * 0.14,
child: Center(
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Text(
snapshot.data.humidity.toString() ==
null
? '-'
: snapshot.data.humidity
.toString(),
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 80,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
Text(
'%',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 60,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
)
],
),
),
),
],
),
),
],
......@@ -456,129 +521,130 @@ Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) {
],
),
),
],
),
),
Container(
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
height: size.height * 0.3,
width: size.width,
child: Column(
children: <Widget>[
Flexible(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
Container(
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
height: size.height * 0.3,
width: size.width,
child: Column(
children: <Widget>[
Container(
width: size.width * 0.43,
height: size.width * 0.45,
margin: const EdgeInsets.all(5.0),
padding: const EdgeInsets.fromLTRB(10, 5, 10, 10),
decoration: BoxDecoration(
color: Color(0xff8E97FD),
borderRadius: BorderRadius.circular(10.0),
),
child: Column(
children: [
Flexible(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: size.width,
height: size.height * 0.05,
child: Center(
child: Text(
'약병 내부 잔량',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
width: size.width * 0.43,
height: size.width * 0.45,
margin: const EdgeInsets.all(5.0),
padding: const EdgeInsets.fromLTRB(10, 5, 10, 10),
decoration: BoxDecoration(
color: Color(0xff8E97FD),
borderRadius: BorderRadius.circular(10.0),
),
),
Container(
width: size.width,
height: size.height * 0.14,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
bottleinformation.balance.toString() ==
null
? '-'
: bottleinformation.balance
.toString(),
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 80,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
child: Column(
children: [
Container(
width: size.width,
height: size.height * 0.05,
child: Center(
child: Text(
'약병 내부 잔량',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
),
Text(
'%',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 60,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
)
],
),
),
Container(
width: size.width,
height: size.height * 0.14,
child: Center(
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Text(
snapshot.data.balance.toString() ==
null
? '-'
: snapshot.data.balance
.toString(),
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 80,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
Text(
'%',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 60,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
)
],
),
),
),
],
),
),
],
),
),
Container(
width: size.width * 0.43,
height: size.width * 0.45,
margin: const EdgeInsets.all(5.0),
padding: const EdgeInsets.fromLTRB(10, 5, 10, 10),
decoration: BoxDecoration(
color: Color(0xff8E97FD),
borderRadius: BorderRadius.circular(10.0),
),
child: Column(
children: [
Container(
width: size.width,
height: size.height * 0.05,
child: Center(
child: Text(
'최근 개폐 시간',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
width: size.width * 0.43,
height: size.width * 0.45,
margin: const EdgeInsets.all(5.0),
padding: const EdgeInsets.fromLTRB(10, 5, 10, 10),
decoration: BoxDecoration(
color: Color(0xff8E97FD),
borderRadius: BorderRadius.circular(10.0),
),
),
Container(
width: size.width,
height: size.height * 0.14,
child: Center(
child: Text(
bottleinformation.recentOpen == null
? '-'
: DateFormat.Hm()
.format(bottleinformation.recentOpen),
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 60,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
child: Column(
children: [
Container(
width: size.width,
height: size.height * 0.05,
child: Center(
child: Text(
'최근 개폐 시간',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
),
),
Container(
width: size.width,
height: size.height * 0.14,
child: Center(
child: Text(
snapshot.data.recentOpen == null
? '-'
: DateFormat.Hm().format(
snapshot.data.recentOpen),
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 60,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
),
),
],
),
),
],
......@@ -589,190 +655,220 @@ Widget ineerInformationpage(BuildContext context, Bottle bottleinformation) {
),
],
),
),
],
),
);
}
},
),
);
}
Widget outerInformationpage(BuildContext context, Bottle bottleinformation) {
Widget outerInformationpage(BuildContext context) {
Bottle _bottleinformation = new Bottle();
//get bottle
Future<Bottle> _getbottle() async {
String usertoken = await UserSecureStorage.getUserToken();
String bottleid = await UserSecureStorage.getBottleId();
Bottle _bottleinformation = new Bottle();
http.Response response = await http.get(
Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'bottle/' + bottleid),
headers: {"authorization": usertoken});
if (response.statusCode == 200) {
Map<String, dynamic> jsonData = jsonDecode(response.body);
print(jsonData);
_bottleinformation = Bottle.fromJson(jsonData);
}
print(1);
print(_bottleinformation.toJson());
return _bottleinformation;
}
final Size size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Colors.white,
body: Container(
height: size.height * 0.9,
margin: EdgeInsets.fromLTRB(0, 30, 0, 0),
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
height: size.height * 0.08,
width: size.width,
child: Center(
body: FutureBuilder(
future: _getbottle(),
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(
'Outside Information',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.black,
fontSize: 32,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w700),
'Error: ${snapshot.error}',
style: TextStyle(fontSize: 15),
),
),
),
Container(
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
height: size.height * 0.20,
width: size.width,
child: Column(
children: <Widget>[
Flexible(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(5, 5, 5, 0),
width: size.width * 0.9,
height: size.height * 0.18,
decoration: BoxDecoration(
color: Color(0xff8E97FD),
borderRadius: BorderRadius.circular(10.0),
),
child: Column(
children: [
Container(
width: size.width,
height: size.height * 0.05,
child: Center(
child: Text(
'권장 약 복용량',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 28,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
);
} else {
print(123412);
print(snapshot.data.dosage);
return Container(
height: size.height * 0.9,
margin: EdgeInsets.fromLTRB(0, 30, 0, 0),
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
height: size.height * 0.08,
width: size.width,
child: Center(
child: Text(
'Outside Information',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.black,
fontSize: 32,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w700),
),
),
),
Container(
padding: EdgeInsets.fromLTRB(5, 0, 5, 5),
margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
height: size.height * 0.20,
width: size.width,
child: Column(
children: <Widget>[
Flexible(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(5, 5, 5, 0),
width: size.width * 0.9,
height: size.height * 0.18,
decoration: BoxDecoration(
color: Color(0xff8E97FD),
borderRadius: BorderRadius.circular(10.0),
),
child: Column(
children: [
Container(
width: size.width,
height: size.height * 0.05,
child: Center(
child: Text(
'권장 약 복용량',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 28,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
),
),
Container(
width: size.width,
height: size.height * 0.12,
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Text(
snapshot.data.dosage == null
? '-'
: snapshot.data.dosage
.toString(),
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 80,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
Text(
' 개',
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 64,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
)
],
),
),
],
),
),
),
Container(
width: size.width,
height: size.height * 0.12,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
bottleinformation.dosage == null
? '-'
: bottleinformation.dosage.toString(),
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 80,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
Text(
' 개',
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 64,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
)
],
),
),
],
],
),
),
),
],
],
),
),
),
],
),
),
Container(
margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
height: size.height * 0.20,
width: size.width,
child: Column(
children: <Widget>[
Flexible(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(5, 5, 5, 0),
width: size.width * 0.9,
height: size.height * 0.18,
decoration: BoxDecoration(
color: Color(0xff8E97FD),
borderRadius: BorderRadius.circular(10.0),
),
child: Column(
children: [
Container(
width: size.width,
height: size.height * 0.05,
child: Center(
child: Text(
'약 복용 시간',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 28,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
Container(
margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
height: size.height * 0.20,
width: size.width,
child: Column(
children: <Widget>[
Flexible(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(5, 5, 5, 0),
width: size.width * 0.9,
height: size.height * 0.18,
decoration: BoxDecoration(
color: Color(0xff8E97FD),
borderRadius: BorderRadius.circular(10.0),
),
),
),
Container(
width: size.width,
height: size.height * 0.12,
child: Center(
child: Text(
'15:57',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 70,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
child: Column(
children: [
Container(
width: size.width,
height: size.height * 0.05,
child: Center(
child: Text(
'약 복용 시간',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 28,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
),
),
Container(
width: size.width,
height: size.height * 0.12,
child: Center(
child: Text(
'15:57',
textAlign: TextAlign.center,
textScaleFactor: 1.0,
style: TextStyle(
color: Colors.white,
fontSize: 70,
fontFamily: 'NotoSansKR',
fontWeight: FontWeight.w800),
),
),
),
],
),
),
),
],
],
),
),
),
],
],
),
),
),
],
),
),
],
),
),
],
),
);
}
}),
);
}
/*
bottom navbar로 이동
appbar로는 저거 만들어서 사용
설정 smartmedicine box를 app bar 로 구현
이건 우선 작업 후 추후 작업
*/
......
......@@ -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);
}
......