165 lines
5.1 KiB
Dart
165 lines
5.1 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());
|
|
}
|
|
|
|
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: Colors.transparent,
|
|
),
|
|
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> {
|
|
int width = 800;
|
|
int height = 1200;
|
|
|
|
Future<void> onClickEnter() async {
|
|
resetScreen();
|
|
Navigator.push(
|
|
context,
|
|
PageRouteBuilder<void>(
|
|
opaque: false,
|
|
pageBuilder: (_, __, ___) => const ImagePage(),
|
|
));
|
|
}
|
|
|
|
@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());
|
|
await windowManager.setBounds(null, position: null, size: size, animate: true);
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
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'),
|
|
keyboardType: TextInputType.number,
|
|
inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly],
|
|
onChanged: (number) {
|
|
width = int.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'),
|
|
keyboardType: TextInputType.number,
|
|
inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly],
|
|
onChanged: (number) {
|
|
height = int.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(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
'(image width will be width - 100)'.toText(size: 10.dp, color: Colors.grey),
|
|
30.dp.gapColumn,
|
|
EasyButton(
|
|
text: 'Enter',
|
|
onPressed: () => onClickEnter(),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|