Browse Source

调整下视图

ValiZhang 9 tháng trước cách đây
mục cha
commit
909288a913

+ 0 - 1
lib/core/repositories/challenge_repository.dart

@@ -4,7 +4,6 @@ abstract class ChallengeRepository {
   Future<List<ChallengeModel>> getChallenges({
     int page=1,
     int pageSize = 20,
-    int actionType= 1,
   });
   Future<ChallengeModel?> getChallengeById(int id);
   Future<ChallengeModel> addChallenge(ChallengeModel challenge);

+ 11 - 11
lib/core/repositories/sqlite_challenge_repository.dart

@@ -15,7 +15,7 @@ class SqliteChallengeRepository implements ChallengeRepository {
     int actionType = 1,
   }) async {
     final db = await dbHelper.database;
-    final maps = await db.query(DatabaseHelper.chllangetTable);
+    final maps = await db.query(DatabaseHelper.challengeTable);
     return maps.map(_mapDatabaseToModel).toList();
   }
 
@@ -23,7 +23,7 @@ class SqliteChallengeRepository implements ChallengeRepository {
   Future<ChallengeModel> addChallenge(ChallengeModel challenge) async {
     final db = await dbHelper.database;
     await db.insert(
-      DatabaseHelper.chllangetTable,
+      DatabaseHelper.challengeTable,
       _mapModelToDatabase(challenge),
       conflictAlgorithm: ConflictAlgorithm.replace,
     );
@@ -45,16 +45,16 @@ class SqliteChallengeRepository implements ChallengeRepository {
       remark: map['remark'],
       parentId: map['parent_id'],
       difficulty: map['difficulty'],
-      finishDate: map['finish_date']
+      finishDate: map['finish_date']!=null
           ? DateTime.fromMillisecondsSinceEpoch(map['finish_date'])
           : null,
-      planFinishDate: map['plan_finish_date']
+      planFinishDate: map['plan_finish_date']!=null
           ? DateTime.fromMillisecondsSinceEpoch(map['plan_finish_date'])
           : null,
-      startDate: map['start_date']
+      startDate: map['start_date']!=null
           ? DateTime.fromMillisecondsSinceEpoch(map['start_date'])
           : null,
-      endDate: map['end_date']
+      endDate: map['end_date']!=null
           ? DateTime.fromMillisecondsSinceEpoch(map['end_date'])
           : null,
     );
@@ -75,8 +75,8 @@ class SqliteChallengeRepository implements ChallengeRepository {
       'difficulty': model.difficulty,
       'start_date': model.startDate?.millisecondsSinceEpoch,
       'end_date': model.endDate?.millisecondsSinceEpoch,
-      'finish_date':model.finishDate,
-      'plan_finish_date':model.planFinishDate,
+      'finish_date':model.finishDate?.millisecondsSinceEpoch,
+      'plan_finish_date':model.planFinishDate?.millisecondsSinceEpoch,
     };
   }
 
@@ -84,7 +84,7 @@ class SqliteChallengeRepository implements ChallengeRepository {
   Future<void> deleteChallenge(int id) async {
     final db = await dbHelper.database;
     await db.delete(
-      DatabaseHelper.chllangetTable,
+      DatabaseHelper.challengeTable,
       where: '${DatabaseHelper.columnId} = ?',
       whereArgs: [id],
     );
@@ -94,7 +94,7 @@ class SqliteChallengeRepository implements ChallengeRepository {
   Future<ChallengeModel?> getChallengeById(int id) async {
     final db = await dbHelper.database;
     final maps = await db.query(
-      DatabaseHelper.chllangetTable,
+      DatabaseHelper.challengeTable,
       where: '${DatabaseHelper.columnId} = ?',
       whereArgs: [id],
       limit: 1,
@@ -110,7 +110,7 @@ class SqliteChallengeRepository implements ChallengeRepository {
   Future<ChallengeModel> updateChallenge(ChallengeModel challenge) async {
     final db = await dbHelper.database;
     await db.update(
-      DatabaseHelper.chllangetTable,
+      DatabaseHelper.challengeTable,
       _mapModelToDatabase(challenge),
       where: '${DatabaseHelper.columnId} = ?',
       whereArgs: [challenge.id],

+ 5 - 2
lib/data/local/database_helper.dart

@@ -5,7 +5,7 @@ class DatabaseHelper {
   static const _databaseName = 'jay_world_app.db';
   static const _databaseVersion = 1;
 
-  static const chllangetTable = 'challenges';
+  static const challengeTable = 'challenges';
   static const columnId = 'id';
   static const columnTitle = 'title';
   // 其他字段...
@@ -20,6 +20,9 @@ class DatabaseHelper {
 
   Future<Database> _initDatabase() async {
     final path = join(await getDatabasesPath(), _databaseName);
+    // await deleteDatabase(path);
+
+    print("===== xxxxxx ======");
     return await openDatabase(
       path,
       version: _databaseVersion,
@@ -29,7 +32,7 @@ class DatabaseHelper {
 
   Future<void> _onCreate(Database db, int version) async {
     await db.execute('''
-      CREATE TABLE $chllangetTable (
+      CREATE TABLE $challengeTable (
         $columnId INTEGER PRIMARY KEY AUTOINCREMENT,
         $columnTitle TEXT NOT NULL,
         action_type INTEGER NOT NULL,

+ 1 - 1
lib/features/challenge/view_models/challenge_list_vm.dart

@@ -27,7 +27,7 @@ class ChallengeListViewModel extends AsyncNotifier<List<ChallengeModel>> {
       final challenges = await _repository.getChallenges();
       state = AsyncValue.data(challenges);
 
-      print('表单提交数据: ${challenges[0].toJson()}');
+      // print('============表单提交数据: ${challenges.length}');
       return challenges;
     } catch (e, stack) {
       state = AsyncValue.error(e, stack);

+ 2 - 2
lib/features/challenge/views/add_challenge_screen.dart

@@ -133,7 +133,7 @@ class _BuildForm extends ConsumerWidget {
             labelText: '计划完成日期',
             onDateSelected: (date) => ref
                 .read(addChallengeProvider.notifier)
-                .updatePlanFinishDate(date!),
+                .updatePlanFinishDate(date ?? DateTime.now()),
           ),
 
           const SizedBox(height: 16),
@@ -141,7 +141,7 @@ class _BuildForm extends ConsumerWidget {
             labelText: '完成日期',
             onDateSelected: (date) => ref
                 .read(addChallengeProvider.notifier)
-                .updateFinishDate(date!),
+                .updateFinishDate(date ?? DateTime.now()),
           ),
 
           const SizedBox(height: 16),