support primary color

This commit is contained in:
Siyi Guo committed 2023-04-13 16:43:48 +08:00
1 parent 595ee6fd6a
commit 90f53a0578
3 files changed
+39 -15

No files matched your search

-1
View File
@@ -38,7 +38,6 @@ class _ImagePageState extends State<ImagePage> with WindowListener {
SizedBox( SizedBox(
width: 50.dp, width: 50.dp,
child: EasyButton( child: EasyButton(
color: Colors.blue,
text: 'reset', text: 'reset',
onPressed: () { onPressed: () {
offsetDx1 = 0; offsetDx1 = 0;
+37 -12
View File
@@ -34,6 +34,9 @@ void main() async {
runApp(const MyApp()); runApp(const MyApp());
} }
var primaryColor = Colors.green;
var secondaryColor = Colors.green;
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({super.key}); const MyApp({super.key});
@@ -45,8 +48,16 @@ class MyApp extends StatelessWidget {
builder: BotToastInit(), builder: BotToastInit(),
title: 'Pixel eye', title: 'Pixel eye',
theme: ThemeData( theme: ThemeData(
primaryColor: Colors.transparent, primaryColor: primaryColor,
colorScheme: ColorScheme.light(
secondary: secondaryColor,
primary: primaryColor,
), ),
appBarTheme: AppBarTheme(
backgroundColor: primaryColor,
),
),
navigatorObservers: [BotToastNavigatorObserver()], navigatorObservers: [BotToastNavigatorObserver()],
//2. registered route observer //2. registered route observer
home: Builder(builder: (context) { home: Builder(builder: (context) {
@@ -66,36 +77,50 @@ class MyHomePage extends StatefulWidget {
State<MyHomePage> createState() => _MyHomePageState(); State<MyHomePage> createState() => _MyHomePageState();
} }
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> with WindowListener {
int width = 800; double width = 800;
int height = 1200; double height = 1200;
Future<void> onClickEnter() async { Future<void> onClickEnter() async {
resetScreen(); resetScreen();
Navigator.push( await Navigator.push(
context, context,
PageRouteBuilder<void>( PageRouteBuilder<void>(
opaque: false, opaque: false,
pageBuilder: (_, __, ___) => const ImagePage(), pageBuilder: (_, __, ___) => const ImagePage(),
)); ));
getScreenSize();
} }
@override @override
initState() { initState() {
super.initState(); super.initState();
width = SP.getDouble(Consts.widthKey, 800).toInt(); getScreenSize();
height = SP.getDouble(Consts.heightKey, 1200).toInt(); }
@override
void onWindowResize() {
super.onWindowResize();
}
void getScreenSize() {
width = SP.getDouble(Consts.widthKey, 800);
height = SP.getDouble(Consts.heightKey, 1200);
setState(() {}); setState(() {});
} }
Future<void> resetScreen() async { Future<void> resetScreen() async {
var size = Size(width.toDouble(), height.toDouble()); var size = Size(width, height);
await windowManager.setBounds(null, position: null, size: size, animate: true); await windowManager.setBounds(null, position: null, size: size, animate: true);
setState(() {}); setState(() {});
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
width = size.width;
height = size.height;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(widget.title), title: Text(widget.title),
@@ -114,11 +139,11 @@ class _MyHomePageState extends State<MyHomePage> {
height: 20.dp, height: 20.dp,
width: 50.dp, width: 50.dp,
child: TextField( child: TextField(
controller: TextEditingController(text: '$width'), controller: TextEditingController(text: '${width.toInt()}'),
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly], inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly],
onChanged: (number) { onChanged: (number) {
width = int.tryParse(number) ?? 800; width = double.tryParse(number) ?? 800;
}, },
style: TextStyle(fontSize: 14.dp, fontWeight: FontWeight.w600), style: TextStyle(fontSize: 14.dp, fontWeight: FontWeight.w600),
decoration: InputDecoration( decoration: InputDecoration(
@@ -133,11 +158,11 @@ class _MyHomePageState extends State<MyHomePage> {
height: 20.dp, height: 20.dp,
width: 50.dp, width: 50.dp,
child: TextField( child: TextField(
controller: TextEditingController(text: '$height'), controller: TextEditingController(text: '${height.toInt()}'),
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly], inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly],
onChanged: (number) { onChanged: (number) {
height = int.tryParse(number) ?? 800; height = double.tryParse(number) ?? 800;
}, },
style: TextStyle(fontSize: 14.dp, fontWeight: FontWeight.w600), style: TextStyle(fontSize: 14.dp, fontWeight: FontWeight.w600),
decoration: InputDecoration( decoration: InputDecoration(
+2 -2
View File
@@ -41,13 +41,13 @@ class EasyButton extends StatelessWidget {
if (states.contains(MaterialState.disabled)) { if (states.contains(MaterialState.disabled)) {
return Colors.grey.withOpacity(0.5); return Colors.grey.withOpacity(0.5);
} }
return color ?? (type == ButtonType.secondary ? Colors.white : Colors.blue); return color ?? (type == ButtonType.secondary ? Colors.white : Theme.of(context).primaryColor);
}), }),
foregroundColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) { foregroundColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) { if (states.contains(MaterialState.disabled)) {
return Colors.grey.withOpacity(0.1); return Colors.grey.withOpacity(0.1);
} }
return color ?? (type == ButtonType.secondary ? Colors.white : Colors.blue); return color ?? (type == ButtonType.secondary ? Colors.white : Theme.of(context).primaryColor);
}), }),
minimumSize: MaterialStateProperty.all(Size(minWidth, height)), minimumSize: MaterialStateProperty.all(Size(minWidth, height)),
shape: MaterialStateProperty.all( shape: MaterialStateProperty.all(