适配windows(测试)

This commit is contained in:
DelLevin-Home
2026-06-30 23:01:37 +08:00
parent 1192f8f7e0
commit afd012b766
9 changed files with 75 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:io';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -7,6 +8,7 @@ import 'package:provider/provider.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter_quill/flutter_quill.dart' as quill;
import 'package:url_launcher/url_launcher.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'pages/home_page.dart';
import 'utils/theme/app_theme.dart';
import 'utils/app_router.dart';
@@ -21,6 +23,11 @@ final RouteObserver<ModalRoute<void>> routeObserver = RouteObserver<ModalRoute<v
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Windows 桌面:使用 FFI 初始化 sqflite
if (Platform.isWindows) {
sqfliteFfiInit();
databaseFactory = databaseFactoryFfi;
}
await UserPrefs.init();
final appProvider = AppProvider();
runApp(MyApp(appProvider: appProvider));

View File

@@ -977,17 +977,19 @@ class _SettingsPageState extends State<SettingsPage> {
body: ListView(
children: [
_buildSectionHeader('显示设置'),
_buildNavigationItem(
icon: Icons.apps_outlined,
title: '应用图标',
subtitle: '更换桌面应用图标',
onTap: () => Navigator.push(context,
MaterialPageRoute(builder: (_) => const AppIconPickerPage())),
),
Divider(
height: 0.5,
indent: 24,
endIndent: 24,
if (!Platform.isWindows)
_buildNavigationItem(
icon: Icons.apps_outlined,
title: '应用图标',
subtitle: '更换桌面应用图标',
onTap: () => Navigator.push(context,
MaterialPageRoute(builder: (_) => const AppIconPickerPage())),
),
if (!Platform.isWindows)
Divider(
height: 0.5,
indent: 24,
endIndent: 24,
color: colors.outlineVariant),
_buildNavigationItem(
icon: Icons.tune_outlined,

View File

@@ -1,4 +1,6 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import '../models/data_models.dart';
import 'slide_up_page_route.dart';
import '../pages/movies/movie_form_page.dart';
@@ -13,7 +15,7 @@ import '../pages/note_plus/note_plus_detail_page.dart';
/// 路由生成器
class AppRouter {
static Route<dynamic> generateRoute(RouteSettings settings) {
static Route<dynamic>? generateRoute(RouteSettings settings) {
switch (settings.name) {
case '/movie-form':
final args = settings.arguments;
@@ -64,6 +66,11 @@ class AppRouter {
if (url == null) {
return _buildUnknownRoute(settings.name);
}
if (Platform.isWindows) {
// Windows 无 webview 支持,用系统浏览器打开
launchUrl(Uri.parse(url));
return null;
}
return SlideUpPageRoute(page: DoubanWebViewPage(url: url));
case '/note-plus-form':

View File

@@ -453,6 +453,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.4.0"
glob:
dependency: transitive
description:
name: glob
sha256: c3f1ee72c96f8f78935e18aa8cecced9ab132419e8625dc187e1c2408efc20de
url: "https://pub.dev"
source: hosted
version: "2.1.3"
hooks:
dependency: transitive
description:
@@ -669,6 +677,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.0"
native_toolchain_c:
dependency: transitive
description:
name: native_toolchain_c
sha256: f9c168717100ae6d9fee9ffb0be379bf1f8b26b0f6bcbd4fdddcd931993a6a72
url: "https://pub.dev"
source: hosted
version: "0.19.2"
nested:
dependency: transitive
description:
@@ -1034,6 +1050,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.5.8"
sqflite_common_ffi:
dependency: "direct main"
description:
name: sqflite_common_ffi
sha256: cd0c7f7de39a08f2d54ef144d9058c46eca8461879aaa648025643455c1e5a20
url: "https://pub.dev"
source: hosted
version: "2.4.0+3"
sqflite_darwin:
dependency: transitive
description:
@@ -1050,6 +1074,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.4.0"
sqlite3:
dependency: transitive
description:
name: sqlite3
sha256: "37356bcb56ce0d9404d602c41e4bdb7765e7e9732a3e47adb3d98c556a6abdad"
url: "https://pub.dev"
source: hosted
version: "3.3.3"
stack_trace:
dependency: transitive
description:

View File

@@ -15,6 +15,7 @@ dependencies:
provider: ^6.1.2
fl_chart: ^0.69.0
sqflite: ^2.3.0
sqflite_common_ffi: ^2.3.0
path: ^1.8.3
image_picker: ^1.0.4
path_provider: ^2.1.1

View File

@@ -38,3 +38,10 @@ target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
# Run the Flutter tool portions of the build. This must not be removed.
add_dependencies(${BINARY_NAME} flutter_assemble)
# Bundle sqlite3.dll for sqflite_common_ffi
add_custom_command(TARGET ${BINARY_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/sqlite3.dll"
"$<TARGET_FILE_DIR:${BINARY_NAME}>/sqlite3.dll"
)

View File

@@ -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"mooknote", origin, size)) {
if (!window.Create(L"MookNote", origin, size)) {
return EXIT_FAILURE;
}
window.SetQuitOnClose(true);

BIN
windows/runner/sqlite3.dll Normal file

Binary file not shown.

View File

@@ -197,6 +197,12 @@ Win32Window::MessageHandler(HWND hwnd,
return 0;
}
case WM_GETMINMAXINFO: {
auto info = reinterpret_cast<MINMAXINFO*>(lparam);
info->ptMinTrackSize.x = 360;
info->ptMinTrackSize.y = 640;
return 0;
}
case WM_SIZE: {
RECT rect = GetClientArea();
if (child_content_ != nullptr) {