고원빈

[complete]

......@@ -6,8 +6,6 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
import '../models/Bottle.dart';
import '../DashBoard.dart';
import '../../utils/user_secure_stoarge.dart';
import '../../utils/DBHelper.dart';
import '../models/UserBottle.dart';
class BottleList extends StatefulWidget {
BottleList({Key key}) : super(key: key);
......@@ -17,12 +15,13 @@ class BottleList extends StatefulWidget {
}
class _BottleListState extends State<BottleList> {
String valueText;
List<Bottle> _bottleList = new List<Bottle>();
TextEditingController _textFieldController = TextEditingController();
Future<String> getBottleList() async {
String hubid = await UserSecureStorage.getHubId();
String usertoken = await UserSecureStorage.getUserToken();
var provider = DBHelper();
http.Response response = await http.get(
Uri.encodeFull(
DotEnv().env['SERVER_URL'] + 'bottle/hub/' + hubid.toString()),
......@@ -40,19 +39,7 @@ class _BottleListState extends State<BottleList> {
Map<String, dynamic> map = values[i];
_bottleList.add(Bottle.fromJson(map));
}
for (int i = 0; i < _bottleList.length; i++) {
UserBottle temp = new UserBottle();
temp.bottleId = _bottleList[i].bottleId;
temp.bottleName = _bottleList[i].bottleId.toString();
provider.createData(temp);
}
List<UserBottle> _userbottleList = new List<UserBottle>();
_userbottleList = await provider.getAllBottle();
for (int i = 0; i < _userbottleList.length; i++) {
print(_userbottleList[i].bottleId);
}
print(provider.getAllBottle());
return "GET";
} else if (response.statusCode == 404) {
return "Not Found";
......
......@@ -130,22 +130,23 @@ class _HubListState extends State<HubList> {
new FlatButton(
child: new Text('등록'),
onPressed: () {
UserSecureStorage.setHubId(widget
.hublist[index]
.toString());
UserSecureStorage.setHubId(
widget.hublist[index].toString());
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext
context) =>
builder:
(BuildContext context) =>
RegisterBottle(),
));
})
],
);
});
},
);
}
}),
},
),
);
},
separatorBuilder: (BuildContext contetx, int index) =>
......
......@@ -5,10 +5,7 @@ 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';
import '../../utils/user_secure_stoarge.dart';
import '../../utils/DBHelper.dart';
import '../models/UserBottle.dart';
class BottleModifyList extends StatefulWidget {
BottleModifyList({Key key}) : super(key: key);
......@@ -23,7 +20,6 @@ class _BottleModifyListState extends State<BottleModifyList> {
String hubid = await UserSecureStorage.getHubId();
String usertoken = await UserSecureStorage.getUserToken();
var provider = DBHelper();
http.Response response = await http.get(
Uri.encodeFull(
DotEnv().env['SERVER_URL'] + 'bottle/hub/' + hubid.toString()),
......@@ -41,19 +37,7 @@ class _BottleModifyListState extends State<BottleModifyList> {
Map<String, dynamic> map = values[i];
_bottleList.add(Bottle.fromJson(map));
}
for (int i = 0; i < _bottleList.length; i++) {
UserBottle temp = new UserBottle();
temp.bottleId = _bottleList[i].bottleId;
temp.bottleName = _bottleList[i].bottleId.toString();
provider.createData(temp);
}
List<UserBottle> _userbottleList = new List<UserBottle>();
_userbottleList = await provider.getAllBottle();
for (int i = 0; i < _userbottleList.length; i++) {
print(_userbottleList[i].bottleId);
}
print(provider.getAllBottle());
return "GET";
} else if (response.statusCode == 404) {
return "Not Found";
......
class UserBottle {
int bottleId;
String bottleName;
UserBottle({this.bottleId, this.bottleName});
factory UserBottle.fromJson(Map<String, dynamic> parsedJson) {
return UserBottle(
bottleId: parsedJson['bottleId'],
bottleName: parsedJson['bottleName'],
);
}
Map<String, dynamic> toJson() =>
{"bottleId": bottleId, "bottleName": bottleName};
}
import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:sqflite/sqflite.dart';
import 'package:path/path.dart';
import '../screens/models/UserBottle.dart';
final String tableName = 'medicinename';
class DBHelper {
DBHelper._();
static final DBHelper _db = DBHelper._();
factory DBHelper() => _db;
static Database _database;
Future<Database> get database async {
if (_database != null) return _database;
_database = await initDB();
return _database;
}
initDB() async {
Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path, 'medicinename.db');
return await openDatabase(
path,
version: 1,
onCreate: (Database db, int version) async {
await db.execute('''
CREATE TABLE $tableName
(bottleId INTEGER PRIMARY KEY,
bottleName TEXT)
''');
},
);
}
createData(UserBottle bottle) async {
final db = await database;
var res = await db.insert(tableName, bottle.toJson(),
conflictAlgorithm: ConflictAlgorithm.replace);
return res;
}
getBottle(int bottleId) async {
final db = await database;
var res =
await db.query(tableName, where: 'bottleId=?', whereArgs: [bottleId]);
return res.isNotEmpty ? UserBottle.fromJson(res.first) : Null;
}
Future<List<UserBottle>> getAllBottle() async {
final db = await database;
var res = await db.query(tableName);
List<UserBottle> list =
res.isNotEmpty ? res.map((c) => UserBottle.fromJson(c)).toList() : [];
return list;
}
updateBottle(UserBottle bottle) async {
final db = await database;
var res = db.update(tableName, bottle.toJson(),
where: 'bottleId=?', whereArgs: [bottle.bottleId]);
return res;
}
}