211 lines
6.8 KiB
Dart
211 lines
6.8 KiB
Dart
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';
|
|
|
|
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 = WindowOptions(
|
|
size: Size(width, height),
|
|
);
|
|
|
|
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
|
await windowManager.show();
|
|
await windowManager.focus();
|
|
});
|
|
|
|
windowManager.addListener(WindowListenerImp());
|
|
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
var primaryColor = Colors.green;
|
|
var secondaryColor = Colors.green;
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
// This widget is the root of your application.
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
builder: BotToastInit(),
|
|
title: 'Pixel eye',
|
|
theme: ThemeData(
|
|
primaryColor: primaryColor,
|
|
colorScheme: ColorScheme.light(
|
|
secondary: secondaryColor,
|
|
primary: primaryColor,
|
|
),
|
|
appBarTheme: AppBarTheme(
|
|
backgroundColor: primaryColor,
|
|
),
|
|
),
|
|
|
|
navigatorObservers: [BotToastNavigatorObserver()],
|
|
//2. registered route observer
|
|
home: Builder(builder: (context) {
|
|
screenSize = MediaQuery.of(context).size;
|
|
return const MyHomePage(title: 'Pixel eye');
|
|
}),
|
|
);
|
|
}
|
|
}
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
const MyHomePage({super.key, required this.title});
|
|
|
|
final String title;
|
|
|
|
@override
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
}
|
|
|
|
class _MyHomePageState extends State<MyHomePage> with WindowListener {
|
|
double width = 800;
|
|
double height = 1200;
|
|
|
|
double paddingWidth = 100;
|
|
|
|
Future<void> onClickEnter() async {
|
|
resetScreen();
|
|
await Navigator.push(
|
|
context,
|
|
PageRouteBuilder<void>(
|
|
opaque: false,
|
|
pageBuilder: (_, __, ___) => ImagePage(paddingWidth: paddingWidth.toInt()),
|
|
));
|
|
getScreenSize();
|
|
}
|
|
|
|
@override
|
|
initState() {
|
|
super.initState();
|
|
getScreenSize();
|
|
}
|
|
|
|
@override
|
|
void onWindowResize() {
|
|
super.onWindowResize();
|
|
}
|
|
|
|
void getScreenSize() {
|
|
width = SP.getDouble(Consts.widthKey, 800);
|
|
height = SP.getDouble(Consts.heightKey, 1200);
|
|
setState(() {});
|
|
}
|
|
|
|
Future<void> resetScreen() async {
|
|
var size = Size(width, height);
|
|
await windowManager.setBounds(null, position: null, size: size, animate: true);
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var size = MediaQuery.of(context).size;
|
|
width = size.width;
|
|
height = size.height;
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(widget.title),
|
|
),
|
|
body: Center(
|
|
child: Padding(
|
|
padding: EdgeInsets.all(8.dp),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
'width:'.toText(size: 9.dp),
|
|
SizedBox(
|
|
height: 20.dp,
|
|
width: 50.dp,
|
|
child: TextField(
|
|
controller: TextEditingController(text: '${width.toInt()}'),
|
|
keyboardType: TextInputType.number,
|
|
inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly],
|
|
onChanged: (number) {
|
|
width = double.tryParse(number) ?? 800;
|
|
},
|
|
style: TextStyle(fontSize: 14.dp, fontWeight: FontWeight.w600),
|
|
decoration: InputDecoration(
|
|
contentPadding: EdgeInsets.all(2.dp),
|
|
hintStyle: TextStyle(fontSize: 14.dp, color: Colors.grey, fontWeight: FontWeight.w600),
|
|
),
|
|
onSubmitted: (_) => onClickEnter(),
|
|
),
|
|
),
|
|
'height:'.toText(size: 9.dp),
|
|
SizedBox(
|
|
height: 20.dp,
|
|
width: 50.dp,
|
|
child: TextField(
|
|
controller: TextEditingController(text: '${height.toInt()}'),
|
|
keyboardType: TextInputType.number,
|
|
inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly],
|
|
onChanged: (number) {
|
|
height = double.tryParse(number) ?? 800;
|
|
},
|
|
style: TextStyle(fontSize: 14.dp, fontWeight: FontWeight.w600),
|
|
decoration: InputDecoration(
|
|
contentPadding: EdgeInsets.all(2.dp),
|
|
hintStyle: TextStyle(fontSize: 14.dp, color: Colors.grey, fontWeight: FontWeight.w600),
|
|
),
|
|
onSubmitted: (_) => onClickEnter(),
|
|
),
|
|
),
|
|
20.gapRow,
|
|
'paddingWidth:'.toText(size: 9.dp),
|
|
SizedBox(
|
|
height: 20.dp,
|
|
width: 50.dp,
|
|
child: TextField(
|
|
controller: TextEditingController(text: '${paddingWidth.toInt()}'),
|
|
keyboardType: TextInputType.number,
|
|
inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly],
|
|
onChanged: (number) {
|
|
paddingWidth = double.tryParse(number) ?? 100;
|
|
},
|
|
style: TextStyle(fontSize: 14.dp, fontWeight: FontWeight.w600),
|
|
decoration: InputDecoration(
|
|
contentPadding: EdgeInsets.all(2.dp),
|
|
hintStyle: TextStyle(fontSize: 14.dp, color: Colors.grey, fontWeight: FontWeight.w600),
|
|
),
|
|
onSubmitted: (_) => onClickEnter(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
'(image width will be width - paddingWidth)'.toText(size: 10.dp, color: Colors.grey),
|
|
30.dp.gapColumn,
|
|
EasyButton(
|
|
text: 'Enter',
|
|
onPressed: () => onClickEnter(),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|