muzzle-velocity/lib/main.dart
2025-02-22 21:14:35 +02:00

80 lines
2.2 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:permission_handler/permission_handler.dart';
import 'themes/day.dart';
import 'themes/night.dart';
import 'note_list.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Permission.storage.request();
LicenseRegistry.addLicense(() async* {
final license = await rootBundle.loadString('google_fonts/OFL.txt');
yield LicenseEntryWithLineBreaks(['google_fonts'], license);
});
runApp(MuzzleVelocityApp());
}
class MuzzleVelocityApp extends StatefulWidget {
@override
_MuzzleVelocityAppState createState() => _MuzzleVelocityAppState();
}
class _MuzzleVelocityAppState extends State<MuzzleVelocityApp> {
ThemeMode _themeMode = ThemeMode.system;
bool showTags = true;
@override
void initState() {
super.initState();
// Ensure the correct theme mode is set on startup
_themeMode =
WidgetsBinding.instance.window.platformBrightness == Brightness.dark
? ThemeMode.dark
: ThemeMode.light;
}
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,
scaffoldBackgroundColor: Color(0xffF6F4F1),
appBarTheme: AppBarTheme(backgroundColor: Color(0xffF6F4F1)),
textTheme: GoogleFonts.ibmPlexMonoTextTheme(dayText),
),
darkTheme: ThemeData(
brightness: Brightness.dark,
scaffoldBackgroundColor: Color(0xFF121212),
appBarTheme: AppBarTheme(backgroundColor: Color(0xFF121212)),
textTheme: GoogleFonts.ibmPlexMonoTextTheme(nightText),
),
themeMode: _themeMode,
home: NoteListScreen(
toggleTheme: _toggleTheme,
toggleTags: _toggleTags,
isDarkMode: _themeMode == ThemeMode.dark,
showTags: showTags,
),
);
}
}