diff --git a/lib/main.dart b/lib/main.dart index e83819e..f9f48ee 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,8 +3,11 @@ import 'package:task_hub/pages/home_page.dart'; import 'package:task_hub/pages/schedule_page.dart'; import 'package:task_hub/pages/settings_page.dart'; import 'package:task_hub/pages/task_page.dart'; +import 'package:window_size/window_size.dart'; void main() { + WidgetsFlutterBinding.ensureInitialized(); + setWindowMinSize(const Size(800, 600)); runApp(const TaskHubApp()); } @@ -14,10 +17,11 @@ class TaskHubApp extends StatelessWidget { @override Widget build(BuildContext context) { return FluentApp( - title: 'TaskHub', + title: '拾光记', themeMode: ThemeMode.system, theme: FluentThemeData( fontFamily: 'CustomFont', + accentColor: Colors.purple ), debugShowCheckedModeBanner: false, home: const MainLayout(), @@ -34,53 +38,36 @@ class MainLayout extends StatefulWidget { class _MainLayoutState extends State { int _currentIndex = 0; - + @override Widget build(BuildContext context) { return NavigationView( - titleBar: TitleBar( - icon: const FlutterLogo(), - title: const Text('TaskHub') - ), + titleBar: TitleBar(title: const Text('拾光记')), pane: NavigationPane( selected: _currentIndex, onChanged: (index) => setState(() => _currentIndex = index), - size: NavigationPaneSize( - openWidth: 150 - ), + size: NavigationPaneSize(openWidth: 150), items: [ PaneItem( icon: const Icon(FluentIcons.home), title: const Text('首页'), - body: Container( - color: Colors.white, - child: const HomePage(), - ), + body: Container(color: Colors.white, child: const HomePage()), ), PaneItem( icon: const Icon(FluentIcons.check_list), title: const Text('待办'), - body: Container( - color: Colors.white, - child: const TaskPage(), - ), + body: Container(color: Colors.white, child: const TaskPage()), ), PaneItem( icon: const Icon(FluentIcons.calendar), title: const Text('日程'), - body: Container( - color: Colors.white, - child: const SchedulePage(), - ), + body: Container(color: Colors.white, child: const SchedulePage()), ), PaneItemSeparator(), PaneItem( icon: const Icon(FluentIcons.settings), title: const Text('设置'), - body: Container( - color: Colors.white, - child: const SettingsPage(), - ), + body: Container(color: Colors.white, child: const SettingsPage()), ), ], footerItems: [ @@ -96,4 +83,4 @@ class _MainLayoutState extends State { ), ); } -} \ No newline at end of file +} diff --git a/lib/pages/task_page.dart b/lib/pages/task_page.dart index 3679e00..ab4749d 100644 --- a/lib/pages/task_page.dart +++ b/lib/pages/task_page.dart @@ -20,12 +20,11 @@ class _TaskPageState extends State { String _sortBy = 'created'; List get _filteredTasks { - List tasks = - _tasks.where((task) { - if (_filter == 'active') return !task.isCompleted; - if (_filter == 'completed') return task.isCompleted; - return true; - }).toList(); + List tasks = _tasks.where((task) { + if (_filter == 'active') return !task.isCompleted; + if (_filter == 'completed') return task.isCompleted; + return true; + }).toList(); tasks.sort((a, b) { switch (_sortBy) { @@ -48,32 +47,30 @@ class _TaskPageState extends State { void _addTask() { showDialog( context: context, - builder: - (context) => TaskDialog( - onSave: (task) { - setState(() { - _tasks.add(task); - }); - }, - ), + builder: (context) => TaskDialog( + onSave: (task) { + setState(() { + _tasks.add(task); + }); + }, + ), ); } void _editTask(Task task) { showDialog( context: context, - builder: - (context) => TaskDialog( - task: task, - onSave: (editedTask) { - setState(() { - final index = _tasks.indexWhere((t) => t.id == task.id); - if (index != -1) { - _tasks[index] = editedTask; - } - }); - }, - ), + builder: (context) => TaskDialog( + task: task, + onSave: (editedTask) { + setState(() { + final index = _tasks.indexWhere((t) => t.id == task.id); + if (index != -1) { + _tasks[index] = editedTask; + } + }); + }, + ), ); } @@ -137,7 +134,7 @@ class _TaskPageState extends State { final activeCount = _tasks.length - completedCount; return Card( - backgroundColor: Colors.grey[20], + backgroundColor: FluentTheme.of(context).accentColor.lighter, child: Padding( padding: const EdgeInsets.all(12.0), child: Row( @@ -157,10 +154,14 @@ class _TaskPageState extends State { children: [ Text( value, - style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), + style: TextStyle( + fontSize: 24, + fontWeight: FontWeight.bold, + color: Colors.white, + ), ), const SizedBox(height: 4), - Text(label, style: TextStyle(color: Colors.grey)), + Text(label, style: TextStyle(color: Colors.white)), ], ); } @@ -232,7 +233,11 @@ class _TaskPageState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Icon(FluentIcons.check_list, size: 64, color: Colors.blue), + Icon( + FluentIcons.check_list, + size: 64, + color: FluentTheme.of(context).accentColor, + ), const SizedBox(height: 20), const Text( '还没有任务', @@ -256,7 +261,7 @@ class _TaskPageState extends State { task: task, onToggleComplete: () => _toggleTaskComplete(task), onEdit: () => _editTask(task), - onDelete: () => _deleteTask(task.id) + onDelete: () => _deleteTask(task.id), ), ); }, diff --git a/lib/widgets/schedule_dialog.dart b/lib/widgets/schedule_dialog.dart index c48e982..41c08e1 100644 --- a/lib/widgets/schedule_dialog.dart +++ b/lib/widgets/schedule_dialog.dart @@ -23,7 +23,9 @@ class _ScheduleDialogState extends State { @override void initState() { super.initState(); - _titleController = TextEditingController(text: widget.schedule?.title ?? ''); + _titleController = TextEditingController( + text: widget.schedule?.title ?? '', + ); _selectedStartTime = widget.schedule?.startTime; _selectedEndTime = widget.schedule?.endTime; _selectedScheduleDate = widget.schedule?.scheduleDate; @@ -35,34 +37,43 @@ class _ScheduleDialogState extends State { super.dispose(); } - void onConfirmClick()async { + void onConfirmClick() async { if (_selectedStartTime == null) { - await displayInfoBar(context, builder: (context, close) { - return InfoBar( - title: const Text('请选择开始时间'), - severity: InfoBarSeverity.error, - ); - }); + await displayInfoBar( + context, + builder: (context, close) { + return InfoBar( + title: const Text('请选择开始时间'), + severity: InfoBarSeverity.error, + ); + }, + ); return; } if (_selectedEndTime == null) { - await displayInfoBar(context, builder: (context, close) { - return InfoBar( - title: const Text('请选择结束时间'), - severity: InfoBarSeverity.error, - ); - }); + await displayInfoBar( + context, + builder: (context, close) { + return InfoBar( + title: const Text('请选择结束时间'), + severity: InfoBarSeverity.error, + ); + }, + ); return; } if (!_selectedEndTime!.isAfter(_selectedStartTime!)) { - await displayInfoBar(context, builder: (context, close) { - return InfoBar( - title: const Text('结束时间必须晚于开始时间'), - severity: InfoBarSeverity.error, - ); - }); + await displayInfoBar( + context, + builder: (context, close) { + return InfoBar( + title: const Text('结束时间必须晚于开始时间'), + severity: InfoBarSeverity.error, + ); + }, + ); return; } @@ -82,7 +93,7 @@ class _ScheduleDialogState extends State { @override Widget build(BuildContext context) { return ContentDialog( - title: Text(widget.schedule == null ? '添加日程' : '编辑日程'), + title: Center(child: Text(widget.schedule == null ? '添加日程' : '编辑日程')), content: _buildForm(), actions: [ Button( diff --git a/lib/widgets/task_dialog.dart b/lib/widgets/task_dialog.dart index 4df39de..2d798b9 100644 --- a/lib/widgets/task_dialog.dart +++ b/lib/widgets/task_dialog.dart @@ -57,7 +57,7 @@ class _TaskDialogState extends State { @override Widget build(BuildContext context) { return ContentDialog( - title: Text(widget.task == null ? '添加任务' : '编辑任务'), + title: Center(child: Text(widget.task == null ? '添加任务' : '编辑任务')), content: _buildForm(), actions: [ Button( diff --git a/lib/widgets/task_item.dart b/lib/widgets/task_item.dart index acb8ee6..9dd5826 100644 --- a/lib/widgets/task_item.dart +++ b/lib/widgets/task_item.dart @@ -36,12 +36,12 @@ class TaskItem extends StatelessWidget { children: [ _buildPriorityIndicator(task.priority), const SizedBox(width: 8), - Expanded(child: _buildTitle()), + Expanded(child: _buildTitle(context)), ], ), - const SizedBox(height: 2), + const SizedBox(height: 4), if (task.desc != null && task.desc!.isNotEmpty) _buildDesc(), - const SizedBox(height: 2), + const SizedBox(height: 4), if (task.dueDate != null || task.scheduleDate != null) _buildDate(), ], @@ -62,14 +62,14 @@ class TaskItem extends StatelessWidget { ); } - Widget _buildTitle() { + Widget _buildTitle(BuildContext context) { return Text( task.title, style: TextStyle( fontSize: 16, - fontWeight: FontWeight.w500, + fontWeight: FontWeight.bold, decoration: task.isCompleted ? TextDecoration.lineThrough : null, - color: task.isCompleted ? Colors.grey : Colors.red, + color: task.isCompleted ? Colors.grey[100] : FluentTheme.of(context).accentColor, ), ); } @@ -78,7 +78,7 @@ class TaskItem extends StatelessWidget { return Text( task.desc!, style: TextStyle( - color: Colors.grey, + color: Colors.grey[150], fontSize: 14, decoration: task.isCompleted ? TextDecoration.lineThrough : null, ), @@ -89,20 +89,20 @@ class TaskItem extends StatelessWidget { return Row( children: [ if (task.dueDate != null) ...[ - const Icon(FluentIcons.calendar, size: 12, color: Colors.grey), + Icon(FluentIcons.calendar, size: 12, color: Colors.grey), const SizedBox(width: 4), Text( '截止日期: ${_formatDate(task.dueDate!)}', - style: const TextStyle(color: Colors.grey, fontSize: 12), + style: TextStyle(color: Colors.grey, fontSize: 12), ), const SizedBox(width: 4), ], if (task.scheduleDate != null) ...[ - const Icon(FluentIcons.clock, size: 12, color: Colors.grey), + Icon(FluentIcons.clock, size: 12, color: Colors.grey), const SizedBox(width: 4), Text( '提醒日期: ${_formatDate(task.scheduleDate!)}', - style: const TextStyle(color: Colors.grey, fontSize: 12), + style: TextStyle(color: Colors.grey, fontSize: 12), ), ], ], diff --git a/pubspec.lock b/pubspec.lock index fa108c2..1a66c52 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -453,6 +453,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.1.1" + window_size: + dependency: "direct main" + description: + name: window_size + sha256: "8ba77a3df7bd686e60b21e699e60e1b103e6515950954b46c4fb6f513586e278" + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.0" xdg_directories: dependency: transitive description: @@ -470,5 +478,5 @@ packages: source: hosted version: "6.6.1" sdks: - dart: ">=3.8.0 <4.0.0" + dart: ">=3.10.0 <4.0.0" flutter: ">=3.32.0" diff --git a/pubspec.yaml b/pubspec.yaml index 907fcc8..1633c95 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1 +1 @@ -name: task_hub description: "A new Flutter project." # The following line prevents the package from being accidentally published to # pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 # followed by an optional build number separated by a +. # Both the version and the builder number may be overridden in flutter # build by specifying --build-name and --build-number, respectively. # In Android, build-name is used as versionName while build-number used as versionCode. # Read more about Android versioning at https://developer.android.com/studio/publish/versioning # In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. version: 1.0.0+1 environment: sdk: ^3.7.0 # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions # consider running `flutter pub upgrade --major-versions`. Alternatively, # dependencies can be manually updated by changing the version numbers below to # the latest version available on pub.dev. To see which dependencies have newer # versions available, run `flutter pub outdated`. dependencies: flutter: sdk: flutter # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.8 flutter_local_notifications: ^19.5.0 syncfusion_flutter_calendar: ^30.1.37 fluent_ui: ^4.15.0 omni_datetime_picker: ^2.3.1 intl: ^0.20.2 dev_dependencies: flutter_test: sdk: flutter # The "flutter_lints" package below contains a set of recommended lints to # encourage good coding practices. The lint set provided by the package is # activated in the `analysis_options.yaml` file located at the root of your # package. See that file for information about deactivating specific lint # rules and activating additional ones. flutter_lints: ^5.0.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec # The following section is specific to Flutter packages. flutter: uses-material-design: true assets: - assets/icons/task.png fonts: - family: CustomFont fonts: - asset: fonts/custom.ttf \ No newline at end of file +name: task_hub description: "待办事项、日程安排" # The following line prevents the package from being accidentally published to # pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 # followed by an optional build number separated by a +. # Both the version and the builder number may be overridden in flutter # build by specifying --build-name and --build-number, respectively. # In Android, build-name is used as versionName while build-number used as versionCode. # Read more about Android versioning at https://developer.android.com/studio/publish/versioning # In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. version: 1.0.0+1 environment: sdk: ^3.10.0 # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions # consider running `flutter pub upgrade --major-versions`. Alternatively, # dependencies can be manually updated by changing the version numbers below to # the latest version available on pub.dev. To see which dependencies have newer # versions available, run `flutter pub outdated`. dependencies: flutter: sdk: flutter # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.8 flutter_local_notifications: ^19.5.0 syncfusion_flutter_calendar: ^30.1.37 fluent_ui: ^4.15.0 omni_datetime_picker: ^2.3.1 intl: ^0.20.2 window_size: ^0.1.0 dev_dependencies: flutter_test: sdk: flutter # The "flutter_lints" package below contains a set of recommended lints to # encourage good coding practices. The lint set provided by the package is # activated in the `analysis_options.yaml` file located at the root of your # package. See that file for information about deactivating specific lint # rules and activating additional ones. flutter_lints: ^5.0.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec # The following section is specific to Flutter packages. flutter: uses-material-design: true assets: - assets/icons/ fonts: - family: CustomFont fonts: - asset: fonts/custom.ttf \ No newline at end of file diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 8b6d468..9372fc5 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,6 +6,9 @@ #include "generated_plugin_registrant.h" +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + WindowSizePluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("WindowSizePlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 93f25e1..2f5dad0 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + window_size ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/windows/runner/main.cpp b/windows/runner/main.cpp index 3d36cf7..d4f7cbd 100644 --- a/windows/runner/main.cpp +++ b/windows/runner/main.cpp @@ -27,7 +27,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, FlutterWindow window(project); Win32Window::Point origin(10, 10); Win32Window::Size size(1280, 720); - if (!window.Create(L"task_hub", origin, size)) { + if (!window.Create(L"TaskHub", origin, size)) { return EXIT_FAILURE; } window.SetQuitOnClose(true); diff --git a/windows/runner/resources/app_icon.ico b/windows/runner/resources/app_icon.ico index c04e20c..fe61b28 100644 Binary files a/windows/runner/resources/app_icon.ico and b/windows/runner/resources/app_icon.ico differ