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
+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(() {});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user