prasule/lib/main.dart
2023-12-25 20:29:51 +01:00

70 lines
2.4 KiB
Dart

import 'dart:io';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:logger/logger.dart';
import 'package:prasule/util/color_schemes.g.dart';
import 'package:prasule/views/home.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:shared_preferences/shared_preferences.dart';
var _materialYou = false;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
var s = await SharedPreferences.getInstance();
_materialYou = s.getBool("useMaterialYou") ?? true;
runApp(const MyApp());
}
final logger = Logger();
class MyApp extends StatelessWidget {
const MyApp({super.key});
static bool appliedYou = false;
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return (Platform.isAndroid)
? DynamicColorBuilder(
builder: (light, dark) {
appliedYou = light != null;
return MaterialApp(
debugShowCheckedModeBanner: false,
localizationsDelegates: const [
AppLocalizations.delegate,
...GlobalMaterialLocalizations.delegates,
...GlobalCupertinoLocalizations.delegates
],
supportedLocales: AppLocalizations.supportedLocales,
title: 'Prašule',
theme: ThemeData(
colorScheme: (_materialYou)
? light ?? lightColorScheme
: lightColorScheme,
useMaterial3: true,
),
darkTheme: ThemeData(
useMaterial3: true,
colorScheme: (_materialYou)
? dark ?? darkColorScheme
: darkColorScheme),
home: const HomeView(),
);
},
)
: Theme(
data: ThemeData(
useMaterial3: true,
colorScheme: (MediaQuery.of(context).platformBrightness ==
Brightness.dark)
? darkColorScheme
: lightColorScheme),
child: const CupertinoApp(
title: 'Prašule',
home: HomeView(),
),
);
}
}