고원빈

[frontend] 2021-05-20~2021-05-22

......@@ -53,9 +53,17 @@ appbar 관련 디자인은 추후 구현 예정
### 2021-05-17
+ server test 완료
### 2021-05-18
+ 회원 가입 SERVER 연동
### 2021-05-19
+ Login 연동
+ 약병 등록 ,허브 등록 구현
### 2021-05-20
+ 시나리오 수정
### 2021-05-21
+ 약병 ,허브 리스트 출력 구현
......
SERVER_URL=
\ No newline at end of file
SERVER_URL=http://192.168.0.3:4000/api/
\ No newline at end of file
......
import 'dart:convert';
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';
class BottleList extends StatefulWidget {
List<Bottle> bottlelist;
BottleList({Key key, this.bottlelist}) : super(key: key);
@override
_BottleListState createState() => _BottleListState();
}
class _BottleListState extends State<BottleList> {
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return Scaffold(
body: Container(
height: size.height,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 70),
Container(
height: size.height * 0.1,
width: size.width,
child: Center(
child: Text(
'등록된 약병 리스트',
textScaleFactor: 1.0,
style: TextStyle(
fontSize: 28,
fontFamily: 'Noto',
fontWeight: FontWeight.bold),
),
),
decoration: BoxDecoration(border: Border.all()),
),
SizedBox(height: 30),
Expanded(
child: ListView.separated(
padding: const EdgeInsets.all(30),
itemCount: widget.bottlelist.length,
itemBuilder: (BuildContext context, int index) {
return Container(
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(border: Border.all()),
child: ListTile(
title: Text(
'BOTTLE ID : ' +
'${widget.bottlelist[index].bottleId}',
style: TextStyle(
color: Colors.black,
fontSize: 20,
fontFamily: 'Noto',
fontWeight: FontWeight.bold),
),
trailing: Icon(Icons.arrow_forward),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => DashBoard(
pageNumber: 1,
bottleID: widget.bottlelist[index].bottleId,
),
));
}),
);
},
separatorBuilder: (BuildContext contetx, int index) =>
const Divider(),
),
)
],
)),
);
}
}
......@@ -6,8 +6,9 @@ import 'package:http/http.dart' as http;
import 'package:flutter_dotenv/flutter_dotenv.dart';
class DashBoard extends StatefulWidget {
int pageNumber = 1;
DashBoard({Key key, this.pageNumber}) : super(key: key);
int pageNumber;
int bottleID;
DashBoard({Key key, this.pageNumber, this.bottleID}) : super(key: key);
@override
_DashBoardState createState() => _DashBoardState();
......
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 'RegisterBottle.dart';
import 'models/Bottle.dart';
import 'BottleList.dart';
class HubList extends StatefulWidget {
List<int> hublist;
HubList({Key key, this.hublist}) : super(key: key);
@override
_HubListState createState() => _HubListState();
}
class _HubListState extends State<HubList> {
List<Bottle> _bottleList = new List<Bottle>();
//Get BottleList
Future<String> getBottleList(int hubid) async {
http.Response response = await http.get(Uri.encodeFull(
DotEnv().env['SERVER_URL'] + 'bottle/hub/' + hubid.toString()));
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));
return "GET";
}
} else if (response.statusCode == 404) {
return "Not Found";
} else {
return "Error";
}
}
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return Scaffold(
body: Container(
height: size.height,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 70),
Container(
height: size.height * 0.1,
width: size.width,
child: Center(
child: Text(
'등록된 허브 리스트',
textScaleFactor: 1.0,
style: TextStyle(
fontSize: 28,
fontFamily: 'Noto',
fontWeight: FontWeight.bold),
),
),
decoration: BoxDecoration(border: Border.all()),
),
SizedBox(height: 30),
Expanded(
child: ListView.separated(
padding: const EdgeInsets.all(30),
itemCount: widget.hublist.length,
itemBuilder: (BuildContext context, int index) {
return Container(
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(border: Border.all()),
child: ListTile(
title: Text(
'HUB ID: ' + '${widget.hublist[index]}',
style: TextStyle(
color: Colors.black,
fontSize: 20,
fontFamily: 'Noto',
fontWeight: FontWeight.bold),
),
trailing: Icon(Icons.arrow_forward),
onTap: () async {
//허브 id로 가져와서 있으면 바로 넘기기
var result =
await getBottleList(widget.hublist[index]);
if (result == "GET") {
print(0);
print(_bottleList);
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
BottleList(
bottlelist: _bottleList,
),
));
} else if (result == "Not Found") {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text('Error'),
content: new Text('등록된 약병이 없습니다.'),
actions: <Widget>[
new FlatButton(
child: new Text('등록'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext
context) =>
RegisterBottle(
hubid: widget
.hublist[index]
.toString()),
));
})
],
);
});
}
}),
);
},
separatorBuilder: (BuildContext contetx, int index) =>
const Divider(),
),
)
],
)),
);
}
}
......@@ -5,14 +5,14 @@ import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:flutter_dotenv/flutter_dotenv.dart';
class RegsiterBottle extends StatefulWidget {
class RegisterBottle extends StatefulWidget {
final String hubid;
RegsiterBottle({Key key, this.hubid}) : super(key: key);
RegisterBottle({Key key, this.hubid}) : super(key: key);
@override
_RegsiterBottleState createState() => _RegsiterBottleState();
_RegisterBottleState createState() => _RegisterBottleState();
}
class _RegsiterBottleState extends State<RegsiterBottle> {
class _RegisterBottleState extends State<RegisterBottle> {
final medicineBottleIDController = TextEditingController();
final medicineHubIDController = TextEditingController();
final medicineHubPortController = TextEditingController();
......
......@@ -6,12 +6,12 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'RegisterBottle.dart';
class RegsiterHub extends StatefulWidget {
class RegisterHub extends StatefulWidget {
@override
_RegsiterHubState createState() => _RegsiterHubState();
_RegisterHubState createState() => _RegisterHubState();
}
class _RegsiterHubState extends State<RegsiterHub> {
class _RegisterHubState extends State<RegisterHub> {
final medicineBottleIDController = TextEditingController();
final medicineHubIDController = TextEditingController();
final medicineHubPortController = TextEditingController();
......@@ -119,7 +119,7 @@ class _RegsiterHubState extends State<RegsiterHub> {
context,
MaterialPageRoute(
builder: (BuildContext context) =>
RegsiterBottle(hubid: medicineHubIDController.text),
RegisterBottle(hubid: medicineHubIDController.text),
));
}
},
......
......@@ -5,6 +5,7 @@ import 'package:http/http.dart' as http;
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:shared_preferences/shared_preferences.dart';
import './DashBoard.dart';
import 'HubList.dart';
import 'RegsiterHub.dart';
class SignInPage extends StatefulWidget {
......@@ -20,6 +21,8 @@ class _SignInPageState extends State<SignInPage> {
final emailController = TextEditingController();
final passwordController = TextEditingController();
List<int> _hublist = new List<int>(); //허브이름을 만들어야 할 것 같은데 임시로 허브 id만 고르게 함
//Login 함수
Future<String> login(String _email, String _password) async {
http.Response response = await http.post(
......@@ -41,10 +44,17 @@ class _SignInPageState extends State<SignInPage> {
//Get Bottle List 함수
Future<String> getHubList() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
http.Response response =
await http.get(Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'hub'));
List<dynamic> values = new List<dynamic>();
values = json.decode(response.body);
if (_hublist.length != 0) {
_hublist.clear();
}
for (int i = 0; i < values.length; i++) {
_hublist.add(values[i]['hubId']);
}
if (response.statusCode == 200) {
return "get완료";
} else if (response.statusCode == 404) {
......@@ -214,7 +224,7 @@ class _SignInPageState extends State<SignInPage> {
MaterialPageRoute(
builder:
(BuildContext context) =>
RegsiterHub(),
RegisterHub(),
));
} else if (result == "get완료") {
Navigator.push(
......@@ -222,7 +232,7 @@ class _SignInPageState extends State<SignInPage> {
MaterialPageRoute(
builder: (BuildContext
context) =>
DashBoard(pageNumber: 1),
HubList(hublist: _hublist),
));
} else {}
}
......
......@@ -3,7 +3,7 @@ class Bottle {
final int temperature;
final int humidity;
final int balance;
final DateTime recentOpen;
final String recentOpen;
final int medicineId;
final int hubId;
final int dosage;
......