muzzle-velocity/lib/main.dart

81 lines
2.2 KiB
Dart
Raw Normal View History

2025-02-22 21:14:35 +02:00
import 'package:flutter/foundation.dart';
2025-02-20 22:40:41 +02:00
import 'package:flutter/material.dart';
2025-02-22 21:14:35 +02:00
import 'package:flutter/services.dart';
2025-02-20 22:40:41 +02:00
import 'package:google_fonts/google_fonts.dart';
2025-02-21 22:02:06 +02:00
import 'package:permission_handler/permission_handler.dart';
2025-02-21 22:51:56 +02:00
import 'themes/day.dart';
import 'themes/night.dart';
import 'note_list.dart';
2025-02-21 22:02:06 +02:00
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Permission.storage.request();
2025-02-22 21:14:35 +02:00
LicenseRegistry.addLicense(() async* {
final license = await rootBundle.loadString('google_fonts/OFL.txt');
yield LicenseEntryWithLineBreaks(['google_fonts'], license);
});
2025-02-20 22:40:41 +02:00
runApp(MuzzleVelocityApp());
}
class MuzzleVelocityApp extends StatefulWidget {
@override
_MuzzleVelocityAppState createState() => _MuzzleVelocityAppState();
}
class _MuzzleVelocityAppState extends State<MuzzleVelocityApp> {
ThemeMode _themeMode = ThemeMode.system;
bool showTags = true;
2025-02-21 17:02:51 +02:00
@override
void initState() {
super.initState();
// Ensure the correct theme mode is set on startup
2025-02-21 22:51:56 +02:00
_themeMode =
WidgetsBinding.instance.window.platformBrightness == Brightness.dark
? ThemeMode.dark
: ThemeMode.light;
2025-02-21 17:02:51 +02:00
}
2025-02-20 22:40:41 +02:00
void _toggleTheme(bool darkMode) {
if (mounted) {
setState(() {
_themeMode = darkMode ? ThemeMode.dark : ThemeMode.light;
});
}
}
void _toggleTags() {
if (mounted) {
setState(() {
showTags = !showTags;
});
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Muzzle Velocity',
theme: ThemeData(
brightness: Brightness.light,
2025-02-21 17:46:41 +02:00
scaffoldBackgroundColor: Color(0xffF6F4F1),
appBarTheme: AppBarTheme(backgroundColor: Color(0xffF6F4F1)),
2025-02-21 22:02:06 +02:00
textTheme: GoogleFonts.ibmPlexMonoTextTheme(dayText),
2025-02-20 22:40:41 +02:00
),
darkTheme: ThemeData(
brightness: Brightness.dark,
2025-02-21 17:46:41 +02:00
scaffoldBackgroundColor: Color(0xFF121212),
appBarTheme: AppBarTheme(backgroundColor: Color(0xFF121212)),
2025-02-21 22:02:06 +02:00
textTheme: GoogleFonts.ibmPlexMonoTextTheme(nightText),
2025-02-20 22:40:41 +02:00
),
themeMode: _themeMode,
home: NoteListScreen(
toggleTheme: _toggleTheme,
toggleTags: _toggleTags,
isDarkMode: _themeMode == ThemeMode.dark,
showTags: showTags,
),
);
}
}