feat: Initial commit
This commit is contained in:
77
lib/main.dart
Normal file
77
lib/main.dart
Normal file
@@ -0,0 +1,77 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
import 'package:winui_n2n/application_exit_control.dart';
|
||||
import 'package:winui_n2n/edge_state.dart';
|
||||
import 'package:winui_n2n/shared_pref_singleton.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await windowManager.ensureInitialized();
|
||||
|
||||
WindowOptions windowOptions = const WindowOptions(
|
||||
size: Size(630, 420),
|
||||
center: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
skipTaskbar: false,
|
||||
titleBarStyle: TitleBarStyle.normal,
|
||||
windowButtonVisibility: false,
|
||||
);
|
||||
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||
await windowManager.show();
|
||||
await windowManager.focus();
|
||||
});
|
||||
|
||||
await initSingleton();
|
||||
runApp(const MainApp());
|
||||
}
|
||||
|
||||
class MainApp extends StatefulWidget {
|
||||
const MainApp({super.key});
|
||||
|
||||
@override
|
||||
State<MainApp> createState() => _MainAppState();
|
||||
|
||||
static _MainAppState of(BuildContext context) {
|
||||
return context.findAncestorStateOfType<_MainAppState>()!;
|
||||
}
|
||||
}
|
||||
|
||||
class _MainAppState extends State<MainApp> {
|
||||
// false = dark, true = light
|
||||
ThemeMode _themeMode =
|
||||
SharedPrefSingleton().appTheme ? ThemeMode.light : ThemeMode.dark;
|
||||
ThemeMode get getCurrentTheme => _themeMode;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(),
|
||||
darkTheme: ThemeData.dark(),
|
||||
themeMode: _themeMode,
|
||||
home: const Scaffold(
|
||||
body: ApplicationExitControl(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void changeTheme(ThemeMode mode) {
|
||||
mode == ThemeMode.light
|
||||
? SharedPrefSingleton().setAppTheme(true).then((onValue) {
|
||||
setState(() {
|
||||
_themeMode = mode;
|
||||
});
|
||||
})
|
||||
: SharedPrefSingleton().setAppTheme(false).then((onValue) {
|
||||
setState(() {
|
||||
_themeMode = mode;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> initSingleton() async {
|
||||
EdgeState.instance;
|
||||
await SharedPrefSingleton().initialize();
|
||||
}
|
Reference in New Issue
Block a user