Skip to content

Commit

Permalink
review code
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaominfc committed Jan 14, 2020
1 parent 910851e commit 6a3d13d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
27 changes: 15 additions & 12 deletions lib/models/dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ class UserDao extends PrimaryDao<UserEntry> {
initTable(Database db, int version) async{
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setInt('users_lastUpdateTime', 0);
await dropTable(db, version);
await db.execute('CREATE TABLE '+ tableName() + ' (id INTEGER PRIMARY KEY, name TEXT, avatar TEXT, signInfo TEXT)');
return super.initTable(db,version);
}

@override
tableStruct(){
return '(id INTEGER PRIMARY KEY, name TEXT, avatar TEXT, signInfo TEXT)';
}
}

Expand Down Expand Up @@ -92,15 +96,15 @@ class GroupDao extends PrimaryDao<GroupEntry> {
return GroupEntry().fromMap(map);
}


@override
initTable(Database db, int version) async{
dropTable(db, version);
await db.execute('CREATE TABLE '+tableName() + ' (id INTEGER PRIMARY KEY, name TEXT, avatar TEXT, version INTEGER, shieldStatus INTEGER)');
String tableName() {
return "im_group";
}

@override
String tableName() {
return "im_group";
tableStruct(){
return '(id INTEGER PRIMARY KEY, name TEXT, avatar TEXT, version INTEGER, shieldStatus INTEGER)';
}
}

Expand Down Expand Up @@ -207,14 +211,13 @@ class SessionDao extends PrimaryDao<SessionEntry>{
}

@override
initTable(Database db, int version) async{
dropTable(db, version);
await db.execute('CREATE TABLE '+tableName() + ' (sessionKey TEXT PRIMARY KEY, sessionId INTEGER, sessionType INTEGER, lastMsg TEXT, updatedTime INTEGER)');
String tableName() {
return "im_session";
}

@override
String tableName() {
return "im_session";
tableStruct() {
return '(sessionKey TEXT PRIMARY KEY, sessionId INTEGER, sessionType INTEGER, lastMsg TEXT, updatedTime INTEGER)';
}

}
Expand Down
8 changes: 8 additions & 0 deletions lib/models/database_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ abstract class PrimaryDao<T extends BaseItem> extends BaseDao{
return null;
}

String tableStruct();

@override
initTable(Database db, int version) async{
dropTable(db, version);
await db.execute('CREATE TABLE '+tableName() + ' ' + tableStruct());
}

Future<int> delete(var id) async{
Database db = await DatabaseHelper.instance.database;
return await db.delete(tableName(), where: primarykey() + ' = ?', whereArgs: [id]);
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/contacts_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ class _ContactsPageState extends State<ContactsPage> {
children: <Widget>[
Container(
margin: const EdgeInsets.only(right: 16.0),
width: 36,
width: 48,
height: 48,
child: ClipOval(
child: FadeInImage(
image: NetworkImage(avatar),
Expand Down

0 comments on commit 6a3d13d

Please sign in to comment.