mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-05-17 21:05:56 +08:00
fix bug:android emulator
This commit is contained in:
@ -6,6 +6,8 @@
|
|||||||
to allow setting breakpoints, to provide hot reload, etc.
|
to allow setting breakpoints, to provide hot reload, etc.
|
||||||
-->
|
-->
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<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
|
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
|
||||||
calls FlutterMain.startInitialization(this); in its onCreate method.
|
calls FlutterMain.startInitialization(this); in its onCreate method.
|
||||||
|
BIN
assets/app.db
BIN
assets/app.db
Binary file not shown.
@ -11,27 +11,38 @@ class Provider {
|
|||||||
//初始化数据库
|
//初始化数据库
|
||||||
// isCreate 用永远 copy 一个新的数据库
|
// isCreate 用永远 copy 一个新的数据库
|
||||||
Future init(bool isCreate) async {
|
Future init(bool isCreate) async {
|
||||||
|
//Get a location using getDatabasesPath
|
||||||
String databasesPath = await getDatabasesPath();
|
String databasesPath = await getDatabasesPath();
|
||||||
String path = join(databasesPath, 'flutter.db');
|
String path = join(databasesPath, 'flutter.db');
|
||||||
try {
|
List<Map> list;
|
||||||
db = await openDatabase(path);
|
// try {
|
||||||
} catch (e) {
|
// db = await openDatabase(path, readOnly: true);
|
||||||
print("Error $e");
|
|
||||||
}
|
// } catch (e) {
|
||||||
if (isCreate) {
|
// print("Error $e");
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (db == null) {
|
||||||
|
// Delete the database
|
||||||
|
await deleteDatabase(path);
|
||||||
|
|
||||||
ByteData data = await rootBundle.load(join("assets", "app.db"));
|
ByteData data = await rootBundle.load(join("assets", "app.db"));
|
||||||
List<int> bytes =
|
List<int> bytes =
|
||||||
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
|
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
|
||||||
await new File(path).writeAsBytes(bytes);
|
await new File(path).writeAsBytes(bytes);
|
||||||
|
|
||||||
db = await openDatabase(path, version: 2,
|
// db = await openDatabase(path, version: 2,
|
||||||
onCreate: (Database db, int version) async {
|
// onCreate: (Database db, int version) async {
|
||||||
print('db created version is $version');
|
// print('db created version is $version');
|
||||||
}, onOpen: (Database db) async {
|
// }, onOpen: (Database db) async {
|
||||||
print('new db opened');
|
// 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 {
|
} else {
|
||||||
// print('Opening existing database');
|
print("Opening existing database");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class _CateCardState extends State<CateCard> {
|
|||||||
Cat childCateCondition = new Cat(parentId: parentId);
|
Cat childCateCondition = new Cat(parentId: parentId);
|
||||||
|
|
||||||
List<Cat> list = await catControl.getList(childCateCondition);
|
List<Cat> list = await catControl.getList(childCateCondition);
|
||||||
if (list.isNotEmpty&&list.length>=1) {
|
if (list.isNotEmpty&&list.length>=1 && this.mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_firstChildList = list;
|
_firstChildList = list;
|
||||||
});
|
});
|
||||||
|
@ -47,6 +47,7 @@ flutter:
|
|||||||
assets:
|
assets:
|
||||||
- assets/app.db
|
- assets/app.db
|
||||||
- assets/images/
|
- assets/images/
|
||||||
|
|
||||||
# To add assets to your application, add an assets section, like this:
|
# To add assets to your application, add an assets section, like this:
|
||||||
# assets:
|
# assets:
|
||||||
# - images/a_dot_burr.jpeg
|
# - images/a_dot_burr.jpeg
|
||||||
|
Reference in New Issue
Block a user