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';
|
2023-12-29 21:39:54 +01:00
|
|
|
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();
|
2023-12-29 21:39:54 +01:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2023-12-29 21:39:54 +01:00
|
|
|
/// Global logger for debugging
|
2023-09-08 11:50:21 +02:00
|
|
|
final logger = Logger();
|
|
|
|
|
2023-12-29 21:39:54 +01:00
|
|
|
/// The application itself
|
2023-09-08 11:50:21 +02:00
|
|
|
class MyApp extends StatelessWidget {
|
2023-12-29 21:39:54 +01:00
|
|
|
/// The application itself
|
2024-01-22 14:41:16 +01:00
|
|
|
const MyApp({super.key, this.locale});
|
2023-12-29 21:39:54 +01:00
|
|
|
|
|
|
|
/// If Material You was applied
|
|
|
|
///
|
|
|
|
/// Used to check if it is supported
|
2023-12-25 20:29:51 +01:00
|
|
|
static bool appliedYou = false;
|
2024-01-22 14:41:16 +01:00
|
|
|
|
|
|
|
/// 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,
|
2023-12-29 21:39:54 +01:00
|
|
|
...GlobalCupertinoLocalizations.delegates,
|
2023-12-25 20:29:51 +01:00
|
|
|
],
|
|
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
2024-01-22 14:41:16 +01:00
|
|
|
locale: locale,
|
2023-12-25 20:29:51 +01:00
|
|
|
title: 'Prašule',
|
|
|
|
theme: ThemeData(
|
2023-12-29 21:39:54 +01:00
|
|
|
colorScheme: _materialYou
|
2023-12-25 20:29:51 +01:00
|
|
|
? light ?? lightColorScheme
|
|
|
|
: lightColorScheme,
|
|
|
|
useMaterial3: true,
|
|
|
|
),
|
|
|
|
darkTheme: ThemeData(
|
2023-12-29 21:39:54 +01:00
|
|
|
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(
|
2023-09-14 18:12:28 +02:00
|
|
|
data: ThemeData(
|
2023-12-29 21:39:54 +01:00
|
|
|
useMaterial3: true,
|
|
|
|
colorScheme:
|
|
|
|
(MediaQuery.of(context).platformBrightness == Brightness.dark)
|
|
|
|
? darkColorScheme
|
|
|
|
: lightColorScheme,
|
|
|
|
),
|
2024-01-29 23:29:15 +01:00
|
|
|
child: CupertinoApp(
|
|
|
|
localizationsDelegates: const [
|
2024-01-09 00:31:03 +01:00
|
|
|
AppLocalizations.delegate,
|
|
|
|
...GlobalMaterialLocalizations.delegates,
|
|
|
|
...GlobalCupertinoLocalizations.delegates,
|
|
|
|
],
|
2023-09-08 11:50:21 +02:00
|
|
|
title: 'Prašule',
|
2024-01-29 23:31:11 +01:00
|
|
|
home: DefaultTextStyle(
|
|
|
|
style: TextStyle(
|
|
|
|
color: ((MediaQuery.of(context).platformBrightness ==
|
|
|
|
Brightness.dark)
|
|
|
|
? darkColorScheme
|
|
|
|
: lightColorScheme)
|
|
|
|
.onPrimary,
|
|
|
|
),
|
|
|
|
child: const HomeView(),
|
|
|
|
),
|
2023-09-08 11:50:21 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|