add sp and support save the width and height
This commit is contained in:
1 parent
1c53032b3f
commit
595ee6fd6a
9 files changed
+187
-10
No files matched your search
@@ -0,0 +1,4 @@
|
||||
mixin Consts {
|
||||
static const widthKey = 'window.width';
|
||||
static const heightKey = 'window.height';
|
||||
}
|
||||
@@ -28,7 +28,6 @@ class _ImagePageState extends State<ImagePage> with WindowListener {
|
||||
double offsetDy1 = 0;
|
||||
double offsetDx2 = 0;
|
||||
double offsetDy2 = 0;
|
||||
var windowFocusNode = FocusNode(canRequestFocus: false);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -84,7 +83,6 @@ class _ImagePageState extends State<ImagePage> with WindowListener {
|
||||
moveChanged: (dx, dy) {
|
||||
offsetDx1 = dx;
|
||||
offsetDy1 = dy;
|
||||
// setState(() {});
|
||||
},
|
||||
dx: offsetDx1,
|
||||
dy: offsetDy1,
|
||||
@@ -97,8 +95,6 @@ class _ImagePageState extends State<ImagePage> with WindowListener {
|
||||
moveChanged: (dx, dy) {
|
||||
offsetDx2 = dx;
|
||||
offsetDy2 = dy;
|
||||
windowFocusNode.unfocus();
|
||||
// setState(() {});
|
||||
},
|
||||
dx: offsetDx2,
|
||||
dy: offsetDy2,
|
||||
@@ -119,10 +115,10 @@ class _ImagePageState extends State<ImagePage> with WindowListener {
|
||||
double dy = 0,
|
||||
Function(double dx, double dy)? moveChanged,
|
||||
}) {
|
||||
var width = MediaQuery.of(context).size.width - 100;
|
||||
if (!show || imageFile == null) {
|
||||
return const SizedBox();
|
||||
}
|
||||
var width = MediaQuery.of(context).size.width - 100;
|
||||
return DraggableArea(
|
||||
key: ValueKey('${DateTime.now()}'),
|
||||
dx: dx,
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
import 'package:px_eye/const/const.dart';
|
||||
import 'package:px_eye/extension/extension.dart';
|
||||
import 'package:px_eye/sp/sp.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
class WindowListenerImp extends WindowListener {
|
||||
@override
|
||||
void onWindowResized() {
|
||||
super.onWindowResized();
|
||||
saveWindowSize();
|
||||
}
|
||||
|
||||
void saveWindowSize() async {
|
||||
var size = await windowManager.getSize();
|
||||
screenSize = size;
|
||||
SP.setDouble(Consts.widthKey, size.width);
|
||||
SP.setDouble(Consts.heightKey, size.height);
|
||||
}
|
||||
}
|
||||
+23
-5
@@ -1,7 +1,10 @@
|
||||
import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:px_eye/const/const.dart';
|
||||
import 'package:px_eye/image/image_page.dart';
|
||||
import 'package:px_eye/interface/window_interface.dart';
|
||||
import 'package:px_eye/sp/sp.dart';
|
||||
import 'package:px_eye/widget/button.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
@@ -9,17 +12,25 @@ import 'extension/extension.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
await SP.init();
|
||||
var width = SP.getDouble(Consts.widthKey, 800);
|
||||
var height = SP.getDouble(Consts.heightKey, 1200);
|
||||
|
||||
// Must add this line.
|
||||
await windowManager.ensureInitialized();
|
||||
|
||||
WindowOptions windowOptions = const WindowOptions(
|
||||
size: Size(800, 1600),
|
||||
WindowOptions windowOptions = WindowOptions(
|
||||
size: Size(width, height),
|
||||
);
|
||||
|
||||
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||
await windowManager.show();
|
||||
await windowManager.focus();
|
||||
});
|
||||
|
||||
windowManager.addListener(WindowListenerImp());
|
||||
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
@@ -57,7 +68,7 @@ class MyHomePage extends StatefulWidget {
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int width = 800;
|
||||
int height = 1600;
|
||||
int height = 1200;
|
||||
|
||||
Future<void> onClickEnter() async {
|
||||
resetScreen();
|
||||
@@ -69,10 +80,17 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
width = SP.getDouble(Consts.widthKey, 800).toInt();
|
||||
height = SP.getDouble(Consts.heightKey, 1200).toInt();
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Future<void> resetScreen() async {
|
||||
var size = Size(width.toDouble(), height.toDouble());
|
||||
Offset newPosition = await calcWindowPosition(size, Alignment.center);
|
||||
await windowManager.setBounds(null, position: newPosition, size: size, animate: true);
|
||||
await windowManager.setBounds(null, position: null, size: size, animate: true);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class SP {
|
||||
static late SharedPreferences prefs;
|
||||
|
||||
static Future<void> init() async {
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
}
|
||||
|
||||
static double getDouble(String key, [double def = 0]) {
|
||||
return prefs.getDouble(key) ?? def;
|
||||
}
|
||||
|
||||
static Future<bool> setDouble(String key, double value) {
|
||||
return prefs.setDouble(key, value);
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,11 @@ import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
import screen_retriever
|
||||
import shared_preferences_foundation
|
||||
import window_manager
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
|
||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
|
||||
}
|
||||
@@ -2,12 +2,16 @@ PODS:
|
||||
- FlutterMacOS (1.0.0)
|
||||
- screen_retriever (0.0.1):
|
||||
- FlutterMacOS
|
||||
- shared_preferences_foundation (0.0.1):
|
||||
- Flutter
|
||||
- FlutterMacOS
|
||||
- window_manager (0.2.0):
|
||||
- FlutterMacOS
|
||||
|
||||
DEPENDENCIES:
|
||||
- FlutterMacOS (from `Flutter/ephemeral`)
|
||||
- screen_retriever (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos`)
|
||||
- shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/macos`)
|
||||
- window_manager (from `Flutter/ephemeral/.symlinks/plugins/window_manager/macos`)
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
@@ -15,12 +19,15 @@ EXTERNAL SOURCES:
|
||||
:path: Flutter/ephemeral
|
||||
screen_retriever:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos
|
||||
shared_preferences_foundation:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/macos
|
||||
window_manager:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/window_manager/macos
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
|
||||
screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38
|
||||
shared_preferences_foundation: 986fc17f3d3251412d18b0265f9c64113a8c2472
|
||||
window_manager: 3a1844359a6295ab1e47659b1a777e36773cd6e8
|
||||
|
||||
PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7
|
||||
|
||||
+112
@@ -73,6 +73,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
file:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: file
|
||||
sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.4"
|
||||
file_picker:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -160,6 +168,38 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.8.2"
|
||||
path_provider_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_linux
|
||||
sha256: "2ae08f2216225427e64ad224a24354221c2c7907e448e6e0e8b57b1eb9f10ad1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.10"
|
||||
path_provider_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_platform_interface
|
||||
sha256: "57585299a729335f1298b43245842678cb9f43a6310351b18fb577d6e33165ec"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.6"
|
||||
path_provider_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_provider_windows
|
||||
sha256: f53720498d5a543f9607db4b0e997c4b5438884de25b0f73098cc2671a51b130
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.5"
|
||||
platform:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: platform
|
||||
sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
plugin_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -168,6 +208,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
process:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: process
|
||||
sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.2.4"
|
||||
screen_retriever:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -176,6 +224,62 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.6"
|
||||
shared_preferences:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: shared_preferences
|
||||
sha256: "858aaa72d8f61637d64e776aca82e1c67e6d9ee07979123c5d17115031c1b13b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
shared_preferences_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_android
|
||||
sha256: "8304d8a1f7d21a429f91dee552792249362b68a331ac5c3c1caf370f658873f6"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
shared_preferences_foundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_foundation
|
||||
sha256: "0c1c16c56c9708aa9c361541a6f0e5cc6fc12a3232d866a687a7b7db30032b07"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.1"
|
||||
shared_preferences_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_linux
|
||||
sha256: "9d387433ca65717bbf1be88f4d5bb18f10508917a8fa2fb02e0fd0d7479a9afa"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
shared_preferences_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_platform_interface
|
||||
sha256: fb5cf25c0235df2d0640ac1b1174f6466bd311f621574997ac59018a6664548d
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
shared_preferences_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_web
|
||||
sha256: "74083203a8eae241e0de4a0d597dbedab3b8fef5563f33cf3c12d7e93c655ca5"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
shared_preferences_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_windows
|
||||
sha256: "5e588e2efef56916a3b229c3bfe81e6a525665a454519ca51dbcc4236a274173"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
@@ -253,6 +357,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.3.2"
|
||||
xdg_directories:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: xdg_directories
|
||||
sha256: ee1505df1426458f7f60aac270645098d318a8b4766d85fde75f76f2e21807d1
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
sdks:
|
||||
dart: ">=2.19.4 <3.0.0"
|
||||
flutter: ">=3.0.0"
|
||||
@@ -38,6 +38,7 @@ dependencies:
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^1.0.2
|
||||
shared_preferences: ^2.1.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in new issue
Block a user