fix bug:android emulator

This commit is contained in:
yifeng.yl
2019-01-10 11:13:13 +08:00
parent 71292363a3
commit dad3e040d4
5 changed files with 28 additions and 14 deletions

View File

@ -6,6 +6,8 @@
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.MODE_WORLD_READABLE"/>
<uses-permission android:name="android.permission.MODE_WORLD_WRITEABLE"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.

Binary file not shown.

View File

@ -11,27 +11,38 @@ class Provider {
//初始化数据库
// isCreate 用永远 copy 一个新的数据库
Future init(bool isCreate) async {
//Get a location using getDatabasesPath
String databasesPath = await getDatabasesPath();
String path = join(databasesPath, 'flutter.db');
try {
db = await openDatabase(path);
} catch (e) {
print("Error $e");
}
if (isCreate) {
List<Map> list;
// try {
// db = await openDatabase(path, readOnly: true);
// } catch (e) {
// print("Error $e");
// }
if (db == null) {
// Delete the database
await deleteDatabase(path);
ByteData data = await rootBundle.load(join("assets", "app.db"));
List<int> bytes =
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
await new File(path).writeAsBytes(bytes);
db = await openDatabase(path, version: 2,
onCreate: (Database db, int version) async {
print('db created version is $version');
}, onOpen: (Database db) async {
print('new db opened');
});
// db = await openDatabase(path, version: 2,
// onCreate: (Database db, int version) async {
// print('db created version is $version');
// }, onOpen: (Database db) async {
// print('new db opened');
// });
db = await openDatabase(path, readOnly: true);
list = await db
.rawQuery('SELECT name FROM sqlite_master WHERE type = "table"');
print('$list 1234567891');
} else {
// print('Opening existing database');
print("Opening existing database");
}
}
}

View File

@ -28,7 +28,7 @@ class _CateCardState extends State<CateCard> {
Cat childCateCondition = new Cat(parentId: parentId);
List<Cat> list = await catControl.getList(childCateCondition);
if (list.isNotEmpty&&list.length>=1) {
if (list.isNotEmpty&&list.length>=1 && this.mounted) {
setState(() {
_firstChildList = list;
});

View File

@ -47,6 +47,7 @@ flutter:
assets:
- assets/app.db
- assets/images/
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg