고원빈

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

...@@ -53,9 +53,17 @@ appbar 관련 디자인은 추후 구현 예정 ...@@ -53,9 +53,17 @@ appbar 관련 디자인은 추후 구현 예정
53 53
54 ### 2021-05-17 54 ### 2021-05-17
55 + server test 완료 55 + server test 완료
56 +
56 ### 2021-05-18 57 ### 2021-05-18
57 + 회원 가입 SERVER 연동 58 + 회원 가입 SERVER 연동
59 +
58 ### 2021-05-19 60 ### 2021-05-19
59 + Login 연동 61 + Login 연동
60 + 약병 등록 ,허브 등록 구현 62 + 약병 등록 ,허브 등록 구현
61 63
64 +### 2021-05-20
65 ++ 시나리오 수정
66 +
67 +### 2021-05-21
68 ++ 약병 ,허브 리스트 출력 구현
69 +
......
1 -SERVER_URL=
...\ No newline at end of file ...\ No newline at end of file
1 +SERVER_URL=http://192.168.0.3:4000/api/
...\ No newline at end of file ...\ No newline at end of file
......
1 +import 'dart:convert';
2 +import 'package:flutter/material.dart';
3 +import 'package:flutter/services.dart';
4 +import 'package:http/http.dart' as http;
5 +import 'package:flutter_dotenv/flutter_dotenv.dart';
6 +import 'models/Bottle.dart';
7 +import 'DashBoard.dart';
8 +
9 +class BottleList extends StatefulWidget {
10 + List<Bottle> bottlelist;
11 + BottleList({Key key, this.bottlelist}) : super(key: key);
12 +
13 + @override
14 + _BottleListState createState() => _BottleListState();
15 +}
16 +
17 +class _BottleListState extends State<BottleList> {
18 + Widget build(BuildContext context) {
19 + final Size size = MediaQuery.of(context).size;
20 + return Scaffold(
21 + body: Container(
22 + height: size.height,
23 + child: Column(
24 + mainAxisAlignment: MainAxisAlignment.center,
25 + children: <Widget>[
26 + SizedBox(height: 70),
27 + Container(
28 + height: size.height * 0.1,
29 + width: size.width,
30 + child: Center(
31 + child: Text(
32 + '등록된 약병 리스트',
33 + textScaleFactor: 1.0,
34 + style: TextStyle(
35 + fontSize: 28,
36 + fontFamily: 'Noto',
37 + fontWeight: FontWeight.bold),
38 + ),
39 + ),
40 + decoration: BoxDecoration(border: Border.all()),
41 + ),
42 + SizedBox(height: 30),
43 + Expanded(
44 + child: ListView.separated(
45 + padding: const EdgeInsets.all(30),
46 + itemCount: widget.bottlelist.length,
47 + itemBuilder: (BuildContext context, int index) {
48 + return Container(
49 + padding: EdgeInsets.all(8.0),
50 + decoration: BoxDecoration(border: Border.all()),
51 + child: ListTile(
52 + title: Text(
53 + 'BOTTLE ID : ' +
54 + '${widget.bottlelist[index].bottleId}',
55 + style: TextStyle(
56 + color: Colors.black,
57 + fontSize: 20,
58 + fontFamily: 'Noto',
59 + fontWeight: FontWeight.bold),
60 + ),
61 + trailing: Icon(Icons.arrow_forward),
62 + onTap: () {
63 + Navigator.push(
64 + context,
65 + MaterialPageRoute(
66 + builder: (BuildContext context) => DashBoard(
67 + pageNumber: 1,
68 + bottleID: widget.bottlelist[index].bottleId,
69 + ),
70 + ));
71 + }),
72 + );
73 + },
74 + separatorBuilder: (BuildContext contetx, int index) =>
75 + const Divider(),
76 + ),
77 + )
78 + ],
79 + )),
80 + );
81 + }
82 +}
...@@ -6,8 +6,9 @@ import 'package:http/http.dart' as http; ...@@ -6,8 +6,9 @@ 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 class DashBoard extends StatefulWidget { 8 class DashBoard extends StatefulWidget {
9 - int pageNumber = 1; 9 + int pageNumber;
10 - DashBoard({Key key, this.pageNumber}) : super(key: key); 10 + int bottleID;
11 + DashBoard({Key key, this.pageNumber, this.bottleID}) : super(key: key);
11 12
12 @override 13 @override
13 _DashBoardState createState() => _DashBoardState(); 14 _DashBoardState createState() => _DashBoardState();
......
1 +import 'package:flutter/cupertino.dart';
2 +import 'package:flutter/material.dart';
3 +import 'dart:convert';
4 +import 'package:http/http.dart' as http;
5 +import 'package:flutter_dotenv/flutter_dotenv.dart';
6 +// Screen import
7 +import 'RegisterBottle.dart';
8 +import 'models/Bottle.dart';
9 +import 'BottleList.dart';
10 +
11 +class HubList extends StatefulWidget {
12 + List<int> hublist;
13 + HubList({Key key, this.hublist}) : super(key: key);
14 +
15 + @override
16 + _HubListState createState() => _HubListState();
17 +}
18 +
19 +class _HubListState extends State<HubList> {
20 + List<Bottle> _bottleList = new List<Bottle>();
21 + //Get BottleList
22 + Future<String> getBottleList(int hubid) async {
23 + http.Response response = await http.get(Uri.encodeFull(
24 + DotEnv().env['SERVER_URL'] + 'bottle/hub/' + hubid.toString()));
25 + if (_bottleList.length != 0) {
26 + _bottleList.clear();
27 + }
28 + if (response.statusCode == 200) {
29 + List<dynamic> values = new List<dynamic>();
30 + values = json.decode(response.body);
31 +
32 + for (int i = 0; i < values.length; i++) {
33 + Map<String, dynamic> map = values[i];
34 + _bottleList.add(Bottle.fromJson(map));
35 + return "GET";
36 + }
37 + } else if (response.statusCode == 404) {
38 + return "Not Found";
39 + } else {
40 + return "Error";
41 + }
42 + }
43 +
44 + Widget build(BuildContext context) {
45 + final Size size = MediaQuery.of(context).size;
46 + return Scaffold(
47 + body: Container(
48 + height: size.height,
49 + child: Column(
50 + mainAxisAlignment: MainAxisAlignment.center,
51 + children: <Widget>[
52 + SizedBox(height: 70),
53 + Container(
54 + height: size.height * 0.1,
55 + width: size.width,
56 + child: Center(
57 + child: Text(
58 + '등록된 허브 리스트',
59 + textScaleFactor: 1.0,
60 + style: TextStyle(
61 + fontSize: 28,
62 + fontFamily: 'Noto',
63 + fontWeight: FontWeight.bold),
64 + ),
65 + ),
66 + decoration: BoxDecoration(border: Border.all()),
67 + ),
68 + SizedBox(height: 30),
69 + Expanded(
70 + child: ListView.separated(
71 + padding: const EdgeInsets.all(30),
72 + itemCount: widget.hublist.length,
73 + itemBuilder: (BuildContext context, int index) {
74 + return Container(
75 + padding: EdgeInsets.all(8.0),
76 + decoration: BoxDecoration(border: Border.all()),
77 + child: ListTile(
78 + title: Text(
79 + 'HUB ID: ' + '${widget.hublist[index]}',
80 + style: TextStyle(
81 + color: Colors.black,
82 + fontSize: 20,
83 + fontFamily: 'Noto',
84 + fontWeight: FontWeight.bold),
85 + ),
86 + trailing: Icon(Icons.arrow_forward),
87 + onTap: () async {
88 + //허브 id로 가져와서 있으면 바로 넘기기
89 + var result =
90 + await getBottleList(widget.hublist[index]);
91 + if (result == "GET") {
92 + print(0);
93 + print(_bottleList);
94 + Navigator.push(
95 + context,
96 + MaterialPageRoute(
97 + builder: (BuildContext context) =>
98 + BottleList(
99 + bottlelist: _bottleList,
100 + ),
101 + ));
102 + } else if (result == "Not Found") {
103 + showDialog(
104 + context: context,
105 + builder: (BuildContext context) {
106 + return AlertDialog(
107 + title: new Text('Error'),
108 + content: new Text('등록된 약병이 없습니다.'),
109 + actions: <Widget>[
110 + new FlatButton(
111 + child: new Text('등록'),
112 + onPressed: () {
113 + Navigator.push(
114 + context,
115 + MaterialPageRoute(
116 + builder: (BuildContext
117 + context) =>
118 + RegisterBottle(
119 + hubid: widget
120 + .hublist[index]
121 + .toString()),
122 + ));
123 + })
124 + ],
125 + );
126 + });
127 + }
128 + }),
129 + );
130 + },
131 + separatorBuilder: (BuildContext contetx, int index) =>
132 + const Divider(),
133 + ),
134 + )
135 + ],
136 + )),
137 + );
138 + }
139 +}
...@@ -5,14 +5,14 @@ import 'package:flutter/material.dart'; ...@@ -5,14 +5,14 @@ import 'package:flutter/material.dart';
5 import 'package:http/http.dart' as http; 5 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 -class RegsiterBottle extends StatefulWidget { 8 +class RegisterBottle extends StatefulWidget {
9 final String hubid; 9 final String hubid;
10 - RegsiterBottle({Key key, this.hubid}) : super(key: key); 10 + RegisterBottle({Key key, this.hubid}) : super(key: key);
11 @override 11 @override
12 - _RegsiterBottleState createState() => _RegsiterBottleState(); 12 + _RegisterBottleState createState() => _RegisterBottleState();
13 } 13 }
14 14
15 -class _RegsiterBottleState extends State<RegsiterBottle> { 15 +class _RegisterBottleState extends State<RegisterBottle> {
16 final medicineBottleIDController = TextEditingController(); 16 final medicineBottleIDController = TextEditingController();
17 final medicineHubIDController = TextEditingController(); 17 final medicineHubIDController = TextEditingController();
18 final medicineHubPortController = TextEditingController(); 18 final medicineHubPortController = TextEditingController();
......
...@@ -6,12 +6,12 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; ...@@ -6,12 +6,12 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
6 6
7 import 'RegisterBottle.dart'; 7 import 'RegisterBottle.dart';
8 8
9 -class RegsiterHub extends StatefulWidget { 9 +class RegisterHub extends StatefulWidget {
10 @override 10 @override
11 - _RegsiterHubState createState() => _RegsiterHubState(); 11 + _RegisterHubState createState() => _RegisterHubState();
12 } 12 }
13 13
14 -class _RegsiterHubState extends State<RegsiterHub> { 14 +class _RegisterHubState extends State<RegisterHub> {
15 final medicineBottleIDController = TextEditingController(); 15 final medicineBottleIDController = TextEditingController();
16 final medicineHubIDController = TextEditingController(); 16 final medicineHubIDController = TextEditingController();
17 final medicineHubPortController = TextEditingController(); 17 final medicineHubPortController = TextEditingController();
...@@ -119,7 +119,7 @@ class _RegsiterHubState extends State<RegsiterHub> { ...@@ -119,7 +119,7 @@ class _RegsiterHubState extends State<RegsiterHub> {
119 context, 119 context,
120 MaterialPageRoute( 120 MaterialPageRoute(
121 builder: (BuildContext context) => 121 builder: (BuildContext context) =>
122 - RegsiterBottle(hubid: medicineHubIDController.text), 122 + RegisterBottle(hubid: medicineHubIDController.text),
123 )); 123 ));
124 } 124 }
125 }, 125 },
......
...@@ -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 'package:shared_preferences/shared_preferences.dart'; 6 import 'package:shared_preferences/shared_preferences.dart';
7 import './DashBoard.dart'; 7 import './DashBoard.dart';
8 +import 'HubList.dart';
8 import 'RegsiterHub.dart'; 9 import 'RegsiterHub.dart';
9 10
10 class SignInPage extends StatefulWidget { 11 class SignInPage extends StatefulWidget {
...@@ -20,6 +21,8 @@ class _SignInPageState extends State<SignInPage> { ...@@ -20,6 +21,8 @@ class _SignInPageState extends State<SignInPage> {
20 final emailController = TextEditingController(); 21 final emailController = TextEditingController();
21 final passwordController = TextEditingController(); 22 final passwordController = TextEditingController();
22 23
24 + List<int> _hublist = new List<int>(); //허브이름을 만들어야 할 것 같은데 임시로 허브 id만 고르게 함
25 +
23 //Login 함수 26 //Login 함수
24 Future<String> login(String _email, String _password) async { 27 Future<String> login(String _email, String _password) async {
25 http.Response response = await http.post( 28 http.Response response = await http.post(
...@@ -41,10 +44,17 @@ class _SignInPageState extends State<SignInPage> { ...@@ -41,10 +44,17 @@ class _SignInPageState extends State<SignInPage> {
41 44
42 //Get Bottle List 함수 45 //Get Bottle List 함수
43 Future<String> getHubList() async { 46 Future<String> getHubList() async {
44 - SharedPreferences prefs = await SharedPreferences.getInstance();
45 -
46 http.Response response = 47 http.Response response =
47 await http.get(Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'hub')); 48 await http.get(Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'hub'));
49 +
50 + List<dynamic> values = new List<dynamic>();
51 + values = json.decode(response.body);
52 + if (_hublist.length != 0) {
53 + _hublist.clear();
54 + }
55 + for (int i = 0; i < values.length; i++) {
56 + _hublist.add(values[i]['hubId']);
57 + }
48 if (response.statusCode == 200) { 58 if (response.statusCode == 200) {
49 return "get완료"; 59 return "get완료";
50 } else if (response.statusCode == 404) { 60 } else if (response.statusCode == 404) {
...@@ -214,7 +224,7 @@ class _SignInPageState extends State<SignInPage> { ...@@ -214,7 +224,7 @@ class _SignInPageState extends State<SignInPage> {
214 MaterialPageRoute( 224 MaterialPageRoute(
215 builder: 225 builder:
216 (BuildContext context) => 226 (BuildContext context) =>
217 - RegsiterHub(), 227 + RegisterHub(),
218 )); 228 ));
219 } else if (result == "get완료") { 229 } else if (result == "get완료") {
220 Navigator.push( 230 Navigator.push(
...@@ -222,7 +232,7 @@ class _SignInPageState extends State<SignInPage> { ...@@ -222,7 +232,7 @@ class _SignInPageState extends State<SignInPage> {
222 MaterialPageRoute( 232 MaterialPageRoute(
223 builder: (BuildContext 233 builder: (BuildContext
224 context) => 234 context) =>
225 - DashBoard(pageNumber: 1), 235 + HubList(hublist: _hublist),
226 )); 236 ));
227 } else {} 237 } else {}
228 } 238 }
......
...@@ -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 DateTime recentOpen; 6 + final String 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;
......