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';
|
2024-06-30 11:30:07 +02:00
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
import 'package:prasule/api/wallet_manager.dart';
|
2023-09-08 11:50:21 +02:00
|
|
|
import 'package:prasule/util/color_schemes.g.dart';
|
|
|
|
import 'package:prasule/views/home.dart';
|
2024-06-30 11:30:07 +02:00
|
|
|
import 'package:prasule/views/initialization_screen.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;
|
2024-06-30 11:30:07 +02:00
|
|
|
|
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.
|
2024-06-30 11:30:07 +02:00
|
|
|
|
2023-09-08 11:50:21 +02:00
|
|
|
@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,
|
|
|
|
),
|
2024-06-30 11:30:07 +02:00
|
|
|
home: const InitializationScreen(),
|
2023-12-25 20:29:51 +01:00
|
|
|
);
|
|
|
|
},
|
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,
|
|
|
|
),
|
2023-09-08 11:50:21 +02:00
|
|
|
child: const CupertinoApp(
|
2024-01-09 00:31:03 +01:00
|
|
|
localizationsDelegates: [
|
|
|
|
AppLocalizations.delegate,
|
|
|
|
...GlobalMaterialLocalizations.delegates,
|
|
|
|
...GlobalCupertinoLocalizations.delegates,
|
|
|
|
],
|
2023-09-08 11:50:21 +02:00
|
|
|
title: 'Prašule',
|
2024-06-30 11:30:07 +02:00
|
|
|
home: InitializationScreen(),
|
2023-09-08 11:50:21 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|