prasule/lib/main.dart

71 lines
2.4 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';
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-10-11 18:37:18 +02:00
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:shared_preferences/shared_preferences.dart';
2023-09-08 11:50:21 +02:00
var _materialYou = false;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
var s = await SharedPreferences.getInstance();
_materialYou = s.getBool("useMaterialYou") ?? true;
2023-09-08 11:50:21 +02:00
runApp(const MyApp());
}
final logger = Logger();
class MyApp extends StatelessWidget {
const MyApp({super.key});
static bool appliedYou = false;
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(
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(),
);
},
2023-09-08 11:50:21 +02:00
)
: Theme(
data: ThemeData(
useMaterial3: true,
colorScheme: (MediaQuery.of(context).platformBrightness ==
Brightness.dark)
? darkColorScheme
: lightColorScheme),
2023-09-08 11:50:21 +02:00
child: const CupertinoApp(
title: 'Prašule',
home: HomeView(),
),
);
}
}