diff --git a/lib/main.dart b/lib/main.dart index 99109ef..28ea652 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:timemanage/screens/dashboard_screen.dart'; +import 'package:timemanage/screen/dashboard_screen.dart'; void main() => runApp(const MyApp()); diff --git a/lib/model/clone_time.dart b/lib/model/clone_time.dart new file mode 100644 index 0000000..6d46c50 --- /dev/null +++ b/lib/model/clone_time.dart @@ -0,0 +1,7 @@ +// 拓展DateTime,实现克隆方法 +extension CloneTime on DateTime { + DateTime clone() { + return DateTime( + year, month, day, hour, minute, second, millisecond, microsecond); + } +} diff --git a/lib/model/project.dart b/lib/model/project.dart new file mode 100644 index 0000000..b18fd4e --- /dev/null +++ b/lib/model/project.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; // Color类要使用这个包 +import 'package:equatable/equatable.dart'; // 比较两个对象是否相等的包 + +class Project extends Equatable { + final int id; + final String name; + final bool archived; // 是否归档 + + // 构造函数 + const Project({ + required this.id, + required this.name, + required this.archived, + }); + + @override + List get props => [id, name, archived]; // 返回属性列表,用于比较两个对象是否相等 + + Project.clone( + Project project, { + String? name, + Color? color, + bool? archived, + }) : this( + id: project.id, + name: name ?? project.name, + archived: archived ?? project.archived, + ); +} diff --git a/lib/model/project_description.dart b/lib/model/project_description.dart new file mode 100644 index 0000000..dcc66dd --- /dev/null +++ b/lib/model/project_description.dart @@ -0,0 +1,12 @@ +import 'package:equatable/equatable.dart'; + +// 项目描述 +class ProjectDescriptionPair extends Equatable { + final int? project; + final String? description; + + const ProjectDescriptionPair(this.project, this.description); + + @override + List get props => [project, description]; +} diff --git a/lib/model/start_of_week.dart b/lib/model/start_of_week.dart new file mode 100644 index 0000000..3606d47 --- /dev/null +++ b/lib/model/start_of_week.dart @@ -0,0 +1,8 @@ +// 设置每周的第一天从周日开始 +extension StartOfWeek on DateTime { + DateTime startOfWeek({int startOfWeekDay = DateTime.sunday}) { + int diff = (7 + (weekday - startOfWeekDay)) % 7; + DateTime dt = add(Duration(days: -diff)); + return DateTime(dt.year, dt.month, dt.day); + } +} diff --git a/lib/model/theme_type.dart b/lib/model/theme_type.dart new file mode 100644 index 0000000..486699d --- /dev/null +++ b/lib/model/theme_type.dart @@ -0,0 +1 @@ +// TODO: 实现主题切换功能 diff --git a/lib/model/timer_entry.dart b/lib/model/timer_entry.dart new file mode 100644 index 0000000..e842a75 --- /dev/null +++ b/lib/model/timer_entry.dart @@ -0,0 +1,58 @@ +import 'package:equatable/equatable.dart'; + +// 计时器实体类 +class TimerEntry extends Equatable { + final int id; + final String? description; + final int? projectID; + final DateTime startTime; + final DateTime? endTime; + final String? notes; + + // 构造函数 + const TimerEntry( + {required this.id, + required this.description, + required this.projectID, + required this.startTime, + required this.endTime, + this.notes = ""}); + + // 返回属性列表,用于比较两个对象是否相等 + @override + List get props => + [id, description, projectID, startTime, endTime, notes]; + @override + bool get stringify => true; + + // 克隆方法 + TimerEntry.clone(TimerEntry timer, + {String? description, + int? projectID, + DateTime? startTime, + DateTime? endTime, + String? notes}) + : this( + id: timer.id, + description: description ?? timer.description, + projectID: projectID ?? timer.projectID, + startTime: startTime ?? timer.startTime, + endTime: endTime ?? timer.endTime, + notes: notes ?? timer.notes, + ); + + // 格式化时间 + static String formatDuration(Duration d) { + if (d.inHours > 0) { + return "${d.inHours}:${(d.inMinutes - (d.inHours * 60)).toString().padLeft(2, "0")}:${(d.inSeconds - (d.inMinutes * 60)).toString().padLeft(2, "0")}"; + } else { + return "${d.inMinutes.toString().padLeft(2, "0")}:${(d.inSeconds - (d.inMinutes * 60)).toString().padLeft(2, "0")}"; + } + } + + // 格式化时间 + String formatTime() { + Duration d = (endTime ?? DateTime.now()).difference(startTime); + return formatDuration(d); + } +} diff --git a/lib/screens/about_screen.dart b/lib/screen/about_screen.dart similarity index 98% rename from lib/screens/about_screen.dart rename to lib/screen/about_screen.dart index 490a78f..e68dff8 100644 --- a/lib/screens/about_screen.dart +++ b/lib/screen/about_screen.dart @@ -68,7 +68,6 @@ class AboutScreen extends StatelessWidget { ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text("请横屏查看"), - // FIXME: 此处持续时间没有3秒 duration: Duration(seconds: 3)), ); launchUrl(Uri.parse( diff --git a/lib/screens/course_screen.dart b/lib/screen/course_screen.dart similarity index 100% rename from lib/screens/course_screen.dart rename to lib/screen/course_screen.dart diff --git a/lib/screens/dashboard_screen.dart b/lib/screen/dashboard_screen.dart similarity index 85% rename from lib/screens/dashboard_screen.dart rename to lib/screen/dashboard_screen.dart index bdf286e..713a934 100644 --- a/lib/screens/dashboard_screen.dart +++ b/lib/screen/dashboard_screen.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; -import 'package:timemanage/screens/projects_screen.dart'; -import 'package:timemanage/screens/reports_screen.dart'; -import 'package:timemanage/screens/export_screen.dart'; -import 'package:timemanage/screens/settings_screen.dart'; -import 'package:timemanage/screens/about_screen.dart'; -import 'package:timemanage/screens/course_screen.dart'; +import 'package:timemanage/screen/projects_screen.dart'; +import 'package:timemanage/screen/reports_screen.dart'; +import 'package:timemanage/screen/export_screen.dart'; +import 'package:timemanage/screen/settings_screen.dart'; +import 'package:timemanage/screen/about_screen.dart'; +import 'package:timemanage/screen/course_screen.dart'; class DashBoardScreen extends StatelessWidget { const DashBoardScreen({super.key}); @@ -100,7 +100,14 @@ class DashBoardScreen extends StatelessWidget { ], ), body: const Center( - child: Text('主界面'), + child: Column( + children: [ + Text('项目列表区'), + Expanded( + child: Text('计时器区'), + ), + ], + ), ), ); } diff --git a/lib/screens/export_screen.dart b/lib/screen/export_screen.dart similarity index 100% rename from lib/screens/export_screen.dart rename to lib/screen/export_screen.dart diff --git a/lib/screens/projects_screen.dart b/lib/screen/projects_screen.dart similarity index 100% rename from lib/screens/projects_screen.dart rename to lib/screen/projects_screen.dart diff --git a/lib/screens/reports_screen.dart b/lib/screen/reports_screen.dart similarity index 100% rename from lib/screens/reports_screen.dart rename to lib/screen/reports_screen.dart diff --git a/lib/screens/settings_screen.dart b/lib/screen/settings_screen.dart similarity index 100% rename from lib/screens/settings_screen.dart rename to lib/screen/settings_screen.dart diff --git a/pubspec.lock b/pubspec.lock index ceba0e3..7207144 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -89,6 +89,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.6" + equatable: + dependency: "direct main" + description: + name: equatable + sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2 + url: "https://pub.dev" + source: hosted + version: "2.0.5" fake_async: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index bbb7ad9..668033e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -36,7 +36,7 @@ dependencies: about: ^2.1.3 font_awesome_flutter: ^9.2.0 url_launcher: ^6.1.14 - + equatable: ^2.0.3 # 用于对象比较 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.