Showing
7 changed files
with
499 additions
and
109 deletions
... | @@ -99,4 +99,7 @@ appbar 관련 디자인은 추후 구현 예정 | ... | @@ -99,4 +99,7 @@ appbar 관련 디자인은 추후 구현 예정 |
99 | + Sqlite 생성 | 99 | + Sqlite 생성 |
100 | 100 | ||
101 | ### 2021-06-01 | 101 | ### 2021-06-01 |
102 | -+ datetime 형식 한국 시간으로 변경 | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
102 | ++ datetime 형식 한국 시간으로 변경 | ||
103 | + | ||
104 | +### 2021-06-02 | ||
105 | ++ 약병 , 허브 추가 제거 관리 페이지 구현 | ... | ... |
1 | import 'package:Smart_Medicine_Box/src/screens/DashBoard.dart'; | 1 | import 'package:Smart_Medicine_Box/src/screens/DashBoard.dart'; |
2 | +import 'package:Smart_Medicine_Box/src/screens/Register/BottleList.dart'; | ||
2 | import 'package:flutter/cupertino.dart'; | 3 | import 'package:flutter/cupertino.dart'; |
3 | import 'dart:convert'; | 4 | import 'dart:convert'; |
4 | import 'package:flutter/material.dart'; | 5 | import 'package:flutter/material.dart'; |
... | @@ -10,7 +11,8 @@ import '../../utils/user_secure_stoarge.dart'; | ... | @@ -10,7 +11,8 @@ import '../../utils/user_secure_stoarge.dart'; |
10 | 11 | ||
11 | class RegisterBottle extends StatefulWidget { | 12 | class RegisterBottle extends StatefulWidget { |
12 | final String hubid; | 13 | final String hubid; |
13 | - RegisterBottle({Key key, this.hubid}) : super(key: key); | 14 | + final bool modify_bottle; |
15 | + RegisterBottle({Key key, this.hubid, this.modify_bottle}) : super(key: key); | ||
14 | @override | 16 | @override |
15 | _RegisterBottleState createState() => _RegisterBottleState(); | 17 | _RegisterBottleState createState() => _RegisterBottleState(); |
16 | } | 18 | } |
... | @@ -106,49 +108,74 @@ class _RegisterBottleState extends State<RegisterBottle> { | ... | @@ -106,49 +108,74 @@ class _RegisterBottleState extends State<RegisterBottle> { |
106 | onPressed: () async { | 108 | onPressed: () async { |
107 | String saveMessage = await registerhub_Validate(); | 109 | String saveMessage = await registerhub_Validate(); |
108 | print(saveMessage); | 110 | print(saveMessage); |
109 | - if (saveMessage == "등록 완료") { | 111 | + print(widget.modify_bottle); |
112 | + if (saveMessage == "등록 완료" && widget.modify_bottle == false) { | ||
110 | showDialog( | 113 | showDialog( |
111 | - context: context, | 114 | + context: context, |
112 | - builder: (BuildContext context) { | 115 | + builder: (BuildContext context) { |
113 | - return AlertDialog( | 116 | + return AlertDialog( |
114 | - title: new Text('약병 등록'), | 117 | + title: new Text('약병 등록'), |
115 | - content: new Text('약병 등록이 완료 되었습니다.'), | 118 | + content: new Text('약병 등록이 완료 되었습니다.'), |
116 | - actions: <Widget>[ | 119 | + actions: <Widget>[ |
117 | - new FlatButton( | 120 | + new FlatButton( |
118 | - child: new Text('Close'), | 121 | + child: new Text('Close'), |
119 | - onPressed: () { | 122 | + onPressed: () { |
120 | - UserSecureStorage.setBottleId( | 123 | + UserSecureStorage.setBottleId( |
121 | - medicineBottleIDController.text); | 124 | + medicineBottleIDController.text); |
122 | - Navigator.push( | 125 | + Navigator.push( |
123 | - context, | 126 | + context, |
124 | - MaterialPageRoute( | 127 | + MaterialPageRoute( |
125 | - builder: (BuildContext context) => | 128 | + builder: (BuildContext context) => |
126 | - SearchMedicine( | 129 | + SearchMedicine( |
127 | - bottleId: medicineBottleIDController.text, | 130 | + bottleId: medicineBottleIDController.text, |
128 | - ), | ||
129 | ), | 131 | ), |
130 | - ); | 132 | + ), |
131 | - }, | 133 | + ); |
132 | - ), | 134 | + }, |
133 | - ], | 135 | + ), |
134 | - ); | 136 | + ], |
135 | - }); | 137 | + ); |
138 | + }, | ||
139 | + ); | ||
140 | + } else if (saveMessage == "등록 완료" && | ||
141 | + widget.modify_bottle == true) { | ||
142 | + print('asdg'); | ||
143 | + await showDialog( | ||
144 | + context: context, | ||
145 | + builder: (BuildContext context) { | ||
146 | + return AlertDialog( | ||
147 | + title: new Text('약병 등록'), | ||
148 | + content: new Text('약병 등록이 완료 되었습니다.'), | ||
149 | + actions: <Widget>[ | ||
150 | + new FlatButton( | ||
151 | + child: new Text('Close'), | ||
152 | + onPressed: () { | ||
153 | + Navigator.of(context).pop(); | ||
154 | + }, | ||
155 | + ), | ||
156 | + ], | ||
157 | + ); | ||
158 | + }, | ||
159 | + ); | ||
160 | + Navigator.of(context).pop(); | ||
136 | } else { | 161 | } else { |
137 | showDialog( | 162 | showDialog( |
138 | - context: context, | 163 | + context: context, |
139 | - builder: (BuildContext context) { | 164 | + builder: (BuildContext context) { |
140 | - return AlertDialog( | 165 | + return AlertDialog( |
141 | - title: new Text('오류'), | 166 | + title: new Text('오류'), |
142 | - content: new Text(saveMessage), | 167 | + content: new Text(saveMessage), |
143 | - actions: <Widget>[ | 168 | + actions: <Widget>[ |
144 | - new FlatButton( | 169 | + new FlatButton( |
145 | - child: new Text('Close'), | 170 | + child: new Text('Close'), |
146 | - onPressed: () { | 171 | + onPressed: () { |
147 | - Navigator.of(context).pop(); | 172 | + Navigator.of(context).pop(); |
148 | - }) | 173 | + }, |
149 | - ], | 174 | + ) |
150 | - ); | 175 | + ], |
151 | - }); | 176 | + ); |
177 | + }, | ||
178 | + ); | ||
152 | } | 179 | } |
153 | }, | 180 | }, |
154 | shape: RoundedRectangleBorder( | 181 | shape: RoundedRectangleBorder( |
... | @@ -167,25 +194,6 @@ class _RegisterBottleState extends State<RegisterBottle> { | ... | @@ -167,25 +194,6 @@ class _RegisterBottleState extends State<RegisterBottle> { |
167 | ) | 194 | ) |
168 | ], | 195 | ], |
169 | ), | 196 | ), |
170 | - bottomNavigationBar: BottomAppBar( | ||
171 | - elevation: 0, | ||
172 | - child: Container( | ||
173 | - height: 70, | ||
174 | - child: Column( | ||
175 | - mainAxisAlignment: MainAxisAlignment.start, | ||
176 | - children: <Widget>[ | ||
177 | - Padding( | ||
178 | - padding: const EdgeInsets.fromLTRB(70, 0, 70, 0), | ||
179 | - child: Text( | ||
180 | - '회원 가입시, 이용 약관 및 개인정보 처리 방침에 동의하는 것으로 간주합니다..', | ||
181 | - style: TextStyle(fontSize: 12, color: Color(0xff747474)), | ||
182 | - textAlign: TextAlign.center, | ||
183 | - ), | ||
184 | - ) | ||
185 | - ], | ||
186 | - ), | ||
187 | - ), | ||
188 | - ), | ||
189 | ); | 197 | ); |
190 | } | 198 | } |
191 | } | 199 | } | ... | ... |
1 | +import 'package:Smart_Medicine_Box/src/screens/SettingPage/HubModifyList.dart'; | ||
1 | import 'package:flutter/cupertino.dart'; | 2 | import 'package:flutter/cupertino.dart'; |
2 | import 'dart:convert'; | 3 | import 'dart:convert'; |
3 | import 'package:flutter/material.dart'; | 4 | import 'package:flutter/material.dart'; |
... | @@ -8,6 +9,9 @@ import 'RegisterBottle.dart'; | ... | @@ -8,6 +9,9 @@ import 'RegisterBottle.dart'; |
8 | import '../../utils/user_secure_stoarge.dart'; | 9 | import '../../utils/user_secure_stoarge.dart'; |
9 | 10 | ||
10 | class RegisterHub extends StatefulWidget { | 11 | class RegisterHub extends StatefulWidget { |
12 | + final int modify_hub; | ||
13 | + | ||
14 | + RegisterHub({Key key, this.modify_hub}) : super(key: key); | ||
11 | @override | 15 | @override |
12 | _RegisterHubState createState() => _RegisterHubState(); | 16 | _RegisterHubState createState() => _RegisterHubState(); |
13 | } | 17 | } |
... | @@ -31,7 +35,7 @@ class _RegisterHubState extends State<RegisterHub> { | ... | @@ -31,7 +35,7 @@ class _RegisterHubState extends State<RegisterHub> { |
31 | 'host': medicineHubHostController.text, | 35 | 'host': medicineHubHostController.text, |
32 | 'port': medicineHubPortController.text, | 36 | 'port': medicineHubPortController.text, |
33 | })); | 37 | })); |
34 | - | 38 | + print(hubresponse.statusCode); |
35 | if (hubresponse.statusCode == 201) { | 39 | if (hubresponse.statusCode == 201) { |
36 | return "허브 등록 완료"; | 40 | return "허브 등록 완료"; |
37 | } else if (hubresponse.statusCode == 409) { | 41 | } else if (hubresponse.statusCode == 409) { |
... | @@ -118,14 +122,40 @@ class _RegisterHubState extends State<RegisterHub> { | ... | @@ -118,14 +122,40 @@ class _RegisterHubState extends State<RegisterHub> { |
118 | child: RaisedButton( | 122 | child: RaisedButton( |
119 | onPressed: () async { | 123 | onPressed: () async { |
120 | String saveMessage = await registerhub_Validate(); | 124 | String saveMessage = await registerhub_Validate(); |
121 | - if (saveMessage == "허브 등록 완료") { | 125 | + print(saveMessage); |
126 | + print(widget.modify_hub); | ||
127 | + if (saveMessage == "허브 등록 완료" && widget.modify_hub == 0) { | ||
122 | UserSecureStorage.setHubId(medicineHubIDController.text); | 128 | UserSecureStorage.setHubId(medicineHubIDController.text); |
123 | Navigator.push( | 129 | Navigator.push( |
124 | - context, | 130 | + context, |
125 | - MaterialPageRoute( | 131 | + MaterialPageRoute( |
126 | - builder: (BuildContext context) => | 132 | + builder: (BuildContext context) => RegisterBottle( |
127 | - RegisterBottle(hubid: medicineHubIDController.text), | 133 | + hubid: medicineHubIDController.text, |
128 | - )); | 134 | + modify_bottle: false, |
135 | + ), | ||
136 | + ), | ||
137 | + ); | ||
138 | + } else if (saveMessage == "허브 등록 완료" && | ||
139 | + widget.modify_hub == 1) { | ||
140 | + Navigator.of(context).pop(); | ||
141 | + } else { | ||
142 | + showDialog( | ||
143 | + context: context, | ||
144 | + builder: (BuildContext context) { | ||
145 | + return AlertDialog( | ||
146 | + title: new Text('오류'), | ||
147 | + content: new Text(saveMessage), | ||
148 | + actions: <Widget>[ | ||
149 | + new FlatButton( | ||
150 | + child: new Text('close'), | ||
151 | + onPressed: () { | ||
152 | + Navigator.of(context).pop(); | ||
153 | + }, | ||
154 | + ) | ||
155 | + ], | ||
156 | + ); | ||
157 | + }, | ||
158 | + ); | ||
129 | } | 159 | } |
130 | }, | 160 | }, |
131 | shape: RoundedRectangleBorder( | 161 | shape: RoundedRectangleBorder( |
... | @@ -133,7 +163,7 @@ class _RegisterHubState extends State<RegisterHub> { | ... | @@ -133,7 +163,7 @@ class _RegisterHubState extends State<RegisterHub> { |
133 | side: BorderSide(color: Colors.blue)), | 163 | side: BorderSide(color: Colors.blue)), |
134 | color: Color(0xff1674f6), | 164 | color: Color(0xff1674f6), |
135 | child: Text( | 165 | child: Text( |
136 | - ' 허브 등록 ', | 166 | + '허브 등록 ', |
137 | textScaleFactor: 1.0, | 167 | textScaleFactor: 1.0, |
138 | style: TextStyle( | 168 | style: TextStyle( |
139 | fontSize: 16, | 169 | fontSize: 16, |
... | @@ -144,25 +174,6 @@ class _RegisterHubState extends State<RegisterHub> { | ... | @@ -144,25 +174,6 @@ class _RegisterHubState extends State<RegisterHub> { |
144 | ) | 174 | ) |
145 | ], | 175 | ], |
146 | ), | 176 | ), |
147 | - bottomNavigationBar: BottomAppBar( | ||
148 | - elevation: 0, | ||
149 | - child: Container( | ||
150 | - height: 70, | ||
151 | - child: Column( | ||
152 | - mainAxisAlignment: MainAxisAlignment.start, | ||
153 | - children: <Widget>[ | ||
154 | - Padding( | ||
155 | - padding: const EdgeInsets.fromLTRB(70, 0, 70, 0), | ||
156 | - child: Text( | ||
157 | - '회원 가입시, 이용 약관 및 개인정보 처리 방침에 동의하는 것으로 간주합니다..', | ||
158 | - style: TextStyle(fontSize: 12, color: Color(0xff747474)), | ||
159 | - textAlign: TextAlign.center, | ||
160 | - ), | ||
161 | - ) | ||
162 | - ], | ||
163 | - ), | ||
164 | - ), | ||
165 | - ), | ||
166 | ); | 177 | ); |
167 | } | 178 | } |
168 | } | 179 | } | ... | ... |
... | @@ -235,9 +235,9 @@ class _SignInPageState extends State<SignInPage> { | ... | @@ -235,9 +235,9 @@ class _SignInPageState extends State<SignInPage> { |
235 | Navigator.push( | 235 | Navigator.push( |
236 | context, | 236 | context, |
237 | MaterialPageRoute( | 237 | MaterialPageRoute( |
238 | - builder: | 238 | + builder: (BuildContext |
239 | - (BuildContext context) => | 239 | + context) => |
240 | - RegisterHub(), | 240 | + RegisterHub(modify_hub: 0), |
241 | )); | 241 | )); |
242 | } else if (result == "get완료") { | 242 | } else if (result == "get완료") { |
243 | UserSecureStorage.setUserId( | 243 | UserSecureStorage.setUserId( | ... | ... |
... | @@ -3,8 +3,7 @@ import 'package:flutter/material.dart'; | ... | @@ -3,8 +3,7 @@ import 'package:flutter/material.dart'; |
3 | import 'package:Smart_Medicine_Box/src/screens/DashBoard.dart'; | 3 | import 'package:Smart_Medicine_Box/src/screens/DashBoard.dart'; |
4 | import 'package:Smart_Medicine_Box/src/screens/SettingPage/Alarm.dart'; | 4 | import 'package:Smart_Medicine_Box/src/screens/SettingPage/Alarm.dart'; |
5 | import 'package:Smart_Medicine_Box/src/screens/SettingPage/DEVInformation.dart'; | 5 | import 'package:Smart_Medicine_Box/src/screens/SettingPage/DEVInformation.dart'; |
6 | -import 'package:Smart_Medicine_Box/src/screens/SettingPage/InformationModify.dart'; | 6 | +import 'package:Smart_Medicine_Box/src/screens/SettingPage/BottleModifyList.dart'; |
7 | -import '../screens/Register/HubList.dart'; | ||
8 | 7 | ||
9 | class SettingPage extends StatefulWidget { | 8 | class SettingPage extends StatefulWidget { |
10 | @override | 9 | @override |
... | @@ -134,7 +133,7 @@ class _SettingPageState extends State<SettingPage> { | ... | @@ -134,7 +133,7 @@ class _SettingPageState extends State<SettingPage> { |
134 | )); | 133 | )); |
135 | }, | 134 | }, |
136 | child: Text( | 135 | child: Text( |
137 | - '허브 등록', | 136 | + '허브 관리', |
138 | textScaleFactor: 1.0, | 137 | textScaleFactor: 1.0, |
139 | style: TextStyle( | 138 | style: TextStyle( |
140 | color: Colors.white, | 139 | color: Colors.white, |
... | @@ -159,11 +158,11 @@ class _SettingPageState extends State<SettingPage> { | ... | @@ -159,11 +158,11 @@ class _SettingPageState extends State<SettingPage> { |
159 | context, | 158 | context, |
160 | MaterialPageRoute( | 159 | MaterialPageRoute( |
161 | builder: (BuildContext context) => | 160 | builder: (BuildContext context) => |
162 | - InformationModify(), | 161 | + BottleModifyList(), |
163 | )); | 162 | )); |
164 | }, | 163 | }, |
165 | child: Text( | 164 | child: Text( |
166 | - '회원 정보 수정', | 165 | + '약병 관리', |
167 | textScaleFactor: 1.0, | 166 | textScaleFactor: 1.0, |
168 | style: TextStyle( | 167 | style: TextStyle( |
169 | color: Colors.white, | 168 | color: Colors.white, | ... | ... |
1 | +import 'dart:convert'; | ||
2 | +import 'package:Smart_Medicine_Box/src/screens/Register/RegisterBottle.dart'; | ||
3 | +import 'package:flutter/material.dart'; | ||
4 | +import 'package:flutter/services.dart'; | ||
5 | +import 'package:http/http.dart' as http; | ||
6 | +import 'package:flutter_dotenv/flutter_dotenv.dart'; | ||
7 | +import '../models/Bottle.dart'; | ||
8 | +import '../DashBoard.dart'; | ||
9 | +import '../../utils/user_secure_stoarge.dart'; | ||
10 | +import '../../utils/DBHelper.dart'; | ||
11 | +import '../models/UserBottle.dart'; | ||
12 | + | ||
13 | +class BottleModifyList extends StatefulWidget { | ||
14 | + BottleModifyList({Key key}) : super(key: key); | ||
15 | + | ||
16 | + @override | ||
17 | + _BottleModifyListState createState() => _BottleModifyListState(); | ||
18 | +} | ||
19 | + | ||
20 | +class _BottleModifyListState extends State<BottleModifyList> { | ||
21 | + List<Bottle> _bottleList = new List<Bottle>(); | ||
22 | + Future<String> getBottleList() async { | ||
23 | + String hubid = await UserSecureStorage.getHubId(); | ||
24 | + String usertoken = await UserSecureStorage.getUserToken(); | ||
25 | + | ||
26 | + var provider = DBHelper(); | ||
27 | + http.Response response = await http.get( | ||
28 | + Uri.encodeFull( | ||
29 | + DotEnv().env['SERVER_URL'] + 'bottle/hub/' + hubid.toString()), | ||
30 | + headers: {"authorization": usertoken}, | ||
31 | + ); | ||
32 | + | ||
33 | + if (_bottleList.length != 0) { | ||
34 | + _bottleList.clear(); | ||
35 | + } | ||
36 | + if (response.statusCode == 200) { | ||
37 | + List<dynamic> values = new List<dynamic>(); | ||
38 | + values = json.decode(response.body); | ||
39 | + | ||
40 | + for (int i = 0; i < values.length; i++) { | ||
41 | + Map<String, dynamic> map = values[i]; | ||
42 | + _bottleList.add(Bottle.fromJson(map)); | ||
43 | + } | ||
44 | + for (int i = 0; i < _bottleList.length; i++) { | ||
45 | + UserBottle temp = new UserBottle(); | ||
46 | + temp.bottleId = _bottleList[i].bottleId; | ||
47 | + temp.bottleName = _bottleList[i].bottleId.toString(); | ||
48 | + provider.createData(temp); | ||
49 | + } | ||
50 | + List<UserBottle> _userbottleList = new List<UserBottle>(); | ||
51 | + _userbottleList = await provider.getAllBottle(); | ||
52 | + for (int i = 0; i < _userbottleList.length; i++) { | ||
53 | + print(_userbottleList[i].bottleId); | ||
54 | + } | ||
55 | + | ||
56 | + print(provider.getAllBottle()); | ||
57 | + return "GET"; | ||
58 | + } else if (response.statusCode == 404) { | ||
59 | + return "Not Found"; | ||
60 | + } else { | ||
61 | + return "Error"; | ||
62 | + } | ||
63 | + } | ||
64 | + | ||
65 | + Future<String> deleteBottle(int index) async { | ||
66 | + String usertoken = await UserSecureStorage.getUserToken(); | ||
67 | + http.Response response = await http.delete( | ||
68 | + Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'bottle/' + index.toString()), | ||
69 | + headers: {"authorization": usertoken}, | ||
70 | + ); | ||
71 | + print('asdgasdga'); | ||
72 | + print(response.statusCode); | ||
73 | + if (response.statusCode == 204) { | ||
74 | + return "Delete"; | ||
75 | + } else { | ||
76 | + return "Error"; | ||
77 | + } | ||
78 | + } | ||
79 | + | ||
80 | + Widget build(BuildContext context) { | ||
81 | + final Size size = MediaQuery.of(context).size; | ||
82 | + return Scaffold( | ||
83 | + appBar: AppBar( | ||
84 | + backgroundColor: Colors.white, | ||
85 | + leading: new Icon(Icons.medical_services_rounded, | ||
86 | + color: Colors.black, size: 45.0), | ||
87 | + title: Text( | ||
88 | + 'Smart Medicine Box', | ||
89 | + style: TextStyle( | ||
90 | + color: Colors.black, | ||
91 | + fontSize: 23, | ||
92 | + fontFamily: 'Noto', | ||
93 | + fontWeight: FontWeight.bold), | ||
94 | + ), | ||
95 | + ), | ||
96 | + body: FutureBuilder( | ||
97 | + future: getBottleList(), | ||
98 | + builder: (BuildContext context, AsyncSnapshot snapshot) { | ||
99 | + if (snapshot.hasData == false) { | ||
100 | + return CircularProgressIndicator(); | ||
101 | + } else if (snapshot.hasError) { | ||
102 | + return Padding( | ||
103 | + padding: const EdgeInsets.all(8.0), | ||
104 | + child: Text( | ||
105 | + 'Error: ${snapshot.error}', | ||
106 | + style: TextStyle(fontSize: 15), | ||
107 | + ), | ||
108 | + ); | ||
109 | + } else { | ||
110 | + return Container( | ||
111 | + height: size.height, | ||
112 | + child: Column( | ||
113 | + mainAxisAlignment: MainAxisAlignment.center, | ||
114 | + children: <Widget>[ | ||
115 | + SizedBox(height: 10), | ||
116 | + Container( | ||
117 | + height: size.height * 0.07, | ||
118 | + width: size.width, | ||
119 | + child: Center( | ||
120 | + child: Text( | ||
121 | + '등록된 약병 리스트', | ||
122 | + textScaleFactor: 1.0, | ||
123 | + style: TextStyle( | ||
124 | + fontSize: 28, | ||
125 | + fontFamily: 'Noto', | ||
126 | + fontWeight: FontWeight.bold), | ||
127 | + ), | ||
128 | + ), | ||
129 | + ), | ||
130 | + SizedBox(height: 10), | ||
131 | + Expanded( | ||
132 | + child: GridView.builder( | ||
133 | + padding: const EdgeInsets.all(30), | ||
134 | + itemCount: | ||
135 | + _bottleList.length == null ? 0 : _bottleList.length, | ||
136 | + gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent( | ||
137 | + maxCrossAxisExtent: 200, | ||
138 | + crossAxisSpacing: 10, | ||
139 | + mainAxisSpacing: 10, | ||
140 | + ), | ||
141 | + itemBuilder: (BuildContext context, int index) { | ||
142 | + return InkResponse( | ||
143 | + splashColor: Colors.transparent, | ||
144 | + child: Container( | ||
145 | + height: 140, | ||
146 | + padding: const EdgeInsets.all(10), | ||
147 | + decoration: BoxDecoration( | ||
148 | + border: Border.all(), | ||
149 | + borderRadius: BorderRadius.all( | ||
150 | + Radius.circular(16.0), | ||
151 | + ), | ||
152 | + ), | ||
153 | + child: Column( | ||
154 | + children: [ | ||
155 | + Container( | ||
156 | + decoration: BoxDecoration( | ||
157 | + border: Border( | ||
158 | + bottom: BorderSide( | ||
159 | + color: Colors.black, | ||
160 | + width: 1, | ||
161 | + style: BorderStyle.solid), | ||
162 | + ), | ||
163 | + ), | ||
164 | + height: 40, | ||
165 | + child: Row( | ||
166 | + mainAxisAlignment: | ||
167 | + MainAxisAlignment.spaceBetween, | ||
168 | + children: [ | ||
169 | + Container( | ||
170 | + height: 40, | ||
171 | + child: Center( | ||
172 | + child: Text( | ||
173 | + '${_bottleList[index].bottleId}', | ||
174 | + style: TextStyle( | ||
175 | + color: Colors.black, | ||
176 | + fontSize: 20, | ||
177 | + fontFamily: 'Noto', | ||
178 | + fontWeight: FontWeight.bold), | ||
179 | + ), | ||
180 | + ), | ||
181 | + ), | ||
182 | + Container( | ||
183 | + child: IconButton( | ||
184 | + alignment: Alignment(0.9, 0), | ||
185 | + icon: Icon( | ||
186 | + Icons.create_sharp, | ||
187 | + color: Colors.black, | ||
188 | + ), | ||
189 | + onPressed: () {}, | ||
190 | + ), | ||
191 | + ), | ||
192 | + ], | ||
193 | + ), | ||
194 | + ), | ||
195 | + SizedBox(height: 10), | ||
196 | + Container( | ||
197 | + height: 90, | ||
198 | + child: Icon( | ||
199 | + Icons.medical_services_outlined, | ||
200 | + size: 100, | ||
201 | + ), | ||
202 | + ) | ||
203 | + ], | ||
204 | + ), | ||
205 | + ), | ||
206 | + onTap: () { | ||
207 | + if (_bottleList.length == 1) { | ||
208 | + showDialog( | ||
209 | + context: context, | ||
210 | + builder: (BuildContext context) { | ||
211 | + return AlertDialog( | ||
212 | + title: new Text('약병 삭제'), | ||
213 | + content: | ||
214 | + new Text('등록된 약병이 하나이므로 해제가 불가능 합니다.'), | ||
215 | + actions: <Widget>[ | ||
216 | + new FlatButton( | ||
217 | + child: new Text('Cloes'), | ||
218 | + onPressed: () { | ||
219 | + Navigator.of(context).pop(); | ||
220 | + }), | ||
221 | + ], | ||
222 | + ); | ||
223 | + }, | ||
224 | + ); | ||
225 | + } else { | ||
226 | + showDialog( | ||
227 | + context: context, | ||
228 | + builder: (BuildContext context) { | ||
229 | + return AlertDialog( | ||
230 | + title: new Text('허브 삭제'), | ||
231 | + content: new Text( | ||
232 | + _bottleList[index].bottleId.toString() + | ||
233 | + '을 삭제 하시겠습니까?'), | ||
234 | + actions: <Widget>[ | ||
235 | + new FlatButton( | ||
236 | + child: new Text('삭제'), | ||
237 | + onPressed: () async { | ||
238 | + print('dfg'); | ||
239 | + await deleteBottle( | ||
240 | + _bottleList[index].bottleId); | ||
241 | + setState(() {}); | ||
242 | + Navigator.of(context).pop(); | ||
243 | + }, | ||
244 | + ), | ||
245 | + new FlatButton( | ||
246 | + child: new Text('취소'), | ||
247 | + onPressed: () { | ||
248 | + Navigator.of(context).pop(); | ||
249 | + }, | ||
250 | + ) | ||
251 | + ], | ||
252 | + ); | ||
253 | + }, | ||
254 | + ); | ||
255 | + } | ||
256 | + }, | ||
257 | + ); | ||
258 | + }, | ||
259 | + ), | ||
260 | + ), | ||
261 | + Container( | ||
262 | + padding: EdgeInsets.fromLTRB(0, 20, 0, 20), | ||
263 | + width: size.width * 0.8, | ||
264 | + height: size.height * 0.13, | ||
265 | + margin: EdgeInsets.only(bottom: 0), | ||
266 | + child: FlatButton( | ||
267 | + height: size.height * 0.06, | ||
268 | + onPressed: () async { | ||
269 | + await Navigator.push( | ||
270 | + context, | ||
271 | + MaterialPageRoute( | ||
272 | + builder: (BuildContext context) => | ||
273 | + RegisterBottle(modify_bottle: true), | ||
274 | + ), | ||
275 | + ); | ||
276 | + setState(() {}); | ||
277 | + }, | ||
278 | + child: Text( | ||
279 | + '약병 추가', | ||
280 | + textScaleFactor: 1.0, | ||
281 | + style: TextStyle( | ||
282 | + color: Colors.white, | ||
283 | + fontSize: 24, | ||
284 | + fontFamily: 'Noto', | ||
285 | + fontWeight: FontWeight.bold), | ||
286 | + ), | ||
287 | + color: Color(0xff0B1E33), | ||
288 | + shape: RoundedRectangleBorder( | ||
289 | + borderRadius: BorderRadius.circular(50)), | ||
290 | + ), | ||
291 | + ), | ||
292 | + ], | ||
293 | + ), | ||
294 | + ); | ||
295 | + } | ||
296 | + }, | ||
297 | + ), | ||
298 | + ); | ||
299 | + } | ||
300 | +} |
1 | +import 'package:Smart_Medicine_Box/src/screens/Register/RegsiterHub.dart'; | ||
1 | import 'package:flutter/cupertino.dart'; | 2 | import 'package:flutter/cupertino.dart'; |
2 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
3 | import 'dart:convert'; | 4 | import 'dart:convert'; |
4 | import 'package:http/http.dart' as http; | 5 | import 'package:http/http.dart' as http; |
5 | import 'package:flutter_dotenv/flutter_dotenv.dart'; | 6 | import 'package:flutter_dotenv/flutter_dotenv.dart'; |
6 | // Screen import | 7 | // Screen import |
7 | -import '../models/Bottle.dart'; | ||
8 | import '../../utils/user_secure_stoarge.dart'; | 8 | import '../../utils/user_secure_stoarge.dart'; |
9 | 9 | ||
10 | class HubModifyList extends StatefulWidget { | 10 | class HubModifyList extends StatefulWidget { |
... | @@ -42,6 +42,19 @@ class _HubModifyListState extends State<HubModifyList> { | ... | @@ -42,6 +42,19 @@ class _HubModifyListState extends State<HubModifyList> { |
42 | } | 42 | } |
43 | } | 43 | } |
44 | 44 | ||
45 | + Future<String> deleteHub(int index) async { | ||
46 | + String usertoken = await UserSecureStorage.getUserToken(); | ||
47 | + http.Response response = await http.delete( | ||
48 | + Uri.encodeFull(DotEnv().env['SERVER_URL'] + 'hub/' + index.toString()), | ||
49 | + headers: {"authorization": usertoken}, | ||
50 | + ); | ||
51 | + if (response.statusCode == 204) { | ||
52 | + return "Delete"; | ||
53 | + } else { | ||
54 | + return "Error"; | ||
55 | + } | ||
56 | + } | ||
57 | + | ||
45 | Widget build(BuildContext context) { | 58 | Widget build(BuildContext context) { |
46 | final Size size = MediaQuery.of(context).size; | 59 | final Size size = MediaQuery.of(context).size; |
47 | return Scaffold( | 60 | return Scaffold( |
... | @@ -107,18 +120,65 @@ class _HubModifyListState extends State<HubModifyList> { | ... | @@ -107,18 +120,65 @@ class _HubModifyListState extends State<HubModifyList> { |
107 | BorderRadius.all(Radius.circular(25.0)), | 120 | BorderRadius.all(Radius.circular(25.0)), |
108 | ), | 121 | ), |
109 | child: ListTile( | 122 | child: ListTile( |
110 | - title: Text( | 123 | + title: Text( |
111 | - 'HUB ID: ' + '${_hublist[index]}', | 124 | + 'HUB ID: ' + '${_hublist[index]}', |
112 | - style: TextStyle( | 125 | + style: TextStyle( |
113 | - color: Colors.black, | 126 | + color: Colors.black, |
114 | - fontSize: 20, | 127 | + fontSize: 20, |
115 | - fontFamily: 'Noto', | 128 | + fontFamily: 'Noto', |
116 | - fontWeight: FontWeight.bold), | 129 | + fontWeight: FontWeight.bold), |
117 | - ), | 130 | + ), |
118 | - trailing: Icon(Icons.highlight_remove), | 131 | + trailing: Icon(Icons.highlight_remove), |
119 | - onTap: () async { | 132 | + onTap: () async { |
120 | - print('삭제 할거임'); | 133 | + if (_hublist.length == 1) { |
121 | - }), | 134 | + showDialog( |
135 | + context: context, | ||
136 | + builder: (BuildContext context) { | ||
137 | + return AlertDialog( | ||
138 | + title: new Text('허브 삭제'), | ||
139 | + content: new Text( | ||
140 | + '등록된 허브가 하나이므로 해제가 불가능 합니다.'), | ||
141 | + actions: <Widget>[ | ||
142 | + new FlatButton( | ||
143 | + child: new Text('Cloes'), | ||
144 | + onPressed: () { | ||
145 | + Navigator.of(context).pop(); | ||
146 | + }), | ||
147 | + ], | ||
148 | + ); | ||
149 | + }, | ||
150 | + ); | ||
151 | + } else { | ||
152 | + showDialog( | ||
153 | + context: context, | ||
154 | + builder: (BuildContext context) { | ||
155 | + return AlertDialog( | ||
156 | + title: new Text('허브 삭제'), | ||
157 | + content: new Text( | ||
158 | + _hublist[index].toString() + | ||
159 | + '을 삭제 하시겠습니까?'), | ||
160 | + actions: <Widget>[ | ||
161 | + new FlatButton( | ||
162 | + child: new Text('삭제'), | ||
163 | + onPressed: () async { | ||
164 | + await deleteHub(_hublist[index]); | ||
165 | + setState(() {}); | ||
166 | + Navigator.of(context).pop(); | ||
167 | + }, | ||
168 | + ), | ||
169 | + new FlatButton( | ||
170 | + child: new Text('취소'), | ||
171 | + onPressed: () { | ||
172 | + Navigator.of(context).pop(); | ||
173 | + }, | ||
174 | + ) | ||
175 | + ], | ||
176 | + ); | ||
177 | + }, | ||
178 | + ); | ||
179 | + } | ||
180 | + }, | ||
181 | + ), | ||
122 | ); | 182 | ); |
123 | }, | 183 | }, |
124 | separatorBuilder: (BuildContext contetx, int index) => | 184 | separatorBuilder: (BuildContext contetx, int index) => |
... | @@ -132,7 +192,16 @@ class _HubModifyListState extends State<HubModifyList> { | ... | @@ -132,7 +192,16 @@ class _HubModifyListState extends State<HubModifyList> { |
132 | margin: EdgeInsets.only(bottom: 0), | 192 | margin: EdgeInsets.only(bottom: 0), |
133 | child: FlatButton( | 193 | child: FlatButton( |
134 | height: size.height * 0.07, | 194 | height: size.height * 0.07, |
135 | - onPressed: () {}, | 195 | + onPressed: () async { |
196 | + await Navigator.push( | ||
197 | + context, | ||
198 | + MaterialPageRoute( | ||
199 | + builder: (BuildContext context) => | ||
200 | + RegisterHub(modify_hub: 1), | ||
201 | + ), | ||
202 | + ); | ||
203 | + setState(() {}); | ||
204 | + }, | ||
136 | child: Text( | 205 | child: Text( |
137 | '허브 추가', | 206 | '허브 추가', |
138 | textScaleFactor: 1.0, | 207 | textScaleFactor: 1.0, | ... | ... |
-
Please register or login to post a comment