Showing
5 changed files
with
10 additions
and
125 deletions
... | @@ -6,8 +6,6 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; | ... | @@ -6,8 +6,6 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; |
6 | import '../models/Bottle.dart'; | 6 | import '../models/Bottle.dart'; |
7 | import '../DashBoard.dart'; | 7 | import '../DashBoard.dart'; |
8 | import '../../utils/user_secure_stoarge.dart'; | 8 | import '../../utils/user_secure_stoarge.dart'; |
9 | -import '../../utils/DBHelper.dart'; | ||
10 | -import '../models/UserBottle.dart'; | ||
11 | 9 | ||
12 | class BottleList extends StatefulWidget { | 10 | class BottleList extends StatefulWidget { |
13 | BottleList({Key key}) : super(key: key); | 11 | BottleList({Key key}) : super(key: key); |
... | @@ -17,12 +15,13 @@ class BottleList extends StatefulWidget { | ... | @@ -17,12 +15,13 @@ class BottleList extends StatefulWidget { |
17 | } | 15 | } |
18 | 16 | ||
19 | class _BottleListState extends State<BottleList> { | 17 | class _BottleListState extends State<BottleList> { |
18 | + String valueText; | ||
20 | List<Bottle> _bottleList = new List<Bottle>(); | 19 | List<Bottle> _bottleList = new List<Bottle>(); |
20 | + TextEditingController _textFieldController = TextEditingController(); | ||
21 | Future<String> getBottleList() async { | 21 | Future<String> getBottleList() async { |
22 | String hubid = await UserSecureStorage.getHubId(); | 22 | String hubid = await UserSecureStorage.getHubId(); |
23 | String usertoken = await UserSecureStorage.getUserToken(); | 23 | String usertoken = await UserSecureStorage.getUserToken(); |
24 | 24 | ||
25 | - var provider = DBHelper(); | ||
26 | http.Response response = await http.get( | 25 | http.Response response = await http.get( |
27 | Uri.encodeFull( | 26 | Uri.encodeFull( |
28 | DotEnv().env['SERVER_URL'] + 'bottle/hub/' + hubid.toString()), | 27 | DotEnv().env['SERVER_URL'] + 'bottle/hub/' + hubid.toString()), |
... | @@ -40,19 +39,7 @@ class _BottleListState extends State<BottleList> { | ... | @@ -40,19 +39,7 @@ class _BottleListState extends State<BottleList> { |
40 | Map<String, dynamic> map = values[i]; | 39 | Map<String, dynamic> map = values[i]; |
41 | _bottleList.add(Bottle.fromJson(map)); | 40 | _bottleList.add(Bottle.fromJson(map)); |
42 | } | 41 | } |
43 | - for (int i = 0; i < _bottleList.length; i++) { | ||
44 | - UserBottle temp = new UserBottle(); | ||
45 | - temp.bottleId = _bottleList[i].bottleId; | ||
46 | - temp.bottleName = _bottleList[i].bottleId.toString(); | ||
47 | - provider.createData(temp); | ||
48 | - } | ||
49 | - List<UserBottle> _userbottleList = new List<UserBottle>(); | ||
50 | - _userbottleList = await provider.getAllBottle(); | ||
51 | - for (int i = 0; i < _userbottleList.length; i++) { | ||
52 | - print(_userbottleList[i].bottleId); | ||
53 | - } | ||
54 | 42 | ||
55 | - print(provider.getAllBottle()); | ||
56 | return "GET"; | 43 | return "GET"; |
57 | } else if (response.statusCode == 404) { | 44 | } else if (response.statusCode == 404) { |
58 | return "Not Found"; | 45 | return "Not Found"; | ... | ... |
... | @@ -130,22 +130,23 @@ class _HubListState extends State<HubList> { | ... | @@ -130,22 +130,23 @@ class _HubListState extends State<HubList> { |
130 | new FlatButton( | 130 | new FlatButton( |
131 | child: new Text('등록'), | 131 | child: new Text('등록'), |
132 | onPressed: () { | 132 | onPressed: () { |
133 | - UserSecureStorage.setHubId(widget | 133 | + UserSecureStorage.setHubId( |
134 | - .hublist[index] | 134 | + widget.hublist[index].toString()); |
135 | - .toString()); | ||
136 | Navigator.push( | 135 | Navigator.push( |
137 | context, | 136 | context, |
138 | MaterialPageRoute( | 137 | MaterialPageRoute( |
139 | - builder: (BuildContext | 138 | + builder: |
140 | - context) => | 139 | + (BuildContext context) => |
141 | RegisterBottle(), | 140 | RegisterBottle(), |
142 | )); | 141 | )); |
143 | }) | 142 | }) |
144 | ], | 143 | ], |
145 | ); | 144 | ); |
146 | - }); | 145 | + }, |
146 | + ); | ||
147 | } | 147 | } |
148 | - }), | 148 | + }, |
149 | + ), | ||
149 | ); | 150 | ); |
150 | }, | 151 | }, |
151 | separatorBuilder: (BuildContext contetx, int index) => | 152 | separatorBuilder: (BuildContext contetx, int index) => | ... | ... |
... | @@ -5,10 +5,7 @@ import 'package:flutter/services.dart'; | ... | @@ -5,10 +5,7 @@ import 'package:flutter/services.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 | import '../models/Bottle.dart'; | 7 | import '../models/Bottle.dart'; |
8 | -import '../DashBoard.dart'; | ||
9 | import '../../utils/user_secure_stoarge.dart'; | 8 | import '../../utils/user_secure_stoarge.dart'; |
10 | -import '../../utils/DBHelper.dart'; | ||
11 | -import '../models/UserBottle.dart'; | ||
12 | 9 | ||
13 | class BottleModifyList extends StatefulWidget { | 10 | class BottleModifyList extends StatefulWidget { |
14 | BottleModifyList({Key key}) : super(key: key); | 11 | BottleModifyList({Key key}) : super(key: key); |
... | @@ -23,7 +20,6 @@ class _BottleModifyListState extends State<BottleModifyList> { | ... | @@ -23,7 +20,6 @@ class _BottleModifyListState extends State<BottleModifyList> { |
23 | String hubid = await UserSecureStorage.getHubId(); | 20 | String hubid = await UserSecureStorage.getHubId(); |
24 | String usertoken = await UserSecureStorage.getUserToken(); | 21 | String usertoken = await UserSecureStorage.getUserToken(); |
25 | 22 | ||
26 | - var provider = DBHelper(); | ||
27 | http.Response response = await http.get( | 23 | http.Response response = await http.get( |
28 | Uri.encodeFull( | 24 | Uri.encodeFull( |
29 | DotEnv().env['SERVER_URL'] + 'bottle/hub/' + hubid.toString()), | 25 | DotEnv().env['SERVER_URL'] + 'bottle/hub/' + hubid.toString()), |
... | @@ -41,19 +37,7 @@ class _BottleModifyListState extends State<BottleModifyList> { | ... | @@ -41,19 +37,7 @@ class _BottleModifyListState extends State<BottleModifyList> { |
41 | Map<String, dynamic> map = values[i]; | 37 | Map<String, dynamic> map = values[i]; |
42 | _bottleList.add(Bottle.fromJson(map)); | 38 | _bottleList.add(Bottle.fromJson(map)); |
43 | } | 39 | } |
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 | 40 | ||
56 | - print(provider.getAllBottle()); | ||
57 | return "GET"; | 41 | return "GET"; |
58 | } else if (response.statusCode == 404) { | 42 | } else if (response.statusCode == 404) { |
59 | return "Not Found"; | 43 | return "Not Found"; | ... | ... |
1 | -class UserBottle { | ||
2 | - int bottleId; | ||
3 | - String bottleName; | ||
4 | - | ||
5 | - UserBottle({this.bottleId, this.bottleName}); | ||
6 | - | ||
7 | - factory UserBottle.fromJson(Map<String, dynamic> parsedJson) { | ||
8 | - return UserBottle( | ||
9 | - bottleId: parsedJson['bottleId'], | ||
10 | - bottleName: parsedJson['bottleName'], | ||
11 | - ); | ||
12 | - } | ||
13 | - | ||
14 | - Map<String, dynamic> toJson() => | ||
15 | - {"bottleId": bottleId, "bottleName": bottleName}; | ||
16 | -} |
1 | -import 'dart:io'; | ||
2 | -import 'package:path_provider/path_provider.dart'; | ||
3 | -import 'package:sqflite/sqflite.dart'; | ||
4 | -import 'package:path/path.dart'; | ||
5 | -import '../screens/models/UserBottle.dart'; | ||
6 | - | ||
7 | -final String tableName = 'medicinename'; | ||
8 | - | ||
9 | -class DBHelper { | ||
10 | - DBHelper._(); | ||
11 | - | ||
12 | - static final DBHelper _db = DBHelper._(); | ||
13 | - | ||
14 | - factory DBHelper() => _db; | ||
15 | - | ||
16 | - static Database _database; | ||
17 | - | ||
18 | - Future<Database> get database async { | ||
19 | - if (_database != null) return _database; | ||
20 | - | ||
21 | - _database = await initDB(); | ||
22 | - return _database; | ||
23 | - } | ||
24 | - | ||
25 | - initDB() async { | ||
26 | - Directory documentsDirectory = await getApplicationDocumentsDirectory(); | ||
27 | - String path = join(documentsDirectory.path, 'medicinename.db'); | ||
28 | - | ||
29 | - return await openDatabase( | ||
30 | - path, | ||
31 | - version: 1, | ||
32 | - onCreate: (Database db, int version) async { | ||
33 | - await db.execute(''' | ||
34 | - CREATE TABLE $tableName | ||
35 | - (bottleId INTEGER PRIMARY KEY, | ||
36 | - bottleName TEXT) | ||
37 | - '''); | ||
38 | - }, | ||
39 | - ); | ||
40 | - } | ||
41 | - | ||
42 | - createData(UserBottle bottle) async { | ||
43 | - final db = await database; | ||
44 | - var res = await db.insert(tableName, bottle.toJson(), | ||
45 | - conflictAlgorithm: ConflictAlgorithm.replace); | ||
46 | - return res; | ||
47 | - } | ||
48 | - | ||
49 | - getBottle(int bottleId) async { | ||
50 | - final db = await database; | ||
51 | - var res = | ||
52 | - await db.query(tableName, where: 'bottleId=?', whereArgs: [bottleId]); | ||
53 | - return res.isNotEmpty ? UserBottle.fromJson(res.first) : Null; | ||
54 | - } | ||
55 | - | ||
56 | - Future<List<UserBottle>> getAllBottle() async { | ||
57 | - final db = await database; | ||
58 | - var res = await db.query(tableName); | ||
59 | - List<UserBottle> list = | ||
60 | - res.isNotEmpty ? res.map((c) => UserBottle.fromJson(c)).toList() : []; | ||
61 | - | ||
62 | - return list; | ||
63 | - } | ||
64 | - | ||
65 | - updateBottle(UserBottle bottle) async { | ||
66 | - final db = await database; | ||
67 | - var res = db.update(tableName, bottle.toJson(), | ||
68 | - where: 'bottleId=?', whereArgs: [bottle.bottleId]); | ||
69 | - return res; | ||
70 | - } | ||
71 | -} |
-
Please register or login to post a comment