prasule/lib/main.dart

93 lines
2.9 KiB
Dart
Raw Normal View History

2023-09-08 11:50:21 +02:00
import 'dart:io';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2023-10-11 18:37:18 +02:00
import 'package:flutter_localizations/flutter_localizations.dart';
2023-09-08 11:50:21 +02:00
import 'package:logger/logger.dart';
import 'package:prasule/util/color_schemes.g.dart';
import 'package:prasule/views/home.dart';
2023-12-25 20:29:51 +01:00
import 'package:shared_preferences/shared_preferences.dart';
2023-09-08 11:50:21 +02:00
2023-12-25 20:29:51 +01:00
var _materialYou = false;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final s = await SharedPreferences.getInstance();
if (!Platform.isAndroid) {
await s.setBool("useMaterialYou", false);
}
2023-12-25 20:29:51 +01:00
_materialYou = s.getBool("useMaterialYou") ?? true;
2023-09-08 11:50:21 +02:00
runApp(const MyApp());
}
/// Global logger for debugging
2023-09-08 11:50:21 +02:00
final logger = Logger();
/// The application itself
2023-09-08 11:50:21 +02:00
class MyApp extends StatelessWidget {
/// The application itself
const MyApp({super.key, this.locale});
/// If Material You was applied
///
/// Used to check if it is supported
2023-12-25 20:29:51 +01:00
static bool appliedYou = false;
/// Override locale, used for testing
final Locale? locale;
2023-09-08 11:50:21 +02:00
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return (Platform.isAndroid)
? DynamicColorBuilder(
2023-12-25 20:29:51 +01:00
builder: (light, dark) {
appliedYou = light != null;
return MaterialApp(
debugShowCheckedModeBanner: false,
localizationsDelegates: const [
AppLocalizations.delegate,
...GlobalMaterialLocalizations.delegates,
...GlobalCupertinoLocalizations.delegates,
2023-12-25 20:29:51 +01:00
],
supportedLocales: AppLocalizations.supportedLocales,
locale: locale,
2023-12-25 20:29:51 +01:00
title: 'Prašule',
theme: ThemeData(
colorScheme: _materialYou
2023-12-25 20:29:51 +01:00
? light ?? lightColorScheme
: lightColorScheme,
useMaterial3: true,
),
darkTheme: ThemeData(
useMaterial3: true,
colorScheme:
_materialYou ? dark ?? darkColorScheme : darkColorScheme,
),
2023-12-25 20:29:51 +01:00
home: const HomeView(),
);
},
2023-09-08 11:50:21 +02:00
)
: Theme(
data: ThemeData(
useMaterial3: true,
colorScheme:
(MediaQuery.of(context).platformBrightness == Brightness.dark)
? darkColorScheme
: lightColorScheme,
),
2024-01-29 23:38:49 +01:00
child: const CupertinoApp(
localizationsDelegates: [
AppLocalizations.delegate,
...GlobalMaterialLocalizations.delegates,
...GlobalCupertinoLocalizations.delegates,
],
2023-09-08 11:50:21 +02:00
title: 'Prašule',
2024-01-29 23:38:49 +01:00
home: HomeView(),
2023-09-08 11:50:21 +02:00
),
);
}
}