diff --git a/apps/onyx/build.yaml b/apps/onyx/build.yaml index d6160f7dc..3ff8f90ad 100644 --- a/apps/onyx/build.yaml +++ b/apps/onyx/build.yaml @@ -1,9 +1,11 @@ targets: $default: builders: - source_gen|combining_builder: - generate_for: - - lib/**.dart + # only to resolve build_runner conflicts + dart_mappable_builder: options: build_extensions: - 'lib/{{path}}/{{file}}.dart': 'lib/{{path}}/generated/{{file}}.g.dart' \ No newline at end of file + 'lib/{{path}}/{{file}}.dart': + - 'lib/{{path}}/generated/{{file}}.mapper.dart' + - 'lib/{{path}}/generated/{{file}}.init.dart' + diff --git a/apps/onyx/lib/core/cache_service.dart b/apps/onyx/lib/core/cache_service.dart index e3fa50085..4d1126344 100644 --- a/apps/onyx/lib/core/cache_service.dart +++ b/apps/onyx/lib/core/cache_service.dart @@ -1,62 +1,118 @@ import 'dart:convert'; import 'package:biometric_storage/biometric_storage.dart'; -import 'package:hive_ce_flutter/hive_flutter.dart'; +import 'package:dart_mappable/dart_mappable.dart'; +import 'package:izlyclient/izlyclient.dart'; +import 'package:lyon1casclient/lyon1casclient.dart'; import 'package:onyx/core/res.dart'; +import 'package:onyx/screens/settings/domain/model/theme_settings_model.dart'; +import 'package:sembast/sembast_io.dart'; + +import 'encrypt_codec.dart'; class CacheService { static List? secureKey; static BiometricStorageFile? _storageFile; static bool? _isBiometricEnabled; + static Database? db; + + static void resetDb() { + db = null; + } + + static Future _getDb({List? secureKey}) async { + if (db == null) { + throw Exception( + "CacheService not initialized. Call CacheService.init() first.", + ); + } + if (secureKey != null) { + // Utilisation du codec d'encryption Sembast (Salsa20) + final codec = getEncryptSembastCodec( + password: base64Url.encode(secureKey), + ); + return await databaseFactoryIo.openDatabase(db!.path, codec: codec); + } + return db!; + } + + static StoreRef _getStore() { + return StoreRef('cached_${E.toString()}'); + } static Future get({int index = 0, List? secureKey}) async { try { - Box box = await Hive.openBox( - "cached_$E", - encryptionCipher: (secureKey != null) ? HiveAesCipher(secureKey) : null, - crashRecovery: false, - ); - return box.get("cache$index"); + final db = await _getDb(secureKey: secureKey); + final store = _getStore(); + final value = await store.record('cache$index').get(db); + + // Try to decode using dart_mappable if possible + if (value != null) { + try { + return MapperContainer.globals.fromValue(value); + } catch (e) { + Res.logger.e("error while decoding cache for $E: $e"); + return value as E; + } + } + return null; } catch (e) { Res.logger.e("error while getting cache for $E: $e"); - await reset(); + await reset(secureKey: secureKey); return null; } } - static Future set(E data, - {int index = 0, List? secureKey}) async { + static Future set( + E data, { + int index = 0, + List? secureKey, + }) async { + dynamic toStore = data; try { - Box box = await Hive.openBox( - "cached_$E", - encryptionCipher: (secureKey != null) ? HiveAesCipher(secureKey) : null, - crashRecovery: false, - ); - await box.put("cache$index", data); - if (secureKey != null) await box.close(); + final db = await _getDb(secureKey: secureKey); + final store = _getStore(); + + var a = RestaurantListModel(restaurantList: []); + var b = ThemeSettingsModel(); + b.toMap(); + a.toMap(); + // Try to encode using dart_mappable if possible + try { + toStore = MapperContainer.globals.toValue(data); + } catch (parseError) { + Res.logger.e("error while encoding cache for $E: $parseError"); + } + + await store.record('cache$index').put(db, toStore); } catch (e) { Res.logger.e("error while setting cache for $E: $e"); - await reset(); + //Res.logger.e("data was: $toStore"); + await reset(secureKey: secureKey); } } static Future exist({int index = 0, List? secureKey}) async { try { - Box box = await Hive.openBox( - "cached_$E", - encryptionCipher: (secureKey != null) ? HiveAesCipher(secureKey) : null, - crashRecovery: false, - ); - return box.containsKey("cache$index"); + final db = await _getDb(secureKey: secureKey); + final store = _getStore(); + return await store.record('cache$index').exists(db); } catch (e) { Res.logger.e("error while checking existence of cache for $E: $e"); - await reset(); + await reset(secureKey: secureKey); return false; } } - static Future reset() async { - await Hive.deleteBoxFromDisk("cached_$E"); + static Future reset({List? secureKey}) async { + try { + final db = await _getDb(secureKey: secureKey); + final store = _getStore(); + // Supprime tous les enregistrements du store + await store.drop(db); + } catch (e) { + Res.logger.e("error while resetting cache for $E: $e"); + } } static Future toggleBiometricAuth(bool biometricAuth) async { @@ -81,8 +137,10 @@ class CacheService { return true; } - static Future> getEncryptionKey(bool biometricAuth, - {bool autoRetry = false}) async { + static Future> getEncryptionKey( + bool biometricAuth, { + bool autoRetry = false, + }) async { if (_isBiometricEnabled != null && _isBiometricEnabled != biometricAuth) { await toggleBiometricAuth(biometricAuth); } @@ -107,7 +165,12 @@ class CacheService { try { String? data = await _storageFile!.read(); if (data == null) { - data = base64Encode(Hive.generateSecureKey()); + // Générer une clé aléatoire (32 bytes) + final key = List.generate( + 32, + (i) => i * DateTime.now().millisecondsSinceEpoch % 256, + ); + data = base64Encode(key); await _storageFile!.write(data); } secureKey = base64Url.decode(data); diff --git a/apps/onyx/lib/core/encrypt_codec.dart b/apps/onyx/lib/core/encrypt_codec.dart new file mode 100644 index 000000000..d38d25598 --- /dev/null +++ b/apps/onyx/lib/core/encrypt_codec.dart @@ -0,0 +1,183 @@ +import 'dart:convert'; +import 'dart:math'; +import 'dart:typed_data'; + +import 'package:crypto/crypto.dart'; +import 'package:encrypt/encrypt.dart'; + +// ignore: implementation_imports +import 'package:sembast/src/api/v2/sembast.dart'; + +final _random = () { + try { + // Try secure + return Random.secure(); + } catch (_) { + return Random(); + } +}(); + +/// Random bytes generator +Uint8List _randBytes(int length) { + return Uint8List.fromList( + List.generate(length, (i) => _random.nextInt(256)), + ); +} + +/// FOR DEMONSTRATION PURPOSES ONLY -- do not use in production as-is! +/// +/// This is a demonstration on how to bring encryption to sembast, but it is an +/// insecure implementation. The encryption is unauthenticated, +/// the password conversion to bytes is underpowered (password hashes like +/// bcyrpt, scrypt, argon2id, and pbkdf2 are some examples of correct algorithms), +/// and the random bytes generator doesn't use a cryptographically secure source +/// of randomness. +/// +/// See https://github.com/tekartik/sembast.dart/pull/339 for more information +/// +/// Generate an encryption password based on a user input password +/// +/// It uses MD5 which generates a 16 bytes blob, size needed for Salsa20 +Uint8List _generateEncryptPassword(String password) { + var blob = Uint8List.fromList(md5.convert(utf8.encode(password)).bytes); + assert(blob.length == 16); + return blob; +} + +/// Salsa20 based encoder +class _EncryptEncoder extends Converter { + final Salsa20 salsa20; + + _EncryptEncoder(this.salsa20); + + @override + String convert(dynamic input) { + // Generate random initial value + final iv = _randBytes(8); + final ivEncoded = base64.encode(iv); + assert(ivEncoded.length == 12); + + // Encode the input value + final encoded = Encrypter( + salsa20, + ).encrypt(json.encode(input), iv: IV(iv)).base64; + + // Prepend the initial value + return '$ivEncoded$encoded'; + } +} + +/// Salsa20 based decoder +class _EncryptDecoder extends Converter { + final Salsa20 salsa20; + + _EncryptDecoder(this.salsa20); + + @override + dynamic convert(String input) { + // Read the initial value that was prepended + assert(input.length >= 12); + final iv = base64.decode(input.substring(0, 12)); + + // Extract the real input + input = input.substring(12); + + // Decode the input + var decoded = json.decode(Encrypter(salsa20).decrypt64(input, iv: IV(iv))); + if (decoded is Map) { + return decoded.cast(); + } + return decoded; + } +} + +/// Salsa20 based Codec +class _EncryptCodec extends Codec { + late _EncryptEncoder _encoder; + late _EncryptDecoder _decoder; + + _EncryptCodec(Uint8List passwordBytes) { + var salsa20 = Salsa20(Key(passwordBytes)); + _encoder = _EncryptEncoder(salsa20); + _decoder = _EncryptDecoder(salsa20); + } + + @override + Converter get decoder => _decoder; + + @override + Converter get encoder => _encoder; +} + +/// Our plain text signature +const _encryptCodecSignature = 'encrypt'; + +/// Create a codec to use to open a database with encrypted stored data. +/// +/// Hash (md5) of the password is used (but never stored) as a key to encrypt +/// the data using the Salsa20 algorithm with a random (8 bytes) initial value +/// +/// This is just used as a demonstration and should not be considered as a +/// reference since its implementation (and storage format) might change. +/// +/// No performance metrics has been made to check whether this is a viable +/// solution for big databases. +/// +/// The usage is then +/// +/// ```dart +/// // Initialize the encryption codec with a user password +/// var codec = getEncryptSembastCodec(password: '[your_user_password]'); +/// // Open the database with the codec +/// Database db = await factory.openDatabase(dbPath, codec: codec); +/// +/// // ...your database is ready to use +/// ``` +SembastCodec getEncryptSembastCodec({required String password}) => SembastCodec( + signature: _encryptCodecSignature, + codec: _EncryptCodec(_generateEncryptPassword(password)), +); + +/// Wrap a factory to always use the codec +class EncryptedDatabaseFactory implements DatabaseFactory { + final DatabaseFactory databaseFactory; + late final SembastCodec codec; + + EncryptedDatabaseFactory({ + required this.databaseFactory, + required String password, + }) { + codec = getEncryptSembastCodec(password: password); + } + + @override + Future deleteDatabase(String path) => + databaseFactory.deleteDatabase(path); + + @override + bool get hasStorage => databaseFactory.hasStorage; + + /// To use with codec, null + @override + Future openDatabase( + String path, { + int? version, + OnVersionChangedFunction? onVersionChanged, + DatabaseMode? mode, + SembastCodec? codec, + }) { + assert(codec == null); + return databaseFactory.openDatabase( + path, + version: version, + onVersionChanged: onVersionChanged, + mode: mode, + codec: this.codec, + ); + } + + @override + Future databaseExists(String path) { + return databaseFactory.databaseExists(path); + } +} diff --git a/apps/onyx/lib/core/generated/res.mapper.dart b/apps/onyx/lib/core/generated/res.mapper.dart new file mode 100644 index 000000000..fd2741348 --- /dev/null +++ b/apps/onyx/lib/core/generated/res.mapper.dart @@ -0,0 +1,75 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../res.dart'; + +class FunctionalitiesMapper extends EnumMapper { + FunctionalitiesMapper._(); + + static FunctionalitiesMapper? _instance; + static FunctionalitiesMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = FunctionalitiesMapper._()); + } + return _instance!; + } + + static Functionalities fromValue(dynamic value) { + ensureInitialized(); + return MapperContainer.globals.fromValue(value); + } + + @override + Functionalities decode(dynamic value) { + switch (value) { + case r'tomuss': + return Functionalities.tomuss; + case r'agenda': + return Functionalities.agenda; + case r'mail': + return Functionalities.mail; + case r'map': + return Functionalities.map; + case r'izly': + return Functionalities.izly; + case r'settings': + return Functionalities.settings; + case r'examen': + return Functionalities.examen; + default: + throw MapperException.unknownEnumValue(value); + } + } + + @override + dynamic encode(Functionalities self) { + switch (self) { + case Functionalities.tomuss: + return r'tomuss'; + case Functionalities.agenda: + return r'agenda'; + case Functionalities.mail: + return r'mail'; + case Functionalities.map: + return r'map'; + case Functionalities.izly: + return r'izly'; + case Functionalities.settings: + return r'settings'; + case Functionalities.examen: + return r'examen'; + } + } +} + +extension FunctionalitiesMapperExtension on Functionalities { + String toValue() { + FunctionalitiesMapper.ensureInitialized(); + return MapperContainer.globals.toValue(this) as String; + } +} + diff --git a/apps/onyx/lib/core/initialisations/hive_init.dart b/apps/onyx/lib/core/initialisations/hive_init.dart deleted file mode 100644 index 9978405f7..000000000 --- a/apps/onyx/lib/core/initialisations/hive_init.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:hive_ce_flutter/hive_flutter.dart'; -import 'package:izlyclient/izlyclient.dart'; -import 'package:lyon1agendaclient/lyon1agendaclient.dart'; -import 'package:lyon1casclient/lyon1casclient.dart'; -import 'package:lyon1examenclient/lyon1examenclient.dart'; -import 'package:lyon1mailclient/lyon1mailclient.dart'; -import 'package:lyon1tomussclient/lyon1tomussclient.dart'; -import 'package:onyx/hive/hive_registrar.g.dart'; -import 'package:polytechcolloscopeclient/polytechcolloscopeclient.dart'; - -Future hiveInit({String? path}) async { - Hive.registerAdapters(); - - IzlyClient.registerAdapters(); - Lyon1TomussClient.registerAdapters(); - Lyon1CasClient.registerAdapters(initHive: false); - Lyon1AgendaClient.registerAdapters(); - Lyon1MailClient.registerAdapters(initHive: false); - PolytechColloscopeClient.registerAdapters(); - Lyon1ExamenClient.registerAdapters(); - - if (path != null || kIsWeb) { - Hive.init(path); - } else { - await Hive.initFlutter(); - } -} - -Future hiveReset({String? path}) async { - hiveInit(path: path); - await Hive.deleteBoxFromDisk('settings'); - await Hive.deleteBoxFromDisk('authentication'); - await Hive.deleteBoxFromDisk('tomuss'); - await Hive.deleteBoxFromDisk('agenda'); - await Hive.deleteBoxFromDisk('mails'); - await Hive.deleteBoxFromDisk('cached_colloscope_data'); -} diff --git a/apps/onyx/lib/core/initialisations/initialisations_export.dart b/apps/onyx/lib/core/initialisations/initialisations_export.dart index b5746c25a..795c42f67 100644 --- a/apps/onyx/lib/core/initialisations/initialisations_export.dart +++ b/apps/onyx/lib/core/initialisations/initialisations_export.dart @@ -1,2 +1,2 @@ export 'custom_scroll_behavior.dart'; -export 'hive_init.dart'; +export 'sembast_init.dart'; diff --git a/apps/onyx/lib/core/initialisations/sembast_init.dart b/apps/onyx/lib/core/initialisations/sembast_init.dart new file mode 100644 index 000000000..6c309756b --- /dev/null +++ b/apps/onyx/lib/core/initialisations/sembast_init.dart @@ -0,0 +1,105 @@ +import 'package:izlyclient/izlyclient.dart' as izly; +import 'package:lyon1agendaclient/lyon1agendaclient.dart' as agenda; +import 'package:lyon1casclient/lyon1casclient.dart' as cas; +import 'package:lyon1examenclient/lyon1examenclient.dart' as examen; +import 'package:lyon1mailclient/lyon1mailclient.dart' as mailclient; +import 'package:lyon1tomussclient/lyon1tomussclient.dart' as tomuss; +import 'package:onyx/core/cache_service.dart'; +import 'package:onyx/core/res.dart' as core; +import 'package:onyx/core/screens/home/state/home_cubit.dart' as home; +import 'package:onyx/screens/mails/states/email_send_cubit.dart' as mail; +import 'package:onyx/screens/settings/settings_export.dart'; +import 'package:path/path.dart'; +import 'package:path_provider/path_provider.dart'; +import 'package:polytechcolloscopeclient/polytechcolloscopeclient.dart' as polytech; +import 'package:sembast/sembast_io.dart'; + +Future initSembastDb([String? dbDirPath]) async { + String path; + if (dbDirPath == null) { + final dir = await getApplicationDocumentsDirectory(); + path = dir.path; + } else { + path = dbDirPath; + } + final dbPath = join(path, 'onyx.db'); + final db = await databaseFactoryIo.openDatabase(dbPath); + CacheService.db = db; + + // Settings mappers + ThemeSettingsModelMapper.ensureInitialized(); + ThemeModeEnumMapper.ensureInitialized(); + SettingsModelMapper.ensureInitialized(); + + // Core mappers + core.FunctionalitiesMapper.ensureInitialized(); + + // Home state mappers + home.HomeStateMapper.ensureInitialized(); + home.HomeStatusMapper.ensureInitialized(); + + // Email mappers + mail.EmailSendStateMapper.ensureInitialized(); + mail.EmailSendStatusMapper.ensureInitialized(); + + // Izly client mappers + izly.CbModelMapper.ensureInitialized(); + izly.IzlyCredentialMapper.ensureInitialized(); + izly.IzlyPaymentModelMapper.ensureInitialized(); + izly.IzlyPaymentModelListMapper.ensureInitialized(); + izly.IzlyQrCodeMapper.ensureInitialized(); + izly.IzlyQrCodeListMapper.ensureInitialized(); + izly.MenuCrousMapper.ensureInitialized(); + izly.MenuTypeMapper.ensureInitialized(); + izly.PlatCrousMapper.ensureInitialized(); + izly.RestaurantModelMapper.ensureInitialized(); + izly.RestaurantListModelMapper.ensureInitialized(); + izly.CrousTypeMapper.ensureInitialized(); + + // Agenda client mappers + agenda.AgendaMapper.ensureInitialized(); + agenda.AgendaResourceMapper.ensureInitialized(); + agenda.DayMapper.ensureInitialized(); + agenda.EventMapper.ensureInitialized(); + + // CAS client mappers + cas.CredentialMapper.ensureInitialized(); + + // Examen client mappers + examen.ExamenListModelMapper.ensureInitialized(); + examen.ExamenModelMapper.ensureInitialized(); + + // Mail client mappers + mailclient.ActionMapper.ensureInitialized(); + mailclient.ActionListMapper.ensureInitialized(); + mailclient.ActionTypeMapper.ensureInitialized(); + mailclient.AddressMapper.ensureInitialized(); + mailclient.MailMapper.ensureInitialized(); + mailclient.MailBoxMapper.ensureInitialized(); + mailclient.MailBoxListMapper.ensureInitialized(); + mailclient.SpecialMailBoxMapper.ensureInitialized(); + + // Tomuss client mappers + tomuss.EnumerationMapper.ensureInitialized(); + tomuss.GradeMapper.ensureInitialized(); + tomuss.PresenceMapper.ensureInitialized(); + tomuss.PresenceColorMapper.ensureInitialized(); + tomuss.SemesterMapper.ensureInitialized(); + tomuss.SemesterListMapper.ensureInitialized(); + tomuss.StageCodeMapper.ensureInitialized(); + tomuss.StudentMapper.ensureInitialized(); + tomuss.TeacherMapper.ensureInitialized(); + tomuss.TeachingUnitMapper.ensureInitialized(); + tomuss.TeachingUnitListMapper.ensureInitialized(); + tomuss.TomussTextMapper.ensureInitialized(); + tomuss.UploadMapper.ensureInitialized(); + tomuss.URLMapper.ensureInitialized(); + + // Polytech colloscope client mappers + polytech.KholleMapper.ensureInitialized(); + polytech.StudentMapper.ensureInitialized(); + polytech.StudentColloscopeMapper.ensureInitialized(); + polytech.YearMapper.ensureInitialized(); + + return db; +} diff --git a/apps/onyx/lib/core/res.dart b/apps/onyx/lib/core/res.dart index 840035c6d..ee36d9594 100644 --- a/apps/onyx/lib/core/res.dart +++ b/apps/onyx/lib/core/res.dart @@ -1,8 +1,11 @@ +import 'package:dart_mappable/dart_mappable.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:logger/logger.dart'; import 'package:responsive_sizer/responsive_sizer.dart'; +part 'generated/res.mapper.dart'; + class Res { static Duration get animationDuration => const Duration(milliseconds: 300); @@ -51,8 +54,9 @@ class Res { static const Duration agendaDayStart = Duration(hours: 6); static const Duration agendaDayEnd = Duration(hours: 22); static const Duration agendaDayDuration = Duration( - hours: 16); // be careful to change this value accordingly to the previous -// 22 - 6 = 16 + hours: 16, + ); // be careful to change this value accordingly to the previous + // 22 - 6 = 16 static final logger = Logger( level: (kDebugMode) ? Level.all : Level.fatal, @@ -98,12 +102,5 @@ class Res { ]; } -enum Functionalities { - tomuss, - agenda, - mail, - map, - izly, - settings, - examen, -} +@MappableEnum() +enum Functionalities { tomuss, agenda, mail, map, izly, settings, examen } diff --git a/apps/onyx/lib/core/screens/bloc_connections/connections/agenda_connections.dart b/apps/onyx/lib/core/screens/bloc_connections/connections/agenda_connections.dart index a6f36c06c..b3eb75534 100644 --- a/apps/onyx/lib/core/screens/bloc_connections/connections/agenda_connections.dart +++ b/apps/onyx/lib/core/screens/bloc_connections/connections/agenda_connections.dart @@ -1,48 +1,44 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:onyx/core/res.dart'; +import 'package:onyx/l10n/app_localizations.dart'; import 'package:onyx/screens/agenda/states/agenda_cubit.dart'; import 'package:onyx/screens/examen/examen_export.dart'; import 'package:onyx/screens/login/states/authentification_cubit.dart'; -import 'package:onyx/screens/settings/domain/model/settings_model.dart'; import 'package:onyx/screens/settings/states/settings_cubit.dart'; import 'package:onyx/screens/tomuss/states/tomuss_cubit.dart'; -import 'package:onyx/l10n/app_localizations.dart'; class AgendaConnection extends BlocListener { - AgendaConnection({ - super.key, - }) : super( - listener: (context, state) { - if (context - .read() - .state - .settings - .colloscopeEnabled == - null && - !context.read().state.settings.fetchAgendaAuto) { - updateColloscopeEnabled(context); - } - }, - ); + AgendaConnection({super.key}) + : super( + listener: (context, state) { + if (context.read().state.settings.colloscopeEnabled == + null && + !context.read().state.settings.fetchAgendaAuto) { + updateColloscopeEnabled(context); + } + }, + ); static void updateColloscopeEnabled(BuildContext context) { SettingsState settingsState = context.read().state; if (!settingsState.settings.fetchAgendaAuto && settingsState.settings.agendaIds.isNotEmpty) { context.read().modify( - settings: settingsState.settings.copyWith( - colloscopeEnabled: settingsState.settings.agendaIds - .any((element) => Res.peipStudentsAgendaIds.contains(element)), - )); + settings: settingsState.settings.copyWith( + colloscopeEnabled: settingsState.settings.agendaIds.any( + (element) => Res.peipStudentsAgendaIds.contains(element), + ), + ), + ); context.read().load( - context.read().state.name, - context.read().state.surname, - context.read().state.username, - context.read().state.settings, - context.read().state.lyon1Cas, - AppLocalizations.of(context), - ); + context.read().state.name, + context.read().state.surname, + context.read().state.username, + context.read().state.settings, + context.read().state.lyon1Cas, + AppLocalizations.of(context), + ); } } } diff --git a/apps/onyx/lib/core/screens/bloc_connections/connections/authentification_connections.dart b/apps/onyx/lib/core/screens/bloc_connections/connections/authentification_connections.dart index abedf1ea7..8133cf54f 100644 --- a/apps/onyx/lib/core/screens/bloc_connections/connections/authentification_connections.dart +++ b/apps/onyx/lib/core/screens/bloc_connections/connections/authentification_connections.dart @@ -7,72 +7,67 @@ import 'package:onyx/screens/agenda/states/agenda_cubit.dart'; import 'package:onyx/screens/examen/states/examen_cubit.dart'; import 'package:onyx/screens/login/states/authentification_cubit.dart'; import 'package:onyx/screens/mails/states/email_cubit.dart'; -import 'package:onyx/screens/settings/domain/model/settings_model.dart'; import 'package:onyx/screens/settings/states/settings_cubit.dart'; import 'package:onyx/screens/tomuss/states/tomuss_cubit.dart'; class AuthentificationConnection extends BlocListener { - AuthentificationConnection({ - super.key, - }) : super( - listener: (context, authState) { - if (authState.status == AuthentificationStatus.authentificated) { - final emailCubit = context.read(); - final localization = AppLocalizations.of(context); - CacheService.getEncryptionKey(context - .read() - .state - .settings - .biometricAuth) - .then( - (key) => CacheService.get(secureKey: key).then( - (value) => emailCubit.connect( - username: value!.username, - password: value.password, - appLocalizations: localization, - ), + AuthentificationConnection({super.key}) + : super( + listener: (context, authState) { + if (authState.status == AuthentificationStatus.authentificated) { + final emailCubit = context.read(); + final localization = AppLocalizations.of(context); + CacheService.getEncryptionKey( + context.read().state.settings.biometricAuth, + ).then( + (key) => CacheService.get(secureKey: key).then( + (value) => emailCubit.connect( + username: value!.username, + password: value.password, + appLocalizations: localization, ), + ), + ); + if (context.read().state.settings.firstLogin) { + context.read().modify( + settings: context.read().state.settings.copyWith( + firstLogin: false, + ), + ); + } + if (AgendaStatus.ready != + context.read().state.status) { + context.read().load( + lyon1Cas: authState.lyon1Cas, + settings: context.read().state.settings, + ); + } + if (TomussStatus.ready != + context.read().state.status) { + context.read().load( + lyon1Cas: authState.lyon1Cas, + settings: context.read().state.settings, + force: true, + ); + } + if (ExamenStatus.ready != + context.read().state.status) { + context.read().load( + context.read().state.name, + context.read().state.surname, + context.read().state.username, + context.read().state.settings, + context.read().state.lyon1Cas, + AppLocalizations.of(context), ); - if (context.read().state.settings.firstLogin) { - context.read().modify( - settings: context - .read() - .state - .settings - .copyWith(firstLogin: false)); - } - if (AgendaStatus.ready != - context.read().state.status) { - context.read().load( - lyon1Cas: authState.lyon1Cas, - settings: context.read().state.settings); - } - if (TomussStatus.ready != - context.read().state.status) { - context.read().load( - lyon1Cas: authState.lyon1Cas, - settings: context.read().state.settings, - force: true, - ); - } - if (ExamenStatus.ready != - context.read().state.status) { - context.read().load( - context.read().state.name, - context.read().state.surname, - context.read().state.username, - context.read().state.settings, - context.read().state.lyon1Cas, - AppLocalizations.of(context), - ); - } - context.read().agendaClient = - Lyon1AgendaClient.useLyon1Cas(authState.lyon1Cas); - context - .read() - .login(context.read().state.settings); } - }, - ); + context.read().agendaClient = + Lyon1AgendaClient.useLyon1Cas(authState.lyon1Cas); + context.read().login( + context.read().state.settings, + ); + } + }, + ); } diff --git a/apps/onyx/lib/core/screens/home/state/home_cubit.mapper.dart b/apps/onyx/lib/core/screens/home/state/generated/home_cubit.mapper.dart similarity index 88% rename from apps/onyx/lib/core/screens/home/state/home_cubit.mapper.dart rename to apps/onyx/lib/core/screens/home/state/generated/home_cubit.mapper.dart index e324ac38a..e27376408 100644 --- a/apps/onyx/lib/core/screens/home/state/home_cubit.mapper.dart +++ b/apps/onyx/lib/core/screens/home/state/generated/home_cubit.mapper.dart @@ -5,7 +5,7 @@ // ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member // ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter -part of 'home_cubit.dart'; +part of '../home_cubit.dart'; class HomeStatusMapper extends EnumMapper { HomeStatusMapper._(); @@ -179,28 +179,27 @@ class _HomeStateCopyWithImpl<$R, $Out> HomeStatus? status, int? selectedIndex, bool? showSecondaryScreens, - }) => - $apply( - FieldCopyWithData({ - if (status != null) #status: status, - if (selectedIndex != null) #selectedIndex: selectedIndex, - if (showSecondaryScreens != null) - #showSecondaryScreens: showSecondaryScreens, - }), - ); + }) => $apply( + FieldCopyWithData({ + if (status != null) #status: status, + if (selectedIndex != null) #selectedIndex: selectedIndex, + if (showSecondaryScreens != null) + #showSecondaryScreens: showSecondaryScreens, + }), + ); @override HomeState $make(CopyWithData data) => HomeState( - status: data.get(#status, or: $value.status), - selectedIndex: data.get(#selectedIndex, or: $value.selectedIndex), - showSecondaryScreens: data.get( - #showSecondaryScreens, - or: $value.showSecondaryScreens, - ), - ); + status: data.get(#status, or: $value.status), + selectedIndex: data.get(#selectedIndex, or: $value.selectedIndex), + showSecondaryScreens: data.get( + #showSecondaryScreens, + or: $value.showSecondaryScreens, + ), + ); @override HomeStateCopyWith<$R2, HomeState, $Out2> $chain<$R2, $Out2>( Then<$Out2, $R2> t, - ) => - _HomeStateCopyWithImpl<$R2, $Out2>($value, $cast, t); + ) => _HomeStateCopyWithImpl<$R2, $Out2>($value, $cast, t); } + diff --git a/apps/onyx/lib/core/screens/home/state/home_cubit.dart b/apps/onyx/lib/core/screens/home/state/home_cubit.dart index 88328c1af..12afa2f5f 100644 --- a/apps/onyx/lib/core/screens/home/state/home_cubit.dart +++ b/apps/onyx/lib/core/screens/home/state/home_cubit.dart @@ -1,31 +1,18 @@ import 'package:dart_mappable/dart_mappable.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -part 'home_cubit.mapper.dart'; - +part 'generated/home_cubit.mapper.dart'; part 'home_state.dart'; class HomeCubit extends Cubit { HomeCubit() - : super(HomeState( - status: HomeStatus.initial, - showSecondaryScreens: false, - )); + : super(HomeState(status: HomeStatus.initial, showSecondaryScreens: false)); void updateSelectedIndex(int index) { - emit( - state.copyWith( - selectedIndex: index, - showSecondaryScreens: false, - ), - ); + emit(state.copyWith(selectedIndex: index, showSecondaryScreens: false)); } void toggleSecondaryScreens() { - emit( - state.copyWith( - showSecondaryScreens: !state.showSecondaryScreens, - ), - ); + emit(state.copyWith(showSecondaryScreens: !state.showSecondaryScreens)); } } diff --git a/apps/onyx/lib/hive/generated/hive_adapters.g.dart b/apps/onyx/lib/hive/generated/hive_adapters.g.dart deleted file mode 100644 index 6bea6e64e..000000000 --- a/apps/onyx/lib/hive/generated/hive_adapters.g.dart +++ /dev/null @@ -1,292 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../hive_adapters.dart'; - -// ************************************************************************** -// AdaptersGenerator -// ************************************************************************** - -class SettingsModelAdapter extends TypeAdapter { - @override - final typeId = 7; - - @override - SettingsModel read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return SettingsModel( - biometricAuth: fields[16] == null ? false : fields[16] as bool, - forceGreen: fields[1] == null ? false : fields[1] as bool, - newGradeNotification: fields[3] == null ? true : fields[3] as bool, - showHiddenUE: fields[4] == null ? false : fields[4] as bool, - fetchAgendaAuto: fields[5] == null ? true : fields[5] as bool, - showMiniCalendar: fields[6] == null ? true : fields[6] as bool, - calendarUpdateNotification: fields[7] == null ? true : fields[7] as bool, - agendaIds: - fields[27] == null ? const [] : (fields[27] as List).cast(), - newMailNotification: fields[9] == null ? true : fields[9] as bool, - blockTrackers: fields[10] == null ? true : fields[10] as bool, - forcedMailTheme: fields[11] == null ? true : fields[11] as bool, - shownAgendaPopup: fields[18] == null ? false : fields[18] as bool, - enabledFunctionalities: fields[12] == null - ? defaultEnabledFunctionalities - : (fields[12] as List).cast(), - disabledFunctionalities: fields[13] == null - ? defaultDisabledFunctionalities - : (fields[13] as List).cast(), - recentGradeDuration: fields[14] == null ? 7 : (fields[14] as num).toInt(), - firstLogin: fields[15] == null ? true : fields[15] as bool, - mock: fields[17] == null ? false : fields[17] as bool, - agendaWeekLength: fields[19] == null ? 5 : (fields[19] as num).toInt(), - agendaWeekReference: fields[20] == null ? 0 : (fields[20] as num).toInt(), - agendaDisabledDays: - fields[21] == null ? const [6, 7] : (fields[21] as List).cast(), - agendaPageTopToBottom: fields[22] == null ? false : fields[22] as bool, - agendaWeekRerenceAlignement: - fields[23] == null ? 0 : (fields[23] as num).toInt(), - colloscopeOverrideStudentId: - fields[25] == null ? -1 : (fields[25] as num).toInt(), - colloscopeOverrideYearId: - fields[26] == null ? 0 : (fields[26] as num).toInt(), - colloscopeEnabled: fields[28] as bool?, - agendaId: (fields[8] as num?)?.toInt(), - examenAddToAgenda: fields[29] == null ? true : fields[29] as bool, - language: fields[30] as String?, - izlyNotification: fields[31] == null ? true : fields[31] as bool, - ); - } - - @override - void write(BinaryWriter writer, SettingsModel obj) { - writer - ..writeByte(29) - ..writeByte(1) - ..write(obj.forceGreen) - ..writeByte(3) - ..write(obj.newGradeNotification) - ..writeByte(4) - ..write(obj.showHiddenUE) - ..writeByte(5) - ..write(obj.fetchAgendaAuto) - ..writeByte(6) - ..write(obj.showMiniCalendar) - ..writeByte(7) - ..write(obj.calendarUpdateNotification) - ..writeByte(8) - ..write(obj.agendaId) - ..writeByte(9) - ..write(obj.newMailNotification) - ..writeByte(10) - ..write(obj.blockTrackers) - ..writeByte(11) - ..write(obj.forcedMailTheme) - ..writeByte(12) - ..write(obj.enabledFunctionalities) - ..writeByte(13) - ..write(obj.disabledFunctionalities) - ..writeByte(14) - ..write(obj.recentGradeDuration) - ..writeByte(15) - ..write(obj.firstLogin) - ..writeByte(16) - ..write(obj.biometricAuth) - ..writeByte(17) - ..write(obj.mock) - ..writeByte(18) - ..write(obj.shownAgendaPopup) - ..writeByte(19) - ..write(obj.agendaWeekLength) - ..writeByte(20) - ..write(obj.agendaWeekReference) - ..writeByte(21) - ..write(obj.agendaDisabledDays) - ..writeByte(22) - ..write(obj.agendaPageTopToBottom) - ..writeByte(23) - ..write(obj.agendaWeekRerenceAlignement) - ..writeByte(25) - ..write(obj.colloscopeOverrideStudentId) - ..writeByte(26) - ..write(obj.colloscopeOverrideYearId) - ..writeByte(27) - ..write(obj.agendaIds) - ..writeByte(28) - ..write(obj.colloscopeEnabled) - ..writeByte(29) - ..write(obj.examenAddToAgenda) - ..writeByte(30) - ..write(obj.language) - ..writeByte(31) - ..write(obj.izlyNotification); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is SettingsModelAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class ThemeModeEnumAdapter extends TypeAdapter { - @override - final typeId = 8; - - @override - ThemeModeEnum read(BinaryReader reader) { - switch (reader.readByte()) { - case 0: - return ThemeModeEnum.system; - case 1: - return ThemeModeEnum.dark; - case 2: - return ThemeModeEnum.light; - default: - return ThemeModeEnum.system; - } - } - - @override - void write(BinaryWriter writer, ThemeModeEnum obj) { - switch (obj) { - case ThemeModeEnum.system: - writer.writeByte(0); - case ThemeModeEnum.dark: - writer.writeByte(1); - case ThemeModeEnum.light: - writer.writeByte(2); - } - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is ThemeModeEnumAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class FunctionalitiesAdapter extends TypeAdapter { - @override - final typeId = 18; - - @override - Functionalities read(BinaryReader reader) { - switch (reader.readByte()) { - case 0: - return Functionalities.tomuss; - case 1: - return Functionalities.agenda; - case 2: - return Functionalities.mail; - case 3: - return Functionalities.map; - case 4: - return Functionalities.izly; - case 5: - return Functionalities.settings; - case 6: - return Functionalities.examen; - default: - return Functionalities.tomuss; - } - } - - @override - void write(BinaryWriter writer, Functionalities obj) { - switch (obj) { - case Functionalities.tomuss: - writer.writeByte(0); - case Functionalities.agenda: - writer.writeByte(1); - case Functionalities.mail: - writer.writeByte(2); - case Functionalities.map: - writer.writeByte(3); - case Functionalities.izly: - writer.writeByte(4); - case Functionalities.settings: - writer.writeByte(5); - case Functionalities.examen: - writer.writeByte(6); - } - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is FunctionalitiesAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class ThemeSettingsModelAdapter extends TypeAdapter { - @override - final typeId = 42; - - @override - ThemeSettingsModel read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return ThemeSettingsModel( - themesCreated: - fields[6] == null ? const [] : (fields[6] as List).cast(), - darkThemeSelected: - fields[1] == null ? 'Dark Default' : fields[1] as String, - lightThemeSelected: - fields[2] == null ? 'Light Default' : fields[2] as String, - favoriteThemes: - fields[8] == null ? const [] : (fields[8] as List).cast(), - themeMode: - fields[4] == null ? ThemeModeEnum.system : fields[4] as ThemeModeEnum, - autoSwitchTheme: fields[5] == null ? true : fields[5] as bool, - themesCreatedString: fields[0] as String?, - favoriteThemesString: fields[3] as String?, - ); - } - - @override - void write(BinaryWriter writer, ThemeSettingsModel obj) { - writer - ..writeByte(8) - ..writeByte(0) - ..write(obj.themesCreatedString) - ..writeByte(1) - ..write(obj.darkThemeSelected) - ..writeByte(2) - ..write(obj.lightThemeSelected) - ..writeByte(3) - ..write(obj.favoriteThemesString) - ..writeByte(4) - ..write(obj.themeMode) - ..writeByte(5) - ..write(obj.autoSwitchTheme) - ..writeByte(6) - ..write(obj.themesCreated) - ..writeByte(8) - ..write(obj.favoriteThemes); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is ThemeSettingsModelAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} diff --git a/apps/onyx/lib/hive/hive_adapters.dart b/apps/onyx/lib/hive/hive_adapters.dart deleted file mode 100644 index 6b3d55159..000000000 --- a/apps/onyx/lib/hive/hive_adapters.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:hive_ce/hive.dart'; -import 'package:onyx/core/res.dart'; -import 'package:onyx/screens/settings/domain/model/settings_model.dart'; -import 'package:onyx/screens/settings/domain/model/theme_mode_enum.dart'; -import 'package:onyx/screens/settings/domain/model/theme_model.dart'; -import 'package:onyx/screens/settings/domain/model/theme_settings_model.dart'; - -@GenerateAdapters([ - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), -]) -part 'generated/hive_adapters.g.dart'; diff --git a/apps/onyx/lib/hive/hive_adapters.g.yaml b/apps/onyx/lib/hive/hive_adapters.g.yaml deleted file mode 100644 index b90d806b2..000000000 --- a/apps/onyx/lib/hive/hive_adapters.g.yaml +++ /dev/null @@ -1,115 +0,0 @@ -# Generated by Hive CE -# Manual modifications may be necessary for certain migrations -# Check in to version control -nextTypeId: 44 -types: - SettingsModel: - typeId: 7 - nextIndex: 32 - fields: - forceGreen: - index: 1 - newGradeNotification: - index: 3 - showHiddenUE: - index: 4 - fetchAgendaAuto: - index: 5 - showMiniCalendar: - index: 6 - calendarUpdateNotification: - index: 7 - agendaId: - index: 8 - newMailNotification: - index: 9 - blockTrackers: - index: 10 - forcedMailTheme: - index: 11 - enabledFunctionalities: - index: 12 - disabledFunctionalities: - index: 13 - recentGradeDuration: - index: 14 - firstLogin: - index: 15 - biometricAuth: - index: 16 - mock: - index: 17 - shownAgendaPopup: - index: 18 - agendaWeekLength: - index: 19 - agendaWeekReference: - index: 20 - agendaDisabledDays: - index: 21 - agendaPageTopToBottom: - index: 22 - agendaWeekRerenceAlignement: - index: 23 - colloscopeOverrideStudentId: - index: 25 - colloscopeOverrideYearId: - index: 26 - agendaIds: - index: 27 - colloscopeEnabled: - index: 28 - examenAddToAgenda: - index: 29 - language: - index: 30 - izlyNotification: - index: 31 - ThemeModeEnum: - typeId: 8 - nextIndex: 3 - fields: - system: - index: 0 - dark: - index: 1 - light: - index: 2 - Functionalities: - typeId: 18 - nextIndex: 7 - fields: - tomuss: - index: 0 - agenda: - index: 1 - mail: - index: 2 - map: - index: 3 - izly: - index: 4 - settings: - index: 5 - examen: - index: 6 - ThemeSettingsModel: - typeId: 42 - nextIndex: 10 - fields: - themesCreatedString: - index: 0 - darkThemeSelected: - index: 1 - lightThemeSelected: - index: 2 - favoriteThemesString: - index: 3 - themeMode: - index: 4 - autoSwitchTheme: - index: 5 - themesCreated: - index: 6 - favoriteThemes: - index: 8 diff --git a/apps/onyx/lib/hive/hive_registrar.g.dart b/apps/onyx/lib/hive/hive_registrar.g.dart deleted file mode 100644 index 78dc79c2d..000000000 --- a/apps/onyx/lib/hive/hive_registrar.g.dart +++ /dev/null @@ -1,24 +0,0 @@ -// Generated by Hive CE -// Do not modify -// Check in to version control - -import 'package:hive_ce/hive.dart'; -import 'package:onyx/hive/hive_adapters.dart'; - -extension HiveRegistrar on HiveInterface { - void registerAdapters() { - registerAdapter(FunctionalitiesAdapter()); - registerAdapter(SettingsModelAdapter()); - registerAdapter(ThemeModeEnumAdapter()); - registerAdapter(ThemeSettingsModelAdapter()); - } -} - -extension IsolatedHiveRegistrar on IsolatedHiveInterface { - void registerAdapters() { - registerAdapter(FunctionalitiesAdapter()); - registerAdapter(SettingsModelAdapter()); - registerAdapter(ThemeModeEnumAdapter()); - registerAdapter(ThemeSettingsModelAdapter()); - } -} diff --git a/apps/onyx/lib/main.dart b/apps/onyx/lib/main.dart index cf378da4c..9cf9a2de7 100644 --- a/apps/onyx/lib/main.dart +++ b/apps/onyx/lib/main.dart @@ -18,14 +18,17 @@ void main() async { WidgetsFlutterBinding.ensureInitialized(); if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) { - Workmanager().initialize(workmanagerHandler, isInDebugMode: kDebugMode); - Workmanager().registerPeriodicTask("updateChecking", "check update", - frequency: const Duration(hours: 1), - constraints: Constraints(networkType: NetworkType.connected)); + Workmanager().initialize(workmanagerHandler); + Workmanager().registerPeriodicTask( + "updateChecking", + "check update", + frequency: const Duration(hours: 1), + constraints: Constraints(networkType: NetworkType.connected), + ); await NotificationLogic.init(); } - await hiveInit(); + await initSembastDb(); SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, diff --git a/apps/onyx/lib/screens/agenda/logic/agenda_logic.dart b/apps/onyx/lib/screens/agenda/logic/agenda_logic.dart index 8bfcf47a2..79e87ce85 100644 --- a/apps/onyx/lib/screens/agenda/logic/agenda_logic.dart +++ b/apps/onyx/lib/screens/agenda/logic/agenda_logic.dart @@ -2,17 +2,18 @@ import 'package:izlyclient/izlyclient.dart'; import 'package:lyon1agendaclient/lyon1agendaclient.dart'; import 'package:onyx/core/cache_service.dart'; import 'package:onyx/core/extensions/extensions_export.dart'; -import 'package:onyx/core/initialisations/initialisations_export.dart'; +import 'package:onyx/core/initialisations/sembast_init.dart'; import 'package:onyx/core/res.dart'; import 'package:onyx/screens/izly/izly_export.dart'; import 'package:onyx/screens/settings/settings_export.dart'; class AgendaLogic { - static Future> load( - {required Lyon1AgendaClient agendaClient, - required SettingsModel settings, - required List ids, - DateTime? maxDate}) async { + static Future> load({ + required Lyon1AgendaClient agendaClient, + required SettingsModel settings, + required List ids, + DateTime? maxDate, + }) async { if (Res.mock) { return dayListMock; } @@ -32,7 +33,7 @@ class AgendaLogic { if (Res.mock) { return dayListMock; } - await hiveInit(path: path); + await initSembastDb(path); if (await CacheService.exist()) { return (await CacheService.get())!.days; } else { @@ -44,14 +45,15 @@ class AgendaLogic { //clean the agenda for (int i = 0; i < days.length; i++) { days[i] = days[i].copyWith( - events: days[i] - .events - .where((element) => element.menuCrous == null) - .toList()); + events: days[i].events + .where((element) => element.menuCrous == null) + .toList(), + ); } List restaurant = await IzlyClient.getRestaurantCrous(); - CacheService.set( - RestaurantListModel(restaurantList: restaurant)); + CacheService.set>( + RestaurantListModel(restaurantList: restaurant).toMap(), + ); List menuToAdd = []; for (var resto in restaurant) { if (await IzlyLogic.isRestaurantFavourite(resto)) { @@ -75,38 +77,47 @@ class AgendaLogic { } startLimit = startLimit.subtract(const Duration(minutes: 1)); endLimit = endLimit.add(const Duration(minutes: 1)); - int dayIndex = days.indexWhere((element) => - element.date.shrink(3).isAtSameMomentAs(menu.date.shrink(3))); + int dayIndex = days.indexWhere( + (element) => + element.date.shrink(3).isAtSameMomentAs(menu.date.shrink(3)), + ); if (dayIndex != -1) { Day day = days[dayIndex]; if (day.events.isNotEmpty) { List<({DateTime start, DateTime end})> pause = [ - (start: day.date, end: day.events.first.start) + (start: day.date, end: day.events.first.start), ]; for (var i = 0; i < day.events.length - 1; i++) { - pause.add( - (start: day.events[i].end, end: day.events[i + 1].start)); + pause.add(( + start: day.events[i].end, + end: day.events[i + 1].start, + )); } pause.add(( start: day.events.last.end, - end: day.date.add(const Duration(days: 1)) + end: day.date.add(const Duration(days: 1)), )); - pause.removeWhere((element) => - element.end.difference(element.start).inHours < 1); + pause.removeWhere( + (element) => element.end.difference(element.start).inHours < 1, + ); for (var i in pause) { - bool startOk = i.start.isAfter(startLimit) && + bool startOk = + i.start.isAfter(startLimit) && i.start.add(const Duration(hours: 1)).isBefore(endLimit); - bool stopOk = i.end.isBefore(endLimit) && + bool stopOk = + i.end.isBefore(endLimit) && i.end .subtract(const Duration(hours: 1)) .isAfter(startLimit); bool inTimeSlot = startLimit.isAfter(i.start) && endLimit.isBefore(i.end); if (startOk || stopOk || inTimeSlot) { - DateTime start = - startLimit.add(const Duration(minutes: 1, hours: 1)); - DateTime end = - endLimit.subtract(const Duration(minutes: 1, hours: 1)); + DateTime start = startLimit.add( + const Duration(minutes: 1, hours: 1), + ); + DateTime end = endLimit.subtract( + const Duration(minutes: 1, hours: 1), + ); if (startOk && stopOk) { if (startLimit.difference(i.start) < endLimit.difference(i.end)) { @@ -123,27 +134,32 @@ class AgendaLogic { end = i.end; start = end.subtract(const Duration(hours: 1)); } - menuToAdd.add((Event( + menuToAdd.add( + (Event( location: resto.name, menuCrous: menu, teacher: "", description: "", name: menu.type.toString(), start: start, - end: end))); + end: end, + )), + ); break; } } } else { - menuToAdd.add((Event( - location: resto.name, - menuCrous: menu, - teacher: "", - description: "", - name: menu.type.toString(), - start: startLimit.add(const Duration(minutes: 1)), - end: endLimit.subtract(const Duration(minutes: 1)), - ))); + menuToAdd.add( + (Event( + location: resto.name, + menuCrous: menu, + teacher: "", + description: "", + name: menu.type.toString(), + start: startLimit.add(const Duration(minutes: 1)), + end: endLimit.subtract(const Duration(minutes: 1)), + )), + ); } } } @@ -152,8 +168,10 @@ class AgendaLogic { //add the new menu to the clean agenda for (var menu in menuToAdd) { - int dayIndex = days.indexWhere((element) => - element.date.shrink(3).isAtSameMomentAs(menu.start.shrink(3))); + int dayIndex = days.indexWhere( + (element) => + element.date.shrink(3).isAtSameMomentAs(menu.start.shrink(3)), + ); if (dayIndex != -1) { days[dayIndex].events.add(menu); days[dayIndex].events.sort((a, b) => a.start.compareTo(b.start)); @@ -243,11 +261,11 @@ class AgendaLogic { ]), for (int i = 4; i < 300; i++) Day( - DateTime(DateTime.now().year + ((DateTime.now().month < 6) ? -1 : 0), - 9) - .add( - Duration(days: i), - ), - const []), + DateTime( + DateTime.now().year + ((DateTime.now().month < 6) ? -1 : 0), + 9, + ).add(Duration(days: i)), + const [], + ), ]; } diff --git a/apps/onyx/lib/screens/agenda/states/agenda_state.dart b/apps/onyx/lib/screens/agenda/states/agenda_state.dart index a8e9a5d0f..81aaec7fc 100644 --- a/apps/onyx/lib/screens/agenda/states/agenda_state.dart +++ b/apps/onyx/lib/screens/agenda/states/agenda_state.dart @@ -18,8 +18,6 @@ enum AgendaStatus { class AgendaState { final AgendaStatus status; late final List realDays; - late final int paddingBefore; - late final int paddingAfter; final List examEvents; final List agendaIds; final int wantedDate; @@ -32,10 +30,10 @@ class AgendaState { this.agendaIds = const [], required SettingsModel settingsModel, }) { + int paddingBefore = 0; + int paddingAfter = 0; if (realDays.isEmpty) { this.realDays = realDays; - this.paddingBefore = 0; - this.paddingAfter = 0; return; } // remove disabled days @@ -70,8 +68,8 @@ class AgendaState { alignementOffset = alignementOffset.positiveModulo(settingsModel.agendaWeekLength); - this.paddingBefore = alignementOffset; - this.paddingAfter = settingsModel.agendaWeekLength - alignementOffset; + paddingBefore = alignementOffset; + paddingAfter = settingsModel.agendaWeekLength - alignementOffset; } //add examEvents diff --git a/apps/onyx/lib/screens/agenda_config/page/agenda_config_page.dart b/apps/onyx/lib/screens/agenda_config/page/agenda_config_page.dart index f47d61750..875e4d6bb 100644 --- a/apps/onyx/lib/screens/agenda_config/page/agenda_config_page.dart +++ b/apps/onyx/lib/screens/agenda_config/page/agenda_config_page.dart @@ -1,17 +1,20 @@ import 'package:animations/animations.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:onyx/l10n/app_localizations.dart'; import 'package:lyon1agendaclient/lyon1agendaclient.dart'; import 'package:onyx/core/res.dart'; import 'package:onyx/core/widgets/core_widget_export.dart'; +import 'package:onyx/l10n/app_localizations.dart'; import 'package:onyx/screens/agenda/agenda_export.dart'; import 'package:onyx/screens/agenda_config/agenda_config_export.dart'; import 'package:responsive_sizer/responsive_sizer.dart'; class AgendaConfigPage extends StatelessWidget { - const AgendaConfigPage( - {super.key, required this.onBack, this.noBack = false}); + const AgendaConfigPage({ + super.key, + required this.onBack, + this.noBack = false, + }); final Function(List backIndexs) onBack; final bool noBack; @@ -22,7 +25,9 @@ class AgendaConfigPage extends StatelessWidget { final ScrollController listScrollController = ScrollController(); return BlocProvider( create: (context) => AgendaConfigCubit( - onBack: onBack, client: context.read().agendaClient), + onBack: onBack, + client: context.read().agendaClient, + ), child: BlocBuilder( builder: (context, state) { Widget? body; @@ -30,32 +35,37 @@ class AgendaConfigPage extends StatelessWidget { case AgendaConfigStatus.initial: context.read().loadResources(); body = StateDisplayingPage( - message: AppLocalizations.of(context).loadingAgendaList); + message: AppLocalizations.of(context).loadingAgendaList, + ); break; case AgendaConfigStatus.loading: body = StateDisplayingPage( - message: AppLocalizations.of(context).loadingAgendaList); + message: AppLocalizations.of(context).loadingAgendaList, + ); break; case AgendaConfigStatus.error: body = StateDisplayingPage( - message: AppLocalizations.of(context).errorAppeared); + message: AppLocalizations.of(context).errorAppeared, + ); break; default: body = BlocListener( listener: (context, state) { if (pageController.hasClients) { pageController.animateToPage( - (state.expandedResources.length).toInt(), - duration: Res.animationDuration, - curve: Curves.easeInOut); + (state.expandedResources.length).toInt(), + duration: Res.animationDuration, + curve: Curves.easeInOut, + ); } }, child: PopScope( - onPopInvokedWithResult: (_, __) async { + onPopInvokedWithResult: (_, _) async { pageController.animateToPage( - pageController.page!.toInt() - 1, - duration: Res.animationDuration, - curve: Curves.easeInOut); + pageController.page!.toInt() - 1, + duration: Res.animationDuration, + curve: Curves.easeInOut, + ); }, child: Stack( alignment: Alignment.bottomCenter, @@ -67,30 +77,30 @@ class AgendaConfigPage extends StatelessWidget { controller: pageController, physics: const NeverScrollableScrollPhysics(), scrollDirection: Axis.vertical, - childrenDelegate: SliverChildBuilderDelegate( - (context, index) { - if (index == 0) { + childrenDelegate: SliverChildBuilderDelegate(( + context, + index, + ) { + if (index == 0) { + return DirListWidget( + dir: AgendaResource( + 0, + AppLocalizations.of(context).agenda, + state.categories, + ), + scrollController: listScrollController, + ); + } else { + if (state.categories.isNotEmpty && + index - 1 < state.expandedResources.length) { return DirListWidget( - dir: AgendaResource( - 0, - AppLocalizations.of(context).agenda, - state.categories, - ), + dir: state.expandedResources[index - 1], scrollController: listScrollController, ); - } else { - if (state.categories.isNotEmpty && - index - 1 < - state.expandedResources.length) { - return DirListWidget( - dir: state.expandedResources[index - 1], - scrollController: listScrollController, - ); - } } - return null; - }, - ), + } + return null; + }), ), ), BlocBuilder( @@ -99,28 +109,28 @@ class AgendaConfigPage extends StatelessWidget { scale: state.choosedIds.isNotEmpty ? 1 : 0, duration: Res.animationDuration, child: Container( - margin: EdgeInsets.only( - bottom: 10.h, - ), + margin: EdgeInsets.only(bottom: 10.h), decoration: BoxDecoration( borderRadius: BorderRadius.circular(100), color: Theme.of(context).primaryColor, boxShadow: [ BoxShadow( - color: Theme.of(context) - .primaryColor - .withValues(alpha: 0.5), + color: Theme.of( + context, + ).primaryColor.withValues(alpha: 0.5), blurRadius: 8, - offset: - const Offset(4, 4), // Shadow position + offset: const Offset( + 4, + 4, + ), // Shadow position ), ], ), child: IconButton( onPressed: () { - context - .read() - .onBack(state.choosedIds); + context.read().onBack( + state.choosedIds, + ); }, icon: Icon( Icons.check_rounded, @@ -133,7 +143,7 @@ class AgendaConfigPage extends StatelessWidget { ), ); }, - ) + ), ], ), ), @@ -152,10 +162,12 @@ class AgendaConfigPage extends StatelessWidget { if (result != null) { List indexs = AgendaConfigLogic.urlToIndexes(result); for (var index in indexs) { - context.read().toggleChooseDir(context - .read() - .state - .categories[index]); + context.read().toggleChooseDir( + context + .read() + .state + .categories[index], + ); } } }, @@ -176,69 +188,72 @@ class AgendaConfigPage extends StatelessWidget { ), ), body: CommonScreenWidget( - header: LayoutBuilder(builder: (context, constraints) { - return Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - if (!noBack) - Padding( - padding: EdgeInsets.only(left: 2.w), - child: Material( - borderRadius: - const BorderRadius.all(Radius.circular(100)), - color: Colors.transparent, - child: InkWell( - borderRadius: - const BorderRadius.all(Radius.circular(100)), - onTap: () { - if (state.status == - AgendaConfigStatus.searchResult) { - context.read().unSearch(); - } else { - Navigator.of(context).pop(); - } - }, - child: const Icon( - Icons.arrow_back_rounded, + header: LayoutBuilder( + builder: (context, constraints) { + return Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + if (!noBack) + Padding( + padding: EdgeInsets.only(left: 2.w), + child: Material( + borderRadius: const BorderRadius.all( + Radius.circular(100), + ), + color: Colors.transparent, + child: InkWell( + borderRadius: const BorderRadius.all( + Radius.circular(100), + ), + onTap: () { + if (state.status == + AgendaConfigStatus.searchResult) { + context.read().unSearch(); + } else { + Navigator.of(context).pop(); + } + }, + child: const Icon(Icons.arrow_back_rounded), ), ), ), - ), - Expanded( - child: Container( - decoration: BoxDecoration( - color: Theme.of(context).colorScheme.surface, - borderRadius: BorderRadius.circular(100), - ), - margin: const EdgeInsets.all(8.0), - child: TextField( - onChanged: (String query) {}, - onSubmitted: (String query) { - context.read().search( - query, - ); - FocusScope.of(context).unfocus(); - }, - style: TextStyle( - color: - Theme.of(context).textTheme.labelLarge!.color, + Expanded( + child: Container( + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.surface, + borderRadius: BorderRadius.circular(100), ), - cursorColor: - Theme.of(context).textTheme.bodyLarge!.color, - decoration: InputDecoration( - // contentPadding: EdgeInsets.symmetric(vertical: 1.5.h), - hintText: - AppLocalizations.of(context).searchInCalendars, - border: InputBorder.none, - contentPadding: EdgeInsets.only(left: 4.w), + margin: const EdgeInsets.all(8.0), + child: TextField( + onChanged: (String query) {}, + onSubmitted: (String query) { + context.read().search(query); + FocusScope.of(context).unfocus(); + }, + style: TextStyle( + color: Theme.of( + context, + ).textTheme.labelLarge!.color, + ), + cursorColor: Theme.of( + context, + ).textTheme.bodyLarge!.color, + decoration: InputDecoration( + // contentPadding: EdgeInsets.symmetric(vertical: 1.5.h), + hintText: AppLocalizations.of( + context, + ).searchInCalendars, + border: InputBorder.none, + contentPadding: EdgeInsets.only(left: 4.w), + ), + expands: false, ), - expands: false, ), ), - ), - ], - ); - }), + ], + ); + }, + ), body: body, ), ); diff --git a/apps/onyx/lib/screens/izly/logic/izly_logic.dart b/apps/onyx/lib/screens/izly/logic/izly_logic.dart index 30755531e..db62b720e 100644 --- a/apps/onyx/lib/screens/izly/logic/izly_logic.dart +++ b/apps/onyx/lib/screens/izly/logic/izly_logic.dart @@ -1,14 +1,16 @@ import 'package:flutter/services.dart'; -import 'package:hive_ce_flutter/hive_flutter.dart'; import 'package:izlyclient/izlyclient.dart'; import 'package:onyx/core/res.dart'; +import 'package:path/path.dart'; +import 'package:path_provider/path_provider.dart'; +import 'package:sembast/sembast_io.dart'; class IzlyLogic { static Future getQrCode(IzlyClient izlyClient) async { if (Res.mock) { - return (await rootBundle.load(Res.izlyMockQrCodePath)) - .buffer - .asUint8List(); + return (await rootBundle.load( + Res.izlyMockQrCodePath, + )).buffer.asUint8List(); } return await izlyClient.getQRCode(); } @@ -23,7 +25,9 @@ class IzlyLogic { } static Future<({Map body, String url})> getTransferUrl( - IzlyClient izlyClient, double amount) async { + IzlyClient izlyClient, + double amount, + ) async { if (Res.mock) { return (url: "google.com", body: const {}); } @@ -32,7 +36,10 @@ class IzlyLogic { } static Future<({Map body, String url})> rechargeWithCB( - IzlyClient izlyClient, double amount, CbModel cb) async { + IzlyClient izlyClient, + double amount, + CbModel cb, + ) async { if (Res.mock) { return (url: "google.com", body: const {}); } @@ -48,8 +55,12 @@ class IzlyLogic { return await izlyClient.getAvailableCBs(); } - static Future rechargeViaSomeoneElse(IzlyClient izlyClient, - double amount, String email, String message) async { + static Future rechargeViaSomeoneElse( + IzlyClient izlyClient, + double amount, + String email, + String message, + ) async { if (Res.mock) { return true; } @@ -57,31 +68,42 @@ class IzlyLogic { return await izlyClient.rechargeViaSomeoneElse(amount, email, message); } + static Future _getDb() async { + final dir = await getApplicationDocumentsDirectory(); + final dbPath = join(dir.path, 'favourite_restaurant.db'); + return await databaseFactoryIo.openDatabase(dbPath); + } + + static final _store = stringMapStoreFactory.store('favourite_restaurant'); + static Future addRestaurantToFavourite( - RestaurantModel restaurant) async { - final box = await Hive.openBox("favourite_restaurant"); - box.put(restaurant.id, true); + RestaurantModel restaurant, + ) async { + final db = await _getDb(); + await _store.record(restaurant.id.toString()).put(db, {'favourite': true}); } static Future removeRestaurantToFavourite( - RestaurantModel restaurant) async { - final box = await Hive.openBox("favourite_restaurant"); - box.put(restaurant.id, false); + RestaurantModel restaurant, + ) async { + final db = await _getDb(); + await _store.record(restaurant.id.toString()).put(db, {'favourite': false}); } static Future isRestaurantFavourite(RestaurantModel restaurant) async { - final box = await Hive.openBox("favourite_restaurant"); - return box.get(restaurant.id, defaultValue: false); + final db = await _getDb(); + final record = + await _store.record(restaurant.id.toString()).get(db) as Map?; + return record != null ? (record['favourite'] ?? false) : false; } static Future> getUserPayments( - IzlyClient izlyClient) async { + IzlyClient izlyClient, + ) async { if (Res.mock) { return paymentModelListMock; } - await reloginIfNeeded(izlyClient); - try { return await izlyClient.getUserPayments(); } catch (e) { diff --git a/apps/onyx/lib/screens/izly/states/izly_cubit.dart b/apps/onyx/lib/screens/izly/states/izly_cubit.dart index 9963f2e7b..350138488 100644 --- a/apps/onyx/lib/screens/izly/states/izly_cubit.dart +++ b/apps/onyx/lib/screens/izly/states/izly_cubit.dart @@ -1,12 +1,14 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:hive_ce_flutter/hive_flutter.dart'; import 'package:izlyclient/izlyclient.dart'; import 'package:onyx/core/cache_service.dart'; import 'package:onyx/core/res.dart'; import 'package:onyx/screens/izly/izly_export.dart'; import 'package:onyx/screens/settings/domain/model/settings_model.dart'; +import 'package:path/path.dart'; +import 'package:path_provider/path_provider.dart'; +import 'package:sembast/sembast_io.dart'; part 'izly_state.dart'; @@ -15,26 +17,37 @@ class IzlyCubit extends Cubit { IzlyCubit() : super(IzlyState(status: IzlyStatus.initial)); - void connect( - {IzlyCredential? credential, required SettingsModel settings}) async { + // Sembast helpers for cached Izly amount + static Future _getDb() async { + final dir = await getApplicationDocumentsDirectory(); + final dbPath = join(dir.path, 'cached_izly_amount.db'); + return await databaseFactoryIo.openDatabase(dbPath); + } + + static final _amountStore = StoreRef('cached_izly_amount'); + + void connect({ + IzlyCredential? credential, + required SettingsModel settings, + }) async { //mock gestion if (Res.mock) { _izlyClient = IzlyClient("mockUsername", "mockPassword"); emit( state.copyWith( - status: IzlyStatus.loaded, - balance: 100.0, - qrCode: (await rootBundle.load(Res.izlyMockQrCodePath)) - .buffer - .asUint8List(), - izlyClient: _izlyClient), + status: IzlyStatus.loaded, + balance: 100.0, + qrCode: (await rootBundle.load( + Res.izlyMockQrCodePath, + )).buffer.asUint8List(), + izlyClient: _izlyClient, + ), ); - return; } - //cache loading - Box box = await Hive.openBox("cached_izly_amount"); - double amount = box.get("amount") ?? 0.0; + //cache loading (Sembast) + final db = await _getDb(); + double amount = await _amountStore.record('amount').get(db) ?? 0.0; emit(state.copyWith(status: IzlyStatus.connecting, balance: amount)); //real load @@ -42,28 +55,38 @@ class IzlyCubit extends Cubit { if (_izlyClient == null || !(await _izlyClient!.isLogged())) { //need to login credential ??= await CacheService.get( - secureKey: - await CacheService.getEncryptionKey(settings.biometricAuth)); + secureKey: await CacheService.getEncryptionKey( + settings.biometricAuth, + ), + ); if (credential == null) { emit(state.copyWith(status: IzlyStatus.noCredentials)); return; } - _izlyClient = IzlyClient(credential.username, credential.password, - corsProxyUrl: (kIsWeb) ? Res.corsProxy : ""); + _izlyClient = IzlyClient( + credential.username, + credential.password, + corsProxyUrl: (kIsWeb) ? Res.corsProxy : "", + ); bool loginResult = await _izlyClient!.login(); if (!loginResult) { if (await CacheService.exist( - secureKey: await CacheService.getEncryptionKey( - settings.biometricAuth))) { + secureKey: await CacheService.getEncryptionKey( + settings.biometricAuth, + ), + )) { emit(state.copyWith(status: IzlyStatus.error)); } else { emit(state.copyWith(status: IzlyStatus.noCredentials)); } return; } else { - await CacheService.set(credential, - secureKey: - await CacheService.getEncryptionKey(settings.biometricAuth)); + await CacheService.set( + credential, + secureKey: await CacheService.getEncryptionKey( + settings.biometricAuth, + ), + ); } } emit(state.copyWith(status: IzlyStatus.loading, izlyClient: _izlyClient)); @@ -72,11 +95,15 @@ class IzlyCubit extends Cubit { var qrCode = await IzlyLogic.getQrCode(_izlyClient!); //load balance double balance = await _izlyClient!.getBalance(); - Box box = await Hive.openBox("cached_izly_amount"); - await box.put("amount", balance); - box.close(); - emit(state.copyWith( - status: IzlyStatus.loaded, balance: balance, qrCode: qrCode)); + // Sembast: save balance + await _amountStore.record('amount').put(db, balance); + emit( + state.copyWith( + status: IzlyStatus.loaded, + balance: balance, + qrCode: qrCode, + ), + ); loadPaymentHistory(); } catch (e) { emit(state.copyWith(status: IzlyStatus.error)); @@ -87,18 +114,24 @@ class IzlyCubit extends Cubit { if (_izlyClient != null) { emit(state.copyWith(status: IzlyStatus.loading)); if (cache && await CacheService.exist()) { - emit(state.copyWith( + emit( + state.copyWith( status: IzlyStatus.cacheLoaded, paymentList: - (await CacheService.get())!.payments)); + (await CacheService.get())!.payments, + ), + ); } try { - List paymentList = - await IzlyLogic.getUserPayments(_izlyClient!); - emit(state.copyWith( - status: IzlyStatus.loaded, paymentList: paymentList)); + List paymentList = await IzlyLogic.getUserPayments( + _izlyClient!, + ); + emit( + state.copyWith(status: IzlyStatus.loaded, paymentList: paymentList), + ); await CacheService.set( - IzlyPaymentModelList(payments: paymentList)); + IzlyPaymentModelList(payments: paymentList), + ); } catch (e) { emit(state.copyWith(status: IzlyStatus.error)); } diff --git a/apps/onyx/lib/screens/mails/logic/email_logic.dart b/apps/onyx/lib/screens/mails/logic/email_logic.dart index 58eaec864..c0ac5166c 100644 --- a/apps/onyx/lib/screens/mails/logic/email_logic.dart +++ b/apps/onyx/lib/screens/mails/logic/email_logic.dart @@ -2,15 +2,20 @@ import 'package:flutter/foundation.dart'; import 'package:lyon1mailclient/lyon1mailclient.dart'; import 'package:onyx/core/cache_service.dart'; import 'package:onyx/core/extensions/special_mail_box_extension.dart'; -import 'package:onyx/core/initialisations/initialisations_export.dart'; +import 'package:onyx/core/initialisations/sembast_init.dart'; import 'package:onyx/core/res.dart'; import 'package:onyx/l10n/app_localizations.dart'; class MailLogic { - static Future connect( - {required String username, required String password}) async { - Lyon1MailClient mailClient = Lyon1MailClient(username, password, - corsProxyUrl: (kIsWeb) ? Res.corsProxy : ""); + static Future connect({ + required String username, + required String password, + }) async { + Lyon1MailClient mailClient = Lyon1MailClient( + username, + password, + corsProxyUrl: (kIsWeb) ? Res.corsProxy : "", + ); if (Res.mock) { return mailClient; } @@ -43,9 +48,10 @@ class MailLogic { removeTrackingImages: blockTrackers, ); mailBox ??= MailBox( - name: appLocalizations.inbox, - specialMailBox: SpecialMailBox.inbox, - emails: const []); + name: appLocalizations.inbox, + specialMailBox: SpecialMailBox.inbox, + emails: const [], + ); if (emailOpt == null || emailOpt.isEmpty) { Res.logger.d("no Mails"); } else { @@ -58,7 +64,7 @@ class MailLogic { if (Res.mock) { return mailboxesMock; } - hiveInit(path: path); + await initSembastDb(path); if (await CacheService.exist()) { return (await CacheService.get())!.mailBoxes; } else { @@ -85,59 +91,64 @@ class MailLogic { static final List emailListMock = [ Mail( - subject: "subjectMock1", - sender: "senderMock1", - excerpt: "excerptMock1", - isRead: false, - date: DateTime(2022, 9, 1, 8), - body: "bodyMock1", - id: 1, - receiver: "receiverMock1", - attachments: const ["attachmentMock1", "attachmentMock2"], - isFlagged: false), + subject: "subjectMock1", + sender: "senderMock1", + excerpt: "excerptMock1", + isRead: false, + date: DateTime(2022, 9, 1, 8), + body: "bodyMock1", + id: 1, + receiver: "receiverMock1", + attachments: const ["attachmentMock1", "attachmentMock2"], + isFlagged: false, + ), Mail( - subject: "subjectMock2", - sender: "senderMock2", - excerpt: "excerptMock2", - isRead: true, - date: DateTime(2022, 9, 1, 9), - body: "bodyMock2", - id: 2, - receiver: "receiverMock2", - attachments: const ["attachmentMock1", "attachmentMock2"], - isFlagged: true), + subject: "subjectMock2", + sender: "senderMock2", + excerpt: "excerptMock2", + isRead: true, + date: DateTime(2022, 9, 1, 9), + body: "bodyMock2", + id: 2, + receiver: "receiverMock2", + attachments: const ["attachmentMock1", "attachmentMock2"], + isFlagged: true, + ), Mail( - subject: "subjectMock3", - sender: "senderMock3", - excerpt: "excerptMock3", - isRead: false, - date: DateTime(2022, 9, 1, 10), - body: "bodyMock3", - id: 3, - receiver: "receiverMock3", - attachments: const ["attachmentMock1", "attachmentMock2"], - isFlagged: false), + subject: "subjectMock3", + sender: "senderMock3", + excerpt: "excerptMock3", + isRead: false, + date: DateTime(2022, 9, 1, 10), + body: "bodyMock3", + id: 3, + receiver: "receiverMock3", + attachments: const ["attachmentMock1", "attachmentMock2"], + isFlagged: false, + ), Mail( - subject: "subjectMock4", - sender: "senderMock4", - excerpt: "excerptMock4", - isRead: true, - date: DateTime(2022, 9, 1, 11), - body: "bodyMock4", - id: 4, - receiver: "receiverMock4", - attachments: const ["attachmentMock1", "attachmentMock2"], - isFlagged: true), + subject: "subjectMock4", + sender: "senderMock4", + excerpt: "excerptMock4", + isRead: true, + date: DateTime(2022, 9, 1, 11), + body: "bodyMock4", + id: 4, + receiver: "receiverMock4", + attachments: const ["attachmentMock1", "attachmentMock2"], + isFlagged: true, + ), Mail( - subject: "subjectMock5", - sender: "senderMock5", - excerpt: "excerptMock5", - isRead: false, - date: DateTime(2022, 9, 1, 12), - body: "bodyMock5", - id: 5, - receiver: "receiverMock5", - attachments: const ["attachmentMock1", "attachmentMock2"], - isFlagged: false), + subject: "subjectMock5", + sender: "senderMock5", + excerpt: "excerptMock5", + isRead: false, + date: DateTime(2022, 9, 1, 12), + body: "bodyMock5", + id: 5, + receiver: "receiverMock5", + attachments: const ["attachmentMock1", "attachmentMock2"], + isFlagged: false, + ), ]; } diff --git a/apps/onyx/lib/screens/mails/pages/emails_page.dart b/apps/onyx/lib/screens/mails/pages/emails_page.dart index 0a3b5e96a..71c651e53 100644 --- a/apps/onyx/lib/screens/mails/pages/emails_page.dart +++ b/apps/onyx/lib/screens/mails/pages/emails_page.dart @@ -11,9 +11,7 @@ import 'package:onyx/screens/settings/settings_export.dart'; import 'package:responsive_sizer/responsive_sizer.dart'; class MailsPage extends StatelessWidget { - const MailsPage({ - super.key, - }); + const MailsPage({super.key}); @override Widget build(BuildContext context) { @@ -25,10 +23,13 @@ class MailsPage extends StatelessWidget { current.status != previous.status, listener: (context, state) { context.read().doQueuedAction( - blockTrackers: - context.read().state.settings.blockTrackers, - appLocalizations: AppLocalizations.of(context), - ); + blockTrackers: context + .read() + .state + .settings + .blockTrackers, + appLocalizations: AppLocalizations.of(context), + ); }, builder: (context, state) { Widget? loadingHeader; @@ -43,7 +44,8 @@ class MailsPage extends StatelessWidget { case MailStatus.cacheSorted: case MailStatus.mailboxesLoaded: loadingHeader = LoadingHeaderWidget( - message: AppLocalizations.of(context).loadingMails); + message: AppLocalizations.of(context).loadingMails, + ); break; case MailStatus.error: loadingHeader = LoadingHeaderWidget( @@ -59,35 +61,35 @@ class MailsPage extends StatelessWidget { final emailCubit = context.read(); final localization = AppLocalizations.of(context); CacheService.getEncryptionKey( - context.read().state.settings.biometricAuth) - .then((key) => CacheService.get(secureKey: key)) - .then( - (value) { - if (value != null) { - emailCubit.connect( - username: value.username, - password: value.password, - appLocalizations: localization, - ); - } - }, - ); + context.read().state.settings.biometricAuth, + ).then((key) => CacheService.get(secureKey: key)).then(( + value, + ) { + if (value != null) { + emailCubit.connect( + username: value.username, + password: value.password, + appLocalizations: localization, + ); + } + }); break; case MailStatus.connected: context.read().load( - blockTrackers: context - .read() - .state - .settings - .blockTrackers, - appLocalizations: AppLocalizations.of(context), - ); + blockTrackers: context + .read() + .state + .settings + .blockTrackers, + appLocalizations: AppLocalizations.of(context), + ); break; case MailStatus.sending: loadingHeader = LoadingHeaderWidget( - message: AppLocalizations.of(context).sendingEmail); + message: AppLocalizations.of(context).sendingEmail, + ); break; case MailStatus.loaded: break; @@ -107,10 +109,10 @@ class MailsPage extends StatelessWidget { break; } return PopScope( - onPopInvokedWithResult: (_, __) { - context - .read() - .unselectAllMails(AppLocalizations.of(context)); + onPopInvokedWithResult: (_, _) { + context.read().unselectAllMails( + AppLocalizations.of(context), + ); }, child: Scaffold( backgroundColor: Theme.of(context).colorScheme.surface, @@ -145,12 +147,15 @@ class MailsPage extends StatelessWidget { padding: EdgeInsets.only(top: 0.7 * Res.bottomNavBarHeight), child: ListView.custom( controller: scrollController, - childrenDelegate: - SliverChildBuilderDelegate((context, index) { + childrenDelegate: SliverChildBuilderDelegate(( + context, + index, + ) { if (index < (state.currentMailBox?.emails.length ?? 0)) { return MailWidget( - email: state.currentMailBox!.emails[index]); + email: state.currentMailBox!.emails[index], + ); } else if ((index == (state.currentMailBox?.emails.length ?? 0)) && (state.currentMailBox?.emails.isNotEmpty ?? @@ -175,14 +180,18 @@ class MailsPage extends StatelessWidget { .state .settings .blockTrackers, - appLocalizations: - AppLocalizations.of(context), + appLocalizations: AppLocalizations.of( + context, + ), ), child: Center( child: Padding( padding: EdgeInsets.all(8.w), - child: Text(AppLocalizations.of(context) - .loadMoreMails), + child: Text( + AppLocalizations.of( + context, + ).loadMoreMails, + ), ), ), ), @@ -197,13 +206,13 @@ class MailsPage extends StatelessWidget { ), onRefresh: () async { context.read().load( - blockTrackers: context - .read() - .state - .settings - .blockTrackers, - appLocalizations: AppLocalizations.of(context), - ); + blockTrackers: context + .read() + .state + .settings + .blockTrackers, + appLocalizations: AppLocalizations.of(context), + ); return; }, ), diff --git a/apps/onyx/lib/screens/mails/states/email_cubit.dart b/apps/onyx/lib/screens/mails/states/email_cubit.dart index 53a005451..786d32822 100644 --- a/apps/onyx/lib/screens/mails/states/email_cubit.dart +++ b/apps/onyx/lib/screens/mails/states/email_cubit.dart @@ -39,7 +39,9 @@ class EmailCubit extends Cubit { if (!kIsWeb) { emailsBoxesComplete = await compute( - MailLogic.cacheLoad, (await getApplicationDocumentsDirectory()).path); + MailLogic.cacheLoad, + (await getApplicationDocumentsDirectory()).path, + ); } if (emailsBoxesComplete.isNotEmpty) { @@ -59,17 +61,14 @@ class EmailCubit extends Cubit { try { username = username; password = password; - mailClient = - await MailLogic.connect(username: username, password: password); - emit(state.copyWith( - status: MailStatus.connected, - connected: true, - )); + mailClient = await MailLogic.connect( + username: username, + password: password, + ); + emit(state.copyWith(status: MailStatus.connected, connected: true)); } catch (e) { Res.logger.e("error while connecting (email): $e"); - emit(state.copyWith( - status: MailStatus.error, - )); + emit(state.copyWith(status: MailStatus.error)); } } } @@ -80,25 +79,28 @@ class EmailCubit extends Cubit { MailBox? mailbox, required AppLocalizations appLocalizations, }) async { - emit(state.copyWith( - status: MailStatus.loading, - )); + emit(state.copyWith(status: MailStatus.loading)); if (Res.mock) { emailsBoxesComplete = MailLogic.mailboxesMock; currentMailBoxIndex = 0; Future.delayed( - const Duration(milliseconds: 500), - () => emit(state.copyWith( - mailBoxes: emailsBoxesComplete, - status: MailStatus.loaded, - currentMailBox: emailsBoxesComplete[currentMailBoxIndex], - ))); + const Duration(milliseconds: 500), + () => emit( + state.copyWith( + mailBoxes: emailsBoxesComplete, + status: MailStatus.loaded, + currentMailBox: emailsBoxesComplete[currentMailBoxIndex], + ), + ), + ); return; } if (cache && !Res.mock && !kIsWeb) { List emailCache = await compute( - MailLogic.cacheLoad, (await getApplicationDocumentsDirectory()).path); + MailLogic.cacheLoad, + (await getApplicationDocumentsDirectory()).path, + ); if (emailCache.isNotEmpty && !listEquals(emailCache, emailsBoxesComplete)) { emailsBoxesComplete = emailCache; @@ -106,10 +108,12 @@ class EmailCubit extends Cubit { if (mailbox != null) { if (mailbox.specialMailBox != null) { currentMailBoxIndex = emailsBoxesComplete.indexWhere( - (element) => element.specialMailBox == mailbox.specialMailBox); + (element) => element.specialMailBox == mailbox.specialMailBox, + ); } else { - currentMailBoxIndex = emailsBoxesComplete - .indexWhere((element) => element.name == mailbox.name); + currentMailBoxIndex = emailsBoxesComplete.indexWhere( + (element) => element.name == mailbox.name, + ); } } if (currentMailBoxIndex == -1) { @@ -118,30 +122,33 @@ class EmailCubit extends Cubit { } else { currentMailBox = emailsBoxesComplete[currentMailBoxIndex]; } - emit(state.copyWith( - mailBoxes: emailsBoxesComplete, - status: MailStatus.cacheLoaded, - currentMailBox: currentMailBox, - )); - filter( - filter: lastFilter, + emit( + state.copyWith( + mailBoxes: emailsBoxesComplete, + status: MailStatus.cacheLoaded, + currentMailBox: currentMailBox, + ), ); + filter(filter: lastFilter); } } try { List emailBoxes = await mailClient!.getMailboxes(); for (var i in emailBoxes) { - if (emailsBoxesComplete - .indexWhere((element) => element.name == i.name) == + if (emailsBoxesComplete.indexWhere( + (element) => element.name == i.name, + ) == -1) { emailsBoxesComplete.add(i); } } - emit(state.copyWith( - mailBoxes: emailsBoxesComplete, - status: MailStatus.mailboxesLoaded, - )); + emit( + state.copyWith( + mailBoxes: emailsBoxesComplete, + status: MailStatus.mailboxesLoaded, + ), + ); MailBox loadedMail = (await MailLogic.load( emailNumber: emailNumber, mailClient: mailClient!, @@ -150,113 +157,123 @@ class EmailCubit extends Cubit { appLocalizations: appLocalizations, )); //put the important mail in firts position - loadedMail.emails.sort((a, b) => (b.isFlagged) - ? 1 - : (a.isFlagged) - ? -1 - : 0); + loadedMail.emails.sort( + (a, b) => (b.isFlagged) + ? 1 + : (a.isFlagged) + ? -1 + : 0, + ); - int index = emailsBoxesComplete.indexWhere((element) => - element.name == loadedMail.name || - element.specialMailBox == loadedMail.specialMailBox); + int index = emailsBoxesComplete.indexWhere( + (element) => + element.name == loadedMail.name || + element.specialMailBox == loadedMail.specialMailBox, + ); if (index != -1) { - emailsBoxesComplete[index] = - emailsBoxesComplete[index].copyWith.emails(loadedMail.emails); + emailsBoxesComplete[index] = emailsBoxesComplete[index].copyWith( + emails: loadedMail.emails, + ); } } catch (e) { Res.logger.e(e); - emit(state.copyWith( - status: MailStatus.error, - )); + emit(state.copyWith(status: MailStatus.error)); return; } CacheService.set( - MailBoxList(mailBoxes: emailsBoxesComplete)); //await à definir + MailBoxList(mailBoxes: emailsBoxesComplete), + ); //await à definir currentMailBoxIndex = emailsBoxesComplete.indexWhere( - (element) => element.specialMailBox == SpecialMailBox.inbox); - emit(state.copyWith( - status: MailStatus.loaded, - mailBoxes: emailsBoxesComplete, - currentMailBox: (mailbox == null && currentMailBoxIndex != -1) - ? emailsBoxesComplete[currentMailBoxIndex] - : mailbox, - )); - filter( - filter: lastFilter, + (element) => element.specialMailBox == SpecialMailBox.inbox, ); + emit( + state.copyWith( + status: MailStatus.loaded, + mailBoxes: emailsBoxesComplete, + currentMailBox: (mailbox == null && currentMailBoxIndex != -1) + ? emailsBoxesComplete[currentMailBoxIndex] + : mailbox, + ), + ); + filter(filter: lastFilter); } - void filter({ - required String filter, - }) async { + void filter({required String filter}) async { lastFilter = filter; - List email = []; + List emails = []; if (filter != "") { - for (var i in emailsBoxesComplete - .firstWhere((element) => state.currentMailBox!.name == element.name) - .emails) { + for (var i + in emailsBoxesComplete + .firstWhere( + (element) => state.currentMailBox!.name == element.name, + ) + .emails) { if (i.subject.toLowerCase().contains(filter.toLowerCase()) || i.excerpt.toLowerCase().contains(filter.toLowerCase()) || i.date.toString().toLowerCase().contains(filter.toLowerCase()) || i.sender.toLowerCase().contains(filter.toLowerCase()) || i.body.toLowerCase().contains(filter.toLowerCase())) { - email.add(i); + emails.add(i); } } } else { - email = emailsBoxesComplete + emails = emailsBoxesComplete .firstWhere((element) => state.currentMailBox!.name == element.name) .emails; } - emit(state.copyWith( - status: (state.status == MailStatus.cacheLoaded) - ? MailStatus.cacheSorted - : MailStatus.sorted, - currentMailBox: state.currentMailBox!.copyWith.emails(email), - )); + emit( + state.copyWith( + status: (state.status == MailStatus.cacheLoaded) + ? MailStatus.cacheSorted + : MailStatus.sorted, + currentMailBox: state.currentMailBox!.copyWith(emails: emails), + ), + ); } - void delete({ - required Mail email, - required MailBox from, - }) async { + void delete({required Mail email, required MailBox from}) async { if (!Res.mock) { mailClient!.addAction( - Action(type: ActionType.delete, mail: email, fromMailBox: from)); + Action(type: ActionType.delete, mail: email, fromMailBox: from), + ); } emailsBoxesComplete[currentMailBoxIndex].emails.remove(email); - emit(state.copyWith( - status: MailStatus.updated, - mailBoxes: emailsBoxesComplete, - currentMailBox: emailsBoxesComplete[currentMailBoxIndex], - )); //do it locally + emit( + state.copyWith( + status: MailStatus.updated, + mailBoxes: emailsBoxesComplete, + currentMailBox: emailsBoxesComplete[currentMailBoxIndex], + ), + ); //do it locally CacheService.set(MailBoxList(mailBoxes: emailsBoxesComplete)); } - void markAsRead({ - required Mail email, - required MailBox from, - }) async { + void markAsRead({required Mail email, required MailBox from}) async { if (!email.isRead) { if (!Res.mock) { - mailClient!.addAction(Action( - type: ActionType.markAsRead, mail: email, fromMailBox: from)); + mailClient!.addAction( + Action(type: ActionType.markAsRead, mail: email, fromMailBox: from), + ); } - int index = - emailsBoxesComplete[currentMailBoxIndex].emails.indexOf(email); + int index = emailsBoxesComplete[currentMailBoxIndex].emails.indexOf( + email, + ); if (index == -1) return; emailsBoxesComplete[currentMailBoxIndex].emails[index] = emailsBoxesComplete[currentMailBoxIndex].emails[index].copyWith( - isRead: true, - ); + isRead: true, + ); CacheService.set( - MailBoxList(mailBoxes: emailsBoxesComplete)); - emit(state.copyWith( - status: MailStatus.updated, - mailBoxes: emailsBoxesComplete, - currentMailBox: emailsBoxesComplete[currentMailBoxIndex], - )); + MailBoxList(mailBoxes: emailsBoxesComplete), + ); + emit( + state.copyWith( + status: MailStatus.updated, + mailBoxes: emailsBoxesComplete, + currentMailBox: emailsBoxesComplete[currentMailBoxIndex], + ), + ); } } @@ -267,26 +284,33 @@ class EmailCubit extends Cubit { }) async { if (!Res.mock) { mailClient!.addAction( - Action(type: ActionType.archive, mail: email, fromMailBox: from)); + Action(type: ActionType.archive, mail: email, fromMailBox: from), + ); } emailsBoxesComplete[currentMailBoxIndex].emails.remove(email); int index = emailsBoxesComplete.indexWhere( - (element) => element.specialMailBox == SpecialMailBox.archive); + (element) => element.specialMailBox == SpecialMailBox.archive, + ); if (index != -1) { emailsBoxesComplete[index].emails.add(email); } else { - emailsBoxesComplete.add(MailBox( + emailsBoxesComplete.add( + MailBox( name: appLocalizations.archive, specialMailBox: SpecialMailBox.archive, - emails: [email])); + emails: [email], + ), + ); } CacheService.set(MailBoxList(mailBoxes: emailsBoxesComplete)); - emit(state.copyWith( - status: MailStatus.updated, - mailBoxes: emailsBoxesComplete, - currentMailBox: emailsBoxesComplete[currentMailBoxIndex], - )); //do it locally + emit( + state.copyWith( + status: MailStatus.updated, + mailBoxes: emailsBoxesComplete, + currentMailBox: emailsBoxesComplete[currentMailBoxIndex], + ), + ); //do it locally } Future move({ @@ -295,113 +319,109 @@ class EmailCubit extends Cubit { required MailBox from, }) async { if (!Res.mock) { - mailClient!.addAction(Action( + mailClient!.addAction( + Action( type: ActionType.move, mail: email, fromMailBox: from, - destinationMailBox: folder)); + destinationMailBox: folder, + ), + ); } emailsBoxesComplete[currentMailBoxIndex].emails.remove(email); emailsBoxesComplete[emailsBoxesComplete.indexOf(folder)].emails.add(email); CacheService.set(MailBoxList(mailBoxes: emailsBoxesComplete)); - emit(state.copyWith( - status: MailStatus.updated, - mailBoxes: emailsBoxesComplete, - currentMailBox: emailsBoxesComplete[currentMailBoxIndex], - )); //do it locally + emit( + state.copyWith( + status: MailStatus.updated, + mailBoxes: emailsBoxesComplete, + currentMailBox: emailsBoxesComplete[currentMailBoxIndex], + ), + ); //do it locally } - void markAsUnread({ - required Mail email, - required MailBox from, - }) async { + void markAsUnread({required Mail email, required MailBox from}) async { if (email.isRead) { if (!Res.mock) { - mailClient!.addAction(Action( - type: ActionType.markAsUnread, mail: email, fromMailBox: from)); + mailClient!.addAction( + Action(type: ActionType.markAsUnread, mail: email, fromMailBox: from), + ); } - int index = - emailsBoxesComplete[currentMailBoxIndex].emails.indexOf(email); + int index = emailsBoxesComplete[currentMailBoxIndex].emails.indexOf( + email, + ); if (index == -1) return; emailsBoxesComplete[currentMailBoxIndex].emails[index] = emailsBoxesComplete[currentMailBoxIndex].emails[index].copyWith( - isRead: false, - ); + isRead: false, + ); CacheService.set( - MailBoxList(mailBoxes: emailsBoxesComplete)); - emit(state.copyWith( - status: MailStatus.updated, - mailBoxes: emailsBoxesComplete, - currentMailBox: emailsBoxesComplete[currentMailBoxIndex], - )); + MailBoxList(mailBoxes: emailsBoxesComplete), + ); + emit( + state.copyWith( + status: MailStatus.updated, + mailBoxes: emailsBoxesComplete, + currentMailBox: emailsBoxesComplete[currentMailBoxIndex], + ), + ); } } - void toggleFlag({ - required Mail email, - required MailBox from, - }) async { + void toggleFlag({required Mail email, required MailBox from}) async { if (email.isFlagged) { - unflag( - email: email, - from: from, - ); + unflag(email: email, from: from); } else { - flag( - email: email, - from: from, - ); + flag(email: email, from: from); } } - void flag({ - required Mail email, - required MailBox from, - }) async { + void flag({required Mail email, required MailBox from}) async { if (!Res.mock) { mailClient!.addAction( - Action(type: ActionType.flag, mail: email, fromMailBox: from)); + Action(type: ActionType.flag, mail: email, fromMailBox: from), + ); } int index = emailsBoxesComplete[currentMailBoxIndex].emails.indexOf(email); if (index == -1) return; emailsBoxesComplete[currentMailBoxIndex].emails[index] = emailsBoxesComplete[currentMailBoxIndex].emails[index].copyWith( - isFlagged: true, - ); + isFlagged: true, + ); CacheService.set(MailBoxList(mailBoxes: emailsBoxesComplete)); - emit(state.copyWith( - status: MailStatus.updated, - mailBoxes: emailsBoxesComplete, - currentMailBox: emailsBoxesComplete[currentMailBoxIndex], - )); + emit( + state.copyWith( + status: MailStatus.updated, + mailBoxes: emailsBoxesComplete, + currentMailBox: emailsBoxesComplete[currentMailBoxIndex], + ), + ); } - void unflag({ - required Mail email, - required MailBox from, - }) async { + void unflag({required Mail email, required MailBox from}) async { if (!Res.mock) { mailClient!.addAction( - Action(type: ActionType.unflag, mail: email, fromMailBox: from)); + Action(type: ActionType.unflag, mail: email, fromMailBox: from), + ); } int index = emailsBoxesComplete[currentMailBoxIndex].emails.indexOf(email); if (index == -1) return; emailsBoxesComplete[currentMailBoxIndex].emails[index] = emailsBoxesComplete[currentMailBoxIndex].emails[index].copyWith( - isFlagged: false, - ); + isFlagged: false, + ); CacheService.set(MailBoxList(mailBoxes: emailsBoxesComplete)); - emit(state.copyWith( - status: MailStatus.updated, - mailBoxes: emailsBoxesComplete, - currentMailBox: emailsBoxesComplete[currentMailBoxIndex], - )); + emit( + state.copyWith( + status: MailStatus.updated, + mailBoxes: emailsBoxesComplete, + currentMailBox: emailsBoxesComplete[currentMailBoxIndex], + ), + ); if (!mailClient!.isAuthenticated && !Res.mock) { if (!await mailClient!.login()) { - emit(state.copyWith( - status: MailStatus.nonFatalError, - )); + emit(state.copyWith(status: MailStatus.nonFatalError)); return; } } @@ -416,13 +436,14 @@ class EmailCubit extends Cubit { required MailBox from, }) async { Action action = Action( - type: (reply) - ? ActionType.reply - : ((forward) ? ActionType.forward : ActionType.send), - mail: email, - originalMessageId: replyOriginalMessageId, - replyAll: replyAll, - fromMailBox: (reply || forward) ? from : null); + type: (reply) + ? ActionType.reply + : ((forward) ? ActionType.forward : ActionType.send), + mail: email, + originalMessageId: replyOriginalMessageId, + replyAll: replyAll, + fromMailBox: (reply || forward) ? from : null, + ); if (!Res.mock) { emit(state.copyWith(status: MailStatus.sending)); await mailClient!.addAction(action); @@ -430,41 +451,29 @@ class EmailCubit extends Cubit { } } - void selectMail({ - required Mail email, - }) { - emit(state.copyWith( - selectedMails: List.from(state.selectedMails)..add(email), - )); + void selectMail({required Mail email}) { + emit( + state.copyWith(selectedMails: List.from(state.selectedMails)..add(email)), + ); } - void unselectMail({ - required Mail emails, - }) { - emit(state.copyWith( - selectedMails: List.from(state.selectedMails)..remove(emails), - )); + void unselectMail({required Mail emails}) { + emit( + state.copyWith( + selectedMails: List.from(state.selectedMails)..remove(emails), + ), + ); } - void unselectAllMails( - AppLocalizations appLocalizations, - ) { - emit(state.copyWith( - selectedMails: [], - )); + void unselectAllMails(AppLocalizations appLocalizations) { + emit(state.copyWith(selectedMails: [])); } - void toggleMailSelection({ - required Mail emails, - }) { + void toggleMailSelection({required Mail emails}) { if (state.selectedMails.contains(emails)) { - unselectMail( - emails: emails, - ); + unselectMail(emails: emails); } else { - selectMail( - email: emails, - ); + selectMail(email: emails); } } @@ -473,13 +482,12 @@ class EmailCubit extends Cubit { required AppLocalizations appLocalizations, }) { emailNumber += 20; - emit(state.copyWith( - status: MailStatus.loading, - )); + emit(state.copyWith(status: MailStatus.loading)); load( - cache: false, - blockTrackers: blockTrackers, - appLocalizations: appLocalizations); + cache: false, + blockTrackers: blockTrackers, + appLocalizations: appLocalizations, + ); return; } @@ -499,8 +507,9 @@ class EmailCubit extends Cubit { if (actions.isEmpty || !state.connected) return; for (Action action in actions) { Res.logger.d("action: $action"); - currentMailBoxIndex = emailsBoxesComplete - .indexWhere((element) => element.name == action.fromMailBox!.name); + currentMailBoxIndex = emailsBoxesComplete.indexWhere( + (element) => element.name == action.fromMailBox!.name, + ); switch (action.type) { case ActionType.archive: archive( @@ -517,22 +526,13 @@ class EmailCubit extends Cubit { ); break; case ActionType.markAsUnread: - markAsUnread( - email: action.mail, - from: action.fromMailBox!, - ); + markAsUnread(email: action.mail, from: action.fromMailBox!); break; case ActionType.send: - send( - email: action.mail, - from: action.fromMailBox!, - ); + send(email: action.mail, from: action.fromMailBox!); break; case ActionType.markAsRead: - markAsRead( - email: action.mail, - from: action.fromMailBox!, - ); + markAsRead(email: action.mail, from: action.fromMailBox!); break; case ActionType.reply: send( @@ -552,22 +552,13 @@ class EmailCubit extends Cubit { ); break; case ActionType.delete: - delete( - email: action.mail, - from: action.fromMailBox!, - ); + delete(email: action.mail, from: action.fromMailBox!); break; case ActionType.flag: - flag( - email: action.mail, - from: action.fromMailBox!, - ); + flag(email: action.mail, from: action.fromMailBox!); break; case ActionType.unflag: - unflag( - email: action.mail, - from: action.fromMailBox!, - ); + unflag(email: action.mail, from: action.fromMailBox!); break; } } diff --git a/apps/onyx/lib/screens/mails/states/email_send_cubit.dart b/apps/onyx/lib/screens/mails/states/email_send_cubit.dart index b777fce1b..75723f532 100644 --- a/apps/onyx/lib/screens/mails/states/email_send_cubit.dart +++ b/apps/onyx/lib/screens/mails/states/email_send_cubit.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_quill/flutter_quill.dart'; @@ -9,22 +9,24 @@ import 'package:onyx/screens/mails/states/email_cubit.dart'; import 'package:vsc_quill_delta_to_html/vsc_quill_delta_to_html.dart'; part 'email_send_state.dart'; -part 'generated/email_send_cubit.g.dart'; +part 'generated/email_send_cubit.mapper.dart'; class EmailSendCubit extends Cubit { EmailSendCubit(int? originalMessage, bool? replyAll, bool reply, bool forward) - : super(EmailSendState(status: EmailSendStatus.initial)) { - emit(state.copyWith( - status: EmailSendStatus.updated, - originalMessage: originalMessage, - replyAll: replyAll, - reply: reply, - forward: forward, - controller: QuillController.basic(), - subjectEditor: TextEditingController(), - destinationEditor: TextEditingController(), - attachments: [], - )); + : super(EmailSendState(status: EmailSendStatus.initial)) { + emit( + state.copyWith( + status: EmailSendStatus.updated, + originalMessage: originalMessage, + replyAll: replyAll, + reply: reply, + forward: forward, + controller: QuillController.basic(), + subjectEditor: TextEditingController(), + destinationEditor: TextEditingController(), + attachments: [], + ), + ); } void addAttachment(File file) { @@ -53,7 +55,7 @@ class EmailSendCubit extends Cubit { state.destinationEditor!.value.text.contains(".")) || (state.originalMessage != null && bodyHtml(state.controller!).isNotEmpty)) { - Mail email = Mail.withAttachments( + Mail email = Mail( subject: state.subjectEditor!.text, sender: "moi", excerpt: "", @@ -83,8 +85,8 @@ class EmailSendCubit extends Cubit { String bodyHtml(QuillController controller) { return QuillDeltaToHtmlConverter( - List.castFrom(controller.document.toDelta().toJson()), - ConverterOptions.forEmail()) - .convert(); + List.castFrom(controller.document.toDelta().toJson()), + ConverterOptions.forEmail(), + ).convert(); } } diff --git a/apps/onyx/lib/screens/mails/states/email_send_state.dart b/apps/onyx/lib/screens/mails/states/email_send_state.dart index 7fd6384ca..fc8bbd731 100644 --- a/apps/onyx/lib/screens/mails/states/email_send_state.dart +++ b/apps/onyx/lib/screens/mails/states/email_send_state.dart @@ -1,9 +1,10 @@ part of 'email_send_cubit.dart'; +@MappableEnum() enum EmailSendStatus { initial, sending, sent, updated, error, inputNotValid } -@CopyWith() -class EmailSendState { +@MappableClass() +class EmailSendState with EmailSendStateMappable { EmailSendStatus status; final QuillController? controller; final TextEditingController? subjectEditor; diff --git a/apps/onyx/lib/screens/mails/states/generated/email_send_cubit.g.dart b/apps/onyx/lib/screens/mails/states/generated/email_send_cubit.g.dart deleted file mode 100644 index 7dcb6f774..000000000 --- a/apps/onyx/lib/screens/mails/states/generated/email_send_cubit.g.dart +++ /dev/null @@ -1,154 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../email_send_cubit.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$EmailSendStateCWProxy { - EmailSendState status(EmailSendStatus status); - - EmailSendState controller(QuillController? controller); - - EmailSendState subjectEditor(TextEditingController? subjectEditor); - - EmailSendState destinationEditor(TextEditingController? destinationEditor); - - EmailSendState originalMessage(int? originalMessage); - - EmailSendState replyAll(bool? replyAll); - - EmailSendState reply(bool? reply); - - EmailSendState forward(bool? forward); - - EmailSendState attachments(List attachments); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `EmailSendState(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// EmailSendState(...).copyWith(id: 12, name: "My name") - /// ``` - EmailSendState call({ - EmailSendStatus status, - QuillController? controller, - TextEditingController? subjectEditor, - TextEditingController? destinationEditor, - int? originalMessage, - bool? replyAll, - bool? reply, - bool? forward, - List attachments, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfEmailSendState.copyWith(...)` or call `instanceOfEmailSendState.copyWith.fieldName(value)` for a single field. -class _$EmailSendStateCWProxyImpl implements _$EmailSendStateCWProxy { - const _$EmailSendStateCWProxyImpl(this._value); - - final EmailSendState _value; - - @override - EmailSendState status(EmailSendStatus status) => call(status: status); - - @override - EmailSendState controller(QuillController? controller) => - call(controller: controller); - - @override - EmailSendState subjectEditor(TextEditingController? subjectEditor) => - call(subjectEditor: subjectEditor); - - @override - EmailSendState destinationEditor(TextEditingController? destinationEditor) => - call(destinationEditor: destinationEditor); - - @override - EmailSendState originalMessage(int? originalMessage) => - call(originalMessage: originalMessage); - - @override - EmailSendState replyAll(bool? replyAll) => call(replyAll: replyAll); - - @override - EmailSendState reply(bool? reply) => call(reply: reply); - - @override - EmailSendState forward(bool? forward) => call(forward: forward); - - @override - EmailSendState attachments(List attachments) => - call(attachments: attachments); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `EmailSendState(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// EmailSendState(...).copyWith(id: 12, name: "My name") - /// ``` - EmailSendState call({ - Object? status = const $CopyWithPlaceholder(), - Object? controller = const $CopyWithPlaceholder(), - Object? subjectEditor = const $CopyWithPlaceholder(), - Object? destinationEditor = const $CopyWithPlaceholder(), - Object? originalMessage = const $CopyWithPlaceholder(), - Object? replyAll = const $CopyWithPlaceholder(), - Object? reply = const $CopyWithPlaceholder(), - Object? forward = const $CopyWithPlaceholder(), - Object? attachments = const $CopyWithPlaceholder(), - }) { - return EmailSendState( - status: status == const $CopyWithPlaceholder() || status == null - ? _value.status - // ignore: cast_nullable_to_non_nullable - : status as EmailSendStatus, - controller: controller == const $CopyWithPlaceholder() - ? _value.controller - // ignore: cast_nullable_to_non_nullable - : controller as QuillController?, - subjectEditor: subjectEditor == const $CopyWithPlaceholder() - ? _value.subjectEditor - // ignore: cast_nullable_to_non_nullable - : subjectEditor as TextEditingController?, - destinationEditor: destinationEditor == const $CopyWithPlaceholder() - ? _value.destinationEditor - // ignore: cast_nullable_to_non_nullable - : destinationEditor as TextEditingController?, - originalMessage: originalMessage == const $CopyWithPlaceholder() - ? _value.originalMessage - // ignore: cast_nullable_to_non_nullable - : originalMessage as int?, - replyAll: replyAll == const $CopyWithPlaceholder() - ? _value.replyAll - // ignore: cast_nullable_to_non_nullable - : replyAll as bool?, - reply: reply == const $CopyWithPlaceholder() - ? _value.reply - // ignore: cast_nullable_to_non_nullable - : reply as bool?, - forward: forward == const $CopyWithPlaceholder() - ? _value.forward - // ignore: cast_nullable_to_non_nullable - : forward as bool?, - attachments: - attachments == const $CopyWithPlaceholder() || attachments == null - ? _value.attachments - // ignore: cast_nullable_to_non_nullable - : attachments as List, - ); - } -} - -extension $EmailSendStateCopyWith on EmailSendState { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfEmailSendState.copyWith(...)` or `instanceOfEmailSendState.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$EmailSendStateCWProxy get copyWith => _$EmailSendStateCWProxyImpl(this); -} diff --git a/apps/onyx/lib/screens/mails/states/generated/email_send_cubit.mapper.dart b/apps/onyx/lib/screens/mails/states/generated/email_send_cubit.mapper.dart new file mode 100644 index 000000000..d31fe81e1 --- /dev/null +++ b/apps/onyx/lib/screens/mails/states/generated/email_send_cubit.mapper.dart @@ -0,0 +1,308 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../email_send_cubit.dart'; + +class EmailSendStatusMapper extends EnumMapper { + EmailSendStatusMapper._(); + + static EmailSendStatusMapper? _instance; + static EmailSendStatusMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = EmailSendStatusMapper._()); + } + return _instance!; + } + + static EmailSendStatus fromValue(dynamic value) { + ensureInitialized(); + return MapperContainer.globals.fromValue(value); + } + + @override + EmailSendStatus decode(dynamic value) { + switch (value) { + case r'initial': + return EmailSendStatus.initial; + case r'sending': + return EmailSendStatus.sending; + case r'sent': + return EmailSendStatus.sent; + case r'updated': + return EmailSendStatus.updated; + case r'error': + return EmailSendStatus.error; + case r'inputNotValid': + return EmailSendStatus.inputNotValid; + default: + throw MapperException.unknownEnumValue(value); + } + } + + @override + dynamic encode(EmailSendStatus self) { + switch (self) { + case EmailSendStatus.initial: + return r'initial'; + case EmailSendStatus.sending: + return r'sending'; + case EmailSendStatus.sent: + return r'sent'; + case EmailSendStatus.updated: + return r'updated'; + case EmailSendStatus.error: + return r'error'; + case EmailSendStatus.inputNotValid: + return r'inputNotValid'; + } + } +} + +extension EmailSendStatusMapperExtension on EmailSendStatus { + String toValue() { + EmailSendStatusMapper.ensureInitialized(); + return MapperContainer.globals.toValue(this) as String; + } +} + +class EmailSendStateMapper extends ClassMapperBase { + EmailSendStateMapper._(); + + static EmailSendStateMapper? _instance; + static EmailSendStateMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = EmailSendStateMapper._()); + EmailSendStatusMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'EmailSendState'; + + static EmailSendStatus _$status(EmailSendState v) => v.status; + static const Field _f$status = Field( + 'status', + _$status, + ); + static QuillController? _$controller(EmailSendState v) => v.controller; + static const Field _f$controller = Field( + 'controller', + _$controller, + opt: true, + ); + static TextEditingController? _$subjectEditor(EmailSendState v) => + v.subjectEditor; + static const Field _f$subjectEditor = + Field('subjectEditor', _$subjectEditor, opt: true); + static TextEditingController? _$destinationEditor(EmailSendState v) => + v.destinationEditor; + static const Field + _f$destinationEditor = Field( + 'destinationEditor', + _$destinationEditor, + opt: true, + ); + static int? _$originalMessage(EmailSendState v) => v.originalMessage; + static const Field _f$originalMessage = Field( + 'originalMessage', + _$originalMessage, + opt: true, + ); + static bool? _$replyAll(EmailSendState v) => v.replyAll; + static const Field _f$replyAll = Field( + 'replyAll', + _$replyAll, + opt: true, + ); + static bool? _$reply(EmailSendState v) => v.reply; + static const Field _f$reply = Field( + 'reply', + _$reply, + opt: true, + ); + static bool? _$forward(EmailSendState v) => v.forward; + static const Field _f$forward = Field( + 'forward', + _$forward, + opt: true, + ); + static List _$attachments(EmailSendState v) => v.attachments; + static const Field> _f$attachments = Field( + 'attachments', + _$attachments, + opt: true, + def: const [], + ); + + @override + final MappableFields fields = const { + #status: _f$status, + #controller: _f$controller, + #subjectEditor: _f$subjectEditor, + #destinationEditor: _f$destinationEditor, + #originalMessage: _f$originalMessage, + #replyAll: _f$replyAll, + #reply: _f$reply, + #forward: _f$forward, + #attachments: _f$attachments, + }; + + static EmailSendState _instantiate(DecodingData data) { + return EmailSendState( + status: data.dec(_f$status), + controller: data.dec(_f$controller), + subjectEditor: data.dec(_f$subjectEditor), + destinationEditor: data.dec(_f$destinationEditor), + originalMessage: data.dec(_f$originalMessage), + replyAll: data.dec(_f$replyAll), + reply: data.dec(_f$reply), + forward: data.dec(_f$forward), + attachments: data.dec(_f$attachments), + ); + } + + @override + final Function instantiate = _instantiate; + + static EmailSendState fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static EmailSendState fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin EmailSendStateMappable { + String toJson() { + return EmailSendStateMapper.ensureInitialized().encodeJson( + this as EmailSendState, + ); + } + + Map toMap() { + return EmailSendStateMapper.ensureInitialized().encodeMap( + this as EmailSendState, + ); + } + + EmailSendStateCopyWith + get copyWith => _EmailSendStateCopyWithImpl( + this as EmailSendState, + $identity, + $identity, + ); + @override + String toString() { + return EmailSendStateMapper.ensureInitialized().stringifyValue( + this as EmailSendState, + ); + } + + @override + bool operator ==(Object other) { + return EmailSendStateMapper.ensureInitialized().equalsValue( + this as EmailSendState, + other, + ); + } + + @override + int get hashCode { + return EmailSendStateMapper.ensureInitialized().hashValue( + this as EmailSendState, + ); + } +} + +extension EmailSendStateValueCopy<$R, $Out> + on ObjectCopyWith<$R, EmailSendState, $Out> { + EmailSendStateCopyWith<$R, EmailSendState, $Out> get $asEmailSendState => + $base.as((v, t, t2) => _EmailSendStateCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class EmailSendStateCopyWith<$R, $In extends EmailSendState, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, File, ObjectCopyWith<$R, File, File>> get attachments; + $R call({ + EmailSendStatus? status, + QuillController? controller, + TextEditingController? subjectEditor, + TextEditingController? destinationEditor, + int? originalMessage, + bool? replyAll, + bool? reply, + bool? forward, + List? attachments, + }); + EmailSendStateCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ); +} + +class _EmailSendStateCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, EmailSendState, $Out> + implements EmailSendStateCopyWith<$R, EmailSendState, $Out> { + _EmailSendStateCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + EmailSendStateMapper.ensureInitialized(); + @override + ListCopyWith<$R, File, ObjectCopyWith<$R, File, File>> get attachments => + ListCopyWith( + $value.attachments, + (v, t) => ObjectCopyWith(v, $identity, t), + (v) => call(attachments: v), + ); + @override + $R call({ + EmailSendStatus? status, + Object? controller = $none, + Object? subjectEditor = $none, + Object? destinationEditor = $none, + Object? originalMessage = $none, + Object? replyAll = $none, + Object? reply = $none, + Object? forward = $none, + List? attachments, + }) => $apply( + FieldCopyWithData({ + if (status != null) #status: status, + if (controller != $none) #controller: controller, + if (subjectEditor != $none) #subjectEditor: subjectEditor, + if (destinationEditor != $none) #destinationEditor: destinationEditor, + if (originalMessage != $none) #originalMessage: originalMessage, + if (replyAll != $none) #replyAll: replyAll, + if (reply != $none) #reply: reply, + if (forward != $none) #forward: forward, + if (attachments != null) #attachments: attachments, + }), + ); + @override + EmailSendState $make(CopyWithData data) => EmailSendState( + status: data.get(#status, or: $value.status), + controller: data.get(#controller, or: $value.controller), + subjectEditor: data.get(#subjectEditor, or: $value.subjectEditor), + destinationEditor: data.get( + #destinationEditor, + or: $value.destinationEditor, + ), + originalMessage: data.get(#originalMessage, or: $value.originalMessage), + replyAll: data.get(#replyAll, or: $value.replyAll), + reply: data.get(#reply, or: $value.reply), + forward: data.get(#forward, or: $value.forward), + attachments: data.get(#attachments, or: $value.attachments), + ); + + @override + EmailSendStateCopyWith<$R2, EmailSendState, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _EmailSendStateCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/apps/onyx/lib/screens/map/widgets/map_widget.dart b/apps/onyx/lib/screens/map/widgets/map_widget.dart index f11759696..9bd0af2ce 100644 --- a/apps/onyx/lib/screens/map/widgets/map_widget.dart +++ b/apps/onyx/lib/screens/map/widgets/map_widget.dart @@ -6,15 +6,15 @@ import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map_animations/flutter_map_animations.dart'; -import 'package:flutter_map_marker_cluster_2/flutter_map_marker_cluster.dart'; -import 'package:path_provider/path_provider.dart'; import 'package:flutter_map_cache/flutter_map_cache.dart'; +import 'package:flutter_map_marker_cluster_2/flutter_map_marker_cluster.dart'; import 'package:http_cache_hive_store/http_cache_hive_store.dart'; import 'package:izlyclient/izlyclient.dart'; import 'package:latlong2/latlong.dart'; import 'package:onyx/core/res.dart'; import 'package:onyx/screens/map/map_export.dart'; import 'package:onyx/screens/map/widgets/popup_widgets/restaurant_pop_up_widget.dart'; +import 'package:path_provider/path_provider.dart'; import 'package:responsive_sizer/responsive_sizer.dart'; class MapWidget extends StatefulWidget { @@ -52,7 +52,8 @@ class _MapWidgetState extends State with TickerProviderStateMixin { @override void initState() { - mapController = widget.mapController ?? + mapController = + widget.mapController ?? AnimatedMapController( vsync: this, curve: Curves.easeInOut, @@ -91,8 +92,9 @@ class _MapWidgetState extends State with TickerProviderStateMixin { if (widget.center == null) { GeolocationLogic.getCurrentLocation( - askPermission: false, context: context) - .then((value) async { + askPermission: false, + context: context, + ).then((value) async { if (value != null) { mapController.centerOnPoint(value, zoom: 16.5); } @@ -126,42 +128,47 @@ class _MapWidgetState extends State with TickerProviderStateMixin { Padding( padding: EdgeInsets.all(2.h), child: IconButton( - onPressed: () { - GeolocationLogic.getCurrentLocation( - askPermission: true, context: context) - .then((value) { - setState(() { - if ((value != null)) { - mapController.centerOnPoint(value, zoom: 15); - } - }); - }); - }, - style: ButtonStyle( - backgroundColor: WidgetStateProperty.all( - Theme.of(context).colorScheme.surface), - ), - icon: Icon( - Icons.location_searching_rounded, - size: 25.sp, - color: Theme.of(context).primaryColor, - )), - ), - Padding( - padding: EdgeInsets.all(2.h), - child: IconButton( onPressed: () { - mapController.centerOnPoint(MapRes.center, zoom: 16.5); + GeolocationLogic.getCurrentLocation( + askPermission: true, + context: context, + ).then((value) { + setState(() { + if ((value != null)) { + mapController.centerOnPoint(value, zoom: 15); + } + }); + }); }, style: ButtonStyle( backgroundColor: WidgetStateProperty.all( - Theme.of(context).colorScheme.surface), + Theme.of(context).colorScheme.surface, + ), ), icon: Icon( - Icons.location_city_rounded, + Icons.location_searching_rounded, size: 25.sp, color: Theme.of(context).primaryColor, - )), + ), + ), + ), + Padding( + padding: EdgeInsets.all(2.h), + child: IconButton( + onPressed: () { + mapController.centerOnPoint(MapRes.center, zoom: 16.5); + }, + style: ButtonStyle( + backgroundColor: WidgetStateProperty.all( + Theme.of(context).colorScheme.surface, + ), + ), + icon: Icon( + Icons.location_city_rounded, + size: 25.sp, + color: Theme.of(context).primaryColor, + ), + ), ), ], ), @@ -171,9 +178,7 @@ class _MapWidgetState extends State with TickerProviderStateMixin { future: getPath(), builder: (context, snap) { if (!snap.hasData) { - return const Center( - child: CircularProgressIndicator(), - ); + return const Center(child: CircularProgressIndicator()); } return PopupScope( popupController: popupLayerController, @@ -183,7 +188,7 @@ class _MapWidgetState extends State with TickerProviderStateMixin { initialZoom: 16.5, maxZoom: MapRes.maxZoom, minZoom: 0, - onTap: (_, __) => popupLayerController.hideAllPopups(), + onTap: (_, _) => popupLayerController.hideAllPopups(), ), mapController: mapController.mapController, children: [ @@ -200,9 +205,7 @@ class _MapWidgetState extends State with TickerProviderStateMixin { ), if (widget.polylines.isNotEmpty && !widget.polylines.any((element) => element.points.isEmpty)) - PolylineLayer( - polylines: widget.polylines, - ), + PolylineLayer(polylines: widget.polylines), if (!kIsWeb && !(Platform.isLinux || Platform.isMacOS || Platform.isWindows)) const CustomCurrentLocationLayerWidget(), @@ -224,7 +227,8 @@ class _MapWidgetState extends State with TickerProviderStateMixin { popupController: popupLayerController, popupBuilder: (context, marker) { int index = widget.batiments.indexWhere( - (element) => element.position == marker.point); + (element) => element.position == marker.point, + ); if (index != -1) { return BatimentPopupWidget( element: widget.batiments[index], @@ -232,9 +236,11 @@ class _MapWidgetState extends State with TickerProviderStateMixin { popupController: popupLayerController, ); } else { - index = widget.restaurant.indexWhere((element) => - element.lat == marker.point.latitude && - element.lon == marker.point.longitude); + index = widget.restaurant.indexWhere( + (element) => + element.lat == marker.point.latitude && + element.lon == marker.point.longitude, + ); return RestaurantPopUpWidget( element: widget.restaurant[index], onTap: widget.onTapNavigate, @@ -276,18 +282,20 @@ class _MapWidgetState extends State with TickerProviderStateMixin { child: Padding( padding: EdgeInsets.all(2.h), child: IconButton( - onPressed: () { - callback(); - }, - style: ButtonStyle( - backgroundColor: WidgetStateProperty.all( - Theme.of(context).colorScheme.surface), + onPressed: () { + callback(); + }, + style: ButtonStyle( + backgroundColor: WidgetStateProperty.all( + Theme.of(context).colorScheme.surface, ), - icon: Icon( - Icons.zoom_in_map_rounded, - size: 25.sp, - color: Theme.of(context).primaryColor, - )), + ), + icon: Icon( + Icons.zoom_in_map_rounded, + size: 25.sp, + color: Theme.of(context).primaryColor, + ), + ), ), ), ], @@ -302,18 +310,20 @@ class _MapWidgetState extends State with TickerProviderStateMixin { child: Padding( padding: EdgeInsets.all(2.h), child: IconButton( - onPressed: () { - callback(); - }, - style: ButtonStyle( - backgroundColor: WidgetStateProperty.all( - Theme.of(context).colorScheme.surface), + onPressed: () { + callback(); + }, + style: ButtonStyle( + backgroundColor: WidgetStateProperty.all( + Theme.of(context).colorScheme.surface, ), - icon: Icon( - Icons.zoom_out_map_rounded, - size: 25.sp, - color: Theme.of(context).primaryColor, - )), + ), + icon: Icon( + Icons.zoom_out_map_rounded, + size: 25.sp, + color: Theme.of(context).primaryColor, + ), + ), ), ), ], diff --git a/apps/onyx/lib/screens/notifications/domain/logic/background_logic.dart b/apps/onyx/lib/screens/notifications/domain/logic/background_logic.dart index e8de7e434..a19c35a3a 100644 --- a/apps/onyx/lib/screens/notifications/domain/logic/background_logic.dart +++ b/apps/onyx/lib/screens/notifications/domain/logic/background_logic.dart @@ -2,12 +2,12 @@ import 'dart:ui'; import 'package:lyon1casclient/lyon1casclient.dart'; import 'package:onyx/core/cache_service.dart'; -import 'package:onyx/core/initialisations/initialisations_export.dart'; +import 'package:onyx/core/initialisations/sembast_init.dart'; import 'package:onyx/core/res.dart'; +import 'package:onyx/l10n/app_localizations.dart'; import 'package:onyx/screens/notifications/notifications_export.dart'; import 'package:onyx/screens/settings/settings_export.dart'; import 'package:workmanager/workmanager.dart'; -import 'package:onyx/l10n/app_localizations.dart'; @pragma('vm:entry-point') void workmanagerHandler() { @@ -23,7 +23,7 @@ void workmanagerHandler() { Future backgroundLogic({bool init = true}) async { if (init) { - await hiveInit(); + await initSembastDb(); await NotificationLogic.init(); } SettingsModel settings = await SettingsLogic.load(); @@ -38,8 +38,10 @@ Future backgroundLogic({bool init = true}) async { if (!settings.firstLogin && !settings.biometricAuth) { Lyon1CasClient lyon1Cas = Lyon1CasClient(); var result = await lyon1Cas.authenticate( - (await CacheService.get( - secureKey: await CacheService.getEncryptionKey(false)))!); + (await CacheService.get( + secureKey: await CacheService.getEncryptionKey(false), + ))!, + ); if (!result.authResult) return false; await tomussNotificationLogic(settings, lyon1Cas, localizations); await emailNotificationLogic(settings, localizations); diff --git a/apps/onyx/lib/screens/settings/domain/logic/settings_logic.dart b/apps/onyx/lib/screens/settings/domain/logic/settings_logic.dart index 632ac6beb..95d5cfd71 100644 --- a/apps/onyx/lib/screens/settings/domain/logic/settings_logic.dart +++ b/apps/onyx/lib/screens/settings/domain/logic/settings_logic.dart @@ -2,7 +2,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:hive_ce_flutter/hive_flutter.dart'; import 'package:izlyclient/izlyclient.dart'; import 'package:lyon1casclient/lyon1casclient.dart'; import 'package:onyx/core/cache_service.dart'; @@ -14,31 +13,43 @@ import 'package:onyx/screens/mails/mails_export.dart'; import 'package:onyx/screens/map/map_export.dart'; import 'package:onyx/screens/settings/settings_export.dart'; import 'package:onyx/screens/tomuss/tomuss_export.dart'; +import 'package:path/path.dart'; +import 'package:path_provider/path_provider.dart'; +import 'package:sembast/sembast_io.dart'; class SettingsLogic { + static Future _getDb() async { + final dir = await getApplicationDocumentsDirectory(); + final dbPath = join(dir.path, 'settings.db'); + return await databaseFactoryIo.openDatabase(dbPath); + } + + static final _settingsStore = StoreRef>( + 'settings_store', + ); + static Future load() async { - if (await Hive.boxExists('settings')) { - Box box = await Hive.openBox('settings'); - SettingsModel? tmpSettings = box.get('settings'); - if (tmpSettings != null) { - Res.mock = tmpSettings.mock; - return tmpSettings; - } else { - throw Exception("Settings not found"); - } + final db = await _getDb(); + final map = await _settingsStore.record('settings').get(db); + if (map != null) { + final tmpSettings = SettingsModelMapper.fromMap(map); + Res.mock = tmpSettings.mock; + return tmpSettings; } else { return const SettingsModel(); } } static Future reset() async { - Box box = await Hive.openBox('settings'); - await box.put('settings', const SettingsModel()); + final db = await _getDb(); + await _settingsStore + .record('settings') + .put(db, const SettingsModel().toMap()); } static Future modify({required SettingsModel settings}) async { - Box box = await Hive.openBox('settings'); - await box.put('settings', settings); + final db = await _getDb(); + await _settingsStore.record('settings').put(db, settings.toMap()); } static void logout(BuildContext context) async { @@ -46,9 +57,15 @@ class SettingsLogic { await context.read().logout(); CacheService.reset(); context.read().disconnect(); - Hive.deleteBoxFromDisk("cached_qr_code"); - Hive.deleteBoxFromDisk("cached_izly_amount"); - Hive.deleteBoxFromDisk("cached_colloscope_data"); + // Suppression des fichiers Sembast de cache + final dir = await getApplicationDocumentsDirectory(); + await databaseFactoryIo.deleteDatabase(join(dir.path, 'cached_qr_code.db')); + await databaseFactoryIo.deleteDatabase( + join(dir.path, 'cached_izly_amount.db'), + ); + await databaseFactoryIo.deleteDatabase( + join(dir.path, 'cached_colloscope_data.db'), + ); CacheService.reset(); CacheService.reset(); CacheService.reset(); @@ -57,7 +74,7 @@ class SettingsLogic { context.read().resetCubit(); context.read().resetCubit(); context.read().resetCubit(); - reset(); + await reset(); context.read().resetCubit(); context.read().load(); context.read().resetCubit(); diff --git a/apps/onyx/lib/screens/settings/domain/model/generated/settings_model.g.dart b/apps/onyx/lib/screens/settings/domain/model/generated/settings_model.g.dart deleted file mode 100644 index 4364370cc..000000000 --- a/apps/onyx/lib/screens/settings/domain/model/generated/settings_model.g.dart +++ /dev/null @@ -1,430 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../settings_model.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$SettingsModelCWProxy { - SettingsModel biometricAuth(bool biometricAuth); - - SettingsModel forceGreen(bool forceGreen); - - SettingsModel newGradeNotification(bool newGradeNotification); - - SettingsModel showHiddenUE(bool showHiddenUE); - - SettingsModel fetchAgendaAuto(bool fetchAgendaAuto); - - SettingsModel showMiniCalendar(bool showMiniCalendar); - - SettingsModel calendarUpdateNotification(bool calendarUpdateNotification); - - SettingsModel agendaIds(List agendaIds); - - SettingsModel newMailNotification(bool newMailNotification); - - SettingsModel blockTrackers(bool blockTrackers); - - SettingsModel forcedMailTheme(bool forcedMailTheme); - - SettingsModel shownAgendaPopup(bool shownAgendaPopup); - - SettingsModel enabledFunctionalities( - List enabledFunctionalities); - - SettingsModel disabledFunctionalities( - List disabledFunctionalities); - - SettingsModel recentGradeDuration(int recentGradeDuration); - - SettingsModel firstLogin(bool firstLogin); - - SettingsModel mock(bool mock); - - SettingsModel agendaWeekLength(int agendaWeekLength); - - SettingsModel agendaWeekReference(int agendaWeekReference); - - SettingsModel agendaDisabledDays(List agendaDisabledDays); - - SettingsModel agendaPageTopToBottom(bool agendaPageTopToBottom); - - SettingsModel agendaWeekRerenceAlignement(int agendaWeekRerenceAlignement); - - SettingsModel colloscopeOverrideStudentId(int colloscopeOverrideStudentId); - - SettingsModel colloscopeOverrideYearId(int colloscopeOverrideYearId); - - SettingsModel colloscopeEnabled(bool? colloscopeEnabled); - - SettingsModel agendaId(int? agendaId); - - SettingsModel examenAddToAgenda(bool examenAddToAgenda); - - SettingsModel language(String? language); - - SettingsModel izlyNotification(bool izlyNotification); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `SettingsModel(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// SettingsModel(...).copyWith(id: 12, name: "My name") - /// ``` - SettingsModel call({ - bool biometricAuth, - bool forceGreen, - bool newGradeNotification, - bool showHiddenUE, - bool fetchAgendaAuto, - bool showMiniCalendar, - bool calendarUpdateNotification, - List agendaIds, - bool newMailNotification, - bool blockTrackers, - bool forcedMailTheme, - bool shownAgendaPopup, - List enabledFunctionalities, - List disabledFunctionalities, - int recentGradeDuration, - bool firstLogin, - bool mock, - int agendaWeekLength, - int agendaWeekReference, - List agendaDisabledDays, - bool agendaPageTopToBottom, - int agendaWeekRerenceAlignement, - int colloscopeOverrideStudentId, - int colloscopeOverrideYearId, - bool? colloscopeEnabled, - int? agendaId, - bool examenAddToAgenda, - String? language, - bool izlyNotification, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfSettingsModel.copyWith(...)` or call `instanceOfSettingsModel.copyWith.fieldName(value)` for a single field. -class _$SettingsModelCWProxyImpl implements _$SettingsModelCWProxy { - const _$SettingsModelCWProxyImpl(this._value); - - final SettingsModel _value; - - @override - SettingsModel biometricAuth(bool biometricAuth) => - call(biometricAuth: biometricAuth); - - @override - SettingsModel forceGreen(bool forceGreen) => call(forceGreen: forceGreen); - - @override - SettingsModel newGradeNotification(bool newGradeNotification) => - call(newGradeNotification: newGradeNotification); - - @override - SettingsModel showHiddenUE(bool showHiddenUE) => - call(showHiddenUE: showHiddenUE); - - @override - SettingsModel fetchAgendaAuto(bool fetchAgendaAuto) => - call(fetchAgendaAuto: fetchAgendaAuto); - - @override - SettingsModel showMiniCalendar(bool showMiniCalendar) => - call(showMiniCalendar: showMiniCalendar); - - @override - SettingsModel calendarUpdateNotification(bool calendarUpdateNotification) => - call(calendarUpdateNotification: calendarUpdateNotification); - - @override - SettingsModel agendaIds(List agendaIds) => call(agendaIds: agendaIds); - - @override - SettingsModel newMailNotification(bool newMailNotification) => - call(newMailNotification: newMailNotification); - - @override - SettingsModel blockTrackers(bool blockTrackers) => - call(blockTrackers: blockTrackers); - - @override - SettingsModel forcedMailTheme(bool forcedMailTheme) => - call(forcedMailTheme: forcedMailTheme); - - @override - SettingsModel shownAgendaPopup(bool shownAgendaPopup) => - call(shownAgendaPopup: shownAgendaPopup); - - @override - SettingsModel enabledFunctionalities( - List enabledFunctionalities) => - call(enabledFunctionalities: enabledFunctionalities); - - @override - SettingsModel disabledFunctionalities( - List disabledFunctionalities) => - call(disabledFunctionalities: disabledFunctionalities); - - @override - SettingsModel recentGradeDuration(int recentGradeDuration) => - call(recentGradeDuration: recentGradeDuration); - - @override - SettingsModel firstLogin(bool firstLogin) => call(firstLogin: firstLogin); - - @override - SettingsModel mock(bool mock) => call(mock: mock); - - @override - SettingsModel agendaWeekLength(int agendaWeekLength) => - call(agendaWeekLength: agendaWeekLength); - - @override - SettingsModel agendaWeekReference(int agendaWeekReference) => - call(agendaWeekReference: agendaWeekReference); - - @override - SettingsModel agendaDisabledDays(List agendaDisabledDays) => - call(agendaDisabledDays: agendaDisabledDays); - - @override - SettingsModel agendaPageTopToBottom(bool agendaPageTopToBottom) => - call(agendaPageTopToBottom: agendaPageTopToBottom); - - @override - SettingsModel agendaWeekRerenceAlignement(int agendaWeekRerenceAlignement) => - call(agendaWeekRerenceAlignement: agendaWeekRerenceAlignement); - - @override - SettingsModel colloscopeOverrideStudentId(int colloscopeOverrideStudentId) => - call(colloscopeOverrideStudentId: colloscopeOverrideStudentId); - - @override - SettingsModel colloscopeOverrideYearId(int colloscopeOverrideYearId) => - call(colloscopeOverrideYearId: colloscopeOverrideYearId); - - @override - SettingsModel colloscopeEnabled(bool? colloscopeEnabled) => - call(colloscopeEnabled: colloscopeEnabled); - - @override - SettingsModel agendaId(int? agendaId) => call(agendaId: agendaId); - - @override - SettingsModel examenAddToAgenda(bool examenAddToAgenda) => - call(examenAddToAgenda: examenAddToAgenda); - - @override - SettingsModel language(String? language) => call(language: language); - - @override - SettingsModel izlyNotification(bool izlyNotification) => - call(izlyNotification: izlyNotification); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `SettingsModel(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// SettingsModel(...).copyWith(id: 12, name: "My name") - /// ``` - SettingsModel call({ - Object? biometricAuth = const $CopyWithPlaceholder(), - Object? forceGreen = const $CopyWithPlaceholder(), - Object? newGradeNotification = const $CopyWithPlaceholder(), - Object? showHiddenUE = const $CopyWithPlaceholder(), - Object? fetchAgendaAuto = const $CopyWithPlaceholder(), - Object? showMiniCalendar = const $CopyWithPlaceholder(), - Object? calendarUpdateNotification = const $CopyWithPlaceholder(), - Object? agendaIds = const $CopyWithPlaceholder(), - Object? newMailNotification = const $CopyWithPlaceholder(), - Object? blockTrackers = const $CopyWithPlaceholder(), - Object? forcedMailTheme = const $CopyWithPlaceholder(), - Object? shownAgendaPopup = const $CopyWithPlaceholder(), - Object? enabledFunctionalities = const $CopyWithPlaceholder(), - Object? disabledFunctionalities = const $CopyWithPlaceholder(), - Object? recentGradeDuration = const $CopyWithPlaceholder(), - Object? firstLogin = const $CopyWithPlaceholder(), - Object? mock = const $CopyWithPlaceholder(), - Object? agendaWeekLength = const $CopyWithPlaceholder(), - Object? agendaWeekReference = const $CopyWithPlaceholder(), - Object? agendaDisabledDays = const $CopyWithPlaceholder(), - Object? agendaPageTopToBottom = const $CopyWithPlaceholder(), - Object? agendaWeekRerenceAlignement = const $CopyWithPlaceholder(), - Object? colloscopeOverrideStudentId = const $CopyWithPlaceholder(), - Object? colloscopeOverrideYearId = const $CopyWithPlaceholder(), - Object? colloscopeEnabled = const $CopyWithPlaceholder(), - Object? agendaId = const $CopyWithPlaceholder(), - Object? examenAddToAgenda = const $CopyWithPlaceholder(), - Object? language = const $CopyWithPlaceholder(), - Object? izlyNotification = const $CopyWithPlaceholder(), - }) { - return SettingsModel( - biometricAuth: - biometricAuth == const $CopyWithPlaceholder() || biometricAuth == null - ? _value.biometricAuth - // ignore: cast_nullable_to_non_nullable - : biometricAuth as bool, - forceGreen: - forceGreen == const $CopyWithPlaceholder() || forceGreen == null - ? _value.forceGreen - // ignore: cast_nullable_to_non_nullable - : forceGreen as bool, - newGradeNotification: - newGradeNotification == const $CopyWithPlaceholder() || - newGradeNotification == null - ? _value.newGradeNotification - // ignore: cast_nullable_to_non_nullable - : newGradeNotification as bool, - showHiddenUE: - showHiddenUE == const $CopyWithPlaceholder() || showHiddenUE == null - ? _value.showHiddenUE - // ignore: cast_nullable_to_non_nullable - : showHiddenUE as bool, - fetchAgendaAuto: fetchAgendaAuto == const $CopyWithPlaceholder() || - fetchAgendaAuto == null - ? _value.fetchAgendaAuto - // ignore: cast_nullable_to_non_nullable - : fetchAgendaAuto as bool, - showMiniCalendar: showMiniCalendar == const $CopyWithPlaceholder() || - showMiniCalendar == null - ? _value.showMiniCalendar - // ignore: cast_nullable_to_non_nullable - : showMiniCalendar as bool, - calendarUpdateNotification: - calendarUpdateNotification == const $CopyWithPlaceholder() || - calendarUpdateNotification == null - ? _value.calendarUpdateNotification - // ignore: cast_nullable_to_non_nullable - : calendarUpdateNotification as bool, - agendaIds: agendaIds == const $CopyWithPlaceholder() || agendaIds == null - ? _value.agendaIds - // ignore: cast_nullable_to_non_nullable - : agendaIds as List, - newMailNotification: - newMailNotification == const $CopyWithPlaceholder() || - newMailNotification == null - ? _value.newMailNotification - // ignore: cast_nullable_to_non_nullable - : newMailNotification as bool, - blockTrackers: - blockTrackers == const $CopyWithPlaceholder() || blockTrackers == null - ? _value.blockTrackers - // ignore: cast_nullable_to_non_nullable - : blockTrackers as bool, - forcedMailTheme: forcedMailTheme == const $CopyWithPlaceholder() || - forcedMailTheme == null - ? _value.forcedMailTheme - // ignore: cast_nullable_to_non_nullable - : forcedMailTheme as bool, - shownAgendaPopup: shownAgendaPopup == const $CopyWithPlaceholder() || - shownAgendaPopup == null - ? _value.shownAgendaPopup - // ignore: cast_nullable_to_non_nullable - : shownAgendaPopup as bool, - enabledFunctionalities: - enabledFunctionalities == const $CopyWithPlaceholder() || - enabledFunctionalities == null - ? _value.enabledFunctionalities - // ignore: cast_nullable_to_non_nullable - : enabledFunctionalities as List, - disabledFunctionalities: - disabledFunctionalities == const $CopyWithPlaceholder() || - disabledFunctionalities == null - ? _value.disabledFunctionalities - // ignore: cast_nullable_to_non_nullable - : disabledFunctionalities as List, - recentGradeDuration: - recentGradeDuration == const $CopyWithPlaceholder() || - recentGradeDuration == null - ? _value.recentGradeDuration - // ignore: cast_nullable_to_non_nullable - : recentGradeDuration as int, - firstLogin: - firstLogin == const $CopyWithPlaceholder() || firstLogin == null - ? _value.firstLogin - // ignore: cast_nullable_to_non_nullable - : firstLogin as bool, - mock: mock == const $CopyWithPlaceholder() || mock == null - ? _value.mock - // ignore: cast_nullable_to_non_nullable - : mock as bool, - agendaWeekLength: agendaWeekLength == const $CopyWithPlaceholder() || - agendaWeekLength == null - ? _value.agendaWeekLength - // ignore: cast_nullable_to_non_nullable - : agendaWeekLength as int, - agendaWeekReference: - agendaWeekReference == const $CopyWithPlaceholder() || - agendaWeekReference == null - ? _value.agendaWeekReference - // ignore: cast_nullable_to_non_nullable - : agendaWeekReference as int, - agendaDisabledDays: agendaDisabledDays == const $CopyWithPlaceholder() || - agendaDisabledDays == null - ? _value.agendaDisabledDays - // ignore: cast_nullable_to_non_nullable - : agendaDisabledDays as List, - agendaPageTopToBottom: - agendaPageTopToBottom == const $CopyWithPlaceholder() || - agendaPageTopToBottom == null - ? _value.agendaPageTopToBottom - // ignore: cast_nullable_to_non_nullable - : agendaPageTopToBottom as bool, - agendaWeekRerenceAlignement: - agendaWeekRerenceAlignement == const $CopyWithPlaceholder() || - agendaWeekRerenceAlignement == null - ? _value.agendaWeekRerenceAlignement - // ignore: cast_nullable_to_non_nullable - : agendaWeekRerenceAlignement as int, - colloscopeOverrideStudentId: - colloscopeOverrideStudentId == const $CopyWithPlaceholder() || - colloscopeOverrideStudentId == null - ? _value.colloscopeOverrideStudentId - // ignore: cast_nullable_to_non_nullable - : colloscopeOverrideStudentId as int, - colloscopeOverrideYearId: - colloscopeOverrideYearId == const $CopyWithPlaceholder() || - colloscopeOverrideYearId == null - ? _value.colloscopeOverrideYearId - // ignore: cast_nullable_to_non_nullable - : colloscopeOverrideYearId as int, - colloscopeEnabled: colloscopeEnabled == const $CopyWithPlaceholder() - ? _value.colloscopeEnabled - // ignore: cast_nullable_to_non_nullable - : colloscopeEnabled as bool?, - agendaId: agendaId == const $CopyWithPlaceholder() - ? _value.agendaId - // ignore: cast_nullable_to_non_nullable - : agendaId as int?, - examenAddToAgenda: examenAddToAgenda == const $CopyWithPlaceholder() || - examenAddToAgenda == null - ? _value.examenAddToAgenda - // ignore: cast_nullable_to_non_nullable - : examenAddToAgenda as bool, - language: language == const $CopyWithPlaceholder() - ? _value.language - // ignore: cast_nullable_to_non_nullable - : language as String?, - izlyNotification: izlyNotification == const $CopyWithPlaceholder() || - izlyNotification == null - ? _value.izlyNotification - // ignore: cast_nullable_to_non_nullable - : izlyNotification as bool, - ); - } -} - -extension $SettingsModelCopyWith on SettingsModel { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfSettingsModel.copyWith(...)` or `instanceOfSettingsModel.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$SettingsModelCWProxy get copyWith => _$SettingsModelCWProxyImpl(this); -} diff --git a/apps/onyx/lib/screens/settings/domain/model/generated/settings_model.mapper.dart b/apps/onyx/lib/screens/settings/domain/model/generated/settings_model.mapper.dart new file mode 100644 index 000000000..777bacb50 --- /dev/null +++ b/apps/onyx/lib/screens/settings/domain/model/generated/settings_model.mapper.dart @@ -0,0 +1,612 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../settings_model.dart'; + +class SettingsModelMapper extends ClassMapperBase { + SettingsModelMapper._(); + + static SettingsModelMapper? _instance; + static SettingsModelMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = SettingsModelMapper._()); + FunctionalitiesMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'SettingsModel'; + + static bool _$biometricAuth(SettingsModel v) => v.biometricAuth; + static const Field _f$biometricAuth = Field( + 'biometricAuth', + _$biometricAuth, + opt: true, + def: false, + ); + static bool _$forceGreen(SettingsModel v) => v.forceGreen; + static const Field _f$forceGreen = Field( + 'forceGreen', + _$forceGreen, + opt: true, + def: false, + ); + static bool _$newGradeNotification(SettingsModel v) => v.newGradeNotification; + static const Field _f$newGradeNotification = Field( + 'newGradeNotification', + _$newGradeNotification, + opt: true, + def: true, + ); + static bool _$showHiddenUE(SettingsModel v) => v.showHiddenUE; + static const Field _f$showHiddenUE = Field( + 'showHiddenUE', + _$showHiddenUE, + opt: true, + def: false, + ); + static bool _$fetchAgendaAuto(SettingsModel v) => v.fetchAgendaAuto; + static const Field _f$fetchAgendaAuto = Field( + 'fetchAgendaAuto', + _$fetchAgendaAuto, + opt: true, + def: true, + ); + static bool _$showMiniCalendar(SettingsModel v) => v.showMiniCalendar; + static const Field _f$showMiniCalendar = Field( + 'showMiniCalendar', + _$showMiniCalendar, + opt: true, + def: true, + ); + static bool _$calendarUpdateNotification(SettingsModel v) => + v.calendarUpdateNotification; + static const Field _f$calendarUpdateNotification = Field( + 'calendarUpdateNotification', + _$calendarUpdateNotification, + opt: true, + def: true, + ); + static List _$agendaIds(SettingsModel v) => v.agendaIds; + static const Field> _f$agendaIds = Field( + 'agendaIds', + _$agendaIds, + opt: true, + def: const [], + ); + static bool _$newMailNotification(SettingsModel v) => v.newMailNotification; + static const Field _f$newMailNotification = Field( + 'newMailNotification', + _$newMailNotification, + opt: true, + def: true, + ); + static bool _$blockTrackers(SettingsModel v) => v.blockTrackers; + static const Field _f$blockTrackers = Field( + 'blockTrackers', + _$blockTrackers, + opt: true, + def: true, + ); + static bool _$forcedMailTheme(SettingsModel v) => v.forcedMailTheme; + static const Field _f$forcedMailTheme = Field( + 'forcedMailTheme', + _$forcedMailTheme, + opt: true, + def: true, + ); + static bool _$shownAgendaPopup(SettingsModel v) => v.shownAgendaPopup; + static const Field _f$shownAgendaPopup = Field( + 'shownAgendaPopup', + _$shownAgendaPopup, + opt: true, + def: false, + ); + static List _$enabledFunctionalities(SettingsModel v) => + v.enabledFunctionalities; + static const Field> + _f$enabledFunctionalities = Field( + 'enabledFunctionalities', + _$enabledFunctionalities, + opt: true, + def: defaultEnabledFunctionalities, + ); + static List _$disabledFunctionalities(SettingsModel v) => + v.disabledFunctionalities; + static const Field> + _f$disabledFunctionalities = Field( + 'disabledFunctionalities', + _$disabledFunctionalities, + opt: true, + def: defaultDisabledFunctionalities, + ); + static int _$recentGradeDuration(SettingsModel v) => v.recentGradeDuration; + static const Field _f$recentGradeDuration = Field( + 'recentGradeDuration', + _$recentGradeDuration, + opt: true, + def: 7, + ); + static bool _$firstLogin(SettingsModel v) => v.firstLogin; + static const Field _f$firstLogin = Field( + 'firstLogin', + _$firstLogin, + opt: true, + def: true, + ); + static bool _$mock(SettingsModel v) => v.mock; + static const Field _f$mock = Field( + 'mock', + _$mock, + opt: true, + def: false, + ); + static int _$agendaWeekLength(SettingsModel v) => v.agendaWeekLength; + static const Field _f$agendaWeekLength = Field( + 'agendaWeekLength', + _$agendaWeekLength, + opt: true, + def: 5, + ); + static int _$agendaWeekReference(SettingsModel v) => v.agendaWeekReference; + static const Field _f$agendaWeekReference = Field( + 'agendaWeekReference', + _$agendaWeekReference, + opt: true, + def: 0, + ); + static List _$agendaDisabledDays(SettingsModel v) => + v.agendaDisabledDays; + static const Field> _f$agendaDisabledDays = Field( + 'agendaDisabledDays', + _$agendaDisabledDays, + opt: true, + def: const [6, 7], + ); + static bool _$agendaPageTopToBottom(SettingsModel v) => + v.agendaPageTopToBottom; + static const Field _f$agendaPageTopToBottom = Field( + 'agendaPageTopToBottom', + _$agendaPageTopToBottom, + opt: true, + def: false, + ); + static int _$agendaWeekRerenceAlignement(SettingsModel v) => + v.agendaWeekRerenceAlignement; + static const Field _f$agendaWeekRerenceAlignement = Field( + 'agendaWeekRerenceAlignement', + _$agendaWeekRerenceAlignement, + opt: true, + def: 0, + ); + static int _$colloscopeOverrideStudentId(SettingsModel v) => + v.colloscopeOverrideStudentId; + static const Field _f$colloscopeOverrideStudentId = Field( + 'colloscopeOverrideStudentId', + _$colloscopeOverrideStudentId, + opt: true, + def: -1, + ); + static int _$colloscopeOverrideYearId(SettingsModel v) => + v.colloscopeOverrideYearId; + static const Field _f$colloscopeOverrideYearId = Field( + 'colloscopeOverrideYearId', + _$colloscopeOverrideYearId, + opt: true, + def: 0, + ); + static bool? _$colloscopeEnabled(SettingsModel v) => v.colloscopeEnabled; + static const Field _f$colloscopeEnabled = Field( + 'colloscopeEnabled', + _$colloscopeEnabled, + opt: true, + ); + static int? _$agendaId(SettingsModel v) => v.agendaId; + static const Field _f$agendaId = Field( + 'agendaId', + _$agendaId, + opt: true, + ); + static bool _$examenAddToAgenda(SettingsModel v) => v.examenAddToAgenda; + static const Field _f$examenAddToAgenda = Field( + 'examenAddToAgenda', + _$examenAddToAgenda, + opt: true, + def: true, + ); + static String? _$language(SettingsModel v) => v.language; + static const Field _f$language = Field( + 'language', + _$language, + opt: true, + ); + static bool _$izlyNotification(SettingsModel v) => v.izlyNotification; + static const Field _f$izlyNotification = Field( + 'izlyNotification', + _$izlyNotification, + opt: true, + def: true, + ); + + @override + final MappableFields fields = const { + #biometricAuth: _f$biometricAuth, + #forceGreen: _f$forceGreen, + #newGradeNotification: _f$newGradeNotification, + #showHiddenUE: _f$showHiddenUE, + #fetchAgendaAuto: _f$fetchAgendaAuto, + #showMiniCalendar: _f$showMiniCalendar, + #calendarUpdateNotification: _f$calendarUpdateNotification, + #agendaIds: _f$agendaIds, + #newMailNotification: _f$newMailNotification, + #blockTrackers: _f$blockTrackers, + #forcedMailTheme: _f$forcedMailTheme, + #shownAgendaPopup: _f$shownAgendaPopup, + #enabledFunctionalities: _f$enabledFunctionalities, + #disabledFunctionalities: _f$disabledFunctionalities, + #recentGradeDuration: _f$recentGradeDuration, + #firstLogin: _f$firstLogin, + #mock: _f$mock, + #agendaWeekLength: _f$agendaWeekLength, + #agendaWeekReference: _f$agendaWeekReference, + #agendaDisabledDays: _f$agendaDisabledDays, + #agendaPageTopToBottom: _f$agendaPageTopToBottom, + #agendaWeekRerenceAlignement: _f$agendaWeekRerenceAlignement, + #colloscopeOverrideStudentId: _f$colloscopeOverrideStudentId, + #colloscopeOverrideYearId: _f$colloscopeOverrideYearId, + #colloscopeEnabled: _f$colloscopeEnabled, + #agendaId: _f$agendaId, + #examenAddToAgenda: _f$examenAddToAgenda, + #language: _f$language, + #izlyNotification: _f$izlyNotification, + }; + + static SettingsModel _instantiate(DecodingData data) { + return SettingsModel( + biometricAuth: data.dec(_f$biometricAuth), + forceGreen: data.dec(_f$forceGreen), + newGradeNotification: data.dec(_f$newGradeNotification), + showHiddenUE: data.dec(_f$showHiddenUE), + fetchAgendaAuto: data.dec(_f$fetchAgendaAuto), + showMiniCalendar: data.dec(_f$showMiniCalendar), + calendarUpdateNotification: data.dec(_f$calendarUpdateNotification), + agendaIds: data.dec(_f$agendaIds), + newMailNotification: data.dec(_f$newMailNotification), + blockTrackers: data.dec(_f$blockTrackers), + forcedMailTheme: data.dec(_f$forcedMailTheme), + shownAgendaPopup: data.dec(_f$shownAgendaPopup), + enabledFunctionalities: data.dec(_f$enabledFunctionalities), + disabledFunctionalities: data.dec(_f$disabledFunctionalities), + recentGradeDuration: data.dec(_f$recentGradeDuration), + firstLogin: data.dec(_f$firstLogin), + mock: data.dec(_f$mock), + agendaWeekLength: data.dec(_f$agendaWeekLength), + agendaWeekReference: data.dec(_f$agendaWeekReference), + agendaDisabledDays: data.dec(_f$agendaDisabledDays), + agendaPageTopToBottom: data.dec(_f$agendaPageTopToBottom), + agendaWeekRerenceAlignement: data.dec(_f$agendaWeekRerenceAlignement), + colloscopeOverrideStudentId: data.dec(_f$colloscopeOverrideStudentId), + colloscopeOverrideYearId: data.dec(_f$colloscopeOverrideYearId), + colloscopeEnabled: data.dec(_f$colloscopeEnabled), + agendaId: data.dec(_f$agendaId), + examenAddToAgenda: data.dec(_f$examenAddToAgenda), + language: data.dec(_f$language), + izlyNotification: data.dec(_f$izlyNotification), + ); + } + + @override + final Function instantiate = _instantiate; + + static SettingsModel fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static SettingsModel fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin SettingsModelMappable { + String toJson() { + return SettingsModelMapper.ensureInitialized().encodeJson( + this as SettingsModel, + ); + } + + Map toMap() { + return SettingsModelMapper.ensureInitialized().encodeMap( + this as SettingsModel, + ); + } + + SettingsModelCopyWith + get copyWith => _SettingsModelCopyWithImpl( + this as SettingsModel, + $identity, + $identity, + ); + @override + String toString() { + return SettingsModelMapper.ensureInitialized().stringifyValue( + this as SettingsModel, + ); + } + + @override + bool operator ==(Object other) { + return SettingsModelMapper.ensureInitialized().equalsValue( + this as SettingsModel, + other, + ); + } + + @override + int get hashCode { + return SettingsModelMapper.ensureInitialized().hashValue( + this as SettingsModel, + ); + } +} + +extension SettingsModelValueCopy<$R, $Out> + on ObjectCopyWith<$R, SettingsModel, $Out> { + SettingsModelCopyWith<$R, SettingsModel, $Out> get $asSettingsModel => + $base.as((v, t, t2) => _SettingsModelCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class SettingsModelCopyWith<$R, $In extends SettingsModel, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, int, ObjectCopyWith<$R, int, int>> get agendaIds; + ListCopyWith< + $R, + Functionalities, + ObjectCopyWith<$R, Functionalities, Functionalities> + > + get enabledFunctionalities; + ListCopyWith< + $R, + Functionalities, + ObjectCopyWith<$R, Functionalities, Functionalities> + > + get disabledFunctionalities; + ListCopyWith<$R, int, ObjectCopyWith<$R, int, int>> get agendaDisabledDays; + $R call({ + bool? biometricAuth, + bool? forceGreen, + bool? newGradeNotification, + bool? showHiddenUE, + bool? fetchAgendaAuto, + bool? showMiniCalendar, + bool? calendarUpdateNotification, + List? agendaIds, + bool? newMailNotification, + bool? blockTrackers, + bool? forcedMailTheme, + bool? shownAgendaPopup, + List? enabledFunctionalities, + List? disabledFunctionalities, + int? recentGradeDuration, + bool? firstLogin, + bool? mock, + int? agendaWeekLength, + int? agendaWeekReference, + List? agendaDisabledDays, + bool? agendaPageTopToBottom, + int? agendaWeekRerenceAlignement, + int? colloscopeOverrideStudentId, + int? colloscopeOverrideYearId, + bool? colloscopeEnabled, + int? agendaId, + bool? examenAddToAgenda, + String? language, + bool? izlyNotification, + }); + SettingsModelCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _SettingsModelCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, SettingsModel, $Out> + implements SettingsModelCopyWith<$R, SettingsModel, $Out> { + _SettingsModelCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + SettingsModelMapper.ensureInitialized(); + @override + ListCopyWith<$R, int, ObjectCopyWith<$R, int, int>> get agendaIds => + ListCopyWith( + $value.agendaIds, + (v, t) => ObjectCopyWith(v, $identity, t), + (v) => call(agendaIds: v), + ); + @override + ListCopyWith< + $R, + Functionalities, + ObjectCopyWith<$R, Functionalities, Functionalities> + > + get enabledFunctionalities => ListCopyWith( + $value.enabledFunctionalities, + (v, t) => ObjectCopyWith(v, $identity, t), + (v) => call(enabledFunctionalities: v), + ); + @override + ListCopyWith< + $R, + Functionalities, + ObjectCopyWith<$R, Functionalities, Functionalities> + > + get disabledFunctionalities => ListCopyWith( + $value.disabledFunctionalities, + (v, t) => ObjectCopyWith(v, $identity, t), + (v) => call(disabledFunctionalities: v), + ); + @override + ListCopyWith<$R, int, ObjectCopyWith<$R, int, int>> get agendaDisabledDays => + ListCopyWith( + $value.agendaDisabledDays, + (v, t) => ObjectCopyWith(v, $identity, t), + (v) => call(agendaDisabledDays: v), + ); + @override + $R call({ + bool? biometricAuth, + bool? forceGreen, + bool? newGradeNotification, + bool? showHiddenUE, + bool? fetchAgendaAuto, + bool? showMiniCalendar, + bool? calendarUpdateNotification, + List? agendaIds, + bool? newMailNotification, + bool? blockTrackers, + bool? forcedMailTheme, + bool? shownAgendaPopup, + List? enabledFunctionalities, + List? disabledFunctionalities, + int? recentGradeDuration, + bool? firstLogin, + bool? mock, + int? agendaWeekLength, + int? agendaWeekReference, + List? agendaDisabledDays, + bool? agendaPageTopToBottom, + int? agendaWeekRerenceAlignement, + int? colloscopeOverrideStudentId, + int? colloscopeOverrideYearId, + Object? colloscopeEnabled = $none, + Object? agendaId = $none, + bool? examenAddToAgenda, + Object? language = $none, + bool? izlyNotification, + }) => $apply( + FieldCopyWithData({ + if (biometricAuth != null) #biometricAuth: biometricAuth, + if (forceGreen != null) #forceGreen: forceGreen, + if (newGradeNotification != null) + #newGradeNotification: newGradeNotification, + if (showHiddenUE != null) #showHiddenUE: showHiddenUE, + if (fetchAgendaAuto != null) #fetchAgendaAuto: fetchAgendaAuto, + if (showMiniCalendar != null) #showMiniCalendar: showMiniCalendar, + if (calendarUpdateNotification != null) + #calendarUpdateNotification: calendarUpdateNotification, + if (agendaIds != null) #agendaIds: agendaIds, + if (newMailNotification != null) + #newMailNotification: newMailNotification, + if (blockTrackers != null) #blockTrackers: blockTrackers, + if (forcedMailTheme != null) #forcedMailTheme: forcedMailTheme, + if (shownAgendaPopup != null) #shownAgendaPopup: shownAgendaPopup, + if (enabledFunctionalities != null) + #enabledFunctionalities: enabledFunctionalities, + if (disabledFunctionalities != null) + #disabledFunctionalities: disabledFunctionalities, + if (recentGradeDuration != null) + #recentGradeDuration: recentGradeDuration, + if (firstLogin != null) #firstLogin: firstLogin, + if (mock != null) #mock: mock, + if (agendaWeekLength != null) #agendaWeekLength: agendaWeekLength, + if (agendaWeekReference != null) + #agendaWeekReference: agendaWeekReference, + if (agendaDisabledDays != null) #agendaDisabledDays: agendaDisabledDays, + if (agendaPageTopToBottom != null) + #agendaPageTopToBottom: agendaPageTopToBottom, + if (agendaWeekRerenceAlignement != null) + #agendaWeekRerenceAlignement: agendaWeekRerenceAlignement, + if (colloscopeOverrideStudentId != null) + #colloscopeOverrideStudentId: colloscopeOverrideStudentId, + if (colloscopeOverrideYearId != null) + #colloscopeOverrideYearId: colloscopeOverrideYearId, + if (colloscopeEnabled != $none) #colloscopeEnabled: colloscopeEnabled, + if (agendaId != $none) #agendaId: agendaId, + if (examenAddToAgenda != null) #examenAddToAgenda: examenAddToAgenda, + if (language != $none) #language: language, + if (izlyNotification != null) #izlyNotification: izlyNotification, + }), + ); + @override + SettingsModel $make(CopyWithData data) => SettingsModel( + biometricAuth: data.get(#biometricAuth, or: $value.biometricAuth), + forceGreen: data.get(#forceGreen, or: $value.forceGreen), + newGradeNotification: data.get( + #newGradeNotification, + or: $value.newGradeNotification, + ), + showHiddenUE: data.get(#showHiddenUE, or: $value.showHiddenUE), + fetchAgendaAuto: data.get(#fetchAgendaAuto, or: $value.fetchAgendaAuto), + showMiniCalendar: data.get(#showMiniCalendar, or: $value.showMiniCalendar), + calendarUpdateNotification: data.get( + #calendarUpdateNotification, + or: $value.calendarUpdateNotification, + ), + agendaIds: data.get(#agendaIds, or: $value.agendaIds), + newMailNotification: data.get( + #newMailNotification, + or: $value.newMailNotification, + ), + blockTrackers: data.get(#blockTrackers, or: $value.blockTrackers), + forcedMailTheme: data.get(#forcedMailTheme, or: $value.forcedMailTheme), + shownAgendaPopup: data.get(#shownAgendaPopup, or: $value.shownAgendaPopup), + enabledFunctionalities: data.get( + #enabledFunctionalities, + or: $value.enabledFunctionalities, + ), + disabledFunctionalities: data.get( + #disabledFunctionalities, + or: $value.disabledFunctionalities, + ), + recentGradeDuration: data.get( + #recentGradeDuration, + or: $value.recentGradeDuration, + ), + firstLogin: data.get(#firstLogin, or: $value.firstLogin), + mock: data.get(#mock, or: $value.mock), + agendaWeekLength: data.get(#agendaWeekLength, or: $value.agendaWeekLength), + agendaWeekReference: data.get( + #agendaWeekReference, + or: $value.agendaWeekReference, + ), + agendaDisabledDays: data.get( + #agendaDisabledDays, + or: $value.agendaDisabledDays, + ), + agendaPageTopToBottom: data.get( + #agendaPageTopToBottom, + or: $value.agendaPageTopToBottom, + ), + agendaWeekRerenceAlignement: data.get( + #agendaWeekRerenceAlignement, + or: $value.agendaWeekRerenceAlignement, + ), + colloscopeOverrideStudentId: data.get( + #colloscopeOverrideStudentId, + or: $value.colloscopeOverrideStudentId, + ), + colloscopeOverrideYearId: data.get( + #colloscopeOverrideYearId, + or: $value.colloscopeOverrideYearId, + ), + colloscopeEnabled: data.get( + #colloscopeEnabled, + or: $value.colloscopeEnabled, + ), + agendaId: data.get(#agendaId, or: $value.agendaId), + examenAddToAgenda: data.get( + #examenAddToAgenda, + or: $value.examenAddToAgenda, + ), + language: data.get(#language, or: $value.language), + izlyNotification: data.get(#izlyNotification, or: $value.izlyNotification), + ); + + @override + SettingsModelCopyWith<$R2, SettingsModel, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _SettingsModelCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/apps/onyx/lib/screens/settings/domain/model/generated/theme_mode_enum.mapper.dart b/apps/onyx/lib/screens/settings/domain/model/generated/theme_mode_enum.mapper.dart new file mode 100644 index 000000000..1d5a1c7cd --- /dev/null +++ b/apps/onyx/lib/screens/settings/domain/model/generated/theme_mode_enum.mapper.dart @@ -0,0 +1,59 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../theme_mode_enum.dart'; + +class ThemeModeEnumMapper extends EnumMapper { + ThemeModeEnumMapper._(); + + static ThemeModeEnumMapper? _instance; + static ThemeModeEnumMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = ThemeModeEnumMapper._()); + } + return _instance!; + } + + static ThemeModeEnum fromValue(dynamic value) { + ensureInitialized(); + return MapperContainer.globals.fromValue(value); + } + + @override + ThemeModeEnum decode(dynamic value) { + switch (value) { + case r'system': + return ThemeModeEnum.system; + case r'dark': + return ThemeModeEnum.dark; + case r'light': + return ThemeModeEnum.light; + default: + throw MapperException.unknownEnumValue(value); + } + } + + @override + dynamic encode(ThemeModeEnum self) { + switch (self) { + case ThemeModeEnum.system: + return r'system'; + case ThemeModeEnum.dark: + return r'dark'; + case ThemeModeEnum.light: + return r'light'; + } + } +} + +extension ThemeModeEnumMapperExtension on ThemeModeEnum { + String toValue() { + ThemeModeEnumMapper.ensureInitialized(); + return MapperContainer.globals.toValue(this) as String; + } +} + diff --git a/apps/onyx/lib/screens/settings/domain/model/generated/theme_settings_model.mapper.dart b/apps/onyx/lib/screens/settings/domain/model/generated/theme_settings_model.mapper.dart new file mode 100644 index 000000000..e368f15b6 --- /dev/null +++ b/apps/onyx/lib/screens/settings/domain/model/generated/theme_settings_model.mapper.dart @@ -0,0 +1,291 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../theme_settings_model.dart'; + +class ThemeSettingsModelMapper extends ClassMapperBase { + ThemeSettingsModelMapper._(); + + static ThemeSettingsModelMapper? _instance; + static ThemeSettingsModelMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = ThemeSettingsModelMapper._()); + ThemeModeEnumMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'ThemeSettingsModel'; + + static String _$darkThemeSelected(ThemeSettingsModel v) => + v.darkThemeSelected; + static const Field _f$darkThemeSelected = Field( + 'darkThemeSelected', + _$darkThemeSelected, + opt: true, + def: 'Dark Default', + ); + static String _$lightThemeSelected(ThemeSettingsModel v) => + v.lightThemeSelected; + static const Field _f$lightThemeSelected = Field( + 'lightThemeSelected', + _$lightThemeSelected, + opt: true, + def: 'Light Default', + ); + static ThemeModeEnum _$themeMode(ThemeSettingsModel v) => v.themeMode; + static const Field _f$themeMode = Field( + 'themeMode', + _$themeMode, + opt: true, + def: ThemeModeEnum.system, + ); + static bool _$autoSwitchTheme(ThemeSettingsModel v) => v.autoSwitchTheme; + static const Field _f$autoSwitchTheme = Field( + 'autoSwitchTheme', + _$autoSwitchTheme, + opt: true, + def: true, + ); + static String _$themesCreatedString(ThemeSettingsModel v) => + v.themesCreatedString; + static const Field _f$themesCreatedString = Field( + 'themesCreatedString', + _$themesCreatedString, + opt: true, + ); + static String _$favoriteThemesString(ThemeSettingsModel v) => + v.favoriteThemesString; + static const Field _f$favoriteThemesString = + Field('favoriteThemesString', _$favoriteThemesString, opt: true); + static List _$lightThemesCreated(ThemeSettingsModel v) => + v.lightThemesCreated; + static const Field> + _f$lightThemesCreated = Field( + 'lightThemesCreated', + _$lightThemesCreated, + mode: FieldMode.member, + ); + static List _$darkThemesCreated(ThemeSettingsModel v) => + v.darkThemesCreated; + static const Field> + _f$darkThemesCreated = Field( + 'darkThemesCreated', + _$darkThemesCreated, + mode: FieldMode.member, + ); + static List _$lightThemesPreset(ThemeSettingsModel v) => + v.lightThemesPreset; + static const Field> + _f$lightThemesPreset = Field( + 'lightThemesPreset', + _$lightThemesPreset, + mode: FieldMode.member, + ); + static List _$darkThemesPreset(ThemeSettingsModel v) => + v.darkThemesPreset; + static const Field> _f$darkThemesPreset = + Field('darkThemesPreset', _$darkThemesPreset, mode: FieldMode.member); + + @override + final MappableFields fields = const { + #darkThemeSelected: _f$darkThemeSelected, + #lightThemeSelected: _f$lightThemeSelected, + #themeMode: _f$themeMode, + #autoSwitchTheme: _f$autoSwitchTheme, + #themesCreatedString: _f$themesCreatedString, + #favoriteThemesString: _f$favoriteThemesString, + #lightThemesCreated: _f$lightThemesCreated, + #darkThemesCreated: _f$darkThemesCreated, + #lightThemesPreset: _f$lightThemesPreset, + #darkThemesPreset: _f$darkThemesPreset, + }; + @override + final Iterable ignore = const [ + 'themesCreated', + 'favoriteThemes', + 'themesPreset', + ]; + + static ThemeSettingsModel _instantiate(DecodingData data) { + return ThemeSettingsModel( + darkThemeSelected: data.dec(_f$darkThemeSelected), + lightThemeSelected: data.dec(_f$lightThemeSelected), + themeMode: data.dec(_f$themeMode), + autoSwitchTheme: data.dec(_f$autoSwitchTheme), + themesCreatedString: data.dec(_f$themesCreatedString), + favoriteThemesString: data.dec(_f$favoriteThemesString), + ); + } + + @override + final Function instantiate = _instantiate; + + static ThemeSettingsModel fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static ThemeSettingsModel fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin ThemeSettingsModelMappable { + String toJson() { + return ThemeSettingsModelMapper.ensureInitialized() + .encodeJson(this as ThemeSettingsModel); + } + + Map toMap() { + return ThemeSettingsModelMapper.ensureInitialized() + .encodeMap(this as ThemeSettingsModel); + } + + ThemeSettingsModelCopyWith< + ThemeSettingsModel, + ThemeSettingsModel, + ThemeSettingsModel + > + get copyWith => + _ThemeSettingsModelCopyWithImpl( + this as ThemeSettingsModel, + $identity, + $identity, + ); + @override + String toString() { + return ThemeSettingsModelMapper.ensureInitialized().stringifyValue( + this as ThemeSettingsModel, + ); + } + + @override + bool operator ==(Object other) { + return ThemeSettingsModelMapper.ensureInitialized().equalsValue( + this as ThemeSettingsModel, + other, + ); + } + + @override + int get hashCode { + return ThemeSettingsModelMapper.ensureInitialized().hashValue( + this as ThemeSettingsModel, + ); + } +} + +extension ThemeSettingsModelValueCopy<$R, $Out> + on ObjectCopyWith<$R, ThemeSettingsModel, $Out> { + ThemeSettingsModelCopyWith<$R, ThemeSettingsModel, $Out> + get $asThemeSettingsModel => $base.as( + (v, t, t2) => _ThemeSettingsModelCopyWithImpl<$R, $Out>(v, t, t2), + ); +} + +abstract class ThemeSettingsModelCopyWith< + $R, + $In extends ThemeSettingsModel, + $Out +> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, ThemeModel, ObjectCopyWith<$R, ThemeModel, ThemeModel>> + get themesCreated; + ListCopyWith<$R, ThemeModel, ObjectCopyWith<$R, ThemeModel, ThemeModel>> + get favoriteThemes; + $R call({ + List? themesCreated, + String? darkThemeSelected, + String? lightThemeSelected, + List? favoriteThemes, + ThemeModeEnum? themeMode, + bool? autoSwitchTheme, + String? themesCreatedString, + String? favoriteThemesString, + }); + ThemeSettingsModelCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ); +} + +class _ThemeSettingsModelCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, ThemeSettingsModel, $Out> + implements ThemeSettingsModelCopyWith<$R, ThemeSettingsModel, $Out> { + _ThemeSettingsModelCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + ThemeSettingsModelMapper.ensureInitialized(); + @override + ListCopyWith<$R, ThemeModel, ObjectCopyWith<$R, ThemeModel, ThemeModel>> + get themesCreated => ListCopyWith( + $value.themesCreated, + (v, t) => ObjectCopyWith(v, $identity, t), + (v) => call(themesCreated: v), + ); + @override + ListCopyWith<$R, ThemeModel, ObjectCopyWith<$R, ThemeModel, ThemeModel>> + get favoriteThemes => ListCopyWith( + $value.favoriteThemes, + (v, t) => ObjectCopyWith(v, $identity, t), + (v) => call(favoriteThemes: v), + ); + @override + $R call({ + List? themesCreated, + String? darkThemeSelected, + String? lightThemeSelected, + List? favoriteThemes, + ThemeModeEnum? themeMode, + bool? autoSwitchTheme, + Object? themesCreatedString = $none, + Object? favoriteThemesString = $none, + }) => $apply( + FieldCopyWithData({ + if (themesCreated != null) #themesCreated: themesCreated, + if (darkThemeSelected != null) #darkThemeSelected: darkThemeSelected, + if (lightThemeSelected != null) #lightThemeSelected: lightThemeSelected, + if (favoriteThemes != null) #favoriteThemes: favoriteThemes, + if (themeMode != null) #themeMode: themeMode, + if (autoSwitchTheme != null) #autoSwitchTheme: autoSwitchTheme, + if (themesCreatedString != $none) + #themesCreatedString: themesCreatedString, + if (favoriteThemesString != $none) + #favoriteThemesString: favoriteThemesString, + }), + ); + @override + ThemeSettingsModel $make(CopyWithData data) => ThemeSettingsModel( + themesCreated: data.get(#themesCreated, or: $value.themesCreated), + darkThemeSelected: data.get( + #darkThemeSelected, + or: $value.darkThemeSelected, + ), + lightThemeSelected: data.get( + #lightThemeSelected, + or: $value.lightThemeSelected, + ), + favoriteThemes: data.get(#favoriteThemes, or: $value.favoriteThemes), + themeMode: data.get(#themeMode, or: $value.themeMode), + autoSwitchTheme: data.get(#autoSwitchTheme, or: $value.autoSwitchTheme), + themesCreatedString: data.get( + #themesCreatedString, + or: $value.themesCreatedString, + ), + favoriteThemesString: data.get( + #favoriteThemesString, + or: $value.favoriteThemesString, + ), + ); + + @override + ThemeSettingsModelCopyWith<$R2, ThemeSettingsModel, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _ThemeSettingsModelCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/apps/onyx/lib/screens/settings/domain/model/settings_model.dart b/apps/onyx/lib/screens/settings/domain/model/settings_model.dart index 0d3bfd5a4..ea575baad 100644 --- a/apps/onyx/lib/screens/settings/domain/model/settings_model.dart +++ b/apps/onyx/lib/screens/settings/domain/model/settings_model.dart @@ -1,8 +1,7 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:onyx/core/res.dart'; -part 'generated/settings_model.g.dart'; +part 'generated/settings_model.mapper.dart'; const List defaultEnabledFunctionalities = [ Functionalities.mail, @@ -16,8 +15,8 @@ const List defaultEnabledFunctionalities = [ const List defaultDisabledFunctionalities = []; -@CopyWith() -class SettingsModel extends Equatable { +@MappableClass() +class SettingsModel with SettingsModelMappable { final bool firstLogin; final bool biometricAuth; @@ -96,39 +95,4 @@ class SettingsModel extends Equatable { this.language, this.izlyNotification = true, }); - - @override - List get props => [ - forceGreen, - newGradeNotification, - showHiddenUE, - fetchAgendaAuto, - showMiniCalendar, - calendarUpdateNotification, - agendaIds, - newMailNotification, - blockTrackers, - forcedMailTheme, - enabledFunctionalities, - disabledFunctionalities, - recentGradeDuration, - firstLogin, - biometricAuth, - mock, - shownAgendaPopup, - agendaWeekLength, - agendaWeekReference, - agendaDisabledDays, - agendaPageTopToBottom, - agendaWeekRerenceAlignement, - colloscopeOverrideStudentId, - colloscopeOverrideYearId, - colloscopeEnabled, - agendaId, - language, - izlyNotification, - ]; - - @override - bool? get stringify => true; } diff --git a/apps/onyx/lib/screens/settings/domain/model/theme_mode_enum.dart b/apps/onyx/lib/screens/settings/domain/model/theme_mode_enum.dart index 46e5018d3..87dc32311 100644 --- a/apps/onyx/lib/screens/settings/domain/model/theme_mode_enum.dart +++ b/apps/onyx/lib/screens/settings/domain/model/theme_mode_enum.dart @@ -1,5 +1,9 @@ +import 'package:dart_mappable/dart_mappable.dart'; import 'package:flutter/material.dart'; +part 'generated/theme_mode_enum.mapper.dart'; + +@MappableEnum() enum ThemeModeEnum { system, dark, diff --git a/apps/onyx/lib/screens/settings/domain/model/theme_settings_model.dart b/apps/onyx/lib/screens/settings/domain/model/theme_settings_model.dart index ac0ea302c..ab4894566 100644 --- a/apps/onyx/lib/screens/settings/domain/model/theme_settings_model.dart +++ b/apps/onyx/lib/screens/settings/domain/model/theme_settings_model.dart @@ -1,63 +1,45 @@ import 'dart:convert'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:flutter/cupertino.dart'; import 'package:onyx/core/theme/theme.dart'; import 'package:onyx/screens/settings/settings_export.dart'; -class ThemeSettingsModel { - late List _themesCreated; +part 'generated/theme_settings_model.mapper.dart'; + +@MappableClass(ignore: ["themesCreated", "favoriteThemes", "themesPreset"]) +class ThemeSettingsModel with ThemeSettingsModelMappable { + late List themesCreated; late final String darkThemeSelected; late final String lightThemeSelected; - late List _favoriteThemes; + late List favoriteThemes; final ThemeModeEnum themeMode; final bool autoSwitchTheme; - final List _themesPreset = - OnyxTheme.themesPreset; //do not save it in hive_ce + final List themesPreset = + OnyxTheme.themesPreset; ThemeSettingsModel({ - List themesCreated = const [], + this.themesCreated = const [], this.darkThemeSelected = 'Dark Default', this.lightThemeSelected = 'Light Default', - List favoriteThemes = const [], + this.favoriteThemes = const [], this.themeMode = ThemeModeEnum.system, this.autoSwitchTheme = true, String? themesCreatedString, String? favoriteThemesString, }) { - _themesCreated = themesCreated; - _favoriteThemes = favoriteThemes; if (themesCreatedString != null) { - themesCreated = jsonDecode(themesCreatedString) - .map((e) => ThemeModel.fromJson(e)) - .toList() - .cast(); + themesCreated = jsonDecode( + themesCreatedString, + ).map((e) => ThemeModel.fromJson(e)).toList().cast(); } if (favoriteThemesString != null) { - favoriteThemes = jsonDecode(favoriteThemesString) - .map((e) => ThemeModel.fromJson(e)) - .toList() - .cast(); + favoriteThemes = jsonDecode( + favoriteThemesString, + ).map((e) => ThemeModel.fromJson(e)).toList().cast(); } } - ThemeSettingsModel copyWith({ - List? themesCreated, - String? darkThemeSelected, - String? lightThemeSelected, - List? favoriteThemes, - ThemeModeEnum? themeMode, - bool? autoSwitchTheme, - }) { - return ThemeSettingsModel( - themesCreated: themesCreated ?? this.themesCreated, - darkThemeSelected: darkThemeSelected ?? this.darkThemeSelected, - lightThemeSelected: lightThemeSelected ?? this.lightThemeSelected, - favoriteThemes: favoriteThemes ?? this.favoriteThemes, - themeMode: themeMode ?? this.themeMode, - autoSwitchTheme: autoSwitchTheme ?? this.autoSwitchTheme, - ); - } - List get lightThemesCreated => themesCreated .where((themeInfo) => themeInfo.theme.brightness == Brightness.light) .toList(); @@ -66,28 +48,14 @@ class ThemeSettingsModel { .where((themeInfo) => themeInfo.theme.brightness == Brightness.dark) .toList(); - List get lightThemesPreset => _themesPreset + List get lightThemesPreset => themesPreset .where((themeInfo) => themeInfo.theme.brightness == Brightness.light) .toList(); - List get darkThemesPreset => _themesPreset + List get darkThemesPreset => themesPreset .where((themeInfo) => themeInfo.theme.brightness == Brightness.dark) .toList(); - List get themesCreated => _themesCreated; - - set themesCreated(List value) { - _themesCreated = value; - } - - List get favoriteThemes => _favoriteThemes; - - set favoriteThemes(List value) { - _favoriteThemes = value; - } - - List get themesPreset => _themesPreset; - String get themesCreatedString => jsonEncode(themesCreated.map((e) => e.toJson()).toList()); diff --git a/apps/onyx/lib/screens/settings/pages/settings_page.dart b/apps/onyx/lib/screens/settings/pages/settings_page.dart index 5d8177cbf..36f7a8aa0 100644 --- a/apps/onyx/lib/screens/settings/pages/settings_page.dart +++ b/apps/onyx/lib/screens/settings/pages/settings_page.dart @@ -2,15 +2,14 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:onyx/l10n/app_localizations.dart'; import 'package:flutter_localized_locales/flutter_localized_locales.dart'; -import 'package:hive_ce_flutter/hive_flutter.dart'; import 'package:izlyclient/izlyclient.dart'; import 'package:lyon1agendaclient/lyon1agendaclient.dart'; import 'package:lyon1mailclient/lyon1mailclient.dart'; import 'package:lyon1tomussclient/lyon1tomussclient.dart'; import 'package:onyx/core/cache_service.dart'; import 'package:onyx/core/res.dart'; +import 'package:onyx/l10n/app_localizations.dart'; import 'package:onyx/screens/agenda/agenda_export.dart'; import 'package:onyx/screens/izly/izly_export.dart'; import 'package:onyx/screens/login/login_export.dart'; @@ -22,12 +21,13 @@ import 'package:onyx/screens/settings/states/theme_cubit.dart'; import 'package:onyx/screens/settings/widgets/draggable_zone_widget.dart'; import 'package:onyx/screens/settings/widgets/drop_down_widget.dart'; import 'package:onyx/screens/tomuss/tomuss_export.dart'; +import 'package:path/path.dart'; +import 'package:path_provider/path_provider.dart'; import 'package:responsive_sizer/responsive_sizer.dart'; +import 'package:sembast/sembast_io.dart'; class SettingsPage extends StatefulWidget { - const SettingsPage({ - super.key, - }); + const SettingsPage({super.key}); @override State createState() => _SettingsPageState(); @@ -38,8 +38,10 @@ class _SettingsPageState extends State { Widget build(BuildContext context) { return BlocBuilder( builder: (context, state) => Container( - color: Theme.of(context).colorScheme.surface, - child: Column(mainAxisSize: MainAxisSize.max, children: [ + color: Theme.of(context).colorScheme.surface, + child: Column( + mainAxisSize: MainAxisSize.max, + children: [ Container( height: Res.bottomNavBarHeight, color: Theme.of(context).cardTheme.color, @@ -62,39 +64,52 @@ class _SettingsPageState extends State { widgets: [ DropDownWidget( text: AppLocalizations.of(context).chooseLanguage, - value: AppLocalizations.supportedLocales.indexWhere( - (element) => - element.languageCode == - context - .read() - .state - .settings - .language) + + value: + AppLocalizations.supportedLocales.indexWhere( + (element) => + element.languageCode == + context + .read() + .state + .settings + .language, + ) + 1, //little trick, if it does not found because null, it will return -1, so +1 to get 0 // afterward we add in the list the auto option items: [ AppLocalizations.of(context).auto, - ...AppLocalizations.supportedLocales.map((e) => - LocaleNames.of(context)?.nameOf(e.languageCode) ?? - e.languageCode) + ...AppLocalizations.supportedLocales.map( + (e) => + LocaleNames.of( + context, + )?.nameOf(e.languageCode) ?? + e.languageCode, + ), ], onChanged: (value) { context.read().modify( - settings: context - .read() - .state - .settings - .copyWith( - language: (value == 0) - ? null - : AppLocalizations - .supportedLocales[value - 1] - .languageCode)); - context.read().loadBatiment((value == 0) - ? const Locale("fr") - : Locale(AppLocalizations - .supportedLocales[value - 1].languageCode)); + settings: context + .read() + .state + .settings + .copyWith( + language: (value == 0) + ? null + : AppLocalizations + .supportedLocales[value - 1] + .languageCode, + ), + ); + context.read().loadBatiment( + (value == 0) + ? const Locale("fr") + : Locale( + AppLocalizations + .supportedLocales[value - 1] + .languageCode, + ), + ); }, ), BlocBuilder( @@ -104,42 +119,41 @@ class _SettingsPageState extends State { }, builder: (context, themeState) { return DropDownWidget( - text: AppLocalizations.of(context).chooseTheme, - items: [ - AppLocalizations.of(context).system, - AppLocalizations.of(context).dark, - AppLocalizations.of(context).light, - ], - value: themeState.themesSettings!.themeMode.index, - onChanged: (choice) { - switch (choice) { - case 0: - context - .read() - .updateThemeMode(ThemeModeEnum.system); - break; - case 1: - context - .read() - .updateThemeMode(ThemeModeEnum.dark); - break; - case 2: - context - .read() - .updateThemeMode(ThemeModeEnum.light); - break; - } - }); + text: AppLocalizations.of(context).chooseTheme, + items: [ + AppLocalizations.of(context).system, + AppLocalizations.of(context).dark, + AppLocalizations.of(context).light, + ], + value: themeState.themesSettings!.themeMode.index, + onChanged: (choice) { + switch (choice) { + case 0: + context.read().updateThemeMode( + ThemeModeEnum.system, + ); + break; + case 1: + context.read().updateThemeMode( + ThemeModeEnum.dark, + ); + break; + case 2: + context.read().updateThemeMode( + ThemeModeEnum.light, + ); + break; + } + }, + ); }, ), - const SizedBox( - height: 5, - ), + const SizedBox(height: 5), MaterialButton( color: Theme.of(context).primaryColor, textColor: Theme.of(context).textTheme.bodyLarge?.color ?? - Colors.black, + Colors.black, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), @@ -158,9 +172,7 @@ class _SettingsPageState extends State { ); }, ), - const SizedBox( - height: 5, - ), + const SizedBox(height: 5), ], ), const DraggableZoneWidget(), @@ -170,127 +182,140 @@ class _SettingsPageState extends State { MaterialButton( color: const Color(0xffbf616a), textColor: Colors.white70, - child: Text(AppLocalizations.of(context).logout, - style: TextStyle(fontSize: 17.sp)), + child: Text( + AppLocalizations.of(context).logout, + style: TextStyle(fontSize: 17.sp), + ), onPressed: () => SettingsLogic.logout(context), ), - const SizedBox( - height: 10, - ), + const SizedBox(height: 10), ], ), SettingsCardWidget( - name: AppLocalizations.of(context).cache, - widgets: [ - MaterialButton( - color: const Color(0xffbf616a), - textColor: Colors.white70, - child: Text( - AppLocalizations.of(context).clearGradeCache, - style: TextStyle(fontSize: 17.sp)), - onPressed: () { - CacheService.reset(); - CacheService.reset(); - context.read().load( - lyon1Cas: context - .read() - .state - .lyon1Cas, - cache: false, - settings: context - .read() - .state - .settings); - }, - ), - MaterialButton( - color: const Color(0xffbf616a), - textColor: Colors.white70, - child: Text( - AppLocalizations.of(context).clearAgendaCache, - style: TextStyle(fontSize: 17.sp)), - onPressed: () { - CacheService.reset(); - context.read().load( - lyon1Cas: context - .read() - .state - .lyon1Cas, - settings: context - .read() - .state - .settings, - cache: false); - }, + name: AppLocalizations.of(context).cache, + widgets: [ + MaterialButton( + color: const Color(0xffbf616a), + textColor: Colors.white70, + child: Text( + AppLocalizations.of(context).clearGradeCache, + style: TextStyle(fontSize: 17.sp), ), - MaterialButton( - color: const Color(0xffbf616a), - textColor: Colors.white70, - child: Text( - AppLocalizations.of(context).clearEmailCache, - style: TextStyle(fontSize: 17.sp)), - onPressed: () { - CacheService.reset(); - context.read().load( - cache: false, - blockTrackers: context - .read() - .state - .settings - .blockTrackers, - appLocalizations: - AppLocalizations.of(context), - ); - }, + onPressed: () { + CacheService.reset(); + CacheService.reset(); + context.read().load( + lyon1Cas: context + .read() + .state + .lyon1Cas, + cache: false, + settings: context + .read() + .state + .settings, + ); + }, + ), + MaterialButton( + color: const Color(0xffbf616a), + textColor: Colors.white70, + child: Text( + AppLocalizations.of(context).clearAgendaCache, + style: TextStyle(fontSize: 17.sp), ), - if (!Platform.isIOS) - MaterialButton( - color: const Color(0xffbf616a), - textColor: Colors.white70, - child: Text( - AppLocalizations.of(context).clearIzlyCache, - style: TextStyle(fontSize: 17.sp)), - onPressed: () { - CacheService.reset(); - CacheService.reset(); - CacheService.reset(); - Hive.deleteBoxFromDisk("cached_qr_code"); - Hive.deleteBoxFromDisk("cached_izly_amount"); - context.read().resetCubit(); - context.read().connect( - settings: context - .read() - .state - .settings); - }, - ), - const SizedBox( - height: 10, + onPressed: () { + CacheService.reset(); + context.read().load( + lyon1Cas: context + .read() + .state + .lyon1Cas, + settings: context + .read() + .state + .settings, + cache: false, + ); + }, + ), + MaterialButton( + color: const Color(0xffbf616a), + textColor: Colors.white70, + child: Text( + AppLocalizations.of(context).clearEmailCache, + style: TextStyle(fontSize: 17.sp), ), - ]), - SettingsCardWidget( - name: AppLocalizations.of(context).notifications, - widgets: [ + onPressed: () { + CacheService.reset(); + context.read().load( + cache: false, + blockTrackers: context + .read() + .state + .settings + .blockTrackers, + appLocalizations: AppLocalizations.of(context), + ); + }, + ), + if (!Platform.isIOS) MaterialButton( color: const Color(0xffbf616a), textColor: Colors.white70, child: Text( - AppLocalizations.of(context) - .checkForNewNotifications, - style: TextStyle(fontSize: 17.sp)), - onPressed: () { - backgroundLogic(init: false); + AppLocalizations.of(context).clearIzlyCache, + style: TextStyle(fontSize: 17.sp), + ), + onPressed: () async { + CacheService.reset(); + CacheService.reset(); + CacheService.reset(); + // Prélever les valeurs du context avant tout await + final izlyCubit = context.read(); + final settings = context + .read() + .state + .settings; + final dir = + await getApplicationDocumentsDirectory(); + await databaseFactoryIo.deleteDatabase( + join(dir.path, 'cached_qr_code.db'), + ); + await databaseFactoryIo.deleteDatabase( + join(dir.path, 'cached_izly_amount.db'), + ); + izlyCubit.resetCubit(); + izlyCubit.connect(settings: settings); }, ), - const SizedBox( - height: 10, + const SizedBox(height: 10), + ], + ), + SettingsCardWidget( + name: AppLocalizations.of(context).notifications, + widgets: [ + MaterialButton( + color: const Color(0xffbf616a), + textColor: Colors.white70, + child: Text( + AppLocalizations.of(context).checkForNewNotifications, + style: TextStyle(fontSize: 17.sp), ), - ]), + onPressed: () { + backgroundLogic(init: false); + }, + ), + const SizedBox(height: 10), + ], + ), const SettingsLinkWidget(), ], ), - ) - ])), + ), + ], + ), + ), ); } } diff --git a/apps/onyx/lib/screens/settings/widgets/draggable_zone_widget.dart b/apps/onyx/lib/screens/settings/widgets/draggable_zone_widget.dart index 5aa8136b9..5afc0c4b2 100644 --- a/apps/onyx/lib/screens/settings/widgets/draggable_zone_widget.dart +++ b/apps/onyx/lib/screens/settings/widgets/draggable_zone_widget.dart @@ -3,8 +3,8 @@ import 'dart:io'; import 'package:drag_and_drop_lists/drag_and_drop_lists.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:onyx/l10n/app_localizations.dart'; import 'package:onyx/core/res.dart'; +import 'package:onyx/l10n/app_localizations.dart'; import 'package:onyx/screens/settings/settings_export.dart'; import 'package:responsive_sizer/responsive_sizer.dart'; @@ -20,82 +20,76 @@ class DraggableZoneWidget extends StatelessWidget { builder: (context, state) { List contents = [ DragAndDropList( - canDrag: false, - decoration: BoxDecoration( - color: Theme.of(context).cardColor, - borderRadius: BorderRadius.circular(10), - ), - contentsWhenEmpty: const SizedBox.shrink(), - header: Padding( - padding: EdgeInsets.only( - top: 2.h, - left: 4.w, - bottom: 0.8.h, - ), - child: Text( - AppLocalizations.of(context).enabled, - style: const TextStyle( - fontWeight: FontWeight.bold, fontSize: 16), + canDrag: false, + decoration: BoxDecoration( + color: Theme.of(context).cardColor, + borderRadius: BorderRadius.circular(10), + ), + contentsWhenEmpty: const SizedBox.shrink(), + header: Padding( + padding: EdgeInsets.only(top: 2.h, left: 4.w, bottom: 0.8.h), + child: Text( + AppLocalizations.of(context).enabled, + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 16, ), ), - horizontalAlignment: MainAxisAlignment.center, - children: [ - for (var i in context - .read() - .state - .settings - .enabledFunctionalities) - if (!(Platform.isIOS && i == Functionalities.izly)) - screenSettingsDragAndDropItem(i) - ]), + ), + horizontalAlignment: MainAxisAlignment.center, + children: [ + for (var i + in context + .read() + .state + .settings + .enabledFunctionalities) + if (!(Platform.isIOS && i == Functionalities.izly)) + screenSettingsDragAndDropItem(i), + ], + ), DragAndDropList( - canDrag: false, - contentsWhenEmpty: const SizedBox.shrink(), - decoration: BoxDecoration( - color: Theme.of(context).cardColor, - borderRadius: BorderRadius.circular(10), - ), - header: Padding( - padding: EdgeInsets.only( - top: 2.h, - left: 4.w, - bottom: 0.8.h, - ), - child: Text( - AppLocalizations.of(context).disabled, - style: const TextStyle( - fontWeight: FontWeight.bold, fontSize: 16), + canDrag: false, + contentsWhenEmpty: const SizedBox.shrink(), + decoration: BoxDecoration( + color: Theme.of(context).cardColor, + borderRadius: BorderRadius.circular(10), + ), + header: Padding( + padding: EdgeInsets.only(top: 2.h, left: 4.w, bottom: 0.8.h), + child: Text( + AppLocalizations.of(context).disabled, + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 16, ), ), - children: [ - for (var i in context - .read() - .state - .settings - .disabledFunctionalities) - if (!(Platform.isIOS && i == Functionalities.izly)) - screenSettingsDragAndDropItem(i) - ]), + ), + children: [ + for (var i + in context + .read() + .state + .settings + .disabledFunctionalities) + if (!(Platform.isIOS && i == Functionalities.izly)) + screenSettingsDragAndDropItem(i), + ], + ), ]; return DragAndDropLists( listPadding: EdgeInsets.symmetric(horizontal: 4.w), disableScrolling: true, - itemDivider: const Divider( - height: 4, - color: Colors.transparent, - ), + itemDivider: const Divider(height: 4, color: Colors.transparent), listDividerOnLastChild: false, - listDivider: Divider( - height: 3.h, - color: Colors.transparent, - ), + listDivider: Divider(height: 3.h, color: Colors.transparent), lastListTargetSize: 0.0, itemDragHandle: DragHandle( verticalAlignment: DragHandleVerticalAlignment.top, onLeft: context.read().state.settings.language == 'ar' - ? true - : false, + ? true + : false, child: Container( padding: EdgeInsets.only( left: 5.w, @@ -122,15 +116,21 @@ class DraggableZoneWidget extends StatelessWidget { context.read().collapseAll(); } }, - onItemReorder: (int oldItemIndex, int oldListIndex, int newItemIndex, - int newListIndex) { - context.read().move( - oldEnabled: oldListIndex == 0, - newEnabled: newListIndex == 0, - oldIndex: oldItemIndex, - newIndex: newItemIndex); - }, - onListReorder: (_, __) {}, + onItemReorder: + ( + int oldItemIndex, + int oldListIndex, + int newItemIndex, + int newListIndex, + ) { + context.read().move( + oldEnabled: oldListIndex == 0, + newEnabled: newListIndex == 0, + oldIndex: oldItemIndex, + newIndex: newItemIndex, + ); + }, + onListReorder: (_, _) {}, ); }, ); diff --git a/apps/onyx/lib/screens/settings/widgets/screen_settings/izly_settings_widget.dart b/apps/onyx/lib/screens/settings/widgets/screen_settings/izly_settings_widget.dart index a3594facb..46b61d462 100644 --- a/apps/onyx/lib/screens/settings/widgets/screen_settings/izly_settings_widget.dart +++ b/apps/onyx/lib/screens/settings/widgets/screen_settings/izly_settings_widget.dart @@ -2,9 +2,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:izlyclient/izlyclient.dart'; import 'package:onyx/core/cache_service.dart'; -import 'package:onyx/screens/izly/izly_export.dart'; import 'package:onyx/l10n/app_localizations.dart'; -import 'package:onyx/screens/settings/domain/model/settings_model.dart'; +import 'package:onyx/screens/izly/izly_export.dart'; import 'package:onyx/screens/settings/states/settings_cubit.dart'; import 'package:onyx/screens/settings/widgets/text_switch_widget.dart'; @@ -20,17 +19,13 @@ class IzlySettingsWidget extends StatelessWidget { value: context.read().state.settings.izlyNotification, onChanged: (value) { context.read().modify( - settings: context - .read() - .state - .settings - .copyWith(izlyNotification: value), - ); + settings: context.read().state.settings.copyWith( + izlyNotification: value, + ), + ); }, ), - const SizedBox( - height: 10, - ), + const SizedBox(height: 10), MaterialButton( minWidth: MediaQuery.of(context).size.width, color: const Color(0xffbf616a), diff --git a/apps/onyx/lib/screens/tomuss/logic/tomuss_logic.dart b/apps/onyx/lib/screens/tomuss/logic/tomuss_logic.dart index e9d979c51..6728dffcc 100644 --- a/apps/onyx/lib/screens/tomuss/logic/tomuss_logic.dart +++ b/apps/onyx/lib/screens/tomuss/logic/tomuss_logic.dart @@ -4,7 +4,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:lyon1tomussclient/lyon1tomussclient.dart'; import 'package:onyx/core/cache_service.dart'; -import 'package:onyx/core/initialisations/initialisations_export.dart'; +import 'package:onyx/core/initialisations/sembast_init.dart'; import 'package:onyx/core/res.dart'; import 'package:onyx/core/theme/grade_color.dart'; import 'package:onyx/screens/settings/settings_export.dart'; @@ -19,22 +19,25 @@ class GetCacheDataPass { class TomussLogic { static Future< - ({ - Student? student, - List? semesters, - List? schoolSubjectModel, - Duration? timeout, - })> - getNameAndSemestersAndNotes( - {required Lyon1TomussClient tomussClient, - Semester? semester, - int? semesterIndex, - bool autoRefresh = true}) async { + ({ + Student? student, + List? semesters, + List? schoolSubjectModel, + Duration? timeout, + }) + > + getNameAndSemestersAndNotes({ + required Lyon1TomussClient tomussClient, + Semester? semester, + int? semesterIndex, + bool autoRefresh = true, + }) async { if (!Res.mock) { ParsedPage? parsedPage = await getParsedPage( - tomussClient: tomussClient, - semestre: semester, - autoRefresh: autoRefresh); + tomussClient: tomussClient, + semestre: semester, + autoRefresh: autoRefresh, + ); if (parsedPage == null) { throw "Impossible de récuperer la page de tomuss"; } @@ -43,7 +46,7 @@ class TomussLogic { student: null, semesters: null, schoolSubjectModel: null, - timeout: parsedPage.timeout + timeout: parsedPage.timeout, ); } if (await CacheService.exist()) { @@ -52,20 +55,30 @@ class TomussLogic { //take all coef and apply them to the new teaching units for (var i = 0; i < parsedPage.teachingunits!.length; i++) { int index = teachingUnitList!.teachingUnitModels.indexWhere( - (element) => element.title == parsedPage.teachingunits![i].title); + (element) => element.title == parsedPage.teachingunits![i].title, + ); if (index != -1) { - for (var j = 0; - j < parsedPage.teachingunits![i].grades.length; - j++) { + for ( + var j = 0; + j < parsedPage.teachingunits![i].grades.length; + j++ + ) { int index2 = teachingUnitList.teachingUnitModels[index].grades - .indexWhere((element) => - element.title == - parsedPage.teachingunits![i].grades[j].title); + .indexWhere( + (element) => + element.title == + parsedPage.teachingunits![i].grades[j].title, + ); if (index2 != -1) { - parsedPage.teachingunits![i].grades[j] = - parsedPage.teachingunits![i].grades[j].copyWith( - coef: teachingUnitList - .teachingUnitModels[index].grades[index2].coef); + parsedPage.teachingunits![i].grades[j] = parsedPage + .teachingunits![i] + .grades[j] + .copyWith( + coef: teachingUnitList + .teachingUnitModels[index] + .grades[index2] + .coef, + ); } } } @@ -75,81 +88,96 @@ class TomussLogic { student: parsedPage.student, semesters: parsedPage.semesters, schoolSubjectModel: parsedPage.teachingunits, - timeout: null + timeout: null, ); } else { return ( student: Student(name: "Jean", surname: "Dupont", email: ""), semesters: [ Semester( - title: "2022/Automne", url: Lyon1TomussClient.currentSemester()) + title: "2022/Automne", + url: Lyon1TomussClient.currentSemester(), + ), ], schoolSubjectModel: teachingUnitsModelListMock, - timeout: null + timeout: null, ); } } - static Future getParsedPage( - {required Lyon1TomussClient tomussClient, - Semester? semestre, - bool autoRefresh = true}) async { + static Future getParsedPage({ + required Lyon1TomussClient tomussClient, + Semester? semestre, + bool autoRefresh = true, + }) async { return await tomussClient.getParsedPage( - semestre?.url ?? Lyon1TomussClient.currentSemester(), - autoRefresh: autoRefresh); + semestre?.url ?? Lyon1TomussClient.currentSemester(), + autoRefresh: autoRefresh, + ); } static Future> getTeachingUnitsCache( - ({String? path, int currentSemesterIndex}) inputData) async { + ({String? path, int currentSemesterIndex}) inputData, + ) async { if (Res.mock) { return teachingUnitsModelListMock; } - await hiveInit(path: inputData.path); + await initSembastDb(inputData.path); if (await CacheService.exist( - index: inputData.currentSemesterIndex)) { + index: inputData.currentSemesterIndex, + )) { return (await CacheService.get( - index: inputData.currentSemesterIndex))! - .teachingUnitModels; + index: inputData.currentSemesterIndex, + ))!.teachingUnitModels; } else { return []; } } static List< - ({ - TeachingUnitElement teachingUnitElement, - TeachingUnit teachingUnit - })> - parseRecentElements( - List teachingUnits, SettingsModel settings) { + ({TeachingUnitElement teachingUnitElement, TeachingUnit teachingUnit}) + > + parseRecentElements( + List teachingUnits, + SettingsModel settings, + ) { List<({TeachingUnitElement teachingUnitElement, TeachingUnit teachingUnit})> - newElements = []; + newElements = []; for (var teachingUnit in teachingUnits) { for (var element in teachingUnit.visibleChildren) { if ((element.date != null) && - element.date!.isAfter(DateTime.now() - .subtract(Duration(days: settings.recentGradeDuration)))) { - newElements - .add((teachingUnitElement: element, teachingUnit: teachingUnit)); + element.date!.isAfter( + DateTime.now().subtract( + Duration(days: settings.recentGradeDuration), + ), + )) { + newElements.add(( + teachingUnitElement: element, + teachingUnit: teachingUnit, + )); } } } - newElements.sort((a, b) => - b.teachingUnitElement.date!.compareTo(a.teachingUnitElement.date!)); + newElements.sort( + (a, b) => + b.teachingUnitElement.date!.compareTo(a.teachingUnitElement.date!), + ); return newElements; } - static Future getDownloadLocalPath( - {required Upload upload, - required String ticket, - required BuildContext context}) async { + static Future getDownloadLocalPath({ + required Upload upload, + required String ticket, + required BuildContext context, + }) async { final directory = await getApplicationDocumentsDirectory(); final file = File('${directory.path}/${upload.fileUrl.split("/").last}'); if (await file.exists()) { return file.path; } else { - List uploadFile = - await upload.getContent(ticket); //email.getAttachment(fileName); + List uploadFile = await upload.getContent( + ticket, + ); //email.getAttachment(fileName); await file.writeAsBytes(uploadFile); return file.path; } @@ -171,10 +199,11 @@ class TomussLogic { } */ - static Color getMainGradeColor( - {required bool forceGreen, - required bool isSeen, - required List grades}) { + static Color getMainGradeColor({ + required bool forceGreen, + required bool isSeen, + required List grades, + }) { if (forceGreen) { return isSeen ? GradeColor.seenGreen : GradeColor.unseenGreen; } else { @@ -183,7 +212,10 @@ class TomussLogic { } else { if (grades.length == 1) { return _getGradeColor( - grade: grades.first, forceGreen: forceGreen, isSeen: isSeen); + grade: grades.first, + forceGreen: forceGreen, + isSeen: isSeen, + ); } double a = 0; double r = 0; @@ -191,8 +223,11 @@ class TomussLogic { double b = 0; double coefSum = 0; for (var i in grades) { - Color tmpColor = - _getGradeColor(grade: i, forceGreen: forceGreen, isSeen: isSeen); + Color tmpColor = _getGradeColor( + grade: i, + forceGreen: forceGreen, + isSeen: isSeen, + ); a += tmpColor.a * (i.coef); r += tmpColor.r * (i.coef); g += tmpColor.g * (i.coef); @@ -211,8 +246,11 @@ class TomussLogic { } } - static Color _getGradeColor( - {required Grade grade, required bool forceGreen, required bool isSeen}) { + static Color _getGradeColor({ + required Grade grade, + required bool forceGreen, + required bool isSeen, + }) { if (forceGreen || !grade.isValid) { return isSeen ? GradeColor.seenGreen : GradeColor.unseenGreen; } else { @@ -229,430 +267,434 @@ class TomussLogic { static final List teachingUnitsModelListMock = [ TeachingUnit( - title: "Algèbre 1 Cursus Prépa", - masters: [ - Teacher(name: "Frank WAGNER", email: "wagner@math.univ-lyon1.fr") - ], - grades: [ - Grade( - title: "Colle1", - author: "frank-olaf.wagner", - numerator: 12.0, - denominator: 20.0, - groupeSize: 88, - average: 13.386, - mediane: 13.0, - isValid: true, - rank: 136, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - Grade( - title: "Colle2", - author: "frank-olaf.wagner", - numerator: 14.0, - denominator: 20.0, - groupeSize: 37, - average: 12.511, - mediane: 12.0, - isValid: true, - rank: 135, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - Grade( - title: "Colle3", - author: "frank-olaf.wagner", - numerator: 10.0, - denominator: 20.0, - groupeSize: 94, - average: 12.596, - mediane: 13.0, - isValid: true, - rank: 130, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - Grade( - title: "Colle4", - author: "frank-olaf.wagner", - numerator: 11.0, - denominator: 20.0, - groupeSize: 76, - average: 12.305, - mediane: 12.0, - isValid: true, - rank: 128, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - Grade( - title: "Colle5", - author: "frank-olaf.wagner", - numerator: 4.0, - denominator: 20.0, - groupeSize: 124, - average: 12.352, - mediane: 13.0, - isValid: true, - rank: 128, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - Grade( - title: "DS1", - author: "frank-olaf.wagner", - numerator: 10.63, - denominator: 16.5, - groupeSize: 30, - average: 8.335, - mediane: 8.0, - isValid: true, - rank: 135, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - Grade( - title: "DS2", - author: "frank-olaf.wagner", - numerator: 8.5, - denominator: 16.0, - groupeSize: 41, - average: 7.228, - mediane: 7.19, - isValid: true, - rank: 131, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - Grade( - title: "DS3", - author: "frank-olaf.wagner", - numerator: 7.5, - denominator: 30.0, - groupeSize: 53, - average: 7.143, - mediane: 7.0, - isValid: true, - rank: 129, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - ], - textValues: const [], - enumerations: const [], - presences: const [], - stageCodes: const [], - uploads: const [], - urls: const [], - ticket: "ticket", - ue: "UE algèbre"), + title: "Algèbre 1 Cursus Prépa", + masters: [ + Teacher(name: "Frank WAGNER", email: "wagner@math.univ-lyon1.fr"), + ], + grades: [ + Grade( + title: "Colle1", + author: "frank-olaf.wagner", + numerator: 12.0, + denominator: 20.0, + groupeSize: 88, + average: 13.386, + mediane: 13.0, + isValid: true, + rank: 136, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + Grade( + title: "Colle2", + author: "frank-olaf.wagner", + numerator: 14.0, + denominator: 20.0, + groupeSize: 37, + average: 12.511, + mediane: 12.0, + isValid: true, + rank: 135, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + Grade( + title: "Colle3", + author: "frank-olaf.wagner", + numerator: 10.0, + denominator: 20.0, + groupeSize: 94, + average: 12.596, + mediane: 13.0, + isValid: true, + rank: 130, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + Grade( + title: "Colle4", + author: "frank-olaf.wagner", + numerator: 11.0, + denominator: 20.0, + groupeSize: 76, + average: 12.305, + mediane: 12.0, + isValid: true, + rank: 128, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + Grade( + title: "Colle5", + author: "frank-olaf.wagner", + numerator: 4.0, + denominator: 20.0, + groupeSize: 124, + average: 12.352, + mediane: 13.0, + isValid: true, + rank: 128, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + Grade( + title: "DS1", + author: "frank-olaf.wagner", + numerator: 10.63, + denominator: 16.5, + groupeSize: 30, + average: 8.335, + mediane: 8.0, + isValid: true, + rank: 135, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + Grade( + title: "DS2", + author: "frank-olaf.wagner", + numerator: 8.5, + denominator: 16.0, + groupeSize: 41, + average: 7.228, + mediane: 7.19, + isValid: true, + rank: 131, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + Grade( + title: "DS3", + author: "frank-olaf.wagner", + numerator: 7.5, + denominator: 30.0, + groupeSize: 53, + average: 7.143, + mediane: 7.0, + isValid: true, + rank: 129, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + ], + textValues: const [], + enumerations: const [], + presences: const [], + stageCodes: const [], + uploads: const [], + urls: const [], + ticket: "ticket", + ue: "UE algèbre", + ), TeachingUnit( - title: "Compétences Numériques et Préparation PIX - Module 1", - masters: [ - Teacher( - name: "Christian TRILLAUD", - email: "christian.trillaud@univ-lyon1.fr") - ], - grades: [ - Grade( - title: "TD/comp1.2_5.2/noteQUEST", - author: "christian.trillaud", - numerator: 8.59, - denominator: 10.0, - groupeSize: 354, - average: 6.495, - mediane: 7.93, - isValid: true, - rank: 1485, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - Grade( - title: "TD/comp1.3/note", - author: "christian.trillaud", - numerator: 8.97, - denominator: 10.0, - groupeSize: 433, - average: 6.676, - mediane: 8.26, - isValid: true, - rank: 1480, - date: DateTime.now(), - children: [ - Grade( - title: "TD/comp1.3/noteQUEST", - author: "christian.trillaud", - numerator: 8.97, - denominator: 10.0, - groupeSize: 376, - average: 6.552, - mediane: 8.03, - isValid: true, - rank: 1480, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - ], - coef: 1.0, - position: 0, - ), - Grade( - title: "TD/comp3.1/note", - author: "christian.trillaud", - numerator: 9.83, - denominator: 10.0, - groupeSize: 101, - average: 6.725, - mediane: 8.28, - isValid: true, - rank: 1483, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - Grade( - title: "compétences/ECUE-PIX/Moyenne_ECUE", - author: "christian.trillaud", - numerator: 14.317, - denominator: 20.0, - groupeSize: 771, - average: 12.205, - mediane: 14.457, - isValid: true, - rank: 1480, - date: DateTime.now(), - children: [ - Grade( - title: "compétences/comp1.3/note", - author: "christian.trillaud", - numerator: 13.57, - denominator: 20.0, - groupeSize: 830, - average: 12.171, - mediane: 14.16, - isValid: true, - rank: 1484, - date: DateTime.now(), - children: [ - Grade( - title: "TD/PIX_TEST/notePIX1.3", - author: "christian.trillaud", - numerator: 4.6, - denominator: 10.0, - groupeSize: 1023, - average: 5.175, - mediane: 6.2, - isValid: true, - rank: 1484, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - Grade( - title: "TD/comp1.3/noteFinale", - author: "christian.trillaud", - numerator: 8.97, - denominator: 10.0, - groupeSize: 433, - average: 6.979, - mediane: 8.26, - isValid: true, - rank: 1479, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - ], - coef: 1.0, - position: 0, - ), - // ... Autres notes - ], - coef: 1.0, - position: 0, - ), - Grade( - title: "compétences/comp3.1/note", - author: "christian.trillaud", - numerator: 13.13, - denominator: 20.0, - groupeSize: 907, - average: 12.176, - mediane: 14.27, - isValid: true, - rank: 1485, - date: DateTime.now(), - children: [ - Grade( - title: "TD/PIX_TEST/notePIX3.1", - author: "christian.trillaud", - numerator: 3.3, - denominator: 10.0, - groupeSize: 1140, - average: 5.234, - mediane: 6.1, - isValid: true, - rank: 1484, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - Grade( - title: "TD/comp3.1/noteFinale", - author: "christian.trillaud", - numerator: 9.83, - denominator: 10.0, - groupeSize: 101, - average: 6.927, - mediane: 8.28, - isValid: true, - rank: 1482, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - ], - coef: 1.0, - position: 0, - ), - Grade( - title: "compétences/comp1.2-5.2/note", - author: "christian.trillaud", - numerator: 16.79, - denominator: 20.0, - groupeSize: 407, - average: 12.882, - mediane: 15.68, - isValid: true, - rank: 1481, - date: DateTime.now(), - children: [ - Grade( - title: "TD/PIX_TEST/notePIX1.2-5.2", - author: "christian.trillaud", - numerator: 8.2, - denominator: 10.0, - groupeSize: 457, - average: 6.215, - mediane: 7.7, - isValid: true, - rank: 1484, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - Grade( - title: "TD/comp1.2_5.2/noteFinale", - author: "christian.trillaud", - numerator: 8.59, - denominator: 10.0, - groupeSize: 423, - average: 6.634, - mediane: 8.04, - isValid: true, - rank: 1478, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - ], - coef: 1.0, - position: 0, - ), - Grade( - title: "compétences/comp4.1/note", - author: "christian.trillaud", - numerator: 13.78, - denominator: 20.0, - groupeSize: 787, - average: 11.472, - mediane: 13.95, - isValid: true, - rank: 1485, - date: DateTime.now(), - children: [ - Grade( - title: "TD/PIX_TEST/notePIX4.1", - author: "christian.trillaud", - numerator: 6.0, - denominator: 10.0, - groupeSize: 752, - average: 5.135, - mediane: 6.2, - isValid: true, - rank: 1484, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - Grade( - title: "TD/comp4.1/noteQUEST", - author: "christian.trillaud", - numerator: 7.78, - denominator: 10.0, - groupeSize: 736, - average: 6.329, - mediane: 7.78, - isValid: true, - rank: 1483, - date: DateTime.now(), - children: const [], - coef: 1.0, - position: 0, - ), - ], - coef: 1.0, - position: 0, - ), - ], - textValues: const [], - enumerations: const [], - presences: const [], - stageCodes: const [], - uploads: const [], - urls: const [], - ticket: "ticket", - ue: "UE pix"), + title: "Compétences Numériques et Préparation PIX - Module 1", + masters: [ + Teacher( + name: "Christian TRILLAUD", + email: "christian.trillaud@univ-lyon1.fr", + ), + ], + grades: [ + Grade( + title: "TD/comp1.2_5.2/noteQUEST", + author: "christian.trillaud", + numerator: 8.59, + denominator: 10.0, + groupeSize: 354, + average: 6.495, + mediane: 7.93, + isValid: true, + rank: 1485, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + Grade( + title: "TD/comp1.3/note", + author: "christian.trillaud", + numerator: 8.97, + denominator: 10.0, + groupeSize: 433, + average: 6.676, + mediane: 8.26, + isValid: true, + rank: 1480, + date: DateTime.now(), + children: [ + Grade( + title: "TD/comp1.3/noteQUEST", + author: "christian.trillaud", + numerator: 8.97, + denominator: 10.0, + groupeSize: 376, + average: 6.552, + mediane: 8.03, + isValid: true, + rank: 1480, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + ], + coef: 1.0, + position: 0, + ), + Grade( + title: "TD/comp3.1/note", + author: "christian.trillaud", + numerator: 9.83, + denominator: 10.0, + groupeSize: 101, + average: 6.725, + mediane: 8.28, + isValid: true, + rank: 1483, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + Grade( + title: "compétences/ECUE-PIX/Moyenne_ECUE", + author: "christian.trillaud", + numerator: 14.317, + denominator: 20.0, + groupeSize: 771, + average: 12.205, + mediane: 14.457, + isValid: true, + rank: 1480, + date: DateTime.now(), + children: [ + Grade( + title: "compétences/comp1.3/note", + author: "christian.trillaud", + numerator: 13.57, + denominator: 20.0, + groupeSize: 830, + average: 12.171, + mediane: 14.16, + isValid: true, + rank: 1484, + date: DateTime.now(), + children: [ + Grade( + title: "TD/PIX_TEST/notePIX1.3", + author: "christian.trillaud", + numerator: 4.6, + denominator: 10.0, + groupeSize: 1023, + average: 5.175, + mediane: 6.2, + isValid: true, + rank: 1484, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + Grade( + title: "TD/comp1.3/noteFinale", + author: "christian.trillaud", + numerator: 8.97, + denominator: 10.0, + groupeSize: 433, + average: 6.979, + mediane: 8.26, + isValid: true, + rank: 1479, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + ], + coef: 1.0, + position: 0, + ), + // ... Autres notes + ], + coef: 1.0, + position: 0, + ), + Grade( + title: "compétences/comp3.1/note", + author: "christian.trillaud", + numerator: 13.13, + denominator: 20.0, + groupeSize: 907, + average: 12.176, + mediane: 14.27, + isValid: true, + rank: 1485, + date: DateTime.now(), + children: [ + Grade( + title: "TD/PIX_TEST/notePIX3.1", + author: "christian.trillaud", + numerator: 3.3, + denominator: 10.0, + groupeSize: 1140, + average: 5.234, + mediane: 6.1, + isValid: true, + rank: 1484, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + Grade( + title: "TD/comp3.1/noteFinale", + author: "christian.trillaud", + numerator: 9.83, + denominator: 10.0, + groupeSize: 101, + average: 6.927, + mediane: 8.28, + isValid: true, + rank: 1482, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + ], + coef: 1.0, + position: 0, + ), + Grade( + title: "compétences/comp1.2-5.2/note", + author: "christian.trillaud", + numerator: 16.79, + denominator: 20.0, + groupeSize: 407, + average: 12.882, + mediane: 15.68, + isValid: true, + rank: 1481, + date: DateTime.now(), + children: [ + Grade( + title: "TD/PIX_TEST/notePIX1.2-5.2", + author: "christian.trillaud", + numerator: 8.2, + denominator: 10.0, + groupeSize: 457, + average: 6.215, + mediane: 7.7, + isValid: true, + rank: 1484, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + Grade( + title: "TD/comp1.2_5.2/noteFinale", + author: "christian.trillaud", + numerator: 8.59, + denominator: 10.0, + groupeSize: 423, + average: 6.634, + mediane: 8.04, + isValid: true, + rank: 1478, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + ], + coef: 1.0, + position: 0, + ), + Grade( + title: "compétences/comp4.1/note", + author: "christian.trillaud", + numerator: 13.78, + denominator: 20.0, + groupeSize: 787, + average: 11.472, + mediane: 13.95, + isValid: true, + rank: 1485, + date: DateTime.now(), + children: [ + Grade( + title: "TD/PIX_TEST/notePIX4.1", + author: "christian.trillaud", + numerator: 6.0, + denominator: 10.0, + groupeSize: 752, + average: 5.135, + mediane: 6.2, + isValid: true, + rank: 1484, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + Grade( + title: "TD/comp4.1/noteQUEST", + author: "christian.trillaud", + numerator: 7.78, + denominator: 10.0, + groupeSize: 736, + average: 6.329, + mediane: 7.78, + isValid: true, + rank: 1483, + date: DateTime.now(), + children: const [], + coef: 1.0, + position: 0, + ), + ], + coef: 1.0, + position: 0, + ), + ], + textValues: const [], + enumerations: const [], + presences: const [], + stageCodes: const [], + uploads: const [], + urls: const [], + ticket: "ticket", + ue: "UE pix", + ), TeachingUnit( - title: "Transversale Préparation Aux Métiers De L'Ingénieur 1", - masters: const [], - grades: const [], - textValues: const [], - enumerations: const [], - presences: const [], - stageCodes: const [], - uploads: const [], - urls: const [], - ticket: "ticket", - ue: "UE ppp2") + title: "Transversale Préparation Aux Métiers De L'Ingénieur 1", + masters: const [], + grades: const [], + textValues: const [], + enumerations: const [], + presences: const [], + stageCodes: const [], + uploads: const [], + urls: const [], + ticket: "ticket", + ue: "UE ppp2", + ), ]; } diff --git a/apps/onyx/lib/screens/tomuss/states/tomuss_cubit.dart b/apps/onyx/lib/screens/tomuss/states/tomuss_cubit.dart index 021083ae5..cd686c062 100644 --- a/apps/onyx/lib/screens/tomuss/states/tomuss_cubit.dart +++ b/apps/onyx/lib/screens/tomuss/states/tomuss_cubit.dart @@ -29,8 +29,12 @@ class TomussCubit extends Cubit { return; } _loading = true; - emit(state.copyWith( - status: TomussStatus.loading, currentSemesterIndex: semestreIndex)); + emit( + state.copyWith( + status: TomussStatus.loading, + currentSemesterIndex: semestreIndex, + ), + ); _tomussClient = Lyon1TomussClient(lyon1Cas); Student? student; List teachingUnits = []; @@ -40,7 +44,7 @@ class TomussCubit extends Cubit { if (semestreIndex != null) { semesterModelWrapper = semesterModelWrapper?.copyWith(currentSemesterIndex: semestreIndex) ?? - SemesterList(const [], currentSemesterIndex: semestreIndex); + SemesterList(const [], currentSemesterIndex: semestreIndex); } if (semesterModelWrapper != null) { await CacheService.set(semesterModelWrapper); @@ -50,40 +54,48 @@ class TomussCubit extends Cubit { if (cache && !kIsWeb) { teachingUnits = await compute(TomussLogic.getTeachingUnitsCache, ( path: (await getApplicationDocumentsDirectory()).path, - currentSemesterIndex: semestreIndex ?? 0 - )); - emit(state.copyWith( - status: TomussStatus.cacheReady, - teachingUnits: teachingUnits, - semesters: semesterModelWrapper?.semestres ?? [], currentSemesterIndex: semestreIndex ?? 0, - newElements: TomussLogic.parseRecentElements(teachingUnits, settings), )); + emit( + state.copyWith( + status: TomussStatus.cacheReady, + teachingUnits: teachingUnits, + semesters: semesterModelWrapper?.semestres ?? [], + currentSemesterIndex: semestreIndex ?? 0, + newElements: TomussLogic.parseRecentElements(teachingUnits, settings), + ), + ); } if (_tomussClient != null && _tomussClient!.lyon1Cas.isAuthenticated) { try { final result = await TomussLogic.getNameAndSemestersAndNotes( - tomussClient: _tomussClient!, - semesterIndex: semestreIndex, - autoRefresh: false, - semester: (semesters.length > (semestreIndex ?? 0)) - ? semesters[semestreIndex ?? 0] - : null); + tomussClient: _tomussClient!, + semesterIndex: semestreIndex, + autoRefresh: false, + semester: (semesters.length > (semestreIndex ?? 0)) + ? semesters[semestreIndex ?? 0] + : null, + ); if (result.timeout != null) { - emit(state.copyWith( - name: result.student?.name, - surname: result.student?.surname, - currentSemesterIndex: semestreIndex ?? 0, - status: TomussStatus.timeout, - timeout: result.timeout, - newElements: - TomussLogic.parseRecentElements(teachingUnits, settings), - )); + emit( + state.copyWith( + name: result.student?.name, + surname: result.student?.surname, + currentSemesterIndex: semestreIndex ?? 0, + status: TomussStatus.timeout, + timeout: result.timeout, + newElements: TomussLogic.parseRecentElements( + teachingUnits, + settings, + ), + ), + ); _loading = false; return; } semestreIndex ??= result.semesters!.indexWhere( - (element) => element.url == Lyon1TomussClient.currentSemester()); + (element) => element.url == Lyon1TomussClient.currentSemester(), + ); semesters = result.semesters!; teachingUnits = result.schoolSubjectModel!; student = result.student; @@ -96,19 +108,23 @@ class TomussCubit extends Cubit { teachingUnits.sort((a, b) => a.title.compareTo(b.title)); CacheService.set( - TeachingUnitList(teachingUnits, semestreIndex), - index: semestreIndex); + TeachingUnitList(teachingUnits, semestreIndex), + index: semestreIndex, + ); CacheService.set( - SemesterList(semesters, currentSemesterIndex: semestreIndex)); - emit(state.copyWith( - name: student?.name, - surname: student?.surname, - status: TomussStatus.ready, - teachingUnits: teachingUnits, - semesters: semesters, - currentSemesterIndex: semestreIndex, - newElements: TomussLogic.parseRecentElements(teachingUnits, settings), - )); + SemesterList(semesters, currentSemesterIndex: semestreIndex), + ); + emit( + state.copyWith( + name: student?.name, + surname: student?.surname, + status: TomussStatus.ready, + teachingUnits: teachingUnits, + semesters: semesters, + currentSemesterIndex: semestreIndex, + newElements: TomussLogic.parseRecentElements(teachingUnits, settings), + ), + ); } _loading = false; } @@ -116,59 +132,73 @@ class TomussCubit extends Cubit { Future updateCoef(Grade grade, double? coef) async { //update state List teachingUnits = state.teachingUnits; - int index = - teachingUnits.indexWhere((element) => element.grades.contains(grade)); + int index = teachingUnits.indexWhere( + (element) => element.grades.contains(grade), + ); if (index == -1) { return; } int gradeIndex = teachingUnits[index].grades.indexOf(grade); - grade = grade.copyWith.coef(coef ?? 1.0); + grade = grade.copyWith(coef: coef ?? 1.0); teachingUnits[index].grades[gradeIndex] = grade; //save in cache await CacheService.set( - TeachingUnitList(teachingUnits, state.currentSemesterIndex)); - emit(state.copyWith( - status: TomussStatus.updated, teachingUnits: teachingUnits)); + TeachingUnitList(teachingUnits, state.currentSemesterIndex), + ); + emit( + state.copyWith( + status: TomussStatus.updated, + teachingUnits: teachingUnits, + ), + ); } Future updateEnumerationValue( - Enumeration enumeration, String value) async { + Enumeration enumeration, + String value, + ) async { List teachingUnits = List.from(state.teachingUnits); final List< - ({ - TeachingUnit teachingUnit, - TeachingUnitElement teachingUnitElement - })> newElements = List.from(state.newElements); - int index = teachingUnits - .indexWhere((element) => element.enumerations.contains(enumeration)); - int recentElementIndex = newElements - .indexWhere((element) => element.teachingUnitElement == enumeration); + ({TeachingUnit teachingUnit, TeachingUnitElement teachingUnitElement}) + > + newElements = List.from(state.newElements); + int index = teachingUnits.indexWhere( + (element) => element.enumerations.contains(enumeration), + ); + int recentElementIndex = newElements.indexWhere( + (element) => element.teachingUnitElement == enumeration, + ); if (index == -1) { return; } - int enumerationIndex = - teachingUnits[index].enumerations.indexOf(enumeration); + int enumerationIndex = teachingUnits[index].enumerations.indexOf( + enumeration, + ); await enumeration.updateValue(value, teachingUnits[index].ticket); - enumeration = enumeration.copyWith.value(value); + enumeration = enumeration.copyWith(value: value); teachingUnits[index].enumerations[enumerationIndex] = enumeration; await CacheService.set( - TeachingUnitList(teachingUnits, state.currentSemesterIndex)); + TeachingUnitList(teachingUnits, state.currentSemesterIndex), + ); if (recentElementIndex != -1) { newElements[recentElementIndex] = ( teachingUnit: state.newElements[recentElementIndex].teachingUnit, - teachingUnitElement: (state.newElements[recentElementIndex] - .teachingUnitElement as Enumeration) - .copyWith - .value(value) + teachingUnitElement: + (state.newElements[recentElementIndex].teachingUnitElement + as Enumeration) + .copyWith(value: value), ); } - emit(state.copyWith( + emit( + state.copyWith( status: TomussStatus.updated, teachingUnits: teachingUnits, - newElements: newElements)); + newElements: newElements, + ), + ); } void resetCubit() async { diff --git a/apps/onyx/pubspec.lock b/apps/onyx/pubspec.lock index 997d6155f..4ee2c6554 100644 --- a/apps/onyx/pubspec.lock +++ b/apps/onyx/pubspec.lock @@ -229,10 +229,10 @@ packages: dependency: transitive description: name: camera_avfoundation - sha256: e4aca5bccaf897b70cac87e5fdd789393310985202442837922fd40325e2733b + sha256: "951ef122d01ebba68b7a54bfe294e8b25585635a90465c311b2f875ae72c412f" url: "https://pub.dev" source: hosted - version: "0.9.21+1" + version: "0.9.21+2" camera_platform_interface: dependency: transitive description: @@ -345,22 +345,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.2" - copy_with_extension: - dependency: "direct main" - description: - name: copy_with_extension - sha256: "907e0af3739528957e61f0193b63041f57b2ce61d4c404299b662270611bcf2e" - url: "https://pub.dev" - source: hosted - version: "9.1.0" - copy_with_extension_gen: - dependency: "direct dev" - description: - name: copy_with_extension_gen - sha256: "7a408314ec69bea716efa8c69bf0a93b3727a8134f8f0218d376be2b13b2b3a7" - url: "https://pub.dev" - source: hosted - version: "9.1.0" coverage: dependency: transitive description: @@ -378,7 +362,7 @@ packages: source: hosted version: "0.3.4+2" crypto: - dependency: transitive + dependency: "direct main" description: name: crypto sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" @@ -404,18 +388,16 @@ packages: dart_mappable: dependency: "direct main" description: - name: dart_mappable - sha256: "15f41a35da8ee690bbfa0059fa241edeeaea73f89a2ba685b354ece07cd8ada6" - url: "https://pub.dev" - source: hosted + path: "/home/eymeric/tmp/dart_mappable/packages/dart_mappable" + relative: false + source: path version: "4.6.0" dart_mappable_builder: dependency: "direct dev" description: - name: dart_mappable_builder - sha256: "1116c70d9923e85e78a9339a67934949334a4190c8a6f46e1fbc908341ce424c" - url: "https://pub.dev" - source: hosted + path: "/home/eymeric/tmp/dart_mappable/packages/dart_mappable_builder" + relative: false + source: path version: "4.6.0" dart_quill_delta: dependency: transitive @@ -866,11 +848,11 @@ packages: dependency: "direct main" description: path: geolocator_android - ref: "13.0.1" - resolved-ref: "9ce78b74d57764f6478bc9e3d68471236f079d10" + ref: HEAD + resolved-ref: f4008db50055c47fdb3191efd5c5fb69b7a3c4f5 url: "https://github.com/onyx-lyon1/flutter-geolocator.git" source: git - version: "4.6.1" + version: "4.6.2" geolocator_apple: dependency: transitive description: @@ -928,29 +910,13 @@ packages: source: hosted version: "0.2.0" hive_ce: - dependency: "direct main" + dependency: transitive description: name: hive_ce sha256: "708bb39050998707c5d422752159f91944d3c81ab42d80e1bd0ee37d8e130658" url: "https://pub.dev" source: hosted version: "2.11.3" - hive_ce_flutter: - dependency: "direct main" - description: - name: hive_ce_flutter - sha256: f5bd57fda84402bca7557fedb8c629c96c8ea10fab4a542968d7b60864ca02cc - url: "https://pub.dev" - source: hosted - version: "2.3.2" - hive_ce_generator: - dependency: "direct dev" - description: - name: hive_ce_generator - sha256: a169feeff2da9cc2c417ce5ae9bcebf7c8a95d7a700492b276909016ad70a786 - url: "https://pub.dev" - source: hosted - version: "1.9.3" html: dependency: transitive description: @@ -1307,7 +1273,7 @@ packages: source: hosted version: "2.2.0" path: - dependency: transitive + dependency: "direct main" description: name: path sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" @@ -1689,6 +1655,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0" + sembast: + dependency: "direct main" + description: + name: sembast + sha256: "7119cf6f79bd1d48c8ec7943f4facd96c15ab26823021ed0792a487c7cd34441" + url: "https://pub.dev" + source: hosted + version: "3.8.5+1" share_plus: dependency: "direct main" description: @@ -1750,14 +1724,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.0" - source_helper: - dependency: transitive - description: - name: source_helper - sha256: a447acb083d3a5ef17f983dd36201aeea33fedadb3228fa831f2f0c92f0f3aca - url: "https://pub.dev" - source: hosted - version: "1.3.7" source_map_stack_trace: dependency: transitive description: @@ -2139,10 +2105,10 @@ packages: description: path: workmanager ref: main - resolved-ref: d34763de2f92529798618d575abac4a54f4359bb + resolved-ref: "83f0f7cf511bbff4d349d132a51dbf19adb41251" url: "https://github.com/fluttercommunity/flutter_workmanager.git" source: git - version: "0.9.0" + version: "0.9.0+2" workmanager_android: dependency: transitive description: @@ -2191,14 +2157,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.3" - yaml_writer: - dependency: transitive - description: - name: yaml_writer - sha256: "69651cd7238411179ac32079937d4aa9a2970150d6b2ae2c6fe6de09402a5dc5" - url: "https://pub.dev" - source: hosted - version: "2.1.0" zxing_lib: dependency: transitive description: diff --git a/apps/onyx/pubspec.yaml b/apps/onyx/pubspec.yaml index 3ddf3f832..d7b5829fa 100644 --- a/apps/onyx/pubspec.yaml +++ b/apps/onyx/pubspec.yaml @@ -6,20 +6,21 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev version: 2.0.11+53 environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.8.0 <4.0.0" dependencies: flutter: sdk: flutter modal_bottom_sheet: ^3.0.0-pre flutter_bloc: ^9.1.0 - hive_ce: ^2.11.3 - hive_ce_flutter: ^2.3.2 + sembast: ^3.6.0 + encrypt: ^5.0.3 + crypto: ^3.0.6 + path: ^1.9.1 url_launcher: ^6.1.14 path_provider: ^2.1.1 animations: ^2.0.8 auto_size_text: ^3.0.0 - copy_with_extension: ^9.1.0 responsive_sizer: ^3.3.1 desktop_window: ^0.4.0 # internationalization @@ -34,7 +35,6 @@ dependencies: #agenda_config qr_code_dart_scan: ^0.11.2 permission_handler: ^12.0.0+1 - encrypt: ^5.0.3 #izly izlyclient: ^1.0.9 @@ -104,8 +104,6 @@ dev_dependencies: sdk: flutter flutter_lints: ^6.0.0 build_runner: ^2.4.10 - hive_ce_generator: ^1.9.2 - copy_with_extension_gen: ^9.1.0 flutter_launcher_icons: ^0.14.3 test: ^1.24.9 dart_mappable_builder: ^4.2.3 diff --git a/apps/onyx/pubspec_overrides.yaml b/apps/onyx/pubspec_overrides.yaml index c0cc2cbc5..407806ea6 100644 --- a/apps/onyx/pubspec_overrides.yaml +++ b/apps/onyx/pubspec_overrides.yaml @@ -3,12 +3,19 @@ dependency_overrides: geolocator_android: git: url: https://github.com/onyx-lyon1/flutter-geolocator.git - ref: 13.0.1 path: geolocator_android json_theme: git: url: https://github.com/wardbj93/json_theme path: packages/json_theme + dart_mappable: + git: + url: https://github.com/hatch01/dart_mappable.git + path: packages/dart_mappable + dart_mappable_builder: + git: + url: https://github.com/hatch01/dart_mappable.git + path: packages/dart_mappable_builder intl: ^0.20.2 izlyclient: path: ../../packages/izlyclient diff --git a/log b/log new file mode 100644 index 000000000..ba3818f14 --- /dev/null +++ b/log @@ -0,0 +1,169 @@ +⚠️ WARNING: HIVE MULTI-ISOLATE RISK DETECTED ⚠️ + +Accessing Hive from an unsafe isolate (current isolate: "Closure: (String?) => Future> from Function 'getCache': static.") +This can lead to DATA CORRUPTION as Hive boxes are not designed for concurrent +access across isolates. Each isolate would maintain its own box cache, +potentially causing data inconsistency and corruption. + +RECOMMENDED ACTIONS: +- Use IsolatedHive instead + + +[D] AgendaCubit: AgendaStatus.cacheReady +[D] AuthentificationCubit: AuthentificationStatus.authentificated +[D] AgendaCubit: AgendaStatus.loading +[D] AgendaCubit: AgendaStatus.connecting +[D] EmailCubit: MailStatus.connecting +Device.orientation : Orientation.portrait +Device.deviceType : DeviceType.linux +Device.screenType : ScreenType.mobile +Device.width : 360.0 +Device.height : 740.0 +Device.boxConstraints : BoxConstraints(w=360.0, h=740.0) +Device.aspectRatio : 0.4864864864864865 +Device.pixelRatio : 1.0 +⚠️ WARNING: HIVE MULTI-ISOLATE RISK DETECTED ⚠️ + +Accessing Hive from an unsafe isolate (current isolate: "Closure: (String?) => Future> from Function 'cacheLoad': static.") +This can lead to DATA CORRUPTION as Hive boxes are not designed for concurrent +access across isolates. Each isolate would maintain its own box cache, +potentially causing data inconsistency and corruption. + +RECOMMENDED ACTIONS: +- Use IsolatedHive instead + + +[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: FormatException: Missing extension byte (at offset 45) +#0 _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1859:7) +#1 Utf8Decoder.convert (dart:convert/utf.dart:350:37) +#2 Utf8Codec.decode (dart:convert/utf.dart:63:20) +#3 IzlyClient.getRestaurantCrous (package:izlyclient/src/izlyclient.dart:229:37) + +#4 MapCubit.loadBatiment (package:onyx/screens/map/states/map_cubit.dart:50:18) + + +[D] SettingsCubit: SettingsStatus.ready +[D] ThemeCubit: ThemeStateStatus.init +[D] ThemeCubit: ThemeStateStatus.loaded +Device.orientation : Orientation.portrait +Device.deviceType : DeviceType.linux +Device.screenType : ScreenType.mobile +Device.width : 360.0 +Device.height : 740.0 +Device.boxConstraints : BoxConstraints(w=360.0, h=740.0) +Device.aspectRatio : 0.4864864864864865 +Device.pixelRatio : 1.0 +[D] IzlyCubit: IzlyStatus.loading +⚠️ WARNING: HIVE MULTI-ISOLATE RISK DETECTED ⚠️ + +Accessing Hive from an unsafe isolate (current isolate: "Closure: (({int currentSemesterIndex, String? path})) => Future> from Function 'getTeachingUnitsCache': static.") +This can lead to DATA CORRUPTION as Hive boxes are not designed for concurrent +access across isolates. Each isolate would maintain its own box cache, +potentially causing data inconsistency and corruption. + +RECOMMENDED ACTIONS: +- Use IsolatedHive instead + + +[D] TomussCubit: TomussStatus.cacheReady +[D] IzlyCubit: IzlyStatus.loaded +[D] IzlyCubit: IzlyStatus.loading +[D] IzlyCubit: IzlyStatus.cacheLoaded +⚠️ WARNING: HIVE MULTI-ISOLATE RISK DETECTED ⚠️ + +Accessing Hive from an unsafe isolate (current isolate: "Closure: (String?) => Future> from Function 'getCache': static.") +This can lead to DATA CORRUPTION as Hive boxes are not designed for concurrent +access across isolates. Each isolate would maintain its own box cache, +potentially causing data inconsistency and corruption. + +RECOMMENDED ACTIONS: +- Use IsolatedHive instead + + +[D] AgendaCubit: AgendaStatus.cacheReady +[D] TomussCubit: TomussStatus.ready +[E] Null check operator used on a null value +[D] ExamenCubit: ExamenStatus.error +[D] IzlyCubit: IzlyStatus.loaded +⚠️ WARNING: HIVE MULTI-ISOLATE RISK DETECTED ⚠️ + +Accessing Hive from an unsafe isolate (current isolate: "Closure: (String?) => Future> from Function 'cacheLoad': static.") +This can lead to DATA CORRUPTION as Hive boxes are not designed for concurrent +access across isolates. Each isolate would maintain its own box cache, +potentially causing data inconsistency and corruption. + +RECOMMENDED ACTIONS: +- Use IsolatedHive instead + + +⚠️ WARNING: HIVE MULTI-ISOLATE RISK DETECTED ⚠️ + +Accessing Hive from an unsafe isolate (current isolate: "Closure: (({int currentSemesterIndex, String? path})) => Future> from Function 'getTeachingUnitsCache': static.") +This can lead to DATA CORRUPTION as Hive boxes are not designed for concurrent +access across isolates. Each isolate would maintain its own box cache, +potentially causing data inconsistency and corruption. + +RECOMMENDED ACTIONS: +- Use IsolatedHive instead + + +[D] TomussCubit: TomussStatus.cacheReady +[D] EmailCubit: MailStatus.connected +[D] EmailCubit: MailStatus.loading +[D] ExamenCubit: ExamenStatus.ready +[D] AgendaCubit: AgendaStatus.cacheReady +[D] AgendaCubit: AgendaStatus.cacheReady +[D] TomussCubit: TomussStatus.ready +[D] ExamenCubit: ExamenStatus.loading +⚠️ WARNING: HIVE MULTI-ISOLATE RISK DETECTED ⚠️ + +Accessing Hive from an unsafe isolate (current isolate: "Closure: (String?) => Future> from Function 'cacheLoad': static.") +This can lead to DATA CORRUPTION as Hive boxes are not designed for concurrent +access across isolates. Each isolate would maintain its own box cache, +potentially causing data inconsistency and corruption. + +RECOMMENDED ACTIONS: +- Use IsolatedHive instead + + +[D] EmailCubit: MailStatus.mailboxesLoaded +[D] AgendaCubit: AgendaStatus.haveToChooseManualy +[D] AgendaConfigCubit: created +[D] AgendaConfigCubit: AgendaConfigStatus.loading +[D] AgendaConfigCubit: AgendaConfigStatus.connecting +[D] ExamenCubit: ExamenStatus.ready +[D] AgendaCubit: AgendaStatus.haveToChooseManualy +[D] AgendaCubit: AgendaStatus.haveToChooseManualy +[D] EmailCubit: MailStatus.loaded +[D] EmailCubit: MailStatus.sorted +[D] AgendaConfigCubit: AgendaConfigStatus.error +[D] EmailCubit: MailStatus.connected +[D] EmailCubit: MailStatus.loading +⚠️ WARNING: HIVE MULTI-ISOLATE RISK DETECTED ⚠️ + +Accessing Hive from an unsafe isolate (current isolate: "Closure: (String?) => Future> from Function 'cacheLoad': static.") +This can lead to DATA CORRUPTION as Hive boxes are not designed for concurrent +access across isolates. Each isolate would maintain its own box cache, +potentially causing data inconsistency and corruption. + +RECOMMENDED ACTIONS: +- Use IsolatedHive instead + + +[D] EmailCubit: MailStatus.mailboxesLoaded +[D] EmailCubit: MailStatus.loaded +[D] EmailCubit: MailStatus.sorted +[D] HomeCubit: HomeStatus.initial +[D] TomussCubit: TomussStatus.loading +⚠️ WARNING: HIVE MULTI-ISOLATE RISK DETECTED ⚠️ + +Accessing Hive from an unsafe isolate (current isolate: "Closure: (({int currentSemesterIndex, String? path})) => Future> from Function 'getTeachingUnitsCache': static.") +This can lead to DATA CORRUPTION as Hive boxes are not designed for concurrent +access across isolates. Each isolate would maintain its own box cache, +potentially causing data inconsistency and corruption. + +RECOMMENDED ACTIONS: +- Use IsolatedHive instead + + +[D] TomussCubit: TomussStatus.cacheReady \ No newline at end of file diff --git a/packages/izlyclient/build.yaml b/packages/izlyclient/build.yaml index d6160f7dc..3ff8f90ad 100644 --- a/packages/izlyclient/build.yaml +++ b/packages/izlyclient/build.yaml @@ -1,9 +1,11 @@ targets: $default: builders: - source_gen|combining_builder: - generate_for: - - lib/**.dart + # only to resolve build_runner conflicts + dart_mappable_builder: options: build_extensions: - 'lib/{{path}}/{{file}}.dart': 'lib/{{path}}/generated/{{file}}.g.dart' \ No newline at end of file + 'lib/{{path}}/{{file}}.dart': + - 'lib/{{path}}/generated/{{file}}.mapper.dart' + - 'lib/{{path}}/generated/{{file}}.init.dart' + diff --git a/packages/izlyclient/lib/hive/generated/hive_adapters.g.dart b/packages/izlyclient/lib/hive/generated/hive_adapters.g.dart deleted file mode 100644 index 4670511c3..000000000 --- a/packages/izlyclient/lib/hive/generated/hive_adapters.g.dart +++ /dev/null @@ -1,439 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../hive_adapters.dart'; - -// ************************************************************************** -// AdaptersGenerator -// ************************************************************************** - -class IzlyCredentialAdapter extends TypeAdapter { - @override - final typeId = 15; - - @override - IzlyCredential read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return IzlyCredential( - username: fields[0] as String, - password: fields[1] as String, - ); - } - - @override - void write(BinaryWriter writer, IzlyCredential obj) { - writer - ..writeByte(2) - ..writeByte(0) - ..write(obj.username) - ..writeByte(1) - ..write(obj.password); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is IzlyCredentialAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class IzlyQrCodeAdapter extends TypeAdapter { - @override - final typeId = 16; - - @override - IzlyQrCode read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return IzlyQrCode( - qrCode: fields[0] as Uint8List, - expirationDate: fields[1] as DateTime, - ); - } - - @override - void write(BinaryWriter writer, IzlyQrCode obj) { - writer - ..writeByte(2) - ..writeByte(0) - ..write(obj.qrCode) - ..writeByte(1) - ..write(obj.expirationDate); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is IzlyQrCodeAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class IzlyQrCodeListAdapter extends TypeAdapter { - @override - final typeId = 17; - - @override - IzlyQrCodeList read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return IzlyQrCodeList( - qrCodes: (fields[0] as List).cast(), - ); - } - - @override - void write(BinaryWriter writer, IzlyQrCodeList obj) { - writer - ..writeByte(1) - ..writeByte(0) - ..write(obj.qrCodes); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is IzlyQrCodeListAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class MenuCrousAdapter extends TypeAdapter { - @override - final typeId = 32; - - @override - MenuCrous read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return MenuCrous( - date: fields[0] as DateTime, - type: fields[1] as MenuType, - plats: (fields[3] as List).cast(), - ); - } - - @override - void write(BinaryWriter writer, MenuCrous obj) { - writer - ..writeByte(3) - ..writeByte(0) - ..write(obj.date) - ..writeByte(1) - ..write(obj.type) - ..writeByte(3) - ..write(obj.plats); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is MenuCrousAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class RestaurantModelAdapter extends TypeAdapter { - @override - final typeId = 33; - - @override - RestaurantModel read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return RestaurantModel( - id: (fields[0] as num).toInt(), - name: fields[1] as String, - description: fields[2] as String, - shortDescription: fields[3] as String, - type: fields[4] as CrousType, - lat: (fields[5] as num).toDouble(), - lon: (fields[6] as num).toDouble(), - opening: fields[7] as String, - menus: (fields[8] as List).cast(), - imageUrl: fields[9] as String, - ); - } - - @override - void write(BinaryWriter writer, RestaurantModel obj) { - writer - ..writeByte(10) - ..writeByte(0) - ..write(obj.id) - ..writeByte(1) - ..write(obj.name) - ..writeByte(2) - ..write(obj.description) - ..writeByte(3) - ..write(obj.shortDescription) - ..writeByte(4) - ..write(obj.type) - ..writeByte(5) - ..write(obj.lat) - ..writeByte(6) - ..write(obj.lon) - ..writeByte(7) - ..write(obj.opening) - ..writeByte(8) - ..write(obj.menus) - ..writeByte(9) - ..write(obj.imageUrl); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is RestaurantModelAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class MenuTypeAdapter extends TypeAdapter { - @override - final typeId = 34; - - @override - MenuType read(BinaryReader reader) { - switch (reader.readByte()) { - case 0: - return MenuType.matin; - case 1: - return MenuType.midi; - case 2: - return MenuType.soir; - default: - return MenuType.matin; - } - } - - @override - void write(BinaryWriter writer, MenuType obj) { - switch (obj) { - case MenuType.matin: - writer.writeByte(0); - case MenuType.midi: - writer.writeByte(1); - case MenuType.soir: - writer.writeByte(2); - } - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is MenuTypeAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class PlatCrousAdapter extends TypeAdapter { - @override - final typeId = 36; - - @override - PlatCrous read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return PlatCrous( - name: fields[0] as String, - variants: (fields[1] as List).cast(), - ); - } - - @override - void write(BinaryWriter writer, PlatCrous obj) { - writer - ..writeByte(2) - ..writeByte(0) - ..write(obj.name) - ..writeByte(1) - ..write(obj.variants); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is PlatCrousAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class CrousTypeAdapter extends TypeAdapter { - @override - final typeId = 38; - - @override - CrousType read(BinaryReader reader) { - switch (reader.readByte()) { - case 0: - return CrousType.restaurant; - case 1: - return CrousType.cafet; - default: - return CrousType.restaurant; - } - } - - @override - void write(BinaryWriter writer, CrousType obj) { - switch (obj) { - case CrousType.restaurant: - writer.writeByte(0); - case CrousType.cafet: - writer.writeByte(1); - } - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is CrousTypeAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class RestaurantListModelAdapter extends TypeAdapter { - @override - final typeId = 39; - - @override - RestaurantListModel read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return RestaurantListModel( - restaurantList: (fields[0] as List).cast(), - ); - } - - @override - void write(BinaryWriter writer, RestaurantListModel obj) { - writer - ..writeByte(1) - ..writeByte(0) - ..write(obj.restaurantList); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is RestaurantListModelAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class IzlyPaymentModelAdapter extends TypeAdapter { - @override - final typeId = 40; - - @override - IzlyPaymentModel read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return IzlyPaymentModel( - paymentTime: fields[3] as DateTime, - amountSpent: (fields[4] as num).toDouble(), - isSucess: fields[2] as bool, - ); - } - - @override - void write(BinaryWriter writer, IzlyPaymentModel obj) { - writer - ..writeByte(3) - ..writeByte(2) - ..write(obj.isSucess) - ..writeByte(3) - ..write(obj.paymentTime) - ..writeByte(4) - ..write(obj.amountSpent); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is IzlyPaymentModelAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class IzlyPaymentModelListAdapter extends TypeAdapter { - @override - final typeId = 41; - - @override - IzlyPaymentModelList read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return IzlyPaymentModelList( - payments: (fields[0] as List).cast(), - ); - } - - @override - void write(BinaryWriter writer, IzlyPaymentModelList obj) { - writer - ..writeByte(1) - ..writeByte(0) - ..write(obj.payments); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is IzlyPaymentModelListAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} diff --git a/packages/izlyclient/lib/hive/hive_adapters.dart b/packages/izlyclient/lib/hive/hive_adapters.dart deleted file mode 100644 index c16daa87f..000000000 --- a/packages/izlyclient/lib/hive/hive_adapters.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'dart:typed_data'; - -import 'package:hive_ce/hive.dart'; -import 'package:izlyclient/src/model/izly_credential.dart'; -import 'package:izlyclient/src/model/izly_payment_model.dart'; -import 'package:izlyclient/src/model/izly_payment_model_list.dart'; -import 'package:izlyclient/src/model/izly_qrcode.dart'; -import 'package:izlyclient/src/model/izly_qrcode_list.dart'; -import 'package:izlyclient/src/model/menu_crous.dart'; -import 'package:izlyclient/src/model/restaurant.dart'; -import 'package:izlyclient/src/model/restaurant_list_model.dart'; - -@GenerateAdapters([ - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), -]) -part 'generated/hive_adapters.g.dart'; diff --git a/packages/izlyclient/lib/hive/hive_adapters.g.yaml b/packages/izlyclient/lib/hive/hive_adapters.g.yaml deleted file mode 100644 index 0525e4599..000000000 --- a/packages/izlyclient/lib/hive/hive_adapters.g.yaml +++ /dev/null @@ -1,109 +0,0 @@ -# Generated by Hive CE -# Manual modifications may be necessary for certain migrations -# Check in to version control -nextTypeId: 42 -types: - IzlyCredential: - typeId: 15 - nextIndex: 2 - fields: - username: - index: 0 - password: - index: 1 - IzlyQrCode: - typeId: 16 - nextIndex: 2 - fields: - qrCode: - index: 0 - expirationDate: - index: 1 - IzlyQrCodeList: - typeId: 17 - nextIndex: 1 - fields: - qrCodes: - index: 0 - MenuCrous: - typeId: 32 - nextIndex: 4 - fields: - date: - index: 0 - type: - index: 1 - plats: - index: 3 - RestaurantModel: - typeId: 33 - nextIndex: 10 - fields: - id: - index: 0 - name: - index: 1 - description: - index: 2 - shortDescription: - index: 3 - type: - index: 4 - lat: - index: 5 - lon: - index: 6 - opening: - index: 7 - menus: - index: 8 - imageUrl: - index: 9 - MenuType: - typeId: 34 - nextIndex: 3 - fields: - matin: - index: 0 - midi: - index: 1 - soir: - index: 2 - PlatCrous: - typeId: 36 - nextIndex: 2 - fields: - name: - index: 0 - variants: - index: 1 - CrousType: - typeId: 38 - nextIndex: 2 - fields: - restaurant: - index: 0 - cafet: - index: 1 - RestaurantListModel: - typeId: 39 - nextIndex: 1 - fields: - restaurantList: - index: 0 - IzlyPaymentModel: - typeId: 40 - nextIndex: 5 - fields: - isSucess: - index: 2 - paymentTime: - index: 3 - amountSpent: - index: 4 - IzlyPaymentModelList: - typeId: 41 - nextIndex: 1 - fields: - payments: - index: 0 diff --git a/packages/izlyclient/lib/hive/hive_registrar.g.dart b/packages/izlyclient/lib/hive/hive_registrar.g.dart deleted file mode 100644 index 42ae945cc..000000000 --- a/packages/izlyclient/lib/hive/hive_registrar.g.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Generated by Hive CE -// Do not modify -// Check in to version control - -import 'package:hive_ce/hive.dart'; -import 'package:izlyclient/hive/hive_adapters.dart'; - -extension HiveRegistrar on HiveInterface { - void registerAdapters() { - registerAdapter(CrousTypeAdapter()); - registerAdapter(IzlyCredentialAdapter()); - registerAdapter(IzlyPaymentModelAdapter()); - registerAdapter(IzlyPaymentModelListAdapter()); - registerAdapter(IzlyQrCodeAdapter()); - registerAdapter(IzlyQrCodeListAdapter()); - registerAdapter(MenuCrousAdapter()); - registerAdapter(MenuTypeAdapter()); - registerAdapter(PlatCrousAdapter()); - registerAdapter(RestaurantListModelAdapter()); - registerAdapter(RestaurantModelAdapter()); - } -} - -extension IsolatedHiveRegistrar on IsolatedHiveInterface { - void registerAdapters() { - registerAdapter(CrousTypeAdapter()); - registerAdapter(IzlyCredentialAdapter()); - registerAdapter(IzlyPaymentModelAdapter()); - registerAdapter(IzlyPaymentModelListAdapter()); - registerAdapter(IzlyQrCodeAdapter()); - registerAdapter(IzlyQrCodeListAdapter()); - registerAdapter(MenuCrousAdapter()); - registerAdapter(MenuTypeAdapter()); - registerAdapter(PlatCrousAdapter()); - registerAdapter(RestaurantListModelAdapter()); - registerAdapter(RestaurantModelAdapter()); - } -} diff --git a/packages/izlyclient/lib/src/izlyclient.dart b/packages/izlyclient/lib/src/izlyclient.dart index 496d4e0fd..5ff2245c1 100755 --- a/packages/izlyclient/lib/src/izlyclient.dart +++ b/packages/izlyclient/lib/src/izlyclient.dart @@ -2,11 +2,9 @@ import 'dart:convert'; import 'dart:typed_data'; import 'package:beautiful_soup_dart/beautiful_soup.dart'; -import 'package:hive_ce/hive.dart'; import 'package:html/dom.dart'; import 'package:html/parser.dart'; import 'package:intl/intl.dart'; -import 'package:izlyclient/hive/hive_registrar.g.dart'; import 'package:izlyclient/izlyclient.dart'; import 'package:requests_plus/requests_plus.dart'; @@ -18,10 +16,6 @@ class IzlyClient { "https://secure-magenta1.be2bill.com/front/form/process"; late final String _corsProxyUrl; - static void registerAdapters() { - Hive.registerAdapters(); - } - final String _username; final String _password; bool _isLogged = false; @@ -34,14 +28,18 @@ class IzlyClient { } Future isLogged() async { - final r = await RequestsPlus.get("$_baseUrl/Home/PaymentInitiation", - corsProxyUrl: _corsProxyUrl); + final r = await RequestsPlus.get( + "$_baseUrl/Home/PaymentInitiation", + corsProxyUrl: _corsProxyUrl, + ); return (r.statusCode == 200); } Future login() async { - var r = await RequestsPlus.get("$_baseUrl/Home/Logon", - corsProxyUrl: _corsProxyUrl); + var r = await RequestsPlus.get( + "$_baseUrl/Home/Logon", + corsProxyUrl: _corsProxyUrl, + ); List content = r .content() .split("\n") @@ -50,15 +48,17 @@ class IzlyClient { int index = content.indexOf(" value="); // ignore: no_leading_underscores_for_local_identifiers, non_constant_identifier_names String __RequestVerificationToken = content[index + 1]; - r = await RequestsPlus.post('$_baseUrl/Home/Logon', - body: { - 'Username': _username, - 'Password': _password, - 'ReturnUrl': '/', - "__RequestVerificationToken": __RequestVerificationToken, - }, - corsProxyUrl: _corsProxyUrl, - followRedirects: false); + r = await RequestsPlus.post( + '$_baseUrl/Home/Logon', + body: { + 'Username': _username, + 'Password': _password, + 'ReturnUrl': '/', + "__RequestVerificationToken": __RequestVerificationToken, + }, + corsProxyUrl: _corsProxyUrl, + followRedirects: false, + ); if (r.statusCode != 302) { throw Exception("Login failed"); } @@ -67,8 +67,10 @@ class IzlyClient { } Future logout() async { - var r = await RequestsPlus.get("$_baseUrl/Home/Logout", - corsProxyUrl: _corsProxyUrl); + var r = await RequestsPlus.get( + "$_baseUrl/Home/Logout", + corsProxyUrl: _corsProxyUrl, + ); if (r.statusCode != 200) { throw Exception("Logout failed"); } @@ -86,40 +88,47 @@ class IzlyClient { } Document document = parse(r.content()); //select the value in the p with id balance - String balance = - document.getElementById("balance")!.innerHtml.split("").first; + String balance = document + .getElementById("balance")! + .innerHtml + .split("") + .first; return double.parse(balance.replaceAll(",", ".")); } Future getQRCode() async { assert(_isLogged); - var r = await RequestsPlus.post("$_baseUrl/Home/CreateQrCodeImg", - body: { - 'numberOfQrCodes': "1", - }, - corsProxyUrl: _corsProxyUrl); + var r = await RequestsPlus.post( + "$_baseUrl/Home/CreateQrCodeImg", + body: {'numberOfQrCodes': "1"}, + corsProxyUrl: _corsProxyUrl, + ); Uint8List result = base64Decode(jsonDecode(r.body)["images"][0]); return result; } Future<({Map body, String url})> getTransferPaymentUrl( - double amount) async { + double amount, + ) async { assert(_isLogged); var r = await RequestsPlus.post( - "$_baseUrl/Home/PaymentInitiationRequest?amount=${amount.toStringAsFixed(2)}", - corsProxyUrl: _corsProxyUrl); + "$_baseUrl/Home/PaymentInitiationRequest?amount=${amount.toStringAsFixed(2)}", + corsProxyUrl: _corsProxyUrl, + ); if (r.statusCode != 200) { throw Exception("Payment failed"); } return ( url: jsonDecode(r.content())["url"].toString(), - body: {} + body: {}, ); } Future> getAvailableCBs() async { - var r = await RequestsPlus.get("$_baseUrl/Home/Recharge", - corsProxyUrl: _corsProxyUrl); + var r = await RequestsPlus.get( + "$_baseUrl/Home/Recharge", + corsProxyUrl: _corsProxyUrl, + ); if (r.statusCode != 200) { throw Exception("Recharge failed"); } @@ -136,24 +145,29 @@ class IzlyClient { } Future<({Map body, String url})> rechargeWithCB( - double amount, CbModel cb) async { + double amount, + CbModel cb, + ) async { assert(amount >= 10.0); if ((cb.id != "newCB")) { - var r = await RequestsPlus.post("$_baseUrl/Home/RechargeConfirm", - body: { - 'dataToSend': - '{"Amount":"${amount.toStringAsFixed(2)}","Code":"$_password","Senders":[{"ID":"${cb.id}","Name":"${cb.name}","Amount":"${amount.toStringAsFixed(2)}"}]}', - 'operation': '', - 'engagementId': '', - }, - corsProxyUrl: _corsProxyUrl); + var r = await RequestsPlus.post( + "$_baseUrl/Home/RechargeConfirm", + body: { + 'dataToSend': + '{"Amount":"${amount.toStringAsFixed(2)}","Code":"$_password","Senders":[{"ID":"${cb.id}","Name":"${cb.name}","Amount":"${amount.toStringAsFixed(2)}"}]}', + 'operation': '', + 'engagementId': '', + }, + corsProxyUrl: _corsProxyUrl, + ); if (r.statusCode != 200) { throw Exception("Recharge failed"); } final jsonData = jsonDecode(r.body); - final securityReturn = - jsonDecode(jsonData["Confirm"]["DalenysData3DSReturn"]); + final securityReturn = jsonDecode( + jsonData["Confirm"]["DalenysData3DSReturn"], + ); return ( url: jsonData["Confirm"]["DalenysUrl3DSReturn"].toString(), body: { @@ -161,34 +175,38 @@ class IzlyClient { 'transaction_public_id': securityReturn['transaction_public_id'], 'card_network': securityReturn['card_network'], 'log_id': securityReturn['log_id'], - } + }, ); } else { - var r = await RequestsPlus.post("$_baseUrl/Home/PaymentCreateRequest", - body: { - 'amount': amount.toStringAsFixed(2), - }, - corsProxyUrl: _corsProxyUrl); + var r = await RequestsPlus.post( + "$_baseUrl/Home/PaymentCreateRequest", + body: {'amount': amount.toStringAsFixed(2)}, + corsProxyUrl: _corsProxyUrl, + ); if (r.hasError) { throw 'web error'; } - r = await RequestsPlus.post("$_baseUrl/Profile/CompleteProfilePayment", - body: { - 'amount': jsonDecode(r.body)["amount"], - 'registered': "true", - 'transferId': jsonDecode(r.body)["transfertId"] - }, - corsProxyUrl: _corsProxyUrl); + r = await RequestsPlus.post( + "$_baseUrl/Profile/CompleteProfilePayment", + body: { + 'amount': jsonDecode(r.body)["amount"], + 'registered': "true", + 'transferId': jsonDecode(r.body)["transfertId"], + }, + corsProxyUrl: _corsProxyUrl, + ); if (r.hasError) { throw 'web error'; } Document parsedHtml = HtmlParser(r.body).parse(); Map body = {}; - for (Node node in parsedHtml.children.first.nodes[2].nodes[1].nodes - .firstWhere( - (element) => element.attributes["id"] == "submit-payment-form") - .nodes - .toList()) { + for (Node node + in parsedHtml.children.first.nodes[2].nodes[1].nodes + .firstWhere( + (element) => element.attributes["id"] == "submit-payment-form", + ) + .nodes + .toList()) { if (node.attributes.containsKey("type") && node.attributes["type"] == "hidden") { body[node.attributes['name'].toString()] = node.attributes['value']; @@ -199,19 +217,23 @@ class IzlyClient { } Future rechargeViaSomeoneElse( - double amount, String email, String message) async { + double amount, + String email, + String message, + ) async { assert(_isLogged); assert(amount >= 10.0); - var r = - await RequestsPlus.post("$_baseUrl/PayInRequest/PayInRequestConfirm", - body: { - "Email": email, - "AmountPad.AmountSelectedValue": "", - "Message": message, - "PadAmount": "0", - "Amount": amount.toStringAsFixed(2), - }, - corsProxyUrl: _corsProxyUrl); + var r = await RequestsPlus.post( + "$_baseUrl/PayInRequest/PayInRequestConfirm", + body: { + "Email": email, + "AmountPad.AmountSelectedValue": "", + "Message": message, + "PadAmount": "0", + "Amount": amount.toStringAsFixed(2), + }, + corsProxyUrl: _corsProxyUrl, + ); if (r.statusCode != 200) { throw Exception("Recharge failed"); } @@ -219,13 +241,17 @@ class IzlyClient { } static Future> getRestaurantCrous() async { - final r = await RequestsPlus.get(_menuUrl, - bodyEncoding: RequestBodyEncoding.JSON); + final r = await RequestsPlus.get( + _menuUrl, + bodyEncoding: RequestBodyEncoding.JSON, + ); if (r.statusCode != 200) { throw Exception("Can't get menu crous"); } - String body = - r.body.replaceAll("\n", "").replaceAll("\t", "").replaceAll("\r", ""); + String body = r.body + .replaceAll("\n", "") + .replaceAll("\t", "") + .replaceAll("\r", ""); final decoded = jsonDecode(body); return (decoded["restaurants"] as List) .map((e) => RestaurantModel.fromJson(e)) @@ -247,13 +273,17 @@ class IzlyClient { List paymentsList = []; for (var i = 0; i < paymentTime.length; i++) { - paymentsList.add(IzlyPaymentModel( - paymentTime: DateFormat('dd/MM/yyyy HH:mm') - .parse(paymentTime[i].element!.nodes.first.data), - amountSpent: double.parse( - amountSpent[i].element!.nodes.first.data.replaceFirst(",", ".")), - isSucess: isSucess[i].element!.nodes.first.data == " Succès ", - )); + paymentsList.add( + IzlyPaymentModel( + paymentTime: DateFormat( + 'dd/MM/yyyy HH:mm', + ).parse(paymentTime[i].element!.nodes.first.data), + amountSpent: double.parse( + amountSpent[i].element!.nodes.first.data.replaceFirst(",", "."), + ), + isSucess: isSucess[i].element!.nodes.first.data == " Succès ", + ), + ); } return paymentsList; diff --git a/packages/izlyclient/lib/src/model/cb_model.dart b/packages/izlyclient/lib/src/model/cb_model.dart index b2cc11823..f20bb5aef 100755 --- a/packages/izlyclient/lib/src/model/cb_model.dart +++ b/packages/izlyclient/lib/src/model/cb_model.dart @@ -1,13 +1,11 @@ -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; -class CbModel extends Equatable { +part 'generated/cb_model.mapper.dart'; + +@MappableClass() +class CbModel with CbModelMappable { final String name; final String id; CbModel(this.name, this.id); - - @override - List get props => [name, id]; - @override - bool get stringify => true; } diff --git a/packages/izlyclient/lib/src/model/generated/cb_model.mapper.dart b/packages/izlyclient/lib/src/model/generated/cb_model.mapper.dart new file mode 100644 index 000000000..da33b6617 --- /dev/null +++ b/packages/izlyclient/lib/src/model/generated/cb_model.mapper.dart @@ -0,0 +1,117 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../cb_model.dart'; + +class CbModelMapper extends ClassMapperBase { + CbModelMapper._(); + + static CbModelMapper? _instance; + static CbModelMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = CbModelMapper._()); + } + return _instance!; + } + + @override + final String id = 'CbModel'; + + static String _$name(CbModel v) => v.name; + static const Field _f$name = Field('name', _$name); + static String _$id(CbModel v) => v.id; + static const Field _f$id = Field('id', _$id); + + @override + final MappableFields fields = const {#name: _f$name, #id: _f$id}; + + static CbModel _instantiate(DecodingData data) { + return CbModel(data.dec(_f$name), data.dec(_f$id)); + } + + @override + final Function instantiate = _instantiate; + + static CbModel fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static CbModel fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin CbModelMappable { + String toJson() { + return CbModelMapper.ensureInitialized().encodeJson( + this as CbModel, + ); + } + + Map toMap() { + return CbModelMapper.ensureInitialized().encodeMap( + this as CbModel, + ); + } + + CbModelCopyWith get copyWith => + _CbModelCopyWithImpl( + this as CbModel, + $identity, + $identity, + ); + @override + String toString() { + return CbModelMapper.ensureInitialized().stringifyValue(this as CbModel); + } + + @override + bool operator ==(Object other) { + return CbModelMapper.ensureInitialized().equalsValue( + this as CbModel, + other, + ); + } + + @override + int get hashCode { + return CbModelMapper.ensureInitialized().hashValue(this as CbModel); + } +} + +extension CbModelValueCopy<$R, $Out> on ObjectCopyWith<$R, CbModel, $Out> { + CbModelCopyWith<$R, CbModel, $Out> get $asCbModel => + $base.as((v, t, t2) => _CbModelCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class CbModelCopyWith<$R, $In extends CbModel, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({String? name, String? id}); + CbModelCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _CbModelCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, CbModel, $Out> + implements CbModelCopyWith<$R, CbModel, $Out> { + _CbModelCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + CbModelMapper.ensureInitialized(); + @override + $R call({String? name, String? id}) => $apply( + FieldCopyWithData({if (name != null) #name: name, if (id != null) #id: id}), + ); + @override + CbModel $make(CopyWithData data) => + CbModel(data.get(#name, or: $value.name), data.get(#id, or: $value.id)); + + @override + CbModelCopyWith<$R2, CbModel, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _CbModelCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/izlyclient/lib/src/model/generated/izly_credential.g.dart b/packages/izlyclient/lib/src/model/generated/izly_credential.g.dart deleted file mode 100644 index 6724bbb37..000000000 --- a/packages/izlyclient/lib/src/model/generated/izly_credential.g.dart +++ /dev/null @@ -1,71 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../izly_credential.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$IzlyCredentialCWProxy { - IzlyCredential username(String username); - - IzlyCredential password(String password); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `IzlyCredential(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// IzlyCredential(...).copyWith(id: 12, name: "My name") - /// ``` - IzlyCredential call({ - String username, - String password, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfIzlyCredential.copyWith(...)` or call `instanceOfIzlyCredential.copyWith.fieldName(value)` for a single field. -class _$IzlyCredentialCWProxyImpl implements _$IzlyCredentialCWProxy { - const _$IzlyCredentialCWProxyImpl(this._value); - - final IzlyCredential _value; - - @override - IzlyCredential username(String username) => call(username: username); - - @override - IzlyCredential password(String password) => call(password: password); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `IzlyCredential(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// IzlyCredential(...).copyWith(id: 12, name: "My name") - /// ``` - IzlyCredential call({ - Object? username = const $CopyWithPlaceholder(), - Object? password = const $CopyWithPlaceholder(), - }) { - return IzlyCredential( - username: username == const $CopyWithPlaceholder() || username == null - ? _value.username - // ignore: cast_nullable_to_non_nullable - : username as String, - password: password == const $CopyWithPlaceholder() || password == null - ? _value.password - // ignore: cast_nullable_to_non_nullable - : password as String, - ); - } -} - -extension $IzlyCredentialCopyWith on IzlyCredential { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfIzlyCredential.copyWith(...)` or `instanceOfIzlyCredential.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$IzlyCredentialCWProxy get copyWith => _$IzlyCredentialCWProxyImpl(this); -} diff --git a/packages/izlyclient/lib/src/model/generated/izly_credential.mapper.dart b/packages/izlyclient/lib/src/model/generated/izly_credential.mapper.dart new file mode 100644 index 000000000..2520062d6 --- /dev/null +++ b/packages/izlyclient/lib/src/model/generated/izly_credential.mapper.dart @@ -0,0 +1,142 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../izly_credential.dart'; + +class IzlyCredentialMapper extends ClassMapperBase { + IzlyCredentialMapper._(); + + static IzlyCredentialMapper? _instance; + static IzlyCredentialMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = IzlyCredentialMapper._()); + } + return _instance!; + } + + @override + final String id = 'IzlyCredential'; + + static String _$username(IzlyCredential v) => v.username; + static const Field _f$username = Field( + 'username', + _$username, + ); + static String _$password(IzlyCredential v) => v.password; + static const Field _f$password = Field( + 'password', + _$password, + ); + + @override + final MappableFields fields = const { + #username: _f$username, + #password: _f$password, + }; + + static IzlyCredential _instantiate(DecodingData data) { + return IzlyCredential( + username: data.dec(_f$username), + password: data.dec(_f$password), + ); + } + + @override + final Function instantiate = _instantiate; + + static IzlyCredential fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static IzlyCredential fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin IzlyCredentialMappable { + String toJson() { + return IzlyCredentialMapper.ensureInitialized().encodeJson( + this as IzlyCredential, + ); + } + + Map toMap() { + return IzlyCredentialMapper.ensureInitialized().encodeMap( + this as IzlyCredential, + ); + } + + IzlyCredentialCopyWith + get copyWith => _IzlyCredentialCopyWithImpl( + this as IzlyCredential, + $identity, + $identity, + ); + @override + String toString() { + return IzlyCredentialMapper.ensureInitialized().stringifyValue( + this as IzlyCredential, + ); + } + + @override + bool operator ==(Object other) { + return IzlyCredentialMapper.ensureInitialized().equalsValue( + this as IzlyCredential, + other, + ); + } + + @override + int get hashCode { + return IzlyCredentialMapper.ensureInitialized().hashValue( + this as IzlyCredential, + ); + } +} + +extension IzlyCredentialValueCopy<$R, $Out> + on ObjectCopyWith<$R, IzlyCredential, $Out> { + IzlyCredentialCopyWith<$R, IzlyCredential, $Out> get $asIzlyCredential => + $base.as((v, t, t2) => _IzlyCredentialCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class IzlyCredentialCopyWith<$R, $In extends IzlyCredential, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({String? username, String? password}); + IzlyCredentialCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ); +} + +class _IzlyCredentialCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, IzlyCredential, $Out> + implements IzlyCredentialCopyWith<$R, IzlyCredential, $Out> { + _IzlyCredentialCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + IzlyCredentialMapper.ensureInitialized(); + @override + $R call({String? username, String? password}) => $apply( + FieldCopyWithData({ + if (username != null) #username: username, + if (password != null) #password: password, + }), + ); + @override + IzlyCredential $make(CopyWithData data) => IzlyCredential( + username: data.get(#username, or: $value.username), + password: data.get(#password, or: $value.password), + ); + + @override + IzlyCredentialCopyWith<$R2, IzlyCredential, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _IzlyCredentialCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/izlyclient/lib/src/model/generated/izly_payment_model.mapper.dart b/packages/izlyclient/lib/src/model/generated/izly_payment_model.mapper.dart new file mode 100644 index 000000000..b0915bf07 --- /dev/null +++ b/packages/izlyclient/lib/src/model/generated/izly_payment_model.mapper.dart @@ -0,0 +1,152 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../izly_payment_model.dart'; + +class IzlyPaymentModelMapper extends ClassMapperBase { + IzlyPaymentModelMapper._(); + + static IzlyPaymentModelMapper? _instance; + static IzlyPaymentModelMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = IzlyPaymentModelMapper._()); + } + return _instance!; + } + + @override + final String id = 'IzlyPaymentModel'; + + static DateTime _$paymentTime(IzlyPaymentModel v) => v.paymentTime; + static const Field _f$paymentTime = Field( + 'paymentTime', + _$paymentTime, + ); + static double _$amountSpent(IzlyPaymentModel v) => v.amountSpent; + static const Field _f$amountSpent = Field( + 'amountSpent', + _$amountSpent, + ); + static bool _$isSucess(IzlyPaymentModel v) => v.isSucess; + static const Field _f$isSucess = Field( + 'isSucess', + _$isSucess, + ); + + @override + final MappableFields fields = const { + #paymentTime: _f$paymentTime, + #amountSpent: _f$amountSpent, + #isSucess: _f$isSucess, + }; + + static IzlyPaymentModel _instantiate(DecodingData data) { + return IzlyPaymentModel( + paymentTime: data.dec(_f$paymentTime), + amountSpent: data.dec(_f$amountSpent), + isSucess: data.dec(_f$isSucess), + ); + } + + @override + final Function instantiate = _instantiate; + + static IzlyPaymentModel fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static IzlyPaymentModel fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin IzlyPaymentModelMappable { + String toJson() { + return IzlyPaymentModelMapper.ensureInitialized() + .encodeJson(this as IzlyPaymentModel); + } + + Map toMap() { + return IzlyPaymentModelMapper.ensureInitialized() + .encodeMap(this as IzlyPaymentModel); + } + + IzlyPaymentModelCopyWith + get copyWith => + _IzlyPaymentModelCopyWithImpl( + this as IzlyPaymentModel, + $identity, + $identity, + ); + @override + String toString() { + return IzlyPaymentModelMapper.ensureInitialized().stringifyValue( + this as IzlyPaymentModel, + ); + } + + @override + bool operator ==(Object other) { + return IzlyPaymentModelMapper.ensureInitialized().equalsValue( + this as IzlyPaymentModel, + other, + ); + } + + @override + int get hashCode { + return IzlyPaymentModelMapper.ensureInitialized().hashValue( + this as IzlyPaymentModel, + ); + } +} + +extension IzlyPaymentModelValueCopy<$R, $Out> + on ObjectCopyWith<$R, IzlyPaymentModel, $Out> { + IzlyPaymentModelCopyWith<$R, IzlyPaymentModel, $Out> + get $asIzlyPaymentModel => + $base.as((v, t, t2) => _IzlyPaymentModelCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class IzlyPaymentModelCopyWith<$R, $In extends IzlyPaymentModel, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({DateTime? paymentTime, double? amountSpent, bool? isSucess}); + IzlyPaymentModelCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ); +} + +class _IzlyPaymentModelCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, IzlyPaymentModel, $Out> + implements IzlyPaymentModelCopyWith<$R, IzlyPaymentModel, $Out> { + _IzlyPaymentModelCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + IzlyPaymentModelMapper.ensureInitialized(); + @override + $R call({DateTime? paymentTime, double? amountSpent, bool? isSucess}) => + $apply( + FieldCopyWithData({ + if (paymentTime != null) #paymentTime: paymentTime, + if (amountSpent != null) #amountSpent: amountSpent, + if (isSucess != null) #isSucess: isSucess, + }), + ); + @override + IzlyPaymentModel $make(CopyWithData data) => IzlyPaymentModel( + paymentTime: data.get(#paymentTime, or: $value.paymentTime), + amountSpent: data.get(#amountSpent, or: $value.amountSpent), + isSucess: data.get(#isSucess, or: $value.isSucess), + ); + + @override + IzlyPaymentModelCopyWith<$R2, IzlyPaymentModel, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _IzlyPaymentModelCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/izlyclient/lib/src/model/generated/izly_payment_model_list.g.dart b/packages/izlyclient/lib/src/model/generated/izly_payment_model_list.g.dart deleted file mode 100644 index 9c31258cc..000000000 --- a/packages/izlyclient/lib/src/model/generated/izly_payment_model_list.g.dart +++ /dev/null @@ -1,63 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../izly_payment_model_list.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$IzlyPaymentModelListCWProxy { - IzlyPaymentModelList payments(List payments); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `IzlyPaymentModelList(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// IzlyPaymentModelList(...).copyWith(id: 12, name: "My name") - /// ``` - IzlyPaymentModelList call({ - List payments, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfIzlyPaymentModelList.copyWith(...)` or call `instanceOfIzlyPaymentModelList.copyWith.fieldName(value)` for a single field. -class _$IzlyPaymentModelListCWProxyImpl - implements _$IzlyPaymentModelListCWProxy { - const _$IzlyPaymentModelListCWProxyImpl(this._value); - - final IzlyPaymentModelList _value; - - @override - IzlyPaymentModelList payments(List payments) => - call(payments: payments); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `IzlyPaymentModelList(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// IzlyPaymentModelList(...).copyWith(id: 12, name: "My name") - /// ``` - IzlyPaymentModelList call({ - Object? payments = const $CopyWithPlaceholder(), - }) { - return IzlyPaymentModelList( - payments: payments == const $CopyWithPlaceholder() || payments == null - ? _value.payments - // ignore: cast_nullable_to_non_nullable - : payments as List, - ); - } -} - -extension $IzlyPaymentModelListCopyWith on IzlyPaymentModelList { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfIzlyPaymentModelList.copyWith(...)` or `instanceOfIzlyPaymentModelList.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$IzlyPaymentModelListCWProxy get copyWith => - _$IzlyPaymentModelListCWProxyImpl(this); -} diff --git a/packages/izlyclient/lib/src/model/generated/izly_payment_model_list.mapper.dart b/packages/izlyclient/lib/src/model/generated/izly_payment_model_list.mapper.dart new file mode 100644 index 000000000..ce8e3424a --- /dev/null +++ b/packages/izlyclient/lib/src/model/generated/izly_payment_model_list.mapper.dart @@ -0,0 +1,152 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../izly_payment_model_list.dart'; + +class IzlyPaymentModelListMapper extends ClassMapperBase { + IzlyPaymentModelListMapper._(); + + static IzlyPaymentModelListMapper? _instance; + static IzlyPaymentModelListMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = IzlyPaymentModelListMapper._()); + IzlyPaymentModelMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'IzlyPaymentModelList'; + + static List _$payments(IzlyPaymentModelList v) => + v.payments; + static const Field> _f$payments = + Field('payments', _$payments); + + @override + final MappableFields fields = const { + #payments: _f$payments, + }; + + static IzlyPaymentModelList _instantiate(DecodingData data) { + return IzlyPaymentModelList(payments: data.dec(_f$payments)); + } + + @override + final Function instantiate = _instantiate; + + static IzlyPaymentModelList fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static IzlyPaymentModelList fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin IzlyPaymentModelListMappable { + String toJson() { + return IzlyPaymentModelListMapper.ensureInitialized() + .encodeJson(this as IzlyPaymentModelList); + } + + Map toMap() { + return IzlyPaymentModelListMapper.ensureInitialized() + .encodeMap(this as IzlyPaymentModelList); + } + + IzlyPaymentModelListCopyWith< + IzlyPaymentModelList, + IzlyPaymentModelList, + IzlyPaymentModelList + > + get copyWith => + _IzlyPaymentModelListCopyWithImpl< + IzlyPaymentModelList, + IzlyPaymentModelList + >(this as IzlyPaymentModelList, $identity, $identity); + @override + String toString() { + return IzlyPaymentModelListMapper.ensureInitialized().stringifyValue( + this as IzlyPaymentModelList, + ); + } + + @override + bool operator ==(Object other) { + return IzlyPaymentModelListMapper.ensureInitialized().equalsValue( + this as IzlyPaymentModelList, + other, + ); + } + + @override + int get hashCode { + return IzlyPaymentModelListMapper.ensureInitialized().hashValue( + this as IzlyPaymentModelList, + ); + } +} + +extension IzlyPaymentModelListValueCopy<$R, $Out> + on ObjectCopyWith<$R, IzlyPaymentModelList, $Out> { + IzlyPaymentModelListCopyWith<$R, IzlyPaymentModelList, $Out> + get $asIzlyPaymentModelList => $base.as( + (v, t, t2) => _IzlyPaymentModelListCopyWithImpl<$R, $Out>(v, t, t2), + ); +} + +abstract class IzlyPaymentModelListCopyWith< + $R, + $In extends IzlyPaymentModelList, + $Out +> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith< + $R, + IzlyPaymentModel, + IzlyPaymentModelCopyWith<$R, IzlyPaymentModel, IzlyPaymentModel> + > + get payments; + $R call({List? payments}); + IzlyPaymentModelListCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ); +} + +class _IzlyPaymentModelListCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, IzlyPaymentModelList, $Out> + implements IzlyPaymentModelListCopyWith<$R, IzlyPaymentModelList, $Out> { + _IzlyPaymentModelListCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + IzlyPaymentModelListMapper.ensureInitialized(); + @override + ListCopyWith< + $R, + IzlyPaymentModel, + IzlyPaymentModelCopyWith<$R, IzlyPaymentModel, IzlyPaymentModel> + > + get payments => ListCopyWith( + $value.payments, + (v, t) => v.copyWith.$chain(t), + (v) => call(payments: v), + ); + @override + $R call({List? payments}) => + $apply(FieldCopyWithData({if (payments != null) #payments: payments})); + @override + IzlyPaymentModelList $make(CopyWithData data) => + IzlyPaymentModelList(payments: data.get(#payments, or: $value.payments)); + + @override + IzlyPaymentModelListCopyWith<$R2, IzlyPaymentModelList, $Out2> + $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _IzlyPaymentModelListCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/izlyclient/lib/src/model/generated/izly_qrcode.g.dart b/packages/izlyclient/lib/src/model/generated/izly_qrcode.g.dart deleted file mode 100644 index 91918e3d5..000000000 --- a/packages/izlyclient/lib/src/model/generated/izly_qrcode.g.dart +++ /dev/null @@ -1,73 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../izly_qrcode.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$IzlyQrCodeCWProxy { - IzlyQrCode qrCode(Uint8List qrCode); - - IzlyQrCode expirationDate(DateTime expirationDate); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `IzlyQrCode(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// IzlyQrCode(...).copyWith(id: 12, name: "My name") - /// ``` - IzlyQrCode call({ - Uint8List qrCode, - DateTime expirationDate, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfIzlyQrCode.copyWith(...)` or call `instanceOfIzlyQrCode.copyWith.fieldName(value)` for a single field. -class _$IzlyQrCodeCWProxyImpl implements _$IzlyQrCodeCWProxy { - const _$IzlyQrCodeCWProxyImpl(this._value); - - final IzlyQrCode _value; - - @override - IzlyQrCode qrCode(Uint8List qrCode) => call(qrCode: qrCode); - - @override - IzlyQrCode expirationDate(DateTime expirationDate) => - call(expirationDate: expirationDate); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `IzlyQrCode(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// IzlyQrCode(...).copyWith(id: 12, name: "My name") - /// ``` - IzlyQrCode call({ - Object? qrCode = const $CopyWithPlaceholder(), - Object? expirationDate = const $CopyWithPlaceholder(), - }) { - return IzlyQrCode( - qrCode: qrCode == const $CopyWithPlaceholder() || qrCode == null - ? _value.qrCode - // ignore: cast_nullable_to_non_nullable - : qrCode as Uint8List, - expirationDate: expirationDate == const $CopyWithPlaceholder() || - expirationDate == null - ? _value.expirationDate - // ignore: cast_nullable_to_non_nullable - : expirationDate as DateTime, - ); - } -} - -extension $IzlyQrCodeCopyWith on IzlyQrCode { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfIzlyQrCode.copyWith(...)` or `instanceOfIzlyQrCode.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$IzlyQrCodeCWProxy get copyWith => _$IzlyQrCodeCWProxyImpl(this); -} diff --git a/packages/izlyclient/lib/src/model/generated/izly_qrcode.mapper.dart b/packages/izlyclient/lib/src/model/generated/izly_qrcode.mapper.dart new file mode 100644 index 000000000..a5366589f --- /dev/null +++ b/packages/izlyclient/lib/src/model/generated/izly_qrcode.mapper.dart @@ -0,0 +1,138 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../izly_qrcode.dart'; + +class IzlyQrCodeMapper extends ClassMapperBase { + IzlyQrCodeMapper._(); + + static IzlyQrCodeMapper? _instance; + static IzlyQrCodeMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = IzlyQrCodeMapper._()); + } + return _instance!; + } + + @override + final String id = 'IzlyQrCode'; + + static Uint8List _$qrCode(IzlyQrCode v) => v.qrCode; + static const Field _f$qrCode = Field( + 'qrCode', + _$qrCode, + ); + static DateTime _$expirationDate(IzlyQrCode v) => v.expirationDate; + static const Field _f$expirationDate = Field( + 'expirationDate', + _$expirationDate, + ); + + @override + final MappableFields fields = const { + #qrCode: _f$qrCode, + #expirationDate: _f$expirationDate, + }; + + static IzlyQrCode _instantiate(DecodingData data) { + return IzlyQrCode( + qrCode: data.dec(_f$qrCode), + expirationDate: data.dec(_f$expirationDate), + ); + } + + @override + final Function instantiate = _instantiate; + + static IzlyQrCode fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static IzlyQrCode fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin IzlyQrCodeMappable { + String toJson() { + return IzlyQrCodeMapper.ensureInitialized().encodeJson( + this as IzlyQrCode, + ); + } + + Map toMap() { + return IzlyQrCodeMapper.ensureInitialized().encodeMap( + this as IzlyQrCode, + ); + } + + IzlyQrCodeCopyWith get copyWith => + _IzlyQrCodeCopyWithImpl( + this as IzlyQrCode, + $identity, + $identity, + ); + @override + String toString() { + return IzlyQrCodeMapper.ensureInitialized().stringifyValue( + this as IzlyQrCode, + ); + } + + @override + bool operator ==(Object other) { + return IzlyQrCodeMapper.ensureInitialized().equalsValue( + this as IzlyQrCode, + other, + ); + } + + @override + int get hashCode { + return IzlyQrCodeMapper.ensureInitialized().hashValue(this as IzlyQrCode); + } +} + +extension IzlyQrCodeValueCopy<$R, $Out> + on ObjectCopyWith<$R, IzlyQrCode, $Out> { + IzlyQrCodeCopyWith<$R, IzlyQrCode, $Out> get $asIzlyQrCode => + $base.as((v, t, t2) => _IzlyQrCodeCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class IzlyQrCodeCopyWith<$R, $In extends IzlyQrCode, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({Uint8List? qrCode, DateTime? expirationDate}); + IzlyQrCodeCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _IzlyQrCodeCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, IzlyQrCode, $Out> + implements IzlyQrCodeCopyWith<$R, IzlyQrCode, $Out> { + _IzlyQrCodeCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + IzlyQrCodeMapper.ensureInitialized(); + @override + $R call({Uint8List? qrCode, DateTime? expirationDate}) => $apply( + FieldCopyWithData({ + if (qrCode != null) #qrCode: qrCode, + if (expirationDate != null) #expirationDate: expirationDate, + }), + ); + @override + IzlyQrCode $make(CopyWithData data) => IzlyQrCode( + qrCode: data.get(#qrCode, or: $value.qrCode), + expirationDate: data.get(#expirationDate, or: $value.expirationDate), + ); + + @override + IzlyQrCodeCopyWith<$R2, IzlyQrCode, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _IzlyQrCodeCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/izlyclient/lib/src/model/generated/izly_qrcode_list.g.dart b/packages/izlyclient/lib/src/model/generated/izly_qrcode_list.g.dart deleted file mode 100644 index 900172571..000000000 --- a/packages/izlyclient/lib/src/model/generated/izly_qrcode_list.g.dart +++ /dev/null @@ -1,60 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../izly_qrcode_list.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$IzlyQrCodeListCWProxy { - IzlyQrCodeList qrCodes(List qrCodes); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `IzlyQrCodeList(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// IzlyQrCodeList(...).copyWith(id: 12, name: "My name") - /// ``` - IzlyQrCodeList call({ - List qrCodes, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfIzlyQrCodeList.copyWith(...)` or call `instanceOfIzlyQrCodeList.copyWith.fieldName(value)` for a single field. -class _$IzlyQrCodeListCWProxyImpl implements _$IzlyQrCodeListCWProxy { - const _$IzlyQrCodeListCWProxyImpl(this._value); - - final IzlyQrCodeList _value; - - @override - IzlyQrCodeList qrCodes(List qrCodes) => call(qrCodes: qrCodes); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `IzlyQrCodeList(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// IzlyQrCodeList(...).copyWith(id: 12, name: "My name") - /// ``` - IzlyQrCodeList call({ - Object? qrCodes = const $CopyWithPlaceholder(), - }) { - return IzlyQrCodeList( - qrCodes: qrCodes == const $CopyWithPlaceholder() || qrCodes == null - ? _value.qrCodes - // ignore: cast_nullable_to_non_nullable - : qrCodes as List, - ); - } -} - -extension $IzlyQrCodeListCopyWith on IzlyQrCodeList { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfIzlyQrCodeList.copyWith(...)` or `instanceOfIzlyQrCodeList.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$IzlyQrCodeListCWProxy get copyWith => _$IzlyQrCodeListCWProxyImpl(this); -} diff --git a/packages/izlyclient/lib/src/model/generated/izly_qrcode_list.mapper.dart b/packages/izlyclient/lib/src/model/generated/izly_qrcode_list.mapper.dart new file mode 100644 index 000000000..4086db953 --- /dev/null +++ b/packages/izlyclient/lib/src/model/generated/izly_qrcode_list.mapper.dart @@ -0,0 +1,135 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../izly_qrcode_list.dart'; + +class IzlyQrCodeListMapper extends ClassMapperBase { + IzlyQrCodeListMapper._(); + + static IzlyQrCodeListMapper? _instance; + static IzlyQrCodeListMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = IzlyQrCodeListMapper._()); + IzlyQrCodeMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'IzlyQrCodeList'; + + static List _$qrCodes(IzlyQrCodeList v) => v.qrCodes; + static const Field> _f$qrCodes = Field( + 'qrCodes', + _$qrCodes, + ); + + @override + final MappableFields fields = const {#qrCodes: _f$qrCodes}; + + static IzlyQrCodeList _instantiate(DecodingData data) { + return IzlyQrCodeList(qrCodes: data.dec(_f$qrCodes)); + } + + @override + final Function instantiate = _instantiate; + + static IzlyQrCodeList fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static IzlyQrCodeList fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin IzlyQrCodeListMappable { + String toJson() { + return IzlyQrCodeListMapper.ensureInitialized().encodeJson( + this as IzlyQrCodeList, + ); + } + + Map toMap() { + return IzlyQrCodeListMapper.ensureInitialized().encodeMap( + this as IzlyQrCodeList, + ); + } + + IzlyQrCodeListCopyWith + get copyWith => _IzlyQrCodeListCopyWithImpl( + this as IzlyQrCodeList, + $identity, + $identity, + ); + @override + String toString() { + return IzlyQrCodeListMapper.ensureInitialized().stringifyValue( + this as IzlyQrCodeList, + ); + } + + @override + bool operator ==(Object other) { + return IzlyQrCodeListMapper.ensureInitialized().equalsValue( + this as IzlyQrCodeList, + other, + ); + } + + @override + int get hashCode { + return IzlyQrCodeListMapper.ensureInitialized().hashValue( + this as IzlyQrCodeList, + ); + } +} + +extension IzlyQrCodeListValueCopy<$R, $Out> + on ObjectCopyWith<$R, IzlyQrCodeList, $Out> { + IzlyQrCodeListCopyWith<$R, IzlyQrCodeList, $Out> get $asIzlyQrCodeList => + $base.as((v, t, t2) => _IzlyQrCodeListCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class IzlyQrCodeListCopyWith<$R, $In extends IzlyQrCodeList, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, IzlyQrCode, IzlyQrCodeCopyWith<$R, IzlyQrCode, IzlyQrCode>> + get qrCodes; + $R call({List? qrCodes}); + IzlyQrCodeListCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ); +} + +class _IzlyQrCodeListCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, IzlyQrCodeList, $Out> + implements IzlyQrCodeListCopyWith<$R, IzlyQrCodeList, $Out> { + _IzlyQrCodeListCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + IzlyQrCodeListMapper.ensureInitialized(); + @override + ListCopyWith<$R, IzlyQrCode, IzlyQrCodeCopyWith<$R, IzlyQrCode, IzlyQrCode>> + get qrCodes => ListCopyWith( + $value.qrCodes, + (v, t) => v.copyWith.$chain(t), + (v) => call(qrCodes: v), + ); + @override + $R call({List? qrCodes}) => + $apply(FieldCopyWithData({if (qrCodes != null) #qrCodes: qrCodes})); + @override + IzlyQrCodeList $make(CopyWithData data) => + IzlyQrCodeList(qrCodes: data.get(#qrCodes, or: $value.qrCodes)); + + @override + IzlyQrCodeListCopyWith<$R2, IzlyQrCodeList, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _IzlyQrCodeListCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/izlyclient/lib/src/model/generated/menu_crous.g.dart b/packages/izlyclient/lib/src/model/generated/menu_crous.g.dart deleted file mode 100644 index 808508b46..000000000 --- a/packages/izlyclient/lib/src/model/generated/menu_crous.g.dart +++ /dev/null @@ -1,146 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../menu_crous.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$MenuCrousCWProxy { - MenuCrous date(DateTime date); - - MenuCrous type(MenuType type); - - MenuCrous plats(List plats); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `MenuCrous(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// MenuCrous(...).copyWith(id: 12, name: "My name") - /// ``` - MenuCrous call({ - DateTime date, - MenuType type, - List plats, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfMenuCrous.copyWith(...)` or call `instanceOfMenuCrous.copyWith.fieldName(value)` for a single field. -class _$MenuCrousCWProxyImpl implements _$MenuCrousCWProxy { - const _$MenuCrousCWProxyImpl(this._value); - - final MenuCrous _value; - - @override - MenuCrous date(DateTime date) => call(date: date); - - @override - MenuCrous type(MenuType type) => call(type: type); - - @override - MenuCrous plats(List plats) => call(plats: plats); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `MenuCrous(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// MenuCrous(...).copyWith(id: 12, name: "My name") - /// ``` - MenuCrous call({ - Object? date = const $CopyWithPlaceholder(), - Object? type = const $CopyWithPlaceholder(), - Object? plats = const $CopyWithPlaceholder(), - }) { - return MenuCrous( - date: date == const $CopyWithPlaceholder() || date == null - ? _value.date - // ignore: cast_nullable_to_non_nullable - : date as DateTime, - type: type == const $CopyWithPlaceholder() || type == null - ? _value.type - // ignore: cast_nullable_to_non_nullable - : type as MenuType, - plats: plats == const $CopyWithPlaceholder() || plats == null - ? _value.plats - // ignore: cast_nullable_to_non_nullable - : plats as List, - ); - } -} - -extension $MenuCrousCopyWith on MenuCrous { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfMenuCrous.copyWith(...)` or `instanceOfMenuCrous.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$MenuCrousCWProxy get copyWith => _$MenuCrousCWProxyImpl(this); -} - -abstract class _$PlatCrousCWProxy { - PlatCrous name(String name); - - PlatCrous variants(List variants); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `PlatCrous(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// PlatCrous(...).copyWith(id: 12, name: "My name") - /// ``` - PlatCrous call({ - String name, - List variants, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfPlatCrous.copyWith(...)` or call `instanceOfPlatCrous.copyWith.fieldName(value)` for a single field. -class _$PlatCrousCWProxyImpl implements _$PlatCrousCWProxy { - const _$PlatCrousCWProxyImpl(this._value); - - final PlatCrous _value; - - @override - PlatCrous name(String name) => call(name: name); - - @override - PlatCrous variants(List variants) => call(variants: variants); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `PlatCrous(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// PlatCrous(...).copyWith(id: 12, name: "My name") - /// ``` - PlatCrous call({ - Object? name = const $CopyWithPlaceholder(), - Object? variants = const $CopyWithPlaceholder(), - }) { - return PlatCrous( - name: name == const $CopyWithPlaceholder() || name == null - ? _value.name - // ignore: cast_nullable_to_non_nullable - : name as String, - variants: variants == const $CopyWithPlaceholder() || variants == null - ? _value.variants - // ignore: cast_nullable_to_non_nullable - : variants as List, - ); - } -} - -extension $PlatCrousCopyWith on PlatCrous { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfPlatCrous.copyWith(...)` or `instanceOfPlatCrous.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$PlatCrousCWProxy get copyWith => _$PlatCrousCWProxyImpl(this); -} diff --git a/packages/izlyclient/lib/src/model/generated/menu_crous.mapper.dart b/packages/izlyclient/lib/src/model/generated/menu_crous.mapper.dart new file mode 100644 index 000000000..30b05681f --- /dev/null +++ b/packages/izlyclient/lib/src/model/generated/menu_crous.mapper.dart @@ -0,0 +1,331 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../menu_crous.dart'; + +class MenuTypeMapper extends EnumMapper { + MenuTypeMapper._(); + + static MenuTypeMapper? _instance; + static MenuTypeMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = MenuTypeMapper._()); + } + return _instance!; + } + + static MenuType fromValue(dynamic value) { + ensureInitialized(); + return MapperContainer.globals.fromValue(value); + } + + @override + MenuType decode(dynamic value) { + switch (value) { + case r'matin': + return MenuType.matin; + case r'midi': + return MenuType.midi; + case r'soir': + return MenuType.soir; + default: + throw MapperException.unknownEnumValue(value); + } + } + + @override + dynamic encode(MenuType self) { + switch (self) { + case MenuType.matin: + return r'matin'; + case MenuType.midi: + return r'midi'; + case MenuType.soir: + return r'soir'; + } + } +} + +extension MenuTypeMapperExtension on MenuType { + String toValue() { + MenuTypeMapper.ensureInitialized(); + return MapperContainer.globals.toValue(this) as String; + } +} + +class MenuCrousMapper extends ClassMapperBase { + MenuCrousMapper._(); + + static MenuCrousMapper? _instance; + static MenuCrousMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = MenuCrousMapper._()); + MenuTypeMapper.ensureInitialized(); + PlatCrousMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'MenuCrous'; + + static DateTime _$date(MenuCrous v) => v.date; + static const Field _f$date = Field('date', _$date); + static MenuType _$type(MenuCrous v) => v.type; + static const Field _f$type = Field('type', _$type); + static List _$plats(MenuCrous v) => v.plats; + static const Field> _f$plats = Field( + 'plats', + _$plats, + ); + + @override + final MappableFields fields = const { + #date: _f$date, + #type: _f$type, + #plats: _f$plats, + }; + + static MenuCrous _instantiate(DecodingData data) { + return MenuCrous( + date: data.dec(_f$date), + type: data.dec(_f$type), + plats: data.dec(_f$plats), + ); + } + + @override + final Function instantiate = _instantiate; + + static MenuCrous fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static MenuCrous fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin MenuCrousMappable { + String toJson() { + return MenuCrousMapper.ensureInitialized().encodeJson( + this as MenuCrous, + ); + } + + Map toMap() { + return MenuCrousMapper.ensureInitialized().encodeMap( + this as MenuCrous, + ); + } + + MenuCrousCopyWith get copyWith => + _MenuCrousCopyWithImpl( + this as MenuCrous, + $identity, + $identity, + ); + @override + String toString() { + return MenuCrousMapper.ensureInitialized().stringifyValue( + this as MenuCrous, + ); + } + + @override + bool operator ==(Object other) { + return MenuCrousMapper.ensureInitialized().equalsValue( + this as MenuCrous, + other, + ); + } + + @override + int get hashCode { + return MenuCrousMapper.ensureInitialized().hashValue(this as MenuCrous); + } +} + +extension MenuCrousValueCopy<$R, $Out> on ObjectCopyWith<$R, MenuCrous, $Out> { + MenuCrousCopyWith<$R, MenuCrous, $Out> get $asMenuCrous => + $base.as((v, t, t2) => _MenuCrousCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class MenuCrousCopyWith<$R, $In extends MenuCrous, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, PlatCrous, PlatCrousCopyWith<$R, PlatCrous, PlatCrous>> + get plats; + $R call({DateTime? date, MenuType? type, List? plats}); + MenuCrousCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _MenuCrousCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, MenuCrous, $Out> + implements MenuCrousCopyWith<$R, MenuCrous, $Out> { + _MenuCrousCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + MenuCrousMapper.ensureInitialized(); + @override + ListCopyWith<$R, PlatCrous, PlatCrousCopyWith<$R, PlatCrous, PlatCrous>> + get plats => ListCopyWith( + $value.plats, + (v, t) => v.copyWith.$chain(t), + (v) => call(plats: v), + ); + @override + $R call({DateTime? date, MenuType? type, List? plats}) => $apply( + FieldCopyWithData({ + if (date != null) #date: date, + if (type != null) #type: type, + if (plats != null) #plats: plats, + }), + ); + @override + MenuCrous $make(CopyWithData data) => MenuCrous( + date: data.get(#date, or: $value.date), + type: data.get(#type, or: $value.type), + plats: data.get(#plats, or: $value.plats), + ); + + @override + MenuCrousCopyWith<$R2, MenuCrous, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _MenuCrousCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + +class PlatCrousMapper extends ClassMapperBase { + PlatCrousMapper._(); + + static PlatCrousMapper? _instance; + static PlatCrousMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = PlatCrousMapper._()); + } + return _instance!; + } + + @override + final String id = 'PlatCrous'; + + static String _$name(PlatCrous v) => v.name; + static const Field _f$name = Field('name', _$name); + static List _$variants(PlatCrous v) => v.variants; + static const Field> _f$variants = Field( + 'variants', + _$variants, + ); + + @override + final MappableFields fields = const { + #name: _f$name, + #variants: _f$variants, + }; + + static PlatCrous _instantiate(DecodingData data) { + return PlatCrous(name: data.dec(_f$name), variants: data.dec(_f$variants)); + } + + @override + final Function instantiate = _instantiate; + + static PlatCrous fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static PlatCrous fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin PlatCrousMappable { + String toJson() { + return PlatCrousMapper.ensureInitialized().encodeJson( + this as PlatCrous, + ); + } + + Map toMap() { + return PlatCrousMapper.ensureInitialized().encodeMap( + this as PlatCrous, + ); + } + + PlatCrousCopyWith get copyWith => + _PlatCrousCopyWithImpl( + this as PlatCrous, + $identity, + $identity, + ); + @override + String toString() { + return PlatCrousMapper.ensureInitialized().stringifyValue( + this as PlatCrous, + ); + } + + @override + bool operator ==(Object other) { + return PlatCrousMapper.ensureInitialized().equalsValue( + this as PlatCrous, + other, + ); + } + + @override + int get hashCode { + return PlatCrousMapper.ensureInitialized().hashValue(this as PlatCrous); + } +} + +extension PlatCrousValueCopy<$R, $Out> on ObjectCopyWith<$R, PlatCrous, $Out> { + PlatCrousCopyWith<$R, PlatCrous, $Out> get $asPlatCrous => + $base.as((v, t, t2) => _PlatCrousCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class PlatCrousCopyWith<$R, $In extends PlatCrous, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> get variants; + $R call({String? name, List? variants}); + PlatCrousCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _PlatCrousCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, PlatCrous, $Out> + implements PlatCrousCopyWith<$R, PlatCrous, $Out> { + _PlatCrousCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + PlatCrousMapper.ensureInitialized(); + @override + ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> get variants => + ListCopyWith( + $value.variants, + (v, t) => ObjectCopyWith(v, $identity, t), + (v) => call(variants: v), + ); + @override + $R call({String? name, List? variants}) => $apply( + FieldCopyWithData({ + if (name != null) #name: name, + if (variants != null) #variants: variants, + }), + ); + @override + PlatCrous $make(CopyWithData data) => PlatCrous( + name: data.get(#name, or: $value.name), + variants: data.get(#variants, or: $value.variants), + ); + + @override + PlatCrousCopyWith<$R2, PlatCrous, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _PlatCrousCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/izlyclient/lib/src/model/generated/restaurant.g.dart b/packages/izlyclient/lib/src/model/generated/restaurant.g.dart deleted file mode 100644 index e4d5f61d5..000000000 --- a/packages/izlyclient/lib/src/model/generated/restaurant.g.dart +++ /dev/null @@ -1,163 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../restaurant.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$RestaurantModelCWProxy { - RestaurantModel id(int id); - - RestaurantModel name(String name); - - RestaurantModel description(String description); - - RestaurantModel shortDescription(String shortDescription); - - RestaurantModel type(CrousType type); - - RestaurantModel lat(double lat); - - RestaurantModel lon(double lon); - - RestaurantModel opening(String opening); - - RestaurantModel menus(List menus); - - RestaurantModel imageUrl(String imageUrl); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `RestaurantModel(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// RestaurantModel(...).copyWith(id: 12, name: "My name") - /// ``` - RestaurantModel call({ - int id, - String name, - String description, - String shortDescription, - CrousType type, - double lat, - double lon, - String opening, - List menus, - String imageUrl, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfRestaurantModel.copyWith(...)` or call `instanceOfRestaurantModel.copyWith.fieldName(value)` for a single field. -class _$RestaurantModelCWProxyImpl implements _$RestaurantModelCWProxy { - const _$RestaurantModelCWProxyImpl(this._value); - - final RestaurantModel _value; - - @override - RestaurantModel id(int id) => call(id: id); - - @override - RestaurantModel name(String name) => call(name: name); - - @override - RestaurantModel description(String description) => - call(description: description); - - @override - RestaurantModel shortDescription(String shortDescription) => - call(shortDescription: shortDescription); - - @override - RestaurantModel type(CrousType type) => call(type: type); - - @override - RestaurantModel lat(double lat) => call(lat: lat); - - @override - RestaurantModel lon(double lon) => call(lon: lon); - - @override - RestaurantModel opening(String opening) => call(opening: opening); - - @override - RestaurantModel menus(List menus) => call(menus: menus); - - @override - RestaurantModel imageUrl(String imageUrl) => call(imageUrl: imageUrl); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `RestaurantModel(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// RestaurantModel(...).copyWith(id: 12, name: "My name") - /// ``` - RestaurantModel call({ - Object? id = const $CopyWithPlaceholder(), - Object? name = const $CopyWithPlaceholder(), - Object? description = const $CopyWithPlaceholder(), - Object? shortDescription = const $CopyWithPlaceholder(), - Object? type = const $CopyWithPlaceholder(), - Object? lat = const $CopyWithPlaceholder(), - Object? lon = const $CopyWithPlaceholder(), - Object? opening = const $CopyWithPlaceholder(), - Object? menus = const $CopyWithPlaceholder(), - Object? imageUrl = const $CopyWithPlaceholder(), - }) { - return RestaurantModel( - id: id == const $CopyWithPlaceholder() || id == null - ? _value.id - // ignore: cast_nullable_to_non_nullable - : id as int, - name: name == const $CopyWithPlaceholder() || name == null - ? _value.name - // ignore: cast_nullable_to_non_nullable - : name as String, - description: - description == const $CopyWithPlaceholder() || description == null - ? _value.description - // ignore: cast_nullable_to_non_nullable - : description as String, - shortDescription: shortDescription == const $CopyWithPlaceholder() || - shortDescription == null - ? _value.shortDescription - // ignore: cast_nullable_to_non_nullable - : shortDescription as String, - type: type == const $CopyWithPlaceholder() || type == null - ? _value.type - // ignore: cast_nullable_to_non_nullable - : type as CrousType, - lat: lat == const $CopyWithPlaceholder() || lat == null - ? _value.lat - // ignore: cast_nullable_to_non_nullable - : lat as double, - lon: lon == const $CopyWithPlaceholder() || lon == null - ? _value.lon - // ignore: cast_nullable_to_non_nullable - : lon as double, - opening: opening == const $CopyWithPlaceholder() || opening == null - ? _value.opening - // ignore: cast_nullable_to_non_nullable - : opening as String, - menus: menus == const $CopyWithPlaceholder() || menus == null - ? _value.menus - // ignore: cast_nullable_to_non_nullable - : menus as List, - imageUrl: imageUrl == const $CopyWithPlaceholder() || imageUrl == null - ? _value.imageUrl - // ignore: cast_nullable_to_non_nullable - : imageUrl as String, - ); - } -} - -extension $RestaurantModelCopyWith on RestaurantModel { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfRestaurantModel.copyWith(...)` or `instanceOfRestaurantModel.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$RestaurantModelCWProxy get copyWith => _$RestaurantModelCWProxyImpl(this); -} diff --git a/packages/izlyclient/lib/src/model/generated/restaurant.mapper.dart b/packages/izlyclient/lib/src/model/generated/restaurant.mapper.dart new file mode 100644 index 000000000..657dbfe83 --- /dev/null +++ b/packages/izlyclient/lib/src/model/generated/restaurant.mapper.dart @@ -0,0 +1,281 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../restaurant.dart'; + +class CrousTypeMapper extends EnumMapper { + CrousTypeMapper._(); + + static CrousTypeMapper? _instance; + static CrousTypeMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = CrousTypeMapper._()); + } + return _instance!; + } + + static CrousType fromValue(dynamic value) { + ensureInitialized(); + return MapperContainer.globals.fromValue(value); + } + + @override + CrousType decode(dynamic value) { + switch (value) { + case r'restaurant': + return CrousType.restaurant; + case r'cafet': + return CrousType.cafet; + default: + throw MapperException.unknownEnumValue(value); + } + } + + @override + dynamic encode(CrousType self) { + switch (self) { + case CrousType.restaurant: + return r'restaurant'; + case CrousType.cafet: + return r'cafet'; + } + } +} + +extension CrousTypeMapperExtension on CrousType { + String toValue() { + CrousTypeMapper.ensureInitialized(); + return MapperContainer.globals.toValue(this) as String; + } +} + +class RestaurantModelMapper extends ClassMapperBase { + RestaurantModelMapper._(); + + static RestaurantModelMapper? _instance; + static RestaurantModelMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = RestaurantModelMapper._()); + CrousTypeMapper.ensureInitialized(); + MenuCrousMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'RestaurantModel'; + + static int _$id(RestaurantModel v) => v.id; + static const Field _f$id = Field('id', _$id); + static String _$name(RestaurantModel v) => v.name; + static const Field _f$name = Field('name', _$name); + static String _$description(RestaurantModel v) => v.description; + static const Field _f$description = Field( + 'description', + _$description, + ); + static String _$shortDescription(RestaurantModel v) => v.shortDescription; + static const Field _f$shortDescription = Field( + 'shortDescription', + _$shortDescription, + ); + static CrousType _$type(RestaurantModel v) => v.type; + static const Field _f$type = Field( + 'type', + _$type, + ); + static double _$lat(RestaurantModel v) => v.lat; + static const Field _f$lat = Field('lat', _$lat); + static double _$lon(RestaurantModel v) => v.lon; + static const Field _f$lon = Field('lon', _$lon); + static String _$opening(RestaurantModel v) => v.opening; + static const Field _f$opening = Field( + 'opening', + _$opening, + ); + static List _$menus(RestaurantModel v) => v.menus; + static const Field> _f$menus = Field( + 'menus', + _$menus, + ); + static String _$imageUrl(RestaurantModel v) => v.imageUrl; + static const Field _f$imageUrl = Field( + 'imageUrl', + _$imageUrl, + ); + + @override + final MappableFields fields = const { + #id: _f$id, + #name: _f$name, + #description: _f$description, + #shortDescription: _f$shortDescription, + #type: _f$type, + #lat: _f$lat, + #lon: _f$lon, + #opening: _f$opening, + #menus: _f$menus, + #imageUrl: _f$imageUrl, + }; + + static RestaurantModel _instantiate(DecodingData data) { + return RestaurantModel( + id: data.dec(_f$id), + name: data.dec(_f$name), + description: data.dec(_f$description), + shortDescription: data.dec(_f$shortDescription), + type: data.dec(_f$type), + lat: data.dec(_f$lat), + lon: data.dec(_f$lon), + opening: data.dec(_f$opening), + menus: data.dec(_f$menus), + imageUrl: data.dec(_f$imageUrl), + ); + } + + @override + final Function instantiate = _instantiate; + + static RestaurantModel fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static RestaurantModel fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin RestaurantModelMappable { + String toJson() { + return RestaurantModelMapper.ensureInitialized() + .encodeJson(this as RestaurantModel); + } + + Map toMap() { + return RestaurantModelMapper.ensureInitialized().encodeMap( + this as RestaurantModel, + ); + } + + RestaurantModelCopyWith + get copyWith => + _RestaurantModelCopyWithImpl( + this as RestaurantModel, + $identity, + $identity, + ); + @override + String toString() { + return RestaurantModelMapper.ensureInitialized().stringifyValue( + this as RestaurantModel, + ); + } + + @override + bool operator ==(Object other) { + return RestaurantModelMapper.ensureInitialized().equalsValue( + this as RestaurantModel, + other, + ); + } + + @override + int get hashCode { + return RestaurantModelMapper.ensureInitialized().hashValue( + this as RestaurantModel, + ); + } +} + +extension RestaurantModelValueCopy<$R, $Out> + on ObjectCopyWith<$R, RestaurantModel, $Out> { + RestaurantModelCopyWith<$R, RestaurantModel, $Out> get $asRestaurantModel => + $base.as((v, t, t2) => _RestaurantModelCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class RestaurantModelCopyWith<$R, $In extends RestaurantModel, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, MenuCrous, MenuCrousCopyWith<$R, MenuCrous, MenuCrous>> + get menus; + $R call({ + int? id, + String? name, + String? description, + String? shortDescription, + CrousType? type, + double? lat, + double? lon, + String? opening, + List? menus, + String? imageUrl, + }); + RestaurantModelCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ); +} + +class _RestaurantModelCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, RestaurantModel, $Out> + implements RestaurantModelCopyWith<$R, RestaurantModel, $Out> { + _RestaurantModelCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + RestaurantModelMapper.ensureInitialized(); + @override + ListCopyWith<$R, MenuCrous, MenuCrousCopyWith<$R, MenuCrous, MenuCrous>> + get menus => ListCopyWith( + $value.menus, + (v, t) => v.copyWith.$chain(t), + (v) => call(menus: v), + ); + @override + $R call({ + int? id, + String? name, + String? description, + String? shortDescription, + CrousType? type, + double? lat, + double? lon, + String? opening, + List? menus, + String? imageUrl, + }) => $apply( + FieldCopyWithData({ + if (id != null) #id: id, + if (name != null) #name: name, + if (description != null) #description: description, + if (shortDescription != null) #shortDescription: shortDescription, + if (type != null) #type: type, + if (lat != null) #lat: lat, + if (lon != null) #lon: lon, + if (opening != null) #opening: opening, + if (menus != null) #menus: menus, + if (imageUrl != null) #imageUrl: imageUrl, + }), + ); + @override + RestaurantModel $make(CopyWithData data) => RestaurantModel( + id: data.get(#id, or: $value.id), + name: data.get(#name, or: $value.name), + description: data.get(#description, or: $value.description), + shortDescription: data.get(#shortDescription, or: $value.shortDescription), + type: data.get(#type, or: $value.type), + lat: data.get(#lat, or: $value.lat), + lon: data.get(#lon, or: $value.lon), + opening: data.get(#opening, or: $value.opening), + menus: data.get(#menus, or: $value.menus), + imageUrl: data.get(#imageUrl, or: $value.imageUrl), + ); + + @override + RestaurantModelCopyWith<$R2, RestaurantModel, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _RestaurantModelCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/izlyclient/lib/src/model/generated/restaurant_list_model.mapper.dart b/packages/izlyclient/lib/src/model/generated/restaurant_list_model.mapper.dart new file mode 100644 index 000000000..82206b4d0 --- /dev/null +++ b/packages/izlyclient/lib/src/model/generated/restaurant_list_model.mapper.dart @@ -0,0 +1,156 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../restaurant_list_model.dart'; + +class RestaurantListModelMapper extends ClassMapperBase { + RestaurantListModelMapper._(); + + static RestaurantListModelMapper? _instance; + static RestaurantListModelMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = RestaurantListModelMapper._()); + RestaurantModelMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'RestaurantListModel'; + + static List _$restaurantList(RestaurantListModel v) => + v.restaurantList; + static const Field> + _f$restaurantList = Field('restaurantList', _$restaurantList); + + @override + final MappableFields fields = const { + #restaurantList: _f$restaurantList, + }; + + static RestaurantListModel _instantiate(DecodingData data) { + return RestaurantListModel(restaurantList: data.dec(_f$restaurantList)); + } + + @override + final Function instantiate = _instantiate; + + static RestaurantListModel fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static RestaurantListModel fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin RestaurantListModelMappable { + String toJson() { + return RestaurantListModelMapper.ensureInitialized() + .encodeJson(this as RestaurantListModel); + } + + Map toMap() { + return RestaurantListModelMapper.ensureInitialized() + .encodeMap(this as RestaurantListModel); + } + + RestaurantListModelCopyWith< + RestaurantListModel, + RestaurantListModel, + RestaurantListModel + > + get copyWith => + _RestaurantListModelCopyWithImpl< + RestaurantListModel, + RestaurantListModel + >(this as RestaurantListModel, $identity, $identity); + @override + String toString() { + return RestaurantListModelMapper.ensureInitialized().stringifyValue( + this as RestaurantListModel, + ); + } + + @override + bool operator ==(Object other) { + return RestaurantListModelMapper.ensureInitialized().equalsValue( + this as RestaurantListModel, + other, + ); + } + + @override + int get hashCode { + return RestaurantListModelMapper.ensureInitialized().hashValue( + this as RestaurantListModel, + ); + } +} + +extension RestaurantListModelValueCopy<$R, $Out> + on ObjectCopyWith<$R, RestaurantListModel, $Out> { + RestaurantListModelCopyWith<$R, RestaurantListModel, $Out> + get $asRestaurantListModel => $base.as( + (v, t, t2) => _RestaurantListModelCopyWithImpl<$R, $Out>(v, t, t2), + ); +} + +abstract class RestaurantListModelCopyWith< + $R, + $In extends RestaurantListModel, + $Out +> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith< + $R, + RestaurantModel, + RestaurantModelCopyWith<$R, RestaurantModel, RestaurantModel> + > + get restaurantList; + $R call({List? restaurantList}); + RestaurantListModelCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ); +} + +class _RestaurantListModelCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, RestaurantListModel, $Out> + implements RestaurantListModelCopyWith<$R, RestaurantListModel, $Out> { + _RestaurantListModelCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + RestaurantListModelMapper.ensureInitialized(); + @override + ListCopyWith< + $R, + RestaurantModel, + RestaurantModelCopyWith<$R, RestaurantModel, RestaurantModel> + > + get restaurantList => ListCopyWith( + $value.restaurantList, + (v, t) => v.copyWith.$chain(t), + (v) => call(restaurantList: v), + ); + @override + $R call({List? restaurantList}) => $apply( + FieldCopyWithData({ + if (restaurantList != null) #restaurantList: restaurantList, + }), + ); + @override + RestaurantListModel $make(CopyWithData data) => RestaurantListModel( + restaurantList: data.get(#restaurantList, or: $value.restaurantList), + ); + + @override + RestaurantListModelCopyWith<$R2, RestaurantListModel, $Out2> + $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _RestaurantListModelCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/izlyclient/lib/src/model/izly_credential.dart b/packages/izlyclient/lib/src/model/izly_credential.dart index cb80a10b9..9bed5e3da 100644 --- a/packages/izlyclient/lib/src/model/izly_credential.dart +++ b/packages/izlyclient/lib/src/model/izly_credential.dart @@ -1,20 +1,11 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; -part 'generated/izly_credential.g.dart'; +part 'generated/izly_credential.mapper.dart'; -@CopyWith() -class IzlyCredential extends Equatable { +@MappableClass() +class IzlyCredential with IzlyCredentialMappable { final String username; final String password; - IzlyCredential({ - required this.username, - required this.password, - }); - - @override - List get props => [username, password]; - @override - bool get stringify => true; + IzlyCredential({required this.username, required this.password}); } diff --git a/packages/izlyclient/lib/src/model/izly_payment_model.dart b/packages/izlyclient/lib/src/model/izly_payment_model.dart index bd34322da..0bc9c0f53 100644 --- a/packages/izlyclient/lib/src/model/izly_payment_model.dart +++ b/packages/izlyclient/lib/src/model/izly_payment_model.dart @@ -1,6 +1,9 @@ -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; -class IzlyPaymentModel extends Equatable { +part 'generated/izly_payment_model.mapper.dart'; + +@MappableClass() +class IzlyPaymentModel with IzlyPaymentModelMappable { final DateTime paymentTime; final double amountSpent; final bool isSucess; @@ -10,10 +13,4 @@ class IzlyPaymentModel extends Equatable { required this.amountSpent, required this.isSucess, }); - - @override - List get props => [paymentTime, amountSpent, isSucess]; - - @override - bool get stringify => true; } diff --git a/packages/izlyclient/lib/src/model/izly_payment_model_list.dart b/packages/izlyclient/lib/src/model/izly_payment_model_list.dart index 5c5620177..d693d1732 100644 --- a/packages/izlyclient/lib/src/model/izly_payment_model_list.dart +++ b/packages/izlyclient/lib/src/model/izly_payment_model_list.dart @@ -1,26 +1,11 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:izlyclient/izlyclient.dart'; -part 'generated/izly_payment_model_list.g.dart'; +part 'generated/izly_payment_model_list.mapper.dart'; -@CopyWith() -class IzlyPaymentModelList extends Equatable { +@MappableClass() +class IzlyPaymentModelList with IzlyPaymentModelListMappable { final List payments; IzlyPaymentModelList({required this.payments}); - - IzlyPaymentModelList copyWith({ - List? payments, - }) { - return IzlyPaymentModelList( - payments: payments ?? this.payments, - ); - } - - @override - List get props => [payments]; - - @override - bool get stringify => true; } diff --git a/packages/izlyclient/lib/src/model/izly_qrcode.dart b/packages/izlyclient/lib/src/model/izly_qrcode.dart index 585707622..bb6f0ef53 100644 --- a/packages/izlyclient/lib/src/model/izly_qrcode.dart +++ b/packages/izlyclient/lib/src/model/izly_qrcode.dart @@ -1,19 +1,13 @@ import 'dart:typed_data'; -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; -part 'generated/izly_qrcode.g.dart'; +part 'generated/izly_qrcode.mapper.dart'; -@CopyWith() -class IzlyQrCode extends Equatable { +@MappableClass() +class IzlyQrCode with IzlyQrCodeMappable { final Uint8List qrCode; final DateTime expirationDate; IzlyQrCode({required this.qrCode, required this.expirationDate}); - - @override - List get props => [qrCode, expirationDate]; - @override - bool get stringify => true; } diff --git a/packages/izlyclient/lib/src/model/izly_qrcode_list.dart b/packages/izlyclient/lib/src/model/izly_qrcode_list.dart index 66f3bde71..3fcc0e784 100644 --- a/packages/izlyclient/lib/src/model/izly_qrcode_list.dart +++ b/packages/izlyclient/lib/src/model/izly_qrcode_list.dart @@ -1,25 +1,11 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:izlyclient/izlyclient.dart'; -part 'generated/izly_qrcode_list.g.dart'; +part 'generated/izly_qrcode_list.mapper.dart'; -@CopyWith() -class IzlyQrCodeList extends Equatable { +@MappableClass() +class IzlyQrCodeList with IzlyQrCodeListMappable { final List qrCodes; IzlyQrCodeList({required this.qrCodes}); - - IzlyQrCodeList copyWith({ - List? qrCodes, - }) { - return IzlyQrCodeList( - qrCodes: qrCodes ?? this.qrCodes, - ); - } - - @override - List get props => [qrCodes]; - @override - bool get stringify => true; } diff --git a/packages/izlyclient/lib/src/model/menu_crous.dart b/packages/izlyclient/lib/src/model/menu_crous.dart index 6bc754f19..eca3f8c5b 100644 --- a/packages/izlyclient/lib/src/model/menu_crous.dart +++ b/packages/izlyclient/lib/src/model/menu_crous.dart @@ -1,12 +1,8 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; -part 'generated/menu_crous.g.dart'; - -// extension ToString on MenuType { -// String toString() {} -// } +part 'generated/menu_crous.mapper.dart'; +@MappableEnum() enum MenuType { matin, midi, @@ -16,64 +12,43 @@ enum MenuType { String toString() => name; } -@CopyWith() -class MenuCrous extends Equatable { +@MappableClass() +class MenuCrous with MenuCrousMappable { final DateTime date; final MenuType type; final List plats; - MenuCrous({ - required this.date, - required this.type, - required this.plats, - }); + MenuCrous({required this.date, required this.type, required this.plats}); static MenuCrous fromJson(Map json, String date) { return MenuCrous( - date: DateTime.parse(date), - type: json["name"] == "matin" - ? MenuType.matin - : json["name"] == "midi" - ? MenuType.midi - : MenuType.soir, - plats: (json["foodcategory"] as List) - .map((e) => PlatCrous.fromJson(e)) - .toList() - // plats: (json["foodcategory"][0]["dishes"] as List) - // .map((e) => PlatCrous.fromJson(e)) - // .toList(), - ); + date: DateTime.parse(date), + type: json["name"] == "matin" + ? MenuType.matin + : json["name"] == "midi" + ? MenuType.midi + : MenuType.soir, + plats: (json["foodcategory"] as List) + .map((e) => PlatCrous.fromJson(e)) + .toList(), + ); } - - @override - List get props => [date, type, plats]; - - @override - bool get stringify => true; } -@CopyWith() -class PlatCrous extends Equatable { +@MappableClass() +class PlatCrous with PlatCrousMappable { final String name; final List variants; - PlatCrous({ - required this.name, - required this.variants, - }); + PlatCrous({required this.name, required this.variants}); static PlatCrous fromJson(Map json) { return PlatCrous( //apply type name: json["name"], - variants: - (json["dishes"] as List).map((e) => e["name"] as String).toList(), + variants: (json["dishes"] as List) + .map((e) => e["name"] as String) + .toList(), ); } - - @override - List get props => [name, variants]; - - @override - bool get stringify => true; } diff --git a/packages/izlyclient/lib/src/model/restaurant.dart b/packages/izlyclient/lib/src/model/restaurant.dart index 334183197..b41906375 100644 --- a/packages/izlyclient/lib/src/model/restaurant.dart +++ b/packages/izlyclient/lib/src/model/restaurant.dart @@ -1,17 +1,13 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; - +import 'package:dart_mappable/dart_mappable.dart'; import 'package:izlyclient/izlyclient.dart'; -part 'generated/restaurant.g.dart'; +part 'generated/restaurant.mapper.dart'; -enum CrousType { - restaurant, - cafet, -} +@MappableEnum() +enum CrousType { restaurant, cafet } -@CopyWith() -class RestaurantModel extends Equatable { +@MappableClass() +class RestaurantModel with RestaurantModelMappable { final int id; final String name; final String description; @@ -42,34 +38,18 @@ class RestaurantModel extends Equatable { name: json["title"], description: json["description"], shortDescription: json["shortdesc"], - type: - json["type"] == "Restaurant" ? CrousType.restaurant : CrousType.cafet, + type: json["type"] == "Restaurant" + ? CrousType.restaurant + : CrousType.cafet, lat: json["lat"], lon: json["lon"], opening: json["opening"], menus: [ for (var e in json["menus"]) for (var meal in e["meal"]) - MenuCrous.fromJson(meal, e["date"] as String) + MenuCrous.fromJson(meal, e["date"] as String), ], imageUrl: json["photo"]["src"], ); } - - @override - List get props => [ - id, - name, - description, - shortDescription, - type, - lat, - lon, - opening, - menus, - imageUrl - ]; - - @override - bool get stringify => true; } diff --git a/packages/izlyclient/lib/src/model/restaurant_list_model.dart b/packages/izlyclient/lib/src/model/restaurant_list_model.dart index 67444b5b4..601283f6b 100644 --- a/packages/izlyclient/lib/src/model/restaurant_list_model.dart +++ b/packages/izlyclient/lib/src/model/restaurant_list_model.dart @@ -1,6 +1,10 @@ +import 'package:dart_mappable/dart_mappable.dart'; import 'package:izlyclient/izlyclient.dart'; -class RestaurantListModel { +part 'generated/restaurant_list_model.mapper.dart'; + +@MappableClass() +class RestaurantListModel with RestaurantListModelMappable { List restaurantList; RestaurantListModel({required this.restaurantList}); diff --git a/packages/izlyclient/pubspec.yaml b/packages/izlyclient/pubspec.yaml index ac25c723a..a3c1f0e0d 100755 --- a/packages/izlyclient/pubspec.yaml +++ b/packages/izlyclient/pubspec.yaml @@ -4,7 +4,7 @@ version: 1.0.10 repository: https://github.com/onyx-lyon1/onyx/tree/main/packages/izlyclient environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.8.0 <4.0.0" # dependencies: # path: ^1.8.0 @@ -14,14 +14,11 @@ dev_dependencies: test: ^1.16.0 dotenv: ^4.0.1 build_runner: ^2.4.6 - hive_ce_generator: ^1.9.2 - copy_with_extension_gen: ^9.1.0 + dart_mappable_builder: ^4.6.0 dependencies: requests_plus: ^4.8.3 html: ^0.15.4 - hive_ce: ^2.2.3 - equatable: ^2.0.5 - copy_with_extension: ^9.1.0 beautiful_soup_dart: ^0.3.0 intl: ^0.20.2 + dart_mappable: ^4.6.0 diff --git a/packages/lyon1agendaclient/build.yaml b/packages/lyon1agendaclient/build.yaml index d6160f7dc..3ff8f90ad 100644 --- a/packages/lyon1agendaclient/build.yaml +++ b/packages/lyon1agendaclient/build.yaml @@ -1,9 +1,11 @@ targets: $default: builders: - source_gen|combining_builder: - generate_for: - - lib/**.dart + # only to resolve build_runner conflicts + dart_mappable_builder: options: build_extensions: - 'lib/{{path}}/{{file}}.dart': 'lib/{{path}}/generated/{{file}}.g.dart' \ No newline at end of file + 'lib/{{path}}/{{file}}.dart': + - 'lib/{{path}}/generated/{{file}}.mapper.dart' + - 'lib/{{path}}/generated/{{file}}.init.dart' + diff --git a/packages/lyon1agendaclient/lib/hive/generated/hive_adapters.g.dart b/packages/lyon1agendaclient/lib/hive/generated/hive_adapters.g.dart deleted file mode 100644 index b2f0164f9..000000000 --- a/packages/lyon1agendaclient/lib/hive/generated/hive_adapters.g.dart +++ /dev/null @@ -1,130 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../hive_adapters.dart'; - -// ************************************************************************** -// AdaptersGenerator -// ************************************************************************** - -class DayAdapter extends TypeAdapter { - @override - final typeId = 1; - - @override - Day read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return Day( - fields[1] as DateTime, - (fields[0] as List).cast(), - ); - } - - @override - void write(BinaryWriter writer, Day obj) { - writer - ..writeByte(2) - ..writeByte(0) - ..write(obj.events) - ..writeByte(1) - ..write(obj.date); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is DayAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class AgendaAdapter extends TypeAdapter { - @override - final typeId = 2; - - @override - Agenda read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return Agenda( - (fields[0] as List).cast(), - ); - } - - @override - void write(BinaryWriter writer, Agenda obj) { - writer - ..writeByte(1) - ..writeByte(0) - ..write(obj.days); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is AgendaAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class EventAdapter extends TypeAdapter { - @override - final typeId = 3; - - @override - Event read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return Event( - location: fields[0] as String, - description: fields[1] as String, - teacher: fields[2] as String, - name: fields[3] as String, - start: fields[4] as DateTime, - end: fields[5] as DateTime, - menuCrous: fields[6] as dynamic, - ); - } - - @override - void write(BinaryWriter writer, Event obj) { - writer - ..writeByte(7) - ..writeByte(0) - ..write(obj.location) - ..writeByte(1) - ..write(obj.description) - ..writeByte(2) - ..write(obj.teacher) - ..writeByte(3) - ..write(obj.name) - ..writeByte(4) - ..write(obj.start) - ..writeByte(5) - ..write(obj.end) - ..writeByte(6) - ..write(obj.menuCrous); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is EventAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} diff --git a/packages/lyon1agendaclient/lib/hive/hive_adapters.dart b/packages/lyon1agendaclient/lib/hive/hive_adapters.dart deleted file mode 100644 index 23772e0f9..000000000 --- a/packages/lyon1agendaclient/lib/hive/hive_adapters.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'package:hive_ce/hive.dart'; -import 'package:lyon1agendaclient/src/model/agenda.dart'; -import 'package:lyon1agendaclient/src/model/day.dart'; -import 'package:lyon1agendaclient/src/model/event.dart'; - -@GenerateAdapters([ - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), -]) -part 'generated/hive_adapters.g.dart'; diff --git a/packages/lyon1agendaclient/lib/hive/hive_adapters.g.yaml b/packages/lyon1agendaclient/lib/hive/hive_adapters.g.yaml deleted file mode 100644 index fee08864c..000000000 --- a/packages/lyon1agendaclient/lib/hive/hive_adapters.g.yaml +++ /dev/null @@ -1,37 +0,0 @@ -# Generated by Hive CE -# Manual modifications may be necessary for certain migrations -# Check in to version control -nextTypeId: 4 -types: - Day: - typeId: 1 - nextIndex: 2 - fields: - events: - index: 0 - date: - index: 1 - Agenda: - typeId: 2 - nextIndex: 1 - fields: - days: - index: 0 - Event: - typeId: 3 - nextIndex: 7 - fields: - location: - index: 0 - description: - index: 1 - teacher: - index: 2 - name: - index: 3 - start: - index: 4 - end: - index: 5 - menuCrous: - index: 6 diff --git a/packages/lyon1agendaclient/lib/hive/hive_registrar.g.dart b/packages/lyon1agendaclient/lib/hive/hive_registrar.g.dart deleted file mode 100644 index 36caffe39..000000000 --- a/packages/lyon1agendaclient/lib/hive/hive_registrar.g.dart +++ /dev/null @@ -1,22 +0,0 @@ -// Generated by Hive CE -// Do not modify -// Check in to version control - -import 'package:hive_ce/hive.dart'; -import 'package:lyon1agendaclient/hive/hive_adapters.dart'; - -extension HiveRegistrar on HiveInterface { - void registerAdapters() { - registerAdapter(AgendaAdapter()); - registerAdapter(DayAdapter()); - registerAdapter(EventAdapter()); - } -} - -extension IsolatedHiveRegistrar on IsolatedHiveInterface { - void registerAdapters() { - registerAdapter(AgendaAdapter()); - registerAdapter(DayAdapter()); - registerAdapter(EventAdapter()); - } -} diff --git a/packages/lyon1agendaclient/lib/lyon1agendaclient.dart b/packages/lyon1agendaclient/lib/lyon1agendaclient.dart index 423c71cd7..66331c9d0 100755 --- a/packages/lyon1agendaclient/lib/lyon1agendaclient.dart +++ b/packages/lyon1agendaclient/lib/lyon1agendaclient.dart @@ -1,7 +1,7 @@ library; export 'src/lyon1agendaclient.dart' show Lyon1AgendaClient; -export 'src/model/agenda.dart' show Agenda; +export 'src/model/agenda.dart'; export 'src/model/agenda_resource.dart'; export 'src/model/day.dart'; export 'src/model/event.dart'; diff --git a/packages/lyon1agendaclient/lib/src/lyon1agendaclient.dart b/packages/lyon1agendaclient/lib/src/lyon1agendaclient.dart index d37365bfb..3b921f7ad 100755 --- a/packages/lyon1agendaclient/lib/src/lyon1agendaclient.dart +++ b/packages/lyon1agendaclient/lib/src/lyon1agendaclient.dart @@ -1,7 +1,5 @@ import 'dart:convert'; -import 'package:hive_ce/hive.dart'; -import 'package:lyon1agendaclient/hive/hive_registrar.g.dart'; import 'package:lyon1agendaclient/lyon1agendaclient.dart'; import 'package:lyon1agendaclient/src/constants/constants.dart'; import 'package:lyon1agendaclient/src/parser/agendaparser.dart'; @@ -20,10 +18,6 @@ class Lyon1AgendaClient { _corsProxyUrl = ""; } - static void registerAdapters() { - Hive.registerAdapters(); - } - Lyon1AgendaClient.useLyon1Cas(final Lyon1CasClient authentication) { _casClient = authentication; _agendaURL = AgendaURL(); @@ -50,7 +44,7 @@ class Lyon1AgendaClient { return check.statusCode == 200 && // Checking the value may not be the most precise way to check if logged in // We could maybe check the rights also for exemple - jsonDecode(check.body)["data"]["active"]; + jsonDecode(check.body)["data"]["active"]; } Map buildAuthHeaders( diff --git a/packages/lyon1agendaclient/lib/src/model/agenda.dart b/packages/lyon1agendaclient/lib/src/model/agenda.dart index e7bb1280a..18a6ae00f 100755 --- a/packages/lyon1agendaclient/lib/src/model/agenda.dart +++ b/packages/lyon1agendaclient/lib/src/model/agenda.dart @@ -1,22 +1,13 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1agendaclient/lyon1agendaclient.dart'; -part 'generated/agenda.g.dart'; +part 'generated/agenda.mapper.dart'; -@CopyWith() -class Agenda extends Equatable { - late final List days; +@MappableClass() +class Agenda with AgendaMappable { + final List days; Agenda(this.days); - Agenda.empty() { - days = []; - } - - @override - List get props => [days]; - - @override - bool get stringify => true; + Agenda.empty() : days = []; } diff --git a/packages/lyon1agendaclient/lib/src/model/agenda_resource.dart b/packages/lyon1agendaclient/lib/src/model/agenda_resource.dart index b0f84fdf6..386ac0f87 100644 --- a/packages/lyon1agendaclient/lib/src/model/agenda_resource.dart +++ b/packages/lyon1agendaclient/lib/src/model/agenda_resource.dart @@ -1,10 +1,9 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; -part 'generated/agenda_resource.g.dart'; +part 'generated/agenda_resource.mapper.dart'; -@CopyWith() -class AgendaResource extends Equatable { +@MappableClass() +class AgendaResource with AgendaResourceMappable { final int? id; final String name; final List? children; @@ -23,10 +22,10 @@ class AgendaResource extends Equatable { branch.sort((a, b) => a.name.compareTo(b.name)); } - return AgendaResource(json['id'] as int?, - (json['name'] ?? json['category'] ?? "") as String, branch); + return AgendaResource( + json['id'] as int?, + (json['name'] ?? json['category'] ?? "") as String, + branch, + ); } - - @override - List get props => [id, name, children]; } diff --git a/packages/lyon1agendaclient/lib/src/model/day.dart b/packages/lyon1agendaclient/lib/src/model/day.dart index c6cb05d39..504fd9d9e 100644 --- a/packages/lyon1agendaclient/lib/src/model/day.dart +++ b/packages/lyon1agendaclient/lib/src/model/day.dart @@ -1,11 +1,10 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1agendaclient/lyon1agendaclient.dart'; -part 'generated/day.g.dart'; +part 'generated/day.mapper.dart'; -@CopyWith() -class Day extends Equatable { +@MappableClass() +class Day with DayMappable { final List events; final DateTime date; @@ -13,7 +12,8 @@ class Day extends Equatable { Event firstEventForDay(final DateTime dt) { return events.firstWhere( - (event) => dt.isAfter(event.start) && dt.isBefore(event.end)); + (event) => dt.isAfter(event.start) && dt.isBefore(event.end), + ); } List allEventsForDay(final DateTime dt) { @@ -24,19 +24,14 @@ class Day extends Equatable { List searchEvents(final String keyword) { final RegExp r = RegExp(keyword, multiLine: true, caseSensitive: false); - return events - .where((event) => - event.location.contains(r) || - event.teacher.contains(r) || - event.name.contains(r) || - event.description.contains(r)) + .where( + (event) => + event.location.contains(r) || + event.teacher.contains(r) || + event.name.contains(r) || + event.description.contains(r), + ) .toList(); } - - @override - List get props => [events, date]; - - @override - bool get stringify => true; } diff --git a/packages/lyon1agendaclient/lib/src/model/event.dart b/packages/lyon1agendaclient/lib/src/model/event.dart index 418b70643..71d3177f3 100644 --- a/packages/lyon1agendaclient/lib/src/model/event.dart +++ b/packages/lyon1agendaclient/lib/src/model/event.dart @@ -1,18 +1,15 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; -part 'generated/event.g.dart'; +part 'generated/event.mapper.dart'; -@CopyWith() -class Event extends Equatable { +@MappableClass() +class Event with EventMappable { late final String location; late final String description; late final String teacher; late final String name; - late final DateTime start; late final DateTime end; - final dynamic menuCrous; Event({ @@ -32,31 +29,16 @@ class Event extends Equatable { .replaceFirst(RegExp("\\(Exported.*", multiLine: true), "") .trim(); name = eventJSON['summary'] ?? ""; - List descriptionSplited = description.split("\\n"); teacher = (descriptionSplited.length - 2 >= 0) ? ((descriptionSplited[descriptionSplited.length - 2] - .split(" ") - .length >= - 2) - ? descriptionSplited[descriptionSplited.length - 2] - : "") + .split(" ") + .length >= + 2) + ? descriptionSplited[descriptionSplited.length - 2] + : "") : ""; start = DateTime.parse(eventJSON['dtstart']['dt']).toLocal(); end = DateTime.parse(eventJSON['dtend']['dt']).toLocal(); } - - @override - List get props => [ - location, - description, - teacher, - name, - start, - end, - menuCrous, - ]; - - @override - bool get stringify => true; } diff --git a/packages/lyon1agendaclient/lib/src/model/generated/agenda.g.dart b/packages/lyon1agendaclient/lib/src/model/generated/agenda.g.dart deleted file mode 100644 index a571331ca..000000000 --- a/packages/lyon1agendaclient/lib/src/model/generated/agenda.g.dart +++ /dev/null @@ -1,60 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../agenda.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$AgendaCWProxy { - Agenda days(List days); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Agenda(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Agenda(...).copyWith(id: 12, name: "My name") - /// ``` - Agenda call({ - List days, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfAgenda.copyWith(...)` or call `instanceOfAgenda.copyWith.fieldName(value)` for a single field. -class _$AgendaCWProxyImpl implements _$AgendaCWProxy { - const _$AgendaCWProxyImpl(this._value); - - final Agenda _value; - - @override - Agenda days(List days) => call(days: days); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Agenda(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Agenda(...).copyWith(id: 12, name: "My name") - /// ``` - Agenda call({ - Object? days = const $CopyWithPlaceholder(), - }) { - return Agenda( - days == const $CopyWithPlaceholder() || days == null - ? _value.days - // ignore: cast_nullable_to_non_nullable - : days as List, - ); - } -} - -extension $AgendaCopyWith on Agenda { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfAgenda.copyWith(...)` or `instanceOfAgenda.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$AgendaCWProxy get copyWith => _$AgendaCWProxyImpl(this); -} diff --git a/packages/lyon1agendaclient/lib/src/model/generated/agenda.mapper.dart b/packages/lyon1agendaclient/lib/src/model/generated/agenda.mapper.dart new file mode 100644 index 000000000..4e8f8499c --- /dev/null +++ b/packages/lyon1agendaclient/lib/src/model/generated/agenda.mapper.dart @@ -0,0 +1,108 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../agenda.dart'; + +class AgendaMapper extends ClassMapperBase { + AgendaMapper._(); + + static AgendaMapper? _instance; + static AgendaMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = AgendaMapper._()); + DayMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'Agenda'; + + static List _$days(Agenda v) => v.days; + static const Field> _f$days = Field('days', _$days); + + @override + final MappableFields fields = const {#days: _f$days}; + + static Agenda _instantiate(DecodingData data) { + return Agenda(data.dec(_f$days)); + } + + @override + final Function instantiate = _instantiate; + + static Agenda fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static Agenda fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin AgendaMappable { + String toJson() { + return AgendaMapper.ensureInitialized().encodeJson(this as Agenda); + } + + Map toMap() { + return AgendaMapper.ensureInitialized().encodeMap(this as Agenda); + } + + AgendaCopyWith get copyWith => + _AgendaCopyWithImpl(this as Agenda, $identity, $identity); + @override + String toString() { + return AgendaMapper.ensureInitialized().stringifyValue(this as Agenda); + } + + @override + bool operator ==(Object other) { + return AgendaMapper.ensureInitialized().equalsValue(this as Agenda, other); + } + + @override + int get hashCode { + return AgendaMapper.ensureInitialized().hashValue(this as Agenda); + } +} + +extension AgendaValueCopy<$R, $Out> on ObjectCopyWith<$R, Agenda, $Out> { + AgendaCopyWith<$R, Agenda, $Out> get $asAgenda => + $base.as((v, t, t2) => _AgendaCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class AgendaCopyWith<$R, $In extends Agenda, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, Day, DayCopyWith<$R, Day, Day>> get days; + $R call({List? days}); + AgendaCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _AgendaCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, Agenda, $Out> + implements AgendaCopyWith<$R, Agenda, $Out> { + _AgendaCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = AgendaMapper.ensureInitialized(); + @override + ListCopyWith<$R, Day, DayCopyWith<$R, Day, Day>> get days => ListCopyWith( + $value.days, + (v, t) => v.copyWith.$chain(t), + (v) => call(days: v), + ); + @override + $R call({List? days}) => + $apply(FieldCopyWithData({if (days != null) #days: days})); + @override + Agenda $make(CopyWithData data) => Agenda(data.get(#days, or: $value.days)); + + @override + AgendaCopyWith<$R2, Agenda, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _AgendaCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1agendaclient/lib/src/model/generated/agenda_resource.g.dart b/packages/lyon1agendaclient/lib/src/model/generated/agenda_resource.g.dart deleted file mode 100644 index 4a2301d2e..000000000 --- a/packages/lyon1agendaclient/lib/src/model/generated/agenda_resource.g.dart +++ /dev/null @@ -1,83 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../agenda_resource.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$AgendaResourceCWProxy { - AgendaResource id(int? id); - - AgendaResource name(String name); - - AgendaResource children(List? children); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `AgendaResource(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// AgendaResource(...).copyWith(id: 12, name: "My name") - /// ``` - AgendaResource call({ - int? id, - String name, - List? children, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfAgendaResource.copyWith(...)` or call `instanceOfAgendaResource.copyWith.fieldName(value)` for a single field. -class _$AgendaResourceCWProxyImpl implements _$AgendaResourceCWProxy { - const _$AgendaResourceCWProxyImpl(this._value); - - final AgendaResource _value; - - @override - AgendaResource id(int? id) => call(id: id); - - @override - AgendaResource name(String name) => call(name: name); - - @override - AgendaResource children(List? children) => - call(children: children); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `AgendaResource(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// AgendaResource(...).copyWith(id: 12, name: "My name") - /// ``` - AgendaResource call({ - Object? id = const $CopyWithPlaceholder(), - Object? name = const $CopyWithPlaceholder(), - Object? children = const $CopyWithPlaceholder(), - }) { - return AgendaResource( - id == const $CopyWithPlaceholder() - ? _value.id - // ignore: cast_nullable_to_non_nullable - : id as int?, - name == const $CopyWithPlaceholder() || name == null - ? _value.name - // ignore: cast_nullable_to_non_nullable - : name as String, - children == const $CopyWithPlaceholder() - ? _value.children - // ignore: cast_nullable_to_non_nullable - : children as List?, - ); - } -} - -extension $AgendaResourceCopyWith on AgendaResource { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfAgendaResource.copyWith(...)` or `instanceOfAgendaResource.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$AgendaResourceCWProxy get copyWith => _$AgendaResourceCWProxyImpl(this); -} diff --git a/packages/lyon1agendaclient/lib/src/model/generated/agenda_resource.mapper.dart b/packages/lyon1agendaclient/lib/src/model/generated/agenda_resource.mapper.dart new file mode 100644 index 000000000..64215b9c4 --- /dev/null +++ b/packages/lyon1agendaclient/lib/src/model/generated/agenda_resource.mapper.dart @@ -0,0 +1,166 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../agenda_resource.dart'; + +class AgendaResourceMapper extends ClassMapperBase { + AgendaResourceMapper._(); + + static AgendaResourceMapper? _instance; + static AgendaResourceMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = AgendaResourceMapper._()); + AgendaResourceMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'AgendaResource'; + + static int? _$id(AgendaResource v) => v.id; + static const Field _f$id = Field('id', _$id); + static String _$name(AgendaResource v) => v.name; + static const Field _f$name = Field('name', _$name); + static List? _$children(AgendaResource v) => v.children; + static const Field> _f$children = Field( + 'children', + _$children, + ); + + @override + final MappableFields fields = const { + #id: _f$id, + #name: _f$name, + #children: _f$children, + }; + + static AgendaResource _instantiate(DecodingData data) { + return AgendaResource( + data.dec(_f$id), + data.dec(_f$name), + data.dec(_f$children), + ); + } + + @override + final Function instantiate = _instantiate; + + static AgendaResource fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static AgendaResource fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin AgendaResourceMappable { + String toJson() { + return AgendaResourceMapper.ensureInitialized().encodeJson( + this as AgendaResource, + ); + } + + Map toMap() { + return AgendaResourceMapper.ensureInitialized().encodeMap( + this as AgendaResource, + ); + } + + AgendaResourceCopyWith + get copyWith => _AgendaResourceCopyWithImpl( + this as AgendaResource, + $identity, + $identity, + ); + @override + String toString() { + return AgendaResourceMapper.ensureInitialized().stringifyValue( + this as AgendaResource, + ); + } + + @override + bool operator ==(Object other) { + return AgendaResourceMapper.ensureInitialized().equalsValue( + this as AgendaResource, + other, + ); + } + + @override + int get hashCode { + return AgendaResourceMapper.ensureInitialized().hashValue( + this as AgendaResource, + ); + } +} + +extension AgendaResourceValueCopy<$R, $Out> + on ObjectCopyWith<$R, AgendaResource, $Out> { + AgendaResourceCopyWith<$R, AgendaResource, $Out> get $asAgendaResource => + $base.as((v, t, t2) => _AgendaResourceCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class AgendaResourceCopyWith<$R, $In extends AgendaResource, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith< + $R, + AgendaResource, + AgendaResourceCopyWith<$R, AgendaResource, AgendaResource> + >? + get children; + $R call({int? id, String? name, List? children}); + AgendaResourceCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ); +} + +class _AgendaResourceCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, AgendaResource, $Out> + implements AgendaResourceCopyWith<$R, AgendaResource, $Out> { + _AgendaResourceCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + AgendaResourceMapper.ensureInitialized(); + @override + ListCopyWith< + $R, + AgendaResource, + AgendaResourceCopyWith<$R, AgendaResource, AgendaResource> + >? + get children => $value.children != null + ? ListCopyWith( + $value.children!, + (v, t) => v.copyWith.$chain(t), + (v) => call(children: v), + ) + : null; + @override + $R call({Object? id = $none, String? name, Object? children = $none}) => + $apply( + FieldCopyWithData({ + if (id != $none) #id: id, + if (name != null) #name: name, + if (children != $none) #children: children, + }), + ); + @override + AgendaResource $make(CopyWithData data) => AgendaResource( + data.get(#id, or: $value.id), + data.get(#name, or: $value.name), + data.get(#children, or: $value.children), + ); + + @override + AgendaResourceCopyWith<$R2, AgendaResource, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _AgendaResourceCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1agendaclient/lib/src/model/generated/day.g.dart b/packages/lyon1agendaclient/lib/src/model/generated/day.g.dart deleted file mode 100644 index 073df6372..000000000 --- a/packages/lyon1agendaclient/lib/src/model/generated/day.g.dart +++ /dev/null @@ -1,71 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../day.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$DayCWProxy { - Day date(DateTime date); - - Day events(List events); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Day(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Day(...).copyWith(id: 12, name: "My name") - /// ``` - Day call({ - DateTime date, - List events, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfDay.copyWith(...)` or call `instanceOfDay.copyWith.fieldName(value)` for a single field. -class _$DayCWProxyImpl implements _$DayCWProxy { - const _$DayCWProxyImpl(this._value); - - final Day _value; - - @override - Day date(DateTime date) => call(date: date); - - @override - Day events(List events) => call(events: events); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Day(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Day(...).copyWith(id: 12, name: "My name") - /// ``` - Day call({ - Object? date = const $CopyWithPlaceholder(), - Object? events = const $CopyWithPlaceholder(), - }) { - return Day( - date == const $CopyWithPlaceholder() || date == null - ? _value.date - // ignore: cast_nullable_to_non_nullable - : date as DateTime, - events == const $CopyWithPlaceholder() || events == null - ? _value.events - // ignore: cast_nullable_to_non_nullable - : events as List, - ); - } -} - -extension $DayCopyWith on Day { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfDay.copyWith(...)` or `instanceOfDay.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$DayCWProxy get copyWith => _$DayCWProxyImpl(this); -} diff --git a/packages/lyon1agendaclient/lib/src/model/generated/day.mapper.dart b/packages/lyon1agendaclient/lib/src/model/generated/day.mapper.dart new file mode 100644 index 000000000..f4a76c101 --- /dev/null +++ b/packages/lyon1agendaclient/lib/src/model/generated/day.mapper.dart @@ -0,0 +1,118 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../day.dart'; + +class DayMapper extends ClassMapperBase { + DayMapper._(); + + static DayMapper? _instance; + static DayMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = DayMapper._()); + EventMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'Day'; + + static DateTime _$date(Day v) => v.date; + static const Field _f$date = Field('date', _$date); + static List _$events(Day v) => v.events; + static const Field> _f$events = Field('events', _$events); + + @override + final MappableFields fields = const {#date: _f$date, #events: _f$events}; + + static Day _instantiate(DecodingData data) { + return Day(data.dec(_f$date), data.dec(_f$events)); + } + + @override + final Function instantiate = _instantiate; + + static Day fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static Day fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin DayMappable { + String toJson() { + return DayMapper.ensureInitialized().encodeJson(this as Day); + } + + Map toMap() { + return DayMapper.ensureInitialized().encodeMap(this as Day); + } + + DayCopyWith get copyWith => + _DayCopyWithImpl(this as Day, $identity, $identity); + @override + String toString() { + return DayMapper.ensureInitialized().stringifyValue(this as Day); + } + + @override + bool operator ==(Object other) { + return DayMapper.ensureInitialized().equalsValue(this as Day, other); + } + + @override + int get hashCode { + return DayMapper.ensureInitialized().hashValue(this as Day); + } +} + +extension DayValueCopy<$R, $Out> on ObjectCopyWith<$R, Day, $Out> { + DayCopyWith<$R, Day, $Out> get $asDay => + $base.as((v, t, t2) => _DayCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class DayCopyWith<$R, $In extends Day, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, Event, EventCopyWith<$R, Event, Event>> get events; + $R call({DateTime? date, List? events}); + DayCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _DayCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, Day, $Out> + implements DayCopyWith<$R, Day, $Out> { + _DayCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = DayMapper.ensureInitialized(); + @override + ListCopyWith<$R, Event, EventCopyWith<$R, Event, Event>> get events => + ListCopyWith( + $value.events, + (v, t) => v.copyWith.$chain(t), + (v) => call(events: v), + ); + @override + $R call({DateTime? date, List? events}) => $apply( + FieldCopyWithData({ + if (date != null) #date: date, + if (events != null) #events: events, + }), + ); + @override + Day $make(CopyWithData data) => Day( + data.get(#date, or: $value.date), + data.get(#events, or: $value.events), + ); + + @override + DayCopyWith<$R2, Day, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _DayCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1agendaclient/lib/src/model/generated/event.g.dart b/packages/lyon1agendaclient/lib/src/model/generated/event.g.dart deleted file mode 100644 index 00470f988..000000000 --- a/packages/lyon1agendaclient/lib/src/model/generated/event.g.dart +++ /dev/null @@ -1,127 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../event.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$EventCWProxy { - Event location(String location); - - Event description(String description); - - Event teacher(String teacher); - - Event name(String name); - - Event start(DateTime start); - - Event end(DateTime end); - - Event menuCrous(dynamic menuCrous); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Event(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Event(...).copyWith(id: 12, name: "My name") - /// ``` - Event call({ - String location, - String description, - String teacher, - String name, - DateTime start, - DateTime end, - dynamic menuCrous, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfEvent.copyWith(...)` or call `instanceOfEvent.copyWith.fieldName(value)` for a single field. -class _$EventCWProxyImpl implements _$EventCWProxy { - const _$EventCWProxyImpl(this._value); - - final Event _value; - - @override - Event location(String location) => call(location: location); - - @override - Event description(String description) => call(description: description); - - @override - Event teacher(String teacher) => call(teacher: teacher); - - @override - Event name(String name) => call(name: name); - - @override - Event start(DateTime start) => call(start: start); - - @override - Event end(DateTime end) => call(end: end); - - @override - Event menuCrous(dynamic menuCrous) => call(menuCrous: menuCrous); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Event(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Event(...).copyWith(id: 12, name: "My name") - /// ``` - Event call({ - Object? location = const $CopyWithPlaceholder(), - Object? description = const $CopyWithPlaceholder(), - Object? teacher = const $CopyWithPlaceholder(), - Object? name = const $CopyWithPlaceholder(), - Object? start = const $CopyWithPlaceholder(), - Object? end = const $CopyWithPlaceholder(), - Object? menuCrous = const $CopyWithPlaceholder(), - }) { - return Event( - location: location == const $CopyWithPlaceholder() || location == null - ? _value.location - // ignore: cast_nullable_to_non_nullable - : location as String, - description: - description == const $CopyWithPlaceholder() || description == null - ? _value.description - // ignore: cast_nullable_to_non_nullable - : description as String, - teacher: teacher == const $CopyWithPlaceholder() || teacher == null - ? _value.teacher - // ignore: cast_nullable_to_non_nullable - : teacher as String, - name: name == const $CopyWithPlaceholder() || name == null - ? _value.name - // ignore: cast_nullable_to_non_nullable - : name as String, - start: start == const $CopyWithPlaceholder() || start == null - ? _value.start - // ignore: cast_nullable_to_non_nullable - : start as DateTime, - end: end == const $CopyWithPlaceholder() || end == null - ? _value.end - // ignore: cast_nullable_to_non_nullable - : end as DateTime, - menuCrous: menuCrous == const $CopyWithPlaceholder() - ? _value.menuCrous - // ignore: cast_nullable_to_non_nullable - : menuCrous as dynamic, - ); - } -} - -extension $EventCopyWith on Event { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfEvent.copyWith(...)` or `instanceOfEvent.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$EventCWProxy get copyWith => _$EventCWProxyImpl(this); -} diff --git a/packages/lyon1agendaclient/lib/src/model/generated/event.mapper.dart b/packages/lyon1agendaclient/lib/src/model/generated/event.mapper.dart new file mode 100644 index 000000000..1329db3d8 --- /dev/null +++ b/packages/lyon1agendaclient/lib/src/model/generated/event.mapper.dart @@ -0,0 +1,168 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../event.dart'; + +class EventMapper extends ClassMapperBase { + EventMapper._(); + + static EventMapper? _instance; + static EventMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = EventMapper._()); + } + return _instance!; + } + + @override + final String id = 'Event'; + + static String _$location(Event v) => v.location; + static const Field _f$location = Field('location', _$location); + static String _$description(Event v) => v.description; + static const Field _f$description = Field( + 'description', + _$description, + ); + static String _$teacher(Event v) => v.teacher; + static const Field _f$teacher = Field('teacher', _$teacher); + static String _$name(Event v) => v.name; + static const Field _f$name = Field('name', _$name); + static DateTime _$start(Event v) => v.start; + static const Field _f$start = Field('start', _$start); + static DateTime _$end(Event v) => v.end; + static const Field _f$end = Field('end', _$end); + static dynamic _$menuCrous(Event v) => v.menuCrous; + static const Field _f$menuCrous = Field( + 'menuCrous', + _$menuCrous, + opt: true, + ); + + @override + final MappableFields fields = const { + #location: _f$location, + #description: _f$description, + #teacher: _f$teacher, + #name: _f$name, + #start: _f$start, + #end: _f$end, + #menuCrous: _f$menuCrous, + }; + + static Event _instantiate(DecodingData data) { + return Event( + location: data.dec(_f$location), + description: data.dec(_f$description), + teacher: data.dec(_f$teacher), + name: data.dec(_f$name), + start: data.dec(_f$start), + end: data.dec(_f$end), + menuCrous: data.dec(_f$menuCrous), + ); + } + + @override + final Function instantiate = _instantiate; + + static Event fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static Event fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin EventMappable { + String toJson() { + return EventMapper.ensureInitialized().encodeJson(this as Event); + } + + Map toMap() { + return EventMapper.ensureInitialized().encodeMap(this as Event); + } + + EventCopyWith get copyWith => + _EventCopyWithImpl(this as Event, $identity, $identity); + @override + String toString() { + return EventMapper.ensureInitialized().stringifyValue(this as Event); + } + + @override + bool operator ==(Object other) { + return EventMapper.ensureInitialized().equalsValue(this as Event, other); + } + + @override + int get hashCode { + return EventMapper.ensureInitialized().hashValue(this as Event); + } +} + +extension EventValueCopy<$R, $Out> on ObjectCopyWith<$R, Event, $Out> { + EventCopyWith<$R, Event, $Out> get $asEvent => + $base.as((v, t, t2) => _EventCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class EventCopyWith<$R, $In extends Event, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({ + String? location, + String? description, + String? teacher, + String? name, + DateTime? start, + DateTime? end, + dynamic menuCrous, + }); + EventCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _EventCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, Event, $Out> + implements EventCopyWith<$R, Event, $Out> { + _EventCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = EventMapper.ensureInitialized(); + @override + $R call({ + String? location, + String? description, + String? teacher, + String? name, + DateTime? start, + DateTime? end, + Object? menuCrous = $none, + }) => $apply( + FieldCopyWithData({ + if (location != null) #location: location, + if (description != null) #description: description, + if (teacher != null) #teacher: teacher, + if (name != null) #name: name, + if (start != null) #start: start, + if (end != null) #end: end, + if (menuCrous != $none) #menuCrous: menuCrous, + }), + ); + @override + Event $make(CopyWithData data) => Event( + location: data.get(#location, or: $value.location), + description: data.get(#description, or: $value.description), + teacher: data.get(#teacher, or: $value.teacher), + name: data.get(#name, or: $value.name), + start: data.get(#start, or: $value.start), + end: data.get(#end, or: $value.end), + menuCrous: data.get(#menuCrous, or: $value.menuCrous), + ); + + @override + EventCopyWith<$R2, Event, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _EventCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1agendaclient/pubspec.lock b/packages/lyon1agendaclient/pubspec.lock index c66f8bdc4..0d0c55c9c 100755 --- a/packages/lyon1agendaclient/pubspec.lock +++ b/packages/lyon1agendaclient/pubspec.lock @@ -17,6 +17,14 @@ packages: url: "https://pub.dev" source: hosted version: "7.7.1" + ansicolor: + dependency: transitive + description: + name: ansicolor + sha256: "50e982d500bc863e1d703448afdbf9e5a72eb48840a4f766fa361ffd6877055f" + url: "https://pub.dev" + source: hosted + version: "2.0.3" args: dependency: transitive description: @@ -153,22 +161,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.2" - copy_with_extension: - dependency: "direct main" - description: - name: copy_with_extension - sha256: "907e0af3739528957e61f0193b63041f57b2ce61d4c404299b662270611bcf2e" - url: "https://pub.dev" - source: hosted - version: "9.1.0" - copy_with_extension_gen: - dependency: "direct dev" - description: - name: copy_with_extension_gen - sha256: "7a408314ec69bea716efa8c69bf0a93b3727a8134f8f0218d376be2b13b2b3a7" - url: "https://pub.dev" - source: hosted - version: "9.1.0" coverage: dependency: transitive description: @@ -193,6 +185,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.2" + dart_mappable: + dependency: "direct main" + description: + name: dart_mappable + sha256: "15f41a35da8ee690bbfa0059fa241edeeaea73f89a2ba685b354ece07cd8ada6" + url: "https://pub.dev" + source: hosted + version: "4.6.0" + dart_mappable_builder: + dependency: "direct dev" + description: + name: dart_mappable_builder + sha256: "1116c70d9923e85e78a9339a67934949334a4190c8a6f46e1fbc908341ce424c" + url: "https://pub.dev" + source: hosted + version: "4.6.0" dart_style: dependency: transitive description: @@ -209,14 +217,6 @@ packages: url: "https://pub.dev" source: hosted version: "4.2.0" - equatable: - dependency: "direct main" - description: - name: equatable - sha256: "567c64b3cb4cf82397aac55f4f0cbd3ca20d77c6c03bedbc4ceaddc08904aef7" - url: "https://pub.dev" - source: hosted - version: "2.0.7" file: dependency: transitive description: @@ -265,22 +265,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.0" - hive_ce: - dependency: "direct main" - description: - name: hive_ce - sha256: "708bb39050998707c5d422752159f91944d3c81ab42d80e1bd0ee37d8e130658" - url: "https://pub.dev" - source: hosted - version: "2.11.3" - hive_ce_generator: - dependency: "direct dev" - description: - name: hive_ce_generator - sha256: a169feeff2da9cc2c417ce5ae9bcebf7c8a95d7a700492b276909016ad70a786 - url: "https://pub.dev" - source: hosted - version: "1.9.3" html: dependency: transitive description: @@ -329,14 +313,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.5" - isolate_channel: - dependency: transitive - description: - name: isolate_channel - sha256: f3d36f783b301e6b312c3450eeb2656b0e7d1db81331af2a151d9083a3f6b18d - url: "https://pub.dev" - source: hosted - version: "0.2.2+1" js: dependency: transitive description: @@ -504,14 +480,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.0" - source_helper: - dependency: transitive - description: - name: source_helper - sha256: a447acb083d3a5ef17f983dd36201aeea33fedadb3228fa831f2f0c92f0f3aca - url: "https://pub.dev" - source: hosted - version: "1.3.7" source_map_stack_trace: dependency: transitive description: @@ -608,6 +576,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.2" + type_plus: + dependency: transitive + description: + name: type_plus + sha256: d5d1019471f0d38b91603adb9b5fd4ce7ab903c879d2fbf1a3f80a630a03fcc9 + url: "https://pub.dev" + source: hosted + version: "2.1.1" typed_data: dependency: transitive description: @@ -672,13 +648,5 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.3" - yaml_writer: - dependency: transitive - description: - name: yaml_writer - sha256: "69651cd7238411179ac32079937d4aa9a2970150d6b2ae2c6fe6de09402a5dc5" - url: "https://pub.dev" - source: hosted - version: "2.1.0" sdks: dart: ">=3.8.0 <4.0.0" diff --git a/packages/lyon1agendaclient/pubspec.yaml b/packages/lyon1agendaclient/pubspec.yaml index 789cacbf7..3be692250 100755 --- a/packages/lyon1agendaclient/pubspec.yaml +++ b/packages/lyon1agendaclient/pubspec.yaml @@ -3,21 +3,18 @@ description: A Dart library for retrieving Lyon 1 University agendas using Lyon1 repository: https://github.com/onyx-lyon1/onyx/tree/main/packages/lyon1agendaclient version: 1.0.10 environment: - sdk: '>=3.0.0 <4.0.0' + sdk: '>=3.8.0 <4.0.0' dev_dependencies: lints: ^6.0.0 test: ^1.20.1 build_runner: ^2.4.6 - hive_ce_generator: ^1.9.2 - copy_with_extension_gen: ^9.1.0 + dart_mappable_builder: ^4.6.0 dependencies: requests_plus: ^4.8.3 lyon1casclient: ^1.0.2 icalendar_parser: ^2.0.0 dotenv: ^4.1.0 - hive_ce: ^2.2.3 - equatable: ^2.0.5 - copy_with_extension: ^9.1.0 + dart_mappable: ^4.6.0 diff --git a/packages/lyon1casclient/build.yaml b/packages/lyon1casclient/build.yaml index d6160f7dc..3ff8f90ad 100644 --- a/packages/lyon1casclient/build.yaml +++ b/packages/lyon1casclient/build.yaml @@ -1,9 +1,11 @@ targets: $default: builders: - source_gen|combining_builder: - generate_for: - - lib/**.dart + # only to resolve build_runner conflicts + dart_mappable_builder: options: build_extensions: - 'lib/{{path}}/{{file}}.dart': 'lib/{{path}}/generated/{{file}}.g.dart' \ No newline at end of file + 'lib/{{path}}/{{file}}.dart': + - 'lib/{{path}}/generated/{{file}}.mapper.dart' + - 'lib/{{path}}/generated/{{file}}.init.dart' + diff --git a/packages/lyon1casclient/lib/hive/generated/hive_adapters.g.dart b/packages/lyon1casclient/lib/hive/generated/hive_adapters.g.dart deleted file mode 100644 index 810f3f8c8..000000000 --- a/packages/lyon1casclient/lib/hive/generated/hive_adapters.g.dart +++ /dev/null @@ -1,47 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../hive_adapters.dart'; - -// ************************************************************************** -// AdaptersGenerator -// ************************************************************************** - -class CredentialAdapter extends TypeAdapter { - @override - final typeId = 4; - - @override - Credential read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return Credential( - fields[0] as String, - fields[1] as String, - tgcToken: fields[2] == null ? "" : fields[2] as String, - ); - } - - @override - void write(BinaryWriter writer, Credential obj) { - writer - ..writeByte(3) - ..writeByte(0) - ..write(obj.username) - ..writeByte(1) - ..write(obj.password) - ..writeByte(2) - ..write(obj.tgcToken); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is CredentialAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} diff --git a/packages/lyon1casclient/lib/hive/hive_adapters.dart b/packages/lyon1casclient/lib/hive/hive_adapters.dart deleted file mode 100644 index 7583e946b..000000000 --- a/packages/lyon1casclient/lib/hive/hive_adapters.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:hive_ce/hive.dart'; -import 'package:lyon1casclient/src/credential.dart'; - -part 'generated/hive_adapters.g.dart'; - -@GenerateAdapters([ - AdapterSpec(), -]) -class HiveAdapters {} diff --git a/packages/lyon1casclient/lib/hive/hive_adapters.g.yaml b/packages/lyon1casclient/lib/hive/hive_adapters.g.yaml deleted file mode 100644 index 7f10e50ca..000000000 --- a/packages/lyon1casclient/lib/hive/hive_adapters.g.yaml +++ /dev/null @@ -1,15 +0,0 @@ -# Generated by Hive CE -# Manual modifications may be necessary for certain migrations -# Check in to version control -nextTypeId: 5 -types: - Credential: - typeId: 4 - nextIndex: 3 - fields: - username: - index: 0 - password: - index: 1 - tgcToken: - index: 2 diff --git a/packages/lyon1casclient/lib/hive/hive_registrar.g.dart b/packages/lyon1casclient/lib/hive/hive_registrar.g.dart deleted file mode 100644 index 988c4a606..000000000 --- a/packages/lyon1casclient/lib/hive/hive_registrar.g.dart +++ /dev/null @@ -1,18 +0,0 @@ -// Generated by Hive CE -// Do not modify -// Check in to version control - -import 'package:hive_ce/hive.dart'; -import 'package:lyon1casclient/hive/hive_adapters.dart'; - -extension HiveRegistrar on HiveInterface { - void registerAdapters() { - registerAdapter(CredentialAdapter()); - } -} - -extension IsolatedHiveRegistrar on IsolatedHiveInterface { - void registerAdapters() { - registerAdapter(CredentialAdapter()); - } -} diff --git a/packages/lyon1casclient/lib/src/credential.dart b/packages/lyon1casclient/lib/src/credential.dart index f25fae924..cba290ea7 100644 --- a/packages/lyon1casclient/lib/src/credential.dart +++ b/packages/lyon1casclient/lib/src/credential.dart @@ -1,19 +1,12 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; -part 'generated/credential.g.dart'; +part 'generated/credential.mapper.dart'; -@CopyWith() -class Credential extends Equatable { +@MappableClass() +class Credential with CredentialMappable { late final String username; late final String password; late final String tgcToken; Credential(this.username, this.password, {this.tgcToken = ""}); - - @override - List get props => [username, password, tgcToken]; - - @override - bool? get stringify => true; } diff --git a/packages/lyon1casclient/lib/src/generated/credential.g.dart b/packages/lyon1casclient/lib/src/generated/credential.g.dart deleted file mode 100644 index 1090be7fa..000000000 --- a/packages/lyon1casclient/lib/src/generated/credential.g.dart +++ /dev/null @@ -1,82 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../credential.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$CredentialCWProxy { - Credential username(String username); - - Credential password(String password); - - Credential tgcToken(String tgcToken); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Credential(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Credential(...).copyWith(id: 12, name: "My name") - /// ``` - Credential call({ - String username, - String password, - String tgcToken, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfCredential.copyWith(...)` or call `instanceOfCredential.copyWith.fieldName(value)` for a single field. -class _$CredentialCWProxyImpl implements _$CredentialCWProxy { - const _$CredentialCWProxyImpl(this._value); - - final Credential _value; - - @override - Credential username(String username) => call(username: username); - - @override - Credential password(String password) => call(password: password); - - @override - Credential tgcToken(String tgcToken) => call(tgcToken: tgcToken); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Credential(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Credential(...).copyWith(id: 12, name: "My name") - /// ``` - Credential call({ - Object? username = const $CopyWithPlaceholder(), - Object? password = const $CopyWithPlaceholder(), - Object? tgcToken = const $CopyWithPlaceholder(), - }) { - return Credential( - username == const $CopyWithPlaceholder() || username == null - ? _value.username - // ignore: cast_nullable_to_non_nullable - : username as String, - password == const $CopyWithPlaceholder() || password == null - ? _value.password - // ignore: cast_nullable_to_non_nullable - : password as String, - tgcToken: tgcToken == const $CopyWithPlaceholder() || tgcToken == null - ? _value.tgcToken - // ignore: cast_nullable_to_non_nullable - : tgcToken as String, - ); - } -} - -extension $CredentialCopyWith on Credential { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfCredential.copyWith(...)` or `instanceOfCredential.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$CredentialCWProxy get copyWith => _$CredentialCWProxyImpl(this); -} diff --git a/packages/lyon1casclient/lib/src/generated/credential.mapper.dart b/packages/lyon1casclient/lib/src/generated/credential.mapper.dart new file mode 100644 index 000000000..af6749941 --- /dev/null +++ b/packages/lyon1casclient/lib/src/generated/credential.mapper.dart @@ -0,0 +1,149 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../credential.dart'; + +class CredentialMapper extends ClassMapperBase { + CredentialMapper._(); + + static CredentialMapper? _instance; + static CredentialMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = CredentialMapper._()); + } + return _instance!; + } + + @override + final String id = 'Credential'; + + static String _$username(Credential v) => v.username; + static const Field _f$username = Field( + 'username', + _$username, + ); + static String _$password(Credential v) => v.password; + static const Field _f$password = Field( + 'password', + _$password, + ); + static String _$tgcToken(Credential v) => v.tgcToken; + static const Field _f$tgcToken = Field( + 'tgcToken', + _$tgcToken, + opt: true, + def: "", + ); + + @override + final MappableFields fields = const { + #username: _f$username, + #password: _f$password, + #tgcToken: _f$tgcToken, + }; + + static Credential _instantiate(DecodingData data) { + return Credential( + data.dec(_f$username), + data.dec(_f$password), + tgcToken: data.dec(_f$tgcToken), + ); + } + + @override + final Function instantiate = _instantiate; + + static Credential fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static Credential fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin CredentialMappable { + String toJson() { + return CredentialMapper.ensureInitialized().encodeJson( + this as Credential, + ); + } + + Map toMap() { + return CredentialMapper.ensureInitialized().encodeMap( + this as Credential, + ); + } + + CredentialCopyWith get copyWith => + _CredentialCopyWithImpl( + this as Credential, + $identity, + $identity, + ); + @override + String toString() { + return CredentialMapper.ensureInitialized().stringifyValue( + this as Credential, + ); + } + + @override + bool operator ==(Object other) { + return CredentialMapper.ensureInitialized().equalsValue( + this as Credential, + other, + ); + } + + @override + int get hashCode { + return CredentialMapper.ensureInitialized().hashValue(this as Credential); + } +} + +extension CredentialValueCopy<$R, $Out> + on ObjectCopyWith<$R, Credential, $Out> { + CredentialCopyWith<$R, Credential, $Out> get $asCredential => + $base.as((v, t, t2) => _CredentialCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class CredentialCopyWith<$R, $In extends Credential, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({String? username, String? password, String? tgcToken}); + CredentialCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _CredentialCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, Credential, $Out> + implements CredentialCopyWith<$R, Credential, $Out> { + _CredentialCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + CredentialMapper.ensureInitialized(); + @override + $R call({String? username, String? password, String? tgcToken}) => $apply( + FieldCopyWithData({ + if (username != null) #username: username, + if (password != null) #password: password, + if (tgcToken != null) #tgcToken: tgcToken, + }), + ); + @override + Credential $make(CopyWithData data) => Credential( + data.get(#username, or: $value.username), + data.get(#password, or: $value.password), + tgcToken: data.get(#tgcToken, or: $value.tgcToken), + ); + + @override + CredentialCopyWith<$R2, Credential, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _CredentialCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1casclient/lib/src/lyon1casclient.dart b/packages/lyon1casclient/lib/src/lyon1casclient.dart index 258bab56e..ea26a5a37 100755 --- a/packages/lyon1casclient/lib/src/lyon1casclient.dart +++ b/packages/lyon1casclient/lib/src/lyon1casclient.dart @@ -1,11 +1,7 @@ // ignore_for_file: depend_on_referenced_packages -import 'dart:io'; - import 'package:beautiful_soup_dart/beautiful_soup.dart'; -import 'package:hive_ce/hive.dart'; import 'package:http/http.dart'; -import 'package:lyon1casclient/hive/hive_registrar.g.dart'; import 'package:requests_plus/requests_plus.dart'; import 'constant/constants.dart'; @@ -16,11 +12,6 @@ class Lyon1CasClient { bool isAuthenticated = false; late final String _corsProxyUrl; - static void registerAdapters({bool initHive = true}) { - Hive.registerAdapters(); - if (initHive) Hive.init(Directory.current.path); - } - String get corsProxyUrl => _corsProxyUrl; Lyon1CasClient({String corsProxyUrl = ""}) { @@ -33,11 +24,13 @@ class Lyon1CasClient { } Future<({bool authResult, Credential credential})> authenticate( - Credential credential, - {bool cookieOnly = false}) async { + Credential credential, { + bool cookieOnly = false, + }) async { if (credential.tgcToken.isNotEmpty) { - CookieJar cookieJar = - await RequestsPlus.getStoredCookies(Constants.casLogin); + CookieJar cookieJar = await RequestsPlus.getStoredCookies( + Constants.casLogin, + ); cookieJar["TGC-CAS"] = Cookie("TGC-CAS", credential.tgcToken); await RequestsPlus.setStoredCookies(Constants.casLogin, cookieJar); } @@ -46,14 +39,16 @@ class Lyon1CasClient { } if (!(await checkAuthentificated())) { await RequestsPlus.clearStoredCookies(Constants.casLogin); - isAuthenticated = - await _authenticationRequest(await getExecToken(), credential); + isAuthenticated = await _authenticationRequest( + await getExecToken(), + credential, + ); } else { isAuthenticated = true; } if (isAuthenticated) { - credential = credential.copyWith.tgcToken((await getTgcToken())); + credential = credential.copyWith(tgcToken: (await getTgcToken())); } return (credential: credential, authResult: isAuthenticated); } @@ -80,9 +75,11 @@ class Lyon1CasClient { url = "${Constants.casLogin}?service=$url${(unsafe ? '/?unsafe=1' : '')}"; } Response? response; - for (var i = 0; - i < maxRetry && (response?.request?.url.host.contains("cas") ?? true); - i++) { + for ( + var i = 0; + i < maxRetry && (response?.request?.url.host.contains("cas") ?? true); + i++ + ) { if (response != null) { url = response.request!.url.toString(); } @@ -112,9 +109,7 @@ class Lyon1CasClient { final response = await RequestsPlus.get( Constants.casLogin, corsProxyUrl: _corsProxyUrl, - headers: { - 'User-Agent': Constants.userAgent, - }, + headers: {'User-Agent': Constants.userAgent}, withCredentials: true, ); @@ -131,7 +126,9 @@ class Lyon1CasClient { } Future _authenticationRequest( - final String execToken, Credential credential) async { + final String execToken, + Credential credential, + ) async { final response = await RequestsPlus.post( Constants.casLogin, corsProxyUrl: _corsProxyUrl, @@ -141,7 +138,7 @@ class Lyon1CasClient { 'lt': '', 'execution': execToken, '_eventId': 'submit', - 'submit': 'SE+CONNECTER' + 'submit': 'SE+CONNECTER', }, headers: { 'User-Agent': Constants.userAgent, diff --git a/packages/lyon1casclient/pubspec.yaml b/packages/lyon1casclient/pubspec.yaml index 3759a48cd..8dabcca31 100644 --- a/packages/lyon1casclient/pubspec.yaml +++ b/packages/lyon1casclient/pubspec.yaml @@ -4,21 +4,18 @@ version: 1.0.9 repository: https://github.com/onyx-lyon1/onxy/tree/main/packages/lyon1casclient environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.8.0 <4.0.0" # Add regular dependencies here. dependencies: beautiful_soup_dart: ^0.3.0 - copy_with_extension: ^9.1.0 - equatable: ^2.0.5 - hive_ce: ^2.2.3 requests_plus: ^4.8.5 http: ^1.1.0 + dart_mappable: ^4.6.0 dev_dependencies: lints: ^6.0.0 test: ^1.24.8 build_runner: ^2.4.6 - hive_ce_generator: ^1.9.2 - copy_with_extension_gen: ^9.1.0 dotenv: ^4.2.0 + dart_mappable_builder: ^4.6.0 diff --git a/packages/lyon1casclient/test/lyon1_cas_test.dart b/packages/lyon1casclient/test/lyon1_cas_test.dart index b986baae7..9b8db0dcc 100755 --- a/packages/lyon1casclient/test/lyon1_cas_test.dart +++ b/packages/lyon1casclient/test/lyon1_cas_test.dart @@ -19,7 +19,6 @@ void main() async { authOK = Lyon1CasClient(); credential = Credential(username, password); - Lyon1CasClient.registerAdapters(); }); test('getExecToken', () async { @@ -27,8 +26,9 @@ void main() async { }); test('authenticate.ok', () async { - final bool isAuthenticated = - (await authOK.authenticate(credential)).authResult; + final bool isAuthenticated = (await authOK.authenticate( + credential, + )).authResult; expect(isAuthenticated, equals(true)); expect((await authOK.checkAuthentificated()), true); }); @@ -37,18 +37,19 @@ void main() async { var authReturn = await authOK.authenticate(credential); await authOK.logout(); expect( - (await authOK.authenticate( - authReturn.credential.copyWith(username: "", password: ""))) - .authResult, - true); + (await authOK.authenticate( + authReturn.credential.copyWith(username: "", password: ""), + )).authResult, + true, + ); }); test('authenticate.fail', () async { await authOK.logout(); Lyon1CasClient authBAD = Lyon1CasClient(); - final bool isAuthenticated = (await authBAD - .authenticate(Credential("p1234567", "not_valid_password"))) - .authResult; + final bool isAuthenticated = (await authBAD.authenticate( + Credential("p1234567", "not_valid_password"), + )).authResult; expect(isAuthenticated, equals(false)); diff --git a/packages/lyon1examenclient/build.yaml b/packages/lyon1examenclient/build.yaml index 2e6be8f54..3ff8f90ad 100644 --- a/packages/lyon1examenclient/build.yaml +++ b/packages/lyon1examenclient/build.yaml @@ -1,9 +1,11 @@ targets: $default: builders: - source_gen|combining_builder: - generate_for: - - lib/**.dart + # only to resolve build_runner conflicts + dart_mappable_builder: options: build_extensions: - "lib/{{path}}/{{file}}.dart": "lib/{{path}}/{{file}}.g.dart" + 'lib/{{path}}/{{file}}.dart': + - 'lib/{{path}}/generated/{{file}}.mapper.dart' + - 'lib/{{path}}/generated/{{file}}.init.dart' + diff --git a/packages/lyon1examenclient/example/lyon1examenclient_example.dart b/packages/lyon1examenclient/example/lyon1examenclient_example.dart index 8d3582604..48f3120c3 100644 --- a/packages/lyon1examenclient/example/lyon1examenclient_example.dart +++ b/packages/lyon1examenclient/example/lyon1examenclient_example.dart @@ -2,7 +2,6 @@ import 'package:lyon1casclient/lyon1casclient.dart'; import 'package:lyon1examenclient/lyon1examenclient.dart'; void main() async { - Lyon1CasClient.registerAdapters(); final lyon1Cas = Lyon1CasClient(); lyon1Cas.authenticate(Credential("username", "password")); final examClient = Lyon1ExamenClient(lyon1Cas); diff --git a/packages/lyon1examenclient/lib/hive/hive_adapters.dart b/packages/lyon1examenclient/lib/hive/hive_adapters.dart deleted file mode 100644 index fb03dc096..000000000 --- a/packages/lyon1examenclient/lib/hive/hive_adapters.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:hive_ce/hive.dart'; -import 'package:lyon1examenclient/src/examen_list_model.dart'; -import 'package:lyon1examenclient/src/examen_model.dart'; - -@GenerateAdapters([ - AdapterSpec(), - AdapterSpec(), -]) -part 'hive_adapters.g.dart'; diff --git a/packages/lyon1examenclient/lib/hive/hive_adapters.g.dart b/packages/lyon1examenclient/lib/hive/hive_adapters.g.dart deleted file mode 100644 index 62262702c..000000000 --- a/packages/lyon1examenclient/lib/hive/hive_adapters.g.dart +++ /dev/null @@ -1,91 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'hive_adapters.dart'; - -// ************************************************************************** -// AdaptersGenerator -// ************************************************************************** - -class ExamenModelAdapter extends TypeAdapter { - @override - final typeId = 48; - - @override - ExamenModel read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return ExamenModel( - title: fields[0] == null ? '' : fields[0] as String?, - codeName: fields[1] == null ? '' : fields[1] as String, - date: fields[2] as DateTime?, - duration: - fields[3] == null ? const Duration(hours: 2) : fields[3] as Duration?, - location: fields[4] == null ? '' : fields[4] as String?, - place: fields[5] == null ? 0 : (fields[5] as num?)?.toInt(), - ); - } - - @override - void write(BinaryWriter writer, ExamenModel obj) { - writer - ..writeByte(6) - ..writeByte(0) - ..write(obj.title) - ..writeByte(1) - ..write(obj.codeName) - ..writeByte(2) - ..write(obj.date) - ..writeByte(3) - ..write(obj.duration) - ..writeByte(4) - ..write(obj.location) - ..writeByte(5) - ..write(obj.place); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is ExamenModelAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class ExamenListModelAdapter extends TypeAdapter { - @override - final typeId = 49; - - @override - ExamenListModel read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return ExamenListModel( - (fields[0] as List).cast(), - ); - } - - @override - void write(BinaryWriter writer, ExamenListModel obj) { - writer - ..writeByte(1) - ..writeByte(0) - ..write(obj.examens); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is ExamenListModelAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} diff --git a/packages/lyon1examenclient/lib/hive/hive_adapters.g.yaml b/packages/lyon1examenclient/lib/hive/hive_adapters.g.yaml deleted file mode 100644 index 7b9d7a1ea..000000000 --- a/packages/lyon1examenclient/lib/hive/hive_adapters.g.yaml +++ /dev/null @@ -1,27 +0,0 @@ -# Generated by Hive CE -# Manual modifications may be necessary for certain migrations -# Check in to version control -nextTypeId: 50 -types: - ExamenModel: - typeId: 48 - nextIndex: 6 - fields: - title: - index: 0 - codeName: - index: 1 - date: - index: 2 - duration: - index: 3 - location: - index: 4 - place: - index: 5 - ExamenListModel: - typeId: 49 - nextIndex: 1 - fields: - examens: - index: 0 diff --git a/packages/lyon1examenclient/lib/hive/hive_registrar.g.dart b/packages/lyon1examenclient/lib/hive/hive_registrar.g.dart deleted file mode 100644 index 8f0761d84..000000000 --- a/packages/lyon1examenclient/lib/hive/hive_registrar.g.dart +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by Hive CE -// Do not modify -// Check in to version control - -import 'package:hive_ce/hive.dart'; -import 'package:lyon1examenclient/hive/hive_adapters.dart'; - -extension HiveRegistrar on HiveInterface { - void registerAdapters() { - registerAdapter(ExamenListModelAdapter()); - registerAdapter(ExamenModelAdapter()); - } -} - -extension IsolatedHiveRegistrar on IsolatedHiveInterface { - void registerAdapters() { - registerAdapter(ExamenListModelAdapter()); - registerAdapter(ExamenModelAdapter()); - } -} diff --git a/packages/lyon1examenclient/lib/src/duration_adapter.dart b/packages/lyon1examenclient/lib/src/duration_adapter.dart deleted file mode 100644 index bb05c0801..000000000 --- a/packages/lyon1examenclient/lib/src/duration_adapter.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:hive_ce/hive.dart'; - -class DurationAdapter extends TypeAdapter { - @override - final int typeId = 50; // or whatever free id you have - - @override - Duration read(BinaryReader reader) { - return Duration(seconds: reader.read()); - } - - @override - void write(BinaryWriter writer, Duration obj) { - writer.write(obj.inSeconds); - } -} diff --git a/packages/lyon1examenclient/lib/src/examen_list_model.dart b/packages/lyon1examenclient/lib/src/examen_list_model.dart index 13e42eeff..b9fa289d7 100644 --- a/packages/lyon1examenclient/lib/src/examen_list_model.dart +++ b/packages/lyon1examenclient/lib/src/examen_list_model.dart @@ -1,6 +1,10 @@ +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1examenclient/src/examen_model.dart'; -class ExamenListModel { +part 'generated/examen_list_model.mapper.dart'; + +@MappableClass() +class ExamenListModel with ExamenListModelMappable { List examens; ExamenListModel(this.examens); diff --git a/packages/lyon1examenclient/lib/src/examen_model.dart b/packages/lyon1examenclient/lib/src/examen_model.dart index b24768082..2e148b752 100644 --- a/packages/lyon1examenclient/lib/src/examen_model.dart +++ b/packages/lyon1examenclient/lib/src/examen_model.dart @@ -1,6 +1,6 @@ import 'package:dart_mappable/dart_mappable.dart'; -part 'examen_model.mapper.dart'; +part 'generated/examen_model.mapper.dart'; @MappableClass() class ExamenModel with ExamenModelMappable { diff --git a/packages/lyon1examenclient/lib/src/generated/examen_list_model.mapper.dart b/packages/lyon1examenclient/lib/src/generated/examen_list_model.mapper.dart new file mode 100644 index 000000000..28cf48626 --- /dev/null +++ b/packages/lyon1examenclient/lib/src/generated/examen_list_model.mapper.dart @@ -0,0 +1,143 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../examen_list_model.dart'; + +class ExamenListModelMapper extends ClassMapperBase { + ExamenListModelMapper._(); + + static ExamenListModelMapper? _instance; + static ExamenListModelMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = ExamenListModelMapper._()); + ExamenModelMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'ExamenListModel'; + + static List _$examens(ExamenListModel v) => v.examens; + static const Field> _f$examens = Field( + 'examens', + _$examens, + ); + + @override + final MappableFields fields = const {#examens: _f$examens}; + + static ExamenListModel _instantiate(DecodingData data) { + return ExamenListModel(data.dec(_f$examens)); + } + + @override + final Function instantiate = _instantiate; + + static ExamenListModel fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static ExamenListModel fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin ExamenListModelMappable { + String toJson() { + return ExamenListModelMapper.ensureInitialized() + .encodeJson(this as ExamenListModel); + } + + Map toMap() { + return ExamenListModelMapper.ensureInitialized().encodeMap( + this as ExamenListModel, + ); + } + + ExamenListModelCopyWith + get copyWith => + _ExamenListModelCopyWithImpl( + this as ExamenListModel, + $identity, + $identity, + ); + @override + String toString() { + return ExamenListModelMapper.ensureInitialized().stringifyValue( + this as ExamenListModel, + ); + } + + @override + bool operator ==(Object other) { + return ExamenListModelMapper.ensureInitialized().equalsValue( + this as ExamenListModel, + other, + ); + } + + @override + int get hashCode { + return ExamenListModelMapper.ensureInitialized().hashValue( + this as ExamenListModel, + ); + } +} + +extension ExamenListModelValueCopy<$R, $Out> + on ObjectCopyWith<$R, ExamenListModel, $Out> { + ExamenListModelCopyWith<$R, ExamenListModel, $Out> get $asExamenListModel => + $base.as((v, t, t2) => _ExamenListModelCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class ExamenListModelCopyWith<$R, $In extends ExamenListModel, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith< + $R, + ExamenModel, + ExamenModelCopyWith<$R, ExamenModel, ExamenModel> + > + get examens; + $R call({List? examens}); + ExamenListModelCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ); +} + +class _ExamenListModelCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, ExamenListModel, $Out> + implements ExamenListModelCopyWith<$R, ExamenListModel, $Out> { + _ExamenListModelCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + ExamenListModelMapper.ensureInitialized(); + @override + ListCopyWith< + $R, + ExamenModel, + ExamenModelCopyWith<$R, ExamenModel, ExamenModel> + > + get examens => ListCopyWith( + $value.examens, + (v, t) => v.copyWith.$chain(t), + (v) => call(examens: v), + ); + @override + $R call({List? examens}) => + $apply(FieldCopyWithData({if (examens != null) #examens: examens})); + @override + ExamenListModel $make(CopyWithData data) => + ExamenListModel(data.get(#examens, or: $value.examens)); + + @override + ExamenListModelCopyWith<$R2, ExamenListModel, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _ExamenListModelCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1examenclient/lib/src/examen_model.mapper.dart b/packages/lyon1examenclient/lib/src/generated/examen_model.mapper.dart similarity index 85% rename from packages/lyon1examenclient/lib/src/examen_model.mapper.dart rename to packages/lyon1examenclient/lib/src/generated/examen_model.mapper.dart index e19409a8c..a5092c5ba 100644 --- a/packages/lyon1examenclient/lib/src/examen_model.mapper.dart +++ b/packages/lyon1examenclient/lib/src/generated/examen_model.mapper.dart @@ -5,7 +5,7 @@ // ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member // ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter -part of 'examen_model.dart'; +part of '../examen_model.dart'; class ExamenModelMapper extends ClassMapperBase { ExamenModelMapper._(); @@ -171,30 +171,29 @@ class _ExamenModelCopyWithImpl<$R, $Out> Object? duration = $none, Object? location = $none, Object? place = $none, - }) => - $apply( - FieldCopyWithData({ - if (title != $none) #title: title, - if (codeName != null) #codeName: codeName, - if (date != $none) #date: date, - if (duration != $none) #duration: duration, - if (location != $none) #location: location, - if (place != $none) #place: place, - }), - ); + }) => $apply( + FieldCopyWithData({ + if (title != $none) #title: title, + if (codeName != null) #codeName: codeName, + if (date != $none) #date: date, + if (duration != $none) #duration: duration, + if (location != $none) #location: location, + if (place != $none) #place: place, + }), + ); @override ExamenModel $make(CopyWithData data) => ExamenModel( - title: data.get(#title, or: $value.title), - codeName: data.get(#codeName, or: $value.codeName), - date: data.get(#date, or: $value.date), - duration: data.get(#duration, or: $value.duration), - location: data.get(#location, or: $value.location), - place: data.get(#place, or: $value.place), - ); + title: data.get(#title, or: $value.title), + codeName: data.get(#codeName, or: $value.codeName), + date: data.get(#date, or: $value.date), + duration: data.get(#duration, or: $value.duration), + location: data.get(#location, or: $value.location), + place: data.get(#place, or: $value.place), + ); @override ExamenModelCopyWith<$R2, ExamenModel, $Out2> $chain<$R2, $Out2>( Then<$Out2, $R2> t, - ) => - _ExamenModelCopyWithImpl<$R2, $Out2>($value, $cast, t); + ) => _ExamenModelCopyWithImpl<$R2, $Out2>($value, $cast, t); } + diff --git a/packages/lyon1examenclient/lib/src/lyon1examenclient_base.dart b/packages/lyon1examenclient/lib/src/lyon1examenclient_base.dart index 02e02ec4f..1a8d90c8f 100644 --- a/packages/lyon1examenclient/lib/src/lyon1examenclient_base.dart +++ b/packages/lyon1examenclient/lib/src/lyon1examenclient_base.dart @@ -1,7 +1,5 @@ import 'package:beautiful_soup_dart/beautiful_soup.dart'; -import 'package:hive_ce/hive.dart'; import 'package:lyon1casclient/lyon1casclient.dart'; -import 'package:lyon1examenclient/hive/hive_registrar.g.dart'; import 'package:lyon1examenclient/lyon1examenclient.dart'; class Lyon1ExamenClient { @@ -12,10 +10,6 @@ class Lyon1ExamenClient { const Lyon1ExamenClient(Lyon1CasClient authentication) : _authentication = authentication; - static void registerAdapters() { - Hive.registerAdapters(); - } - Future> fetchExams() async { final resp = (await _authentication.serviceRequest(examensUrl)); final body = resp.body; diff --git a/packages/lyon1examenclient/pubspec.yaml b/packages/lyon1examenclient/pubspec.yaml index 1b420f362..10518daa2 100644 --- a/packages/lyon1examenclient/pubspec.yaml +++ b/packages/lyon1examenclient/pubspec.yaml @@ -1,5 +1,5 @@ name: lyon1examenclient -description: A Dart library that provides seamless integration with Lyon 1 University's exam service, leveraging the Lyon 1 CAS (Central Authentication Service) system for user authentication. +description: A Dart library that provides seamless integration with Lyon 1 University's exam service, leveraging the Lyon 1 CAS (Central Authentication Service) system for user authentication. version: 1.0.9 repository: https://github.com/onyx-lyon1/onyx/tree/main/packages/lyon1examenclient @@ -8,14 +8,12 @@ environment: dependencies: beautiful_soup_dart: ^0.3.0 - dart_mappable: ^4.2.0 - hive_ce: ^2.2.3 + dart_mappable: ^4.6.0 lyon1casclient: ^1.0.7 dev_dependencies: lints: ^6.0.0 test: ^1.24.0 - dart_mappable_builder: ^4.2.3 + dart_mappable_builder: ^4.6.0 build_runner: ^2.4.7 dotenv: ^4.2.0 - hive_ce_generator: ^1.9.2 diff --git a/packages/lyon1examenclient/test/lyon1examenclient_test.dart b/packages/lyon1examenclient/test/lyon1examenclient_test.dart index 67715ae41..610a0e16d 100644 --- a/packages/lyon1examenclient/test/lyon1examenclient_test.dart +++ b/packages/lyon1examenclient/test/lyon1examenclient_test.dart @@ -1,7 +1,7 @@ +import 'package:dotenv/dotenv.dart'; import 'package:lyon1casclient/lyon1casclient.dart'; import 'package:lyon1examenclient/lyon1examenclient.dart'; import 'package:test/test.dart'; -import 'package:dotenv/dotenv.dart'; void main() { late Lyon1ExamenClient examClient; @@ -9,7 +9,6 @@ void main() { DotEnv env = DotEnv(includePlatformEnvironment: true); setUpAll(() async { - Lyon1CasClient.registerAdapters(); env.load(); final String username = env['USERNAME'] ?? ""; final String password = env['PASSWORD'] ?? ""; diff --git a/packages/lyon1mailclient/build.yaml b/packages/lyon1mailclient/build.yaml index d6160f7dc..3ff8f90ad 100644 --- a/packages/lyon1mailclient/build.yaml +++ b/packages/lyon1mailclient/build.yaml @@ -1,9 +1,11 @@ targets: $default: builders: - source_gen|combining_builder: - generate_for: - - lib/**.dart + # only to resolve build_runner conflicts + dart_mappable_builder: options: build_extensions: - 'lib/{{path}}/{{file}}.dart': 'lib/{{path}}/generated/{{file}}.g.dart' \ No newline at end of file + 'lib/{{path}}/{{file}}.dart': + - 'lib/{{path}}/generated/{{file}}.mapper.dart' + - 'lib/{{path}}/generated/{{file}}.init.dart' + diff --git a/packages/lyon1mailclient/example/example.dart b/packages/lyon1mailclient/example/example.dart index 2c70382d1..62614e893 100755 --- a/packages/lyon1mailclient/example/example.dart +++ b/packages/lyon1mailclient/example/example.dart @@ -1,7 +1,6 @@ import 'package:lyon1mailclient/lyon1mailclient.dart'; void main() async { - Lyon1MailClient.registerAdapters(); final Lyon1MailClient mailClient = Lyon1MailClient("p1234567", "a_valid_password"); diff --git a/packages/lyon1mailclient/lib/hive/generated/hive_adapters.g.dart b/packages/lyon1mailclient/lib/hive/generated/hive_adapters.g.dart deleted file mode 100644 index ce6389ccd..000000000 --- a/packages/lyon1mailclient/lib/hive/generated/hive_adapters.g.dart +++ /dev/null @@ -1,343 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../hive_adapters.dart'; - -// ************************************************************************** -// AdaptersGenerator -// ************************************************************************** - -class MailAdapter extends TypeAdapter { - @override - final typeId = 5; - - @override - Mail read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return Mail( - subject: fields[0] as String, - sender: fields[1] as String, - excerpt: fields[2] as String, - isRead: fields[5] as bool, - date: fields[7] as DateTime, - body: fields[3] as String, - id: (fields[4] as num?)?.toInt(), - receiver: fields[8] as String, - attachments: (fields[9] as List).cast(), - isFlagged: fields[6] as bool, - ); - } - - @override - void write(BinaryWriter writer, Mail obj) { - writer - ..writeByte(10) - ..writeByte(0) - ..write(obj.subject) - ..writeByte(1) - ..write(obj.sender) - ..writeByte(2) - ..write(obj.excerpt) - ..writeByte(3) - ..write(obj.body) - ..writeByte(4) - ..write(obj.id) - ..writeByte(5) - ..write(obj.isRead) - ..writeByte(6) - ..write(obj.isFlagged) - ..writeByte(7) - ..write(obj.date) - ..writeByte(8) - ..write(obj.receiver) - ..writeByte(9) - ..write(obj.attachments); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is MailAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class MailBoxAdapter extends TypeAdapter { - @override - final typeId = 19; - - @override - MailBox read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return MailBox( - name: fields[0] as String, - emails: (fields[2] as List).cast(), - specialMailBox: fields[1] as SpecialMailBox?, - ); - } - - @override - void write(BinaryWriter writer, MailBox obj) { - writer - ..writeByte(3) - ..writeByte(0) - ..write(obj.name) - ..writeByte(1) - ..write(obj.specialMailBox) - ..writeByte(2) - ..write(obj.emails); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is MailBoxAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class SpecialMailBoxAdapter extends TypeAdapter { - @override - final typeId = 20; - - @override - SpecialMailBox read(BinaryReader reader) { - switch (reader.readByte()) { - case 0: - return SpecialMailBox.inbox; - case 1: - return SpecialMailBox.sent; - case 2: - return SpecialMailBox.trash; - case 3: - return SpecialMailBox.flagged; - case 4: - return SpecialMailBox.archive; - default: - return SpecialMailBox.inbox; - } - } - - @override - void write(BinaryWriter writer, SpecialMailBox obj) { - switch (obj) { - case SpecialMailBox.inbox: - writer.writeByte(0); - case SpecialMailBox.sent: - writer.writeByte(1); - case SpecialMailBox.trash: - writer.writeByte(2); - case SpecialMailBox.flagged: - writer.writeByte(3); - case SpecialMailBox.archive: - writer.writeByte(4); - } - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is SpecialMailBoxAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class MailBoxListAdapter extends TypeAdapter { - @override - final typeId = 21; - - @override - MailBoxList read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return MailBoxList( - mailBoxes: (fields[0] as List).cast(), - ); - } - - @override - void write(BinaryWriter writer, MailBoxList obj) { - writer - ..writeByte(1) - ..writeByte(0) - ..write(obj.mailBoxes); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is MailBoxListAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class ActionTypeAdapter extends TypeAdapter { - @override - final typeId = 22; - - @override - ActionType read(BinaryReader reader) { - switch (reader.readByte()) { - case 0: - return ActionType.archive; - case 1: - return ActionType.markAsRead; - case 2: - return ActionType.markAsUnread; - case 3: - return ActionType.move; - case 4: - return ActionType.send; - case 5: - return ActionType.reply; - case 7: - return ActionType.forward; - case 8: - return ActionType.delete; - case 9: - return ActionType.flag; - case 10: - return ActionType.unflag; - default: - return ActionType.archive; - } - } - - @override - void write(BinaryWriter writer, ActionType obj) { - switch (obj) { - case ActionType.archive: - writer.writeByte(0); - case ActionType.markAsRead: - writer.writeByte(1); - case ActionType.markAsUnread: - writer.writeByte(2); - case ActionType.move: - writer.writeByte(3); - case ActionType.send: - writer.writeByte(4); - case ActionType.reply: - writer.writeByte(5); - case ActionType.forward: - writer.writeByte(7); - case ActionType.delete: - writer.writeByte(8); - case ActionType.flag: - writer.writeByte(9); - case ActionType.unflag: - writer.writeByte(10); - } - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is ActionTypeAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class ActionAdapter extends TypeAdapter { - @override - final typeId = 23; - - @override - Action read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return Action( - type: fields[0] as ActionType, - mail: fields[4] as Mail, - fromMailBox: fields[1] as MailBox?, - originalMessageId: (fields[5] as num?)?.toInt(), - replyAll: fields[6] as bool?, - destinationMailBox: fields[8] as MailBox?, - ); - } - - @override - void write(BinaryWriter writer, Action obj) { - writer - ..writeByte(6) - ..writeByte(0) - ..write(obj.type) - ..writeByte(1) - ..write(obj.fromMailBox) - ..writeByte(4) - ..write(obj.mail) - ..writeByte(5) - ..write(obj.originalMessageId) - ..writeByte(6) - ..write(obj.replyAll) - ..writeByte(8) - ..write(obj.destinationMailBox); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is ActionAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class ActionListAdapter extends TypeAdapter { - @override - final typeId = 24; - - @override - ActionList read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return ActionList( - action: (fields[0] as List).cast(), - ); - } - - @override - void write(BinaryWriter writer, ActionList obj) { - writer - ..writeByte(1) - ..writeByte(0) - ..write(obj.action); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is ActionListAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} diff --git a/packages/lyon1mailclient/lib/hive/hive_adapters.dart b/packages/lyon1mailclient/lib/hive/hive_adapters.dart deleted file mode 100644 index c49a04357..000000000 --- a/packages/lyon1mailclient/lib/hive/hive_adapters.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'package:hive_ce/hive.dart'; -import 'package:lyon1mailclient/src/model/action.dart'; -import 'package:lyon1mailclient/src/model/action_list.dart'; -import 'package:lyon1mailclient/src/model/action_type.dart'; -import 'package:lyon1mailclient/src/model/mail.dart'; -import 'package:lyon1mailclient/src/model/mail_box.dart'; -import 'package:lyon1mailclient/src/model/mail_box_list.dart'; - -@GenerateAdapters([ - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), -]) -part 'generated/hive_adapters.g.dart'; diff --git a/packages/lyon1mailclient/lib/hive/hive_adapters.g.yaml b/packages/lyon1mailclient/lib/hive/hive_adapters.g.yaml deleted file mode 100644 index a6ab7f045..000000000 --- a/packages/lyon1mailclient/lib/hive/hive_adapters.g.yaml +++ /dev/null @@ -1,105 +0,0 @@ -# Generated by Hive CE -# Manual modifications may be necessary for certain migrations -# Check in to version control -nextTypeId: 25 -types: - Mail: - typeId: 5 - nextIndex: 13 - fields: - subject: - index: 0 - sender: - index: 1 - excerpt: - index: 2 - body: - index: 3 - id: - index: 4 - isRead: - index: 5 - isFlagged: - index: 6 - date: - index: 7 - receiver: - index: 8 - attachments: - index: 9 - MailBox: - typeId: 19 - nextIndex: 3 - fields: - name: - index: 0 - specialMailBox: - index: 1 - emails: - index: 2 - SpecialMailBox: - typeId: 20 - nextIndex: 5 - fields: - inbox: - index: 0 - sent: - index: 1 - trash: - index: 2 - flagged: - index: 3 - archive: - index: 4 - MailBoxList: - typeId: 21 - nextIndex: 1 - fields: - mailBoxes: - index: 0 - ActionType: - typeId: 22 - nextIndex: 11 - fields: - archive: - index: 0 - markAsRead: - index: 1 - markAsUnread: - index: 2 - move: - index: 3 - send: - index: 4 - reply: - index: 5 - forward: - index: 7 - delete: - index: 8 - flag: - index: 9 - unflag: - index: 10 - Action: - typeId: 23 - nextIndex: 9 - fields: - type: - index: 0 - fromMailBox: - index: 1 - mail: - index: 4 - originalMessageId: - index: 5 - replyAll: - index: 6 - destinationMailBox: - index: 8 - ActionList: - typeId: 24 - nextIndex: 1 - fields: - action: - index: 0 diff --git a/packages/lyon1mailclient/lib/hive/hive_registrar.g.dart b/packages/lyon1mailclient/lib/hive/hive_registrar.g.dart deleted file mode 100644 index e787b87e3..000000000 --- a/packages/lyon1mailclient/lib/hive/hive_registrar.g.dart +++ /dev/null @@ -1,30 +0,0 @@ -// Generated by Hive CE -// Do not modify -// Check in to version control - -import 'package:hive_ce/hive.dart'; -import 'package:lyon1mailclient/hive/hive_adapters.dart'; - -extension HiveRegistrar on HiveInterface { - void registerAdapters() { - registerAdapter(ActionAdapter()); - registerAdapter(ActionListAdapter()); - registerAdapter(ActionTypeAdapter()); - registerAdapter(MailAdapter()); - registerAdapter(MailBoxAdapter()); - registerAdapter(MailBoxListAdapter()); - registerAdapter(SpecialMailBoxAdapter()); - } -} - -extension IsolatedHiveRegistrar on IsolatedHiveInterface { - void registerAdapters() { - registerAdapter(ActionAdapter()); - registerAdapter(ActionListAdapter()); - registerAdapter(ActionTypeAdapter()); - registerAdapter(MailAdapter()); - registerAdapter(MailBoxAdapter()); - registerAdapter(MailBoxListAdapter()); - registerAdapter(SpecialMailBoxAdapter()); - } -} diff --git a/packages/lyon1mailclient/lib/src/lyon1mailclient.dart b/packages/lyon1mailclient/lib/src/lyon1mailclient.dart index dfd1872b3..fdca16771 100755 --- a/packages/lyon1mailclient/lib/src/lyon1mailclient.dart +++ b/packages/lyon1mailclient/lib/src/lyon1mailclient.dart @@ -4,9 +4,8 @@ import 'dart:io'; import 'package:collection/collection.dart'; import 'package:enough_mail/enough_mail.dart'; -import 'package:hive_ce/hive.dart'; -import 'package:lyon1mailclient/hive/hive_registrar.g.dart'; import 'package:lyon1mailclient/lyon1mailclient.dart'; +import 'package:lyon1mailclient/src/sembast_helper.dart'; import 'package:requests_plus/requests_plus.dart'; import 'config/config.dart'; @@ -31,11 +30,6 @@ class Lyon1MailClient { _corsProxyUrl = corsProxyUrl; } - static void registerAdapters({bool initHive = true}) { - Hive.registerAdapters(); - if (initHive) Hive.init(Directory.current.path); - } - Future login() async { await _client.connectToServer( Lyon1MailClientConfig.imapHost, Lyon1MailClientConfig.imapPort, @@ -162,9 +156,7 @@ class Lyon1MailClient { .add(Mail.fromRaw(email, removeTrackingImages: removeTrackingImages)); } if (mailbox.name.contains("Boîte d'envoi")) { - Box actionsBox = await Hive.openBox("cached_0"); - ActionList actionList = - actionsBox.get("cache0") ?? ActionList(action: []); + ActionList actionList = await SembastActionCache.getActions(); for (Action action in actionList.action) { switch (action.type) { case ActionType.send: @@ -438,11 +430,10 @@ class Lyon1MailClient { } Future addAction(Action action, {bool autoDoAction = true}) async { - Box box = await Hive.openBox("cached_0"); - ActionList wrapper = box.get("cache0") ?? ActionList(action: []); + ActionList wrapper = await SembastActionCache.getActions(); if (!wrapper.action.contains(action)) { wrapper.action.add(action); - await box.put("cache0", wrapper); + await SembastActionCache.putActions(wrapper); if (autoDoAction) { await doActions(); } @@ -450,21 +441,19 @@ class Lyon1MailClient { } Future removeAction(Action action) async { - Box box = await Hive.openBox("cached_0"); - ActionList wrapper = box.get("cache0") ?? ActionList(action: []); + ActionList wrapper = await SembastActionCache.getActions(); while (wrapper.action.contains(action)) { wrapper.action.remove(action); } - await box.put("cache0", wrapper); + await SembastActionCache.putActions(wrapper); } Future cleanActions() async { - await Hive.deleteBoxFromDisk("cached_0"); + await SembastActionCache.clearActions(); } Future> getActions() async { - Box box = await Hive.openBox("cached_0"); - return List.from(box.get("cache0")?.action ?? []); + return List.from((await SembastActionCache.getActions()).action); } Future doActions() async { diff --git a/packages/lyon1mailclient/lib/src/model/action.dart b/packages/lyon1mailclient/lib/src/model/action.dart index 9e3c6990d..c45c1a0c4 100644 --- a/packages/lyon1mailclient/lib/src/model/action.dart +++ b/packages/lyon1mailclient/lib/src/model/action.dart @@ -1,11 +1,10 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1mailclient/lyon1mailclient.dart'; -part 'generated/action.g.dart'; +part 'generated/action.mapper.dart'; -@CopyWith() -class Action extends Equatable { +@MappableClass() +class Action with ActionMappable { final ActionType type; final MailBox? fromMailBox; final Mail mail; @@ -84,17 +83,4 @@ class Action extends Equatable { break; } } - - @override - List get props => [ - type, - fromMailBox, - mail, - originalMessageId, - replyAll, - destinationMailBox, - ]; - - @override - bool? get stringify => true; } diff --git a/packages/lyon1mailclient/lib/src/model/action_list.dart b/packages/lyon1mailclient/lib/src/model/action_list.dart index 31d0b2b32..c993e81d7 100644 --- a/packages/lyon1mailclient/lib/src/model/action_list.dart +++ b/packages/lyon1mailclient/lib/src/model/action_list.dart @@ -1,18 +1,11 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1mailclient/lyon1mailclient.dart'; -part 'generated/action_list.g.dart'; +part 'generated/action_list.mapper.dart'; -@CopyWith() -class ActionList extends Equatable { +@MappableClass() +class ActionList with ActionListMappable { final List action; ActionList({required this.action}); - - @override - List get props => [action]; - - @override - bool? get stringify => true; } diff --git a/packages/lyon1mailclient/lib/src/model/action_type.dart b/packages/lyon1mailclient/lib/src/model/action_type.dart index 7df99a42d..fd71e94c4 100644 --- a/packages/lyon1mailclient/lib/src/model/action_type.dart +++ b/packages/lyon1mailclient/lib/src/model/action_type.dart @@ -1,3 +1,8 @@ +import 'package:dart_mappable/dart_mappable.dart'; + +part 'generated/action_type.mapper.dart'; + +@MappableEnum() enum ActionType { archive, markAsRead, diff --git a/packages/lyon1mailclient/lib/src/model/address.dart b/packages/lyon1mailclient/lib/src/model/address.dart index d39dc04bf..cdb1f7d70 100755 --- a/packages/lyon1mailclient/lib/src/model/address.dart +++ b/packages/lyon1mailclient/lib/src/model/address.dart @@ -1,18 +1,11 @@ -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; -class Address extends Equatable { - final String _email; - final String _name; +part 'generated/address.mapper.dart'; - Address(this._email, this._name); +@MappableClass() +class Address with AddressMappable { + final String email; + final String name; - String get email => _email; - - String get name => _name; - - @override - List get props => [_email, _name]; - - @override - bool? get stringify => true; + Address(this.email, this.name); } diff --git a/packages/lyon1mailclient/lib/src/model/generated/action.g.dart b/packages/lyon1mailclient/lib/src/model/generated/action.g.dart deleted file mode 100644 index 2f461d078..000000000 --- a/packages/lyon1mailclient/lib/src/model/generated/action.g.dart +++ /dev/null @@ -1,117 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../action.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$ActionCWProxy { - Action type(ActionType type); - - Action mail(Mail mail); - - Action fromMailBox(MailBox? fromMailBox); - - Action originalMessageId(int? originalMessageId); - - Action replyAll(bool? replyAll); - - Action destinationMailBox(MailBox? destinationMailBox); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Action(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Action(...).copyWith(id: 12, name: "My name") - /// ``` - Action call({ - ActionType type, - Mail mail, - MailBox? fromMailBox, - int? originalMessageId, - bool? replyAll, - MailBox? destinationMailBox, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfAction.copyWith(...)` or call `instanceOfAction.copyWith.fieldName(value)` for a single field. -class _$ActionCWProxyImpl implements _$ActionCWProxy { - const _$ActionCWProxyImpl(this._value); - - final Action _value; - - @override - Action type(ActionType type) => call(type: type); - - @override - Action mail(Mail mail) => call(mail: mail); - - @override - Action fromMailBox(MailBox? fromMailBox) => call(fromMailBox: fromMailBox); - - @override - Action originalMessageId(int? originalMessageId) => - call(originalMessageId: originalMessageId); - - @override - Action replyAll(bool? replyAll) => call(replyAll: replyAll); - - @override - Action destinationMailBox(MailBox? destinationMailBox) => - call(destinationMailBox: destinationMailBox); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Action(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Action(...).copyWith(id: 12, name: "My name") - /// ``` - Action call({ - Object? type = const $CopyWithPlaceholder(), - Object? mail = const $CopyWithPlaceholder(), - Object? fromMailBox = const $CopyWithPlaceholder(), - Object? originalMessageId = const $CopyWithPlaceholder(), - Object? replyAll = const $CopyWithPlaceholder(), - Object? destinationMailBox = const $CopyWithPlaceholder(), - }) { - return Action( - type: type == const $CopyWithPlaceholder() || type == null - ? _value.type - // ignore: cast_nullable_to_non_nullable - : type as ActionType, - mail: mail == const $CopyWithPlaceholder() || mail == null - ? _value.mail - // ignore: cast_nullable_to_non_nullable - : mail as Mail, - fromMailBox: fromMailBox == const $CopyWithPlaceholder() - ? _value.fromMailBox - // ignore: cast_nullable_to_non_nullable - : fromMailBox as MailBox?, - originalMessageId: originalMessageId == const $CopyWithPlaceholder() - ? _value.originalMessageId - // ignore: cast_nullable_to_non_nullable - : originalMessageId as int?, - replyAll: replyAll == const $CopyWithPlaceholder() - ? _value.replyAll - // ignore: cast_nullable_to_non_nullable - : replyAll as bool?, - destinationMailBox: destinationMailBox == const $CopyWithPlaceholder() - ? _value.destinationMailBox - // ignore: cast_nullable_to_non_nullable - : destinationMailBox as MailBox?, - ); - } -} - -extension $ActionCopyWith on Action { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfAction.copyWith(...)` or `instanceOfAction.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$ActionCWProxy get copyWith => _$ActionCWProxyImpl(this); -} diff --git a/packages/lyon1mailclient/lib/src/model/generated/action.mapper.dart b/packages/lyon1mailclient/lib/src/model/generated/action.mapper.dart new file mode 100644 index 000000000..fa127e281 --- /dev/null +++ b/packages/lyon1mailclient/lib/src/model/generated/action.mapper.dart @@ -0,0 +1,192 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../action.dart'; + +class ActionMapper extends ClassMapperBase { + ActionMapper._(); + + static ActionMapper? _instance; + static ActionMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = ActionMapper._()); + ActionTypeMapper.ensureInitialized(); + MailMapper.ensureInitialized(); + MailBoxMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'Action'; + + static ActionType _$type(Action v) => v.type; + static const Field _f$type = Field('type', _$type); + static Mail _$mail(Action v) => v.mail; + static const Field _f$mail = Field('mail', _$mail); + static MailBox? _$fromMailBox(Action v) => v.fromMailBox; + static const Field _f$fromMailBox = Field( + 'fromMailBox', + _$fromMailBox, + opt: true, + ); + static int? _$originalMessageId(Action v) => v.originalMessageId; + static const Field _f$originalMessageId = Field( + 'originalMessageId', + _$originalMessageId, + opt: true, + ); + static bool? _$replyAll(Action v) => v.replyAll; + static const Field _f$replyAll = Field( + 'replyAll', + _$replyAll, + opt: true, + ); + static MailBox? _$destinationMailBox(Action v) => v.destinationMailBox; + static const Field _f$destinationMailBox = Field( + 'destinationMailBox', + _$destinationMailBox, + opt: true, + ); + + @override + final MappableFields fields = const { + #type: _f$type, + #mail: _f$mail, + #fromMailBox: _f$fromMailBox, + #originalMessageId: _f$originalMessageId, + #replyAll: _f$replyAll, + #destinationMailBox: _f$destinationMailBox, + }; + + static Action _instantiate(DecodingData data) { + return Action( + type: data.dec(_f$type), + mail: data.dec(_f$mail), + fromMailBox: data.dec(_f$fromMailBox), + originalMessageId: data.dec(_f$originalMessageId), + replyAll: data.dec(_f$replyAll), + destinationMailBox: data.dec(_f$destinationMailBox), + ); + } + + @override + final Function instantiate = _instantiate; + + static Action fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static Action fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin ActionMappable { + String toJson() { + return ActionMapper.ensureInitialized().encodeJson(this as Action); + } + + Map toMap() { + return ActionMapper.ensureInitialized().encodeMap(this as Action); + } + + ActionCopyWith get copyWith => + _ActionCopyWithImpl(this as Action, $identity, $identity); + @override + String toString() { + return ActionMapper.ensureInitialized().stringifyValue(this as Action); + } + + @override + bool operator ==(Object other) { + return ActionMapper.ensureInitialized().equalsValue(this as Action, other); + } + + @override + int get hashCode { + return ActionMapper.ensureInitialized().hashValue(this as Action); + } +} + +extension ActionValueCopy<$R, $Out> on ObjectCopyWith<$R, Action, $Out> { + ActionCopyWith<$R, Action, $Out> get $asAction => + $base.as((v, t, t2) => _ActionCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class ActionCopyWith<$R, $In extends Action, $Out> + implements ClassCopyWith<$R, $In, $Out> { + MailCopyWith<$R, Mail, Mail> get mail; + MailBoxCopyWith<$R, MailBox, MailBox>? get fromMailBox; + MailBoxCopyWith<$R, MailBox, MailBox>? get destinationMailBox; + $R call({ + ActionType? type, + Mail? mail, + MailBox? fromMailBox, + int? originalMessageId, + bool? replyAll, + MailBox? destinationMailBox, + }); + ActionCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _ActionCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, Action, $Out> + implements ActionCopyWith<$R, Action, $Out> { + _ActionCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = ActionMapper.ensureInitialized(); + @override + MailCopyWith<$R, Mail, Mail> get mail => + $value.mail.copyWith.$chain((v) => call(mail: v)); + @override + MailBoxCopyWith<$R, MailBox, MailBox>? get fromMailBox => + $value.fromMailBox?.copyWith.$chain((v) => call(fromMailBox: v)); + @override + MailBoxCopyWith<$R, MailBox, MailBox>? get destinationMailBox => $value + .destinationMailBox + ?.copyWith + .$chain((v) => call(destinationMailBox: v)); + @override + $R call({ + ActionType? type, + Mail? mail, + Object? fromMailBox = $none, + Object? originalMessageId = $none, + Object? replyAll = $none, + Object? destinationMailBox = $none, + }) => $apply( + FieldCopyWithData({ + if (type != null) #type: type, + if (mail != null) #mail: mail, + if (fromMailBox != $none) #fromMailBox: fromMailBox, + if (originalMessageId != $none) #originalMessageId: originalMessageId, + if (replyAll != $none) #replyAll: replyAll, + if (destinationMailBox != $none) #destinationMailBox: destinationMailBox, + }), + ); + @override + Action $make(CopyWithData data) => Action( + type: data.get(#type, or: $value.type), + mail: data.get(#mail, or: $value.mail), + fromMailBox: data.get(#fromMailBox, or: $value.fromMailBox), + originalMessageId: data.get( + #originalMessageId, + or: $value.originalMessageId, + ), + replyAll: data.get(#replyAll, or: $value.replyAll), + destinationMailBox: data.get( + #destinationMailBox, + or: $value.destinationMailBox, + ), + ); + + @override + ActionCopyWith<$R2, Action, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _ActionCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1mailclient/lib/src/model/generated/action_list.g.dart b/packages/lyon1mailclient/lib/src/model/generated/action_list.g.dart deleted file mode 100644 index f61f07476..000000000 --- a/packages/lyon1mailclient/lib/src/model/generated/action_list.g.dart +++ /dev/null @@ -1,60 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../action_list.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$ActionListCWProxy { - ActionList action(List action); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `ActionList(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// ActionList(...).copyWith(id: 12, name: "My name") - /// ``` - ActionList call({ - List action, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfActionList.copyWith(...)` or call `instanceOfActionList.copyWith.fieldName(value)` for a single field. -class _$ActionListCWProxyImpl implements _$ActionListCWProxy { - const _$ActionListCWProxyImpl(this._value); - - final ActionList _value; - - @override - ActionList action(List action) => call(action: action); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `ActionList(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// ActionList(...).copyWith(id: 12, name: "My name") - /// ``` - ActionList call({ - Object? action = const $CopyWithPlaceholder(), - }) { - return ActionList( - action: action == const $CopyWithPlaceholder() || action == null - ? _value.action - // ignore: cast_nullable_to_non_nullable - : action as List, - ); - } -} - -extension $ActionListCopyWith on ActionList { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfActionList.copyWith(...)` or `instanceOfActionList.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$ActionListCWProxy get copyWith => _$ActionListCWProxyImpl(this); -} diff --git a/packages/lyon1mailclient/lib/src/model/generated/action_list.mapper.dart b/packages/lyon1mailclient/lib/src/model/generated/action_list.mapper.dart new file mode 100644 index 000000000..d38358d65 --- /dev/null +++ b/packages/lyon1mailclient/lib/src/model/generated/action_list.mapper.dart @@ -0,0 +1,130 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../action_list.dart'; + +class ActionListMapper extends ClassMapperBase { + ActionListMapper._(); + + static ActionListMapper? _instance; + static ActionListMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = ActionListMapper._()); + ActionMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'ActionList'; + + static List _$action(ActionList v) => v.action; + static const Field> _f$action = Field( + 'action', + _$action, + ); + + @override + final MappableFields fields = const {#action: _f$action}; + + static ActionList _instantiate(DecodingData data) { + return ActionList(action: data.dec(_f$action)); + } + + @override + final Function instantiate = _instantiate; + + static ActionList fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static ActionList fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin ActionListMappable { + String toJson() { + return ActionListMapper.ensureInitialized().encodeJson( + this as ActionList, + ); + } + + Map toMap() { + return ActionListMapper.ensureInitialized().encodeMap( + this as ActionList, + ); + } + + ActionListCopyWith get copyWith => + _ActionListCopyWithImpl( + this as ActionList, + $identity, + $identity, + ); + @override + String toString() { + return ActionListMapper.ensureInitialized().stringifyValue( + this as ActionList, + ); + } + + @override + bool operator ==(Object other) { + return ActionListMapper.ensureInitialized().equalsValue( + this as ActionList, + other, + ); + } + + @override + int get hashCode { + return ActionListMapper.ensureInitialized().hashValue(this as ActionList); + } +} + +extension ActionListValueCopy<$R, $Out> + on ObjectCopyWith<$R, ActionList, $Out> { + ActionListCopyWith<$R, ActionList, $Out> get $asActionList => + $base.as((v, t, t2) => _ActionListCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class ActionListCopyWith<$R, $In extends ActionList, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, Action, ActionCopyWith<$R, Action, Action>> get action; + $R call({List? action}); + ActionListCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _ActionListCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, ActionList, $Out> + implements ActionListCopyWith<$R, ActionList, $Out> { + _ActionListCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + ActionListMapper.ensureInitialized(); + @override + ListCopyWith<$R, Action, ActionCopyWith<$R, Action, Action>> get action => + ListCopyWith( + $value.action, + (v, t) => v.copyWith.$chain(t), + (v) => call(action: v), + ); + @override + $R call({List? action}) => + $apply(FieldCopyWithData({if (action != null) #action: action})); + @override + ActionList $make(CopyWithData data) => + ActionList(action: data.get(#action, or: $value.action)); + + @override + ActionListCopyWith<$R2, ActionList, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _ActionListCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1mailclient/lib/src/model/generated/action_type.mapper.dart b/packages/lyon1mailclient/lib/src/model/generated/action_type.mapper.dart new file mode 100644 index 000000000..74d2a4395 --- /dev/null +++ b/packages/lyon1mailclient/lib/src/model/generated/action_type.mapper.dart @@ -0,0 +1,87 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../action_type.dart'; + +class ActionTypeMapper extends EnumMapper { + ActionTypeMapper._(); + + static ActionTypeMapper? _instance; + static ActionTypeMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = ActionTypeMapper._()); + } + return _instance!; + } + + static ActionType fromValue(dynamic value) { + ensureInitialized(); + return MapperContainer.globals.fromValue(value); + } + + @override + ActionType decode(dynamic value) { + switch (value) { + case r'archive': + return ActionType.archive; + case r'markAsRead': + return ActionType.markAsRead; + case r'markAsUnread': + return ActionType.markAsUnread; + case r'move': + return ActionType.move; + case r'send': + return ActionType.send; + case r'reply': + return ActionType.reply; + case r'forward': + return ActionType.forward; + case r'delete': + return ActionType.delete; + case r'flag': + return ActionType.flag; + case r'unflag': + return ActionType.unflag; + default: + throw MapperException.unknownEnumValue(value); + } + } + + @override + dynamic encode(ActionType self) { + switch (self) { + case ActionType.archive: + return r'archive'; + case ActionType.markAsRead: + return r'markAsRead'; + case ActionType.markAsUnread: + return r'markAsUnread'; + case ActionType.move: + return r'move'; + case ActionType.send: + return r'send'; + case ActionType.reply: + return r'reply'; + case ActionType.forward: + return r'forward'; + case ActionType.delete: + return r'delete'; + case ActionType.flag: + return r'flag'; + case ActionType.unflag: + return r'unflag'; + } + } +} + +extension ActionTypeMapperExtension on ActionType { + String toValue() { + ActionTypeMapper.ensureInitialized(); + return MapperContainer.globals.toValue(this) as String; + } +} + diff --git a/packages/lyon1mailclient/lib/src/model/generated/address.mapper.dart b/packages/lyon1mailclient/lib/src/model/generated/address.mapper.dart new file mode 100644 index 000000000..17abc3ab9 --- /dev/null +++ b/packages/lyon1mailclient/lib/src/model/generated/address.mapper.dart @@ -0,0 +1,125 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../address.dart'; + +class AddressMapper extends ClassMapperBase
{ + AddressMapper._(); + + static AddressMapper? _instance; + static AddressMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = AddressMapper._()); + } + return _instance!; + } + + @override + final String id = 'Address'; + + static String _$email(Address v) => v.email; + static const Field _f$email = Field('email', _$email); + static String _$name(Address v) => v.name; + static const Field _f$name = Field('name', _$name); + + @override + final MappableFields
fields = const { + #email: _f$email, + #name: _f$name, + }; + + static Address _instantiate(DecodingData data) { + return Address(data.dec(_f$email), data.dec(_f$name)); + } + + @override + final Function instantiate = _instantiate; + + static Address fromMap(Map map) { + return ensureInitialized().decodeMap
(map); + } + + static Address fromJson(String json) { + return ensureInitialized().decodeJson
(json); + } +} + +mixin AddressMappable { + String toJson() { + return AddressMapper.ensureInitialized().encodeJson
( + this as Address, + ); + } + + Map toMap() { + return AddressMapper.ensureInitialized().encodeMap
( + this as Address, + ); + } + + AddressCopyWith get copyWith => + _AddressCopyWithImpl( + this as Address, + $identity, + $identity, + ); + @override + String toString() { + return AddressMapper.ensureInitialized().stringifyValue(this as Address); + } + + @override + bool operator ==(Object other) { + return AddressMapper.ensureInitialized().equalsValue( + this as Address, + other, + ); + } + + @override + int get hashCode { + return AddressMapper.ensureInitialized().hashValue(this as Address); + } +} + +extension AddressValueCopy<$R, $Out> on ObjectCopyWith<$R, Address, $Out> { + AddressCopyWith<$R, Address, $Out> get $asAddress => + $base.as((v, t, t2) => _AddressCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class AddressCopyWith<$R, $In extends Address, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({String? email, String? name}); + AddressCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _AddressCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, Address, $Out> + implements AddressCopyWith<$R, Address, $Out> { + _AddressCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase
$mapper = + AddressMapper.ensureInitialized(); + @override + $R call({String? email, String? name}) => $apply( + FieldCopyWithData({ + if (email != null) #email: email, + if (name != null) #name: name, + }), + ); + @override + Address $make(CopyWithData data) => Address( + data.get(#email, or: $value.email), + data.get(#name, or: $value.name), + ); + + @override + AddressCopyWith<$R2, Address, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _AddressCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1mailclient/lib/src/model/generated/mail.g.dart b/packages/lyon1mailclient/lib/src/model/generated/mail.g.dart deleted file mode 100644 index f2861bedb..000000000 --- a/packages/lyon1mailclient/lib/src/model/generated/mail.g.dart +++ /dev/null @@ -1,160 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../mail.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$MailCWProxy { - Mail subject(String subject); - - Mail sender(String sender); - - Mail excerpt(String excerpt); - - Mail isRead(bool isRead); - - Mail date(DateTime date); - - Mail body(String body); - - Mail id(int? id); - - Mail receiver(String receiver); - - Mail attachments(List attachments); - - Mail isFlagged(bool isFlagged); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Mail(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Mail(...).copyWith(id: 12, name: "My name") - /// ``` - Mail call({ - String subject, - String sender, - String excerpt, - bool isRead, - DateTime date, - String body, - int? id, - String receiver, - List attachments, - bool isFlagged, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfMail.copyWith(...)` or call `instanceOfMail.copyWith.fieldName(value)` for a single field. -class _$MailCWProxyImpl implements _$MailCWProxy { - const _$MailCWProxyImpl(this._value); - - final Mail _value; - - @override - Mail subject(String subject) => call(subject: subject); - - @override - Mail sender(String sender) => call(sender: sender); - - @override - Mail excerpt(String excerpt) => call(excerpt: excerpt); - - @override - Mail isRead(bool isRead) => call(isRead: isRead); - - @override - Mail date(DateTime date) => call(date: date); - - @override - Mail body(String body) => call(body: body); - - @override - Mail id(int? id) => call(id: id); - - @override - Mail receiver(String receiver) => call(receiver: receiver); - - @override - Mail attachments(List attachments) => call(attachments: attachments); - - @override - Mail isFlagged(bool isFlagged) => call(isFlagged: isFlagged); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Mail(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Mail(...).copyWith(id: 12, name: "My name") - /// ``` - Mail call({ - Object? subject = const $CopyWithPlaceholder(), - Object? sender = const $CopyWithPlaceholder(), - Object? excerpt = const $CopyWithPlaceholder(), - Object? isRead = const $CopyWithPlaceholder(), - Object? date = const $CopyWithPlaceholder(), - Object? body = const $CopyWithPlaceholder(), - Object? id = const $CopyWithPlaceholder(), - Object? receiver = const $CopyWithPlaceholder(), - Object? attachments = const $CopyWithPlaceholder(), - Object? isFlagged = const $CopyWithPlaceholder(), - }) { - return Mail( - subject: subject == const $CopyWithPlaceholder() || subject == null - ? _value.subject - // ignore: cast_nullable_to_non_nullable - : subject as String, - sender: sender == const $CopyWithPlaceholder() || sender == null - ? _value.sender - // ignore: cast_nullable_to_non_nullable - : sender as String, - excerpt: excerpt == const $CopyWithPlaceholder() || excerpt == null - ? _value.excerpt - // ignore: cast_nullable_to_non_nullable - : excerpt as String, - isRead: isRead == const $CopyWithPlaceholder() || isRead == null - ? _value.isRead - // ignore: cast_nullable_to_non_nullable - : isRead as bool, - date: date == const $CopyWithPlaceholder() || date == null - ? _value.date - // ignore: cast_nullable_to_non_nullable - : date as DateTime, - body: body == const $CopyWithPlaceholder() || body == null - ? _value.body - // ignore: cast_nullable_to_non_nullable - : body as String, - id: id == const $CopyWithPlaceholder() - ? _value.id - // ignore: cast_nullable_to_non_nullable - : id as int?, - receiver: receiver == const $CopyWithPlaceholder() || receiver == null - ? _value.receiver - // ignore: cast_nullable_to_non_nullable - : receiver as String, - attachments: - attachments == const $CopyWithPlaceholder() || attachments == null - ? _value.attachments - // ignore: cast_nullable_to_non_nullable - : attachments as List, - isFlagged: isFlagged == const $CopyWithPlaceholder() || isFlagged == null - ? _value.isFlagged - // ignore: cast_nullable_to_non_nullable - : isFlagged as bool, - ); - } -} - -extension $MailCopyWith on Mail { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfMail.copyWith(...)` or `instanceOfMail.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$MailCWProxy get copyWith => _$MailCWProxyImpl(this); -} diff --git a/packages/lyon1mailclient/lib/src/model/generated/mail.mapper.dart b/packages/lyon1mailclient/lib/src/model/generated/mail.mapper.dart new file mode 100644 index 000000000..dd92524d2 --- /dev/null +++ b/packages/lyon1mailclient/lib/src/model/generated/mail.mapper.dart @@ -0,0 +1,248 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../mail.dart'; + +class MailMapper extends ClassMapperBase { + MailMapper._(); + + static MailMapper? _instance; + static MailMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = MailMapper._()); + } + return _instance!; + } + + @override + final String id = 'Mail'; + + static String _$subject(Mail v) => v.subject; + static const Field _f$subject = Field('subject', _$subject); + static String _$sender(Mail v) => v.sender; + static const Field _f$sender = Field('sender', _$sender); + static String _$excerpt(Mail v) => v.excerpt; + static const Field _f$excerpt = Field('excerpt', _$excerpt); + static bool _$isRead(Mail v) => v.isRead; + static const Field _f$isRead = Field('isRead', _$isRead); + static DateTime _$date(Mail v) => v.date; + static const Field _f$date = Field('date', _$date); + static String _$body(Mail v) => v.body; + static const Field _f$body = Field('body', _$body); + static int? _$id(Mail v) => v.id; + static const Field _f$id = Field('id', _$id); + static String _$receiver(Mail v) => v.receiver; + static const Field _f$receiver = Field('receiver', _$receiver); + static List _$attachments(Mail v) => v.attachments; + static const Field> _f$attachments = Field( + 'attachments', + _$attachments, + ); + static bool _$isFlagged(Mail v) => v.isFlagged; + static const Field _f$isFlagged = Field('isFlagged', _$isFlagged); + static MimeMessage? _$rawMail(Mail v) => v.rawMail; + static const Field _f$rawMail = Field( + 'rawMail', + _$rawMail, + opt: true, + ); + static List _$attachmentsFiles(Mail v) => v.attachmentsFiles; + static const Field> _f$attachmentsFiles = Field( + 'attachmentsFiles', + _$attachmentsFiles, + opt: true, + def: const [], + ); + static bool _$removeTrackingImages(Mail v) => v.removeTrackingImages; + static const Field _f$removeTrackingImages = Field( + 'removeTrackingImages', + _$removeTrackingImages, + opt: true, + def: false, + ); + + @override + final MappableFields fields = const { + #subject: _f$subject, + #sender: _f$sender, + #excerpt: _f$excerpt, + #isRead: _f$isRead, + #date: _f$date, + #body: _f$body, + #id: _f$id, + #receiver: _f$receiver, + #attachments: _f$attachments, + #isFlagged: _f$isFlagged, + #rawMail: _f$rawMail, + #attachmentsFiles: _f$attachmentsFiles, + #removeTrackingImages: _f$removeTrackingImages, + }; + @override + final Iterable ignore = const ['rawMail', 'attachmentsFiles']; + + static Mail _instantiate(DecodingData data) { + return Mail( + subject: data.dec(_f$subject), + sender: data.dec(_f$sender), + excerpt: data.dec(_f$excerpt), + isRead: data.dec(_f$isRead), + date: data.dec(_f$date), + body: data.dec(_f$body), + id: data.dec(_f$id), + receiver: data.dec(_f$receiver), + attachments: data.dec(_f$attachments), + isFlagged: data.dec(_f$isFlagged), + rawMail: data.dec(_f$rawMail), + attachmentsFiles: data.dec(_f$attachmentsFiles), + removeTrackingImages: data.dec(_f$removeTrackingImages), + ); + } + + @override + final Function instantiate = _instantiate; + + static Mail fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static Mail fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin MailMappable { + String toJson() { + return MailMapper.ensureInitialized().encodeJson(this as Mail); + } + + Map toMap() { + return MailMapper.ensureInitialized().encodeMap(this as Mail); + } + + MailCopyWith get copyWith => + _MailCopyWithImpl(this as Mail, $identity, $identity); + @override + String toString() { + return MailMapper.ensureInitialized().stringifyValue(this as Mail); + } + + @override + bool operator ==(Object other) { + return MailMapper.ensureInitialized().equalsValue(this as Mail, other); + } + + @override + int get hashCode { + return MailMapper.ensureInitialized().hashValue(this as Mail); + } +} + +extension MailValueCopy<$R, $Out> on ObjectCopyWith<$R, Mail, $Out> { + MailCopyWith<$R, Mail, $Out> get $asMail => + $base.as((v, t, t2) => _MailCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class MailCopyWith<$R, $In extends Mail, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> get attachments; + ListCopyWith<$R, File, ObjectCopyWith<$R, File, File>> get attachmentsFiles; + $R call({ + String? subject, + String? sender, + String? excerpt, + bool? isRead, + DateTime? date, + String? body, + int? id, + String? receiver, + List? attachments, + bool? isFlagged, + MimeMessage? rawMail, + List? attachmentsFiles, + bool? removeTrackingImages, + }); + MailCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _MailCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, Mail, $Out> + implements MailCopyWith<$R, Mail, $Out> { + _MailCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = MailMapper.ensureInitialized(); + @override + ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> + get attachments => ListCopyWith( + $value.attachments, + (v, t) => ObjectCopyWith(v, $identity, t), + (v) => call(attachments: v), + ); + @override + ListCopyWith<$R, File, ObjectCopyWith<$R, File, File>> get attachmentsFiles => + ListCopyWith( + $value.attachmentsFiles, + (v, t) => ObjectCopyWith(v, $identity, t), + (v) => call(attachmentsFiles: v), + ); + @override + $R call({ + String? subject, + String? sender, + String? excerpt, + bool? isRead, + DateTime? date, + String? body, + Object? id = $none, + String? receiver, + List? attachments, + bool? isFlagged, + Object? rawMail = $none, + List? attachmentsFiles, + bool? removeTrackingImages, + }) => $apply( + FieldCopyWithData({ + if (subject != null) #subject: subject, + if (sender != null) #sender: sender, + if (excerpt != null) #excerpt: excerpt, + if (isRead != null) #isRead: isRead, + if (date != null) #date: date, + if (body != null) #body: body, + if (id != $none) #id: id, + if (receiver != null) #receiver: receiver, + if (attachments != null) #attachments: attachments, + if (isFlagged != null) #isFlagged: isFlagged, + if (rawMail != $none) #rawMail: rawMail, + if (attachmentsFiles != null) #attachmentsFiles: attachmentsFiles, + if (removeTrackingImages != null) + #removeTrackingImages: removeTrackingImages, + }), + ); + @override + Mail $make(CopyWithData data) => Mail( + subject: data.get(#subject, or: $value.subject), + sender: data.get(#sender, or: $value.sender), + excerpt: data.get(#excerpt, or: $value.excerpt), + isRead: data.get(#isRead, or: $value.isRead), + date: data.get(#date, or: $value.date), + body: data.get(#body, or: $value.body), + id: data.get(#id, or: $value.id), + receiver: data.get(#receiver, or: $value.receiver), + attachments: data.get(#attachments, or: $value.attachments), + isFlagged: data.get(#isFlagged, or: $value.isFlagged), + rawMail: data.get(#rawMail, or: $value.rawMail), + attachmentsFiles: data.get(#attachmentsFiles, or: $value.attachmentsFiles), + removeTrackingImages: data.get( + #removeTrackingImages, + or: $value.removeTrackingImages, + ), + ); + + @override + MailCopyWith<$R2, Mail, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _MailCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1mailclient/lib/src/model/generated/mail_box.g.dart b/packages/lyon1mailclient/lib/src/model/generated/mail_box.g.dart deleted file mode 100644 index dba18dd82..000000000 --- a/packages/lyon1mailclient/lib/src/model/generated/mail_box.g.dart +++ /dev/null @@ -1,83 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../mail_box.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$MailBoxCWProxy { - MailBox name(String name); - - MailBox emails(List emails); - - MailBox specialMailBox(SpecialMailBox? specialMailBox); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `MailBox(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// MailBox(...).copyWith(id: 12, name: "My name") - /// ``` - MailBox call({ - String name, - List emails, - SpecialMailBox? specialMailBox, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfMailBox.copyWith(...)` or call `instanceOfMailBox.copyWith.fieldName(value)` for a single field. -class _$MailBoxCWProxyImpl implements _$MailBoxCWProxy { - const _$MailBoxCWProxyImpl(this._value); - - final MailBox _value; - - @override - MailBox name(String name) => call(name: name); - - @override - MailBox emails(List emails) => call(emails: emails); - - @override - MailBox specialMailBox(SpecialMailBox? specialMailBox) => - call(specialMailBox: specialMailBox); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `MailBox(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// MailBox(...).copyWith(id: 12, name: "My name") - /// ``` - MailBox call({ - Object? name = const $CopyWithPlaceholder(), - Object? emails = const $CopyWithPlaceholder(), - Object? specialMailBox = const $CopyWithPlaceholder(), - }) { - return MailBox( - name: name == const $CopyWithPlaceholder() || name == null - ? _value.name - // ignore: cast_nullable_to_non_nullable - : name as String, - emails: emails == const $CopyWithPlaceholder() || emails == null - ? _value.emails - // ignore: cast_nullable_to_non_nullable - : emails as List, - specialMailBox: specialMailBox == const $CopyWithPlaceholder() - ? _value.specialMailBox - // ignore: cast_nullable_to_non_nullable - : specialMailBox as SpecialMailBox?, - ); - } -} - -extension $MailBoxCopyWith on MailBox { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfMailBox.copyWith(...)` or `instanceOfMailBox.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$MailBoxCWProxy get copyWith => _$MailBoxCWProxyImpl(this); -} diff --git a/packages/lyon1mailclient/lib/src/model/generated/mail_box.mapper.dart b/packages/lyon1mailclient/lib/src/model/generated/mail_box.mapper.dart new file mode 100644 index 000000000..5de778685 --- /dev/null +++ b/packages/lyon1mailclient/lib/src/model/generated/mail_box.mapper.dart @@ -0,0 +1,207 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../mail_box.dart'; + +class SpecialMailBoxMapper extends EnumMapper { + SpecialMailBoxMapper._(); + + static SpecialMailBoxMapper? _instance; + static SpecialMailBoxMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = SpecialMailBoxMapper._()); + } + return _instance!; + } + + static SpecialMailBox fromValue(dynamic value) { + ensureInitialized(); + return MapperContainer.globals.fromValue(value); + } + + @override + SpecialMailBox decode(dynamic value) { + switch (value) { + case r'inbox': + return SpecialMailBox.inbox; + case r'sent': + return SpecialMailBox.sent; + case r'trash': + return SpecialMailBox.trash; + case r'flagged': + return SpecialMailBox.flagged; + case r'archive': + return SpecialMailBox.archive; + default: + throw MapperException.unknownEnumValue(value); + } + } + + @override + dynamic encode(SpecialMailBox self) { + switch (self) { + case SpecialMailBox.inbox: + return r'inbox'; + case SpecialMailBox.sent: + return r'sent'; + case SpecialMailBox.trash: + return r'trash'; + case SpecialMailBox.flagged: + return r'flagged'; + case SpecialMailBox.archive: + return r'archive'; + } + } +} + +extension SpecialMailBoxMapperExtension on SpecialMailBox { + String toValue() { + SpecialMailBoxMapper.ensureInitialized(); + return MapperContainer.globals.toValue(this) as String; + } +} + +class MailBoxMapper extends ClassMapperBase { + MailBoxMapper._(); + + static MailBoxMapper? _instance; + static MailBoxMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = MailBoxMapper._()); + MailMapper.ensureInitialized(); + SpecialMailBoxMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'MailBox'; + + static String _$name(MailBox v) => v.name; + static const Field _f$name = Field('name', _$name); + static List _$emails(MailBox v) => v.emails; + static const Field> _f$emails = Field('emails', _$emails); + static SpecialMailBox? _$specialMailBox(MailBox v) => v.specialMailBox; + static const Field _f$specialMailBox = Field( + 'specialMailBox', + _$specialMailBox, + opt: true, + ); + + @override + final MappableFields fields = const { + #name: _f$name, + #emails: _f$emails, + #specialMailBox: _f$specialMailBox, + }; + + static MailBox _instantiate(DecodingData data) { + return MailBox( + name: data.dec(_f$name), + emails: data.dec(_f$emails), + specialMailBox: data.dec(_f$specialMailBox), + ); + } + + @override + final Function instantiate = _instantiate; + + static MailBox fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static MailBox fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin MailBoxMappable { + String toJson() { + return MailBoxMapper.ensureInitialized().encodeJson( + this as MailBox, + ); + } + + Map toMap() { + return MailBoxMapper.ensureInitialized().encodeMap( + this as MailBox, + ); + } + + MailBoxCopyWith get copyWith => + _MailBoxCopyWithImpl( + this as MailBox, + $identity, + $identity, + ); + @override + String toString() { + return MailBoxMapper.ensureInitialized().stringifyValue(this as MailBox); + } + + @override + bool operator ==(Object other) { + return MailBoxMapper.ensureInitialized().equalsValue( + this as MailBox, + other, + ); + } + + @override + int get hashCode { + return MailBoxMapper.ensureInitialized().hashValue(this as MailBox); + } +} + +extension MailBoxValueCopy<$R, $Out> on ObjectCopyWith<$R, MailBox, $Out> { + MailBoxCopyWith<$R, MailBox, $Out> get $asMailBox => + $base.as((v, t, t2) => _MailBoxCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class MailBoxCopyWith<$R, $In extends MailBox, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, Mail, MailCopyWith<$R, Mail, Mail>> get emails; + $R call({String? name, List? emails, SpecialMailBox? specialMailBox}); + MailBoxCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _MailBoxCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, MailBox, $Out> + implements MailBoxCopyWith<$R, MailBox, $Out> { + _MailBoxCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + MailBoxMapper.ensureInitialized(); + @override + ListCopyWith<$R, Mail, MailCopyWith<$R, Mail, Mail>> get emails => + ListCopyWith( + $value.emails, + (v, t) => v.copyWith.$chain(t), + (v) => call(emails: v), + ); + @override + $R call({String? name, List? emails, Object? specialMailBox = $none}) => + $apply( + FieldCopyWithData({ + if (name != null) #name: name, + if (emails != null) #emails: emails, + if (specialMailBox != $none) #specialMailBox: specialMailBox, + }), + ); + @override + MailBox $make(CopyWithData data) => MailBox( + name: data.get(#name, or: $value.name), + emails: data.get(#emails, or: $value.emails), + specialMailBox: data.get(#specialMailBox, or: $value.specialMailBox), + ); + + @override + MailBoxCopyWith<$R2, MailBox, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _MailBoxCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1mailclient/lib/src/model/generated/mail_box_list.g.dart b/packages/lyon1mailclient/lib/src/model/generated/mail_box_list.g.dart deleted file mode 100644 index 4c6d9bb10..000000000 --- a/packages/lyon1mailclient/lib/src/model/generated/mail_box_list.g.dart +++ /dev/null @@ -1,60 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../mail_box_list.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$MailBoxListCWProxy { - MailBoxList mailBoxes(List mailBoxes); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `MailBoxList(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// MailBoxList(...).copyWith(id: 12, name: "My name") - /// ``` - MailBoxList call({ - List mailBoxes, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfMailBoxList.copyWith(...)` or call `instanceOfMailBoxList.copyWith.fieldName(value)` for a single field. -class _$MailBoxListCWProxyImpl implements _$MailBoxListCWProxy { - const _$MailBoxListCWProxyImpl(this._value); - - final MailBoxList _value; - - @override - MailBoxList mailBoxes(List mailBoxes) => call(mailBoxes: mailBoxes); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `MailBoxList(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// MailBoxList(...).copyWith(id: 12, name: "My name") - /// ``` - MailBoxList call({ - Object? mailBoxes = const $CopyWithPlaceholder(), - }) { - return MailBoxList( - mailBoxes: mailBoxes == const $CopyWithPlaceholder() || mailBoxes == null - ? _value.mailBoxes - // ignore: cast_nullable_to_non_nullable - : mailBoxes as List, - ); - } -} - -extension $MailBoxListCopyWith on MailBoxList { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfMailBoxList.copyWith(...)` or `instanceOfMailBoxList.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$MailBoxListCWProxy get copyWith => _$MailBoxListCWProxyImpl(this); -} diff --git a/packages/lyon1mailclient/lib/src/model/generated/mail_box_list.mapper.dart b/packages/lyon1mailclient/lib/src/model/generated/mail_box_list.mapper.dart new file mode 100644 index 000000000..b0c98ce93 --- /dev/null +++ b/packages/lyon1mailclient/lib/src/model/generated/mail_box_list.mapper.dart @@ -0,0 +1,131 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../mail_box_list.dart'; + +class MailBoxListMapper extends ClassMapperBase { + MailBoxListMapper._(); + + static MailBoxListMapper? _instance; + static MailBoxListMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = MailBoxListMapper._()); + MailBoxMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'MailBoxList'; + + static List _$mailBoxes(MailBoxList v) => v.mailBoxes; + static const Field> _f$mailBoxes = Field( + 'mailBoxes', + _$mailBoxes, + ); + + @override + final MappableFields fields = const {#mailBoxes: _f$mailBoxes}; + + static MailBoxList _instantiate(DecodingData data) { + return MailBoxList(mailBoxes: data.dec(_f$mailBoxes)); + } + + @override + final Function instantiate = _instantiate; + + static MailBoxList fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static MailBoxList fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin MailBoxListMappable { + String toJson() { + return MailBoxListMapper.ensureInitialized().encodeJson( + this as MailBoxList, + ); + } + + Map toMap() { + return MailBoxListMapper.ensureInitialized().encodeMap( + this as MailBoxList, + ); + } + + MailBoxListCopyWith get copyWith => + _MailBoxListCopyWithImpl( + this as MailBoxList, + $identity, + $identity, + ); + @override + String toString() { + return MailBoxListMapper.ensureInitialized().stringifyValue( + this as MailBoxList, + ); + } + + @override + bool operator ==(Object other) { + return MailBoxListMapper.ensureInitialized().equalsValue( + this as MailBoxList, + other, + ); + } + + @override + int get hashCode { + return MailBoxListMapper.ensureInitialized().hashValue(this as MailBoxList); + } +} + +extension MailBoxListValueCopy<$R, $Out> + on ObjectCopyWith<$R, MailBoxList, $Out> { + MailBoxListCopyWith<$R, MailBoxList, $Out> get $asMailBoxList => + $base.as((v, t, t2) => _MailBoxListCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class MailBoxListCopyWith<$R, $In extends MailBoxList, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, MailBox, MailBoxCopyWith<$R, MailBox, MailBox>> + get mailBoxes; + $R call({List? mailBoxes}); + MailBoxListCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _MailBoxListCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, MailBoxList, $Out> + implements MailBoxListCopyWith<$R, MailBoxList, $Out> { + _MailBoxListCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + MailBoxListMapper.ensureInitialized(); + @override + ListCopyWith<$R, MailBox, MailBoxCopyWith<$R, MailBox, MailBox>> + get mailBoxes => ListCopyWith( + $value.mailBoxes, + (v, t) => v.copyWith.$chain(t), + (v) => call(mailBoxes: v), + ); + @override + $R call({List? mailBoxes}) => + $apply(FieldCopyWithData({if (mailBoxes != null) #mailBoxes: mailBoxes})); + @override + MailBoxList $make(CopyWithData data) => + MailBoxList(mailBoxes: data.get(#mailBoxes, or: $value.mailBoxes)); + + @override + MailBoxListCopyWith<$R2, MailBoxList, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _MailBoxListCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1mailclient/lib/src/model/mail.dart b/packages/lyon1mailclient/lib/src/model/mail.dart index 03c4a150d..aadcd08a7 100755 --- a/packages/lyon1mailclient/lib/src/model/mail.dart +++ b/packages/lyon1mailclient/lib/src/model/mail.dart @@ -2,18 +2,20 @@ import 'dart:io'; import 'dart:math'; import 'dart:typed_data'; -import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:enough_mail/enough_mail.dart'; import 'package:enough_mail_html/enough_mail_html.dart'; -import 'package:equatable/equatable.dart'; import 'package:lyon1mailclient/src/config/config.dart'; -part 'generated/mail.g.dart'; +part 'generated/mail.mapper.dart'; -@CopyWith() +@MappableClass(ignore: ['rawMail', 'attachmentsFiles']) // ignore: must_be_immutable -class Mail extends Equatable { - late final MimeMessage? _rawMail; +class Mail with MailMappable { + late final MimeMessage? rawMail; // Changement: plus de nullable + + // Ajout pour satisfaire dart_mappable (non utilisé ailleurs) + late final bool removeTrackingImages; late final String subject; late final String sender; @@ -26,17 +28,16 @@ class Mail extends Equatable { late final String receiver; late final List attachments; - late List _attachmentsFiles; + late List attachmentsFiles; - Mail.fromRaw(MimeMessage rawMail, {bool removeTrackingImages = false}) { - _rawMail = rawMail; - subject = rawMail.decodeSubject() ?? ""; - sender = rawMail.fromEmail ?? "n/a"; - isRead = rawMail.hasFlag(MessageFlags.seen); - date = rawMail.decodeDate() ?? DateTime.now(); - isFlagged = rawMail.isFlagged; + Mail.fromRaw(MimeMessage this.rawMail, {this.removeTrackingImages = false}) { + subject = rawMail!.decodeSubject() ?? ""; + sender = rawMail!.fromEmail ?? "n/a"; + isRead = rawMail!.hasFlag(MessageFlags.seen); + date = rawMail!.decodeDate() ?? DateTime.now(); + isFlagged = rawMail!.isFlagged; - body = rawMail.transformToHtml( + body = rawMail!.transformToHtml( blockExternalImages: removeTrackingImages, emptyMessageText: 'Le message est vide', enableDarkMode: false, @@ -51,13 +52,13 @@ class Mail extends Equatable { .replaceAll("\n", "") .length, 100)); - id = rawMail.sequenceId; - receiver = rawMail.to! + id = rawMail!.sequenceId; + receiver = rawMail!.to! .map((e) => e.email) .toList() .join(", "); //.substring(0, receiver.length - 2); - if (rawMail.hasAttachments()) { - attachments = rawMail.allPartsFlat + if (rawMail!.hasAttachments()) { + attachments = rawMail!.allPartsFlat .where((element) => element.decodeFileName() != null) .map((e) => e.decodeFileName()) .toList() @@ -65,9 +66,10 @@ class Mail extends Equatable { } else { attachments = []; } - _attachmentsFiles = []; + attachmentsFiles = []; } + @MappableConstructor() Mail({ required this.subject, required this.sender, @@ -79,33 +81,16 @@ class Mail extends Equatable { required this.receiver, required this.attachments, required this.isFlagged, - }) { - _rawMail = null; - _attachmentsFiles = []; - } - - Mail.withAttachments({ - required this.subject, - required this.sender, - required this.excerpt, - required this.isRead, - required this.date, - required this.body, - required this.id, - required this.receiver, - required this.attachments, - required this.isFlagged, - List attachmentsFiles = const [], - }) { - _rawMail = null; - _attachmentsFiles = attachmentsFiles; - } + this.rawMail, + this.attachmentsFiles = const [], + this.removeTrackingImages = false, // Ajouté + }); Mail.forSending({ required this.subject, required this.body, required this.receiver, - List attachmentsFiles = const [], + this.attachmentsFiles = const [], }) { sender = ""; excerpt = HtmlToPlainTextConverter.convert(body) @@ -120,10 +105,11 @@ class Mail extends Equatable { isRead = false; date = DateTime.now(); id = null; - attachments = _attachmentsFiles.map((e) => e.path.split("/").last).toList(); + attachments = attachmentsFiles.map((e) => e.path.split("/").last).toList(); isFlagged = false; - _rawMail = null; - _attachmentsFiles = attachmentsFiles; + // rawMail n'est pas utilisé ici, on met une valeur fictive + rawMail = MimeMessage(); + removeTrackingImages = false; } Mail.forReplying({ @@ -146,10 +132,11 @@ class Mail extends Equatable { isRead = false; date = DateTime.now(); id = null; - attachments = _attachmentsFiles.map((e) => e.path.split("/").last).toList(); + attachments = attachmentsFiles.map((e) => e.path.split("/").last).toList(); isFlagged = false; - _rawMail = null; - _attachmentsFiles = attachmentsFiles; + rawMail = MimeMessage(); + removeTrackingImages = false; + attachmentsFiles = attachmentsFiles; } Mail.forForwarding({ @@ -172,10 +159,11 @@ class Mail extends Equatable { isRead = false; date = DateTime.now(); id = null; - attachments = _attachmentsFiles.map((e) => e.path.split("/").last).toList(); + attachments = attachmentsFiles.map((e) => e.path.split("/").last).toList(); isFlagged = false; - _rawMail = null; - _attachmentsFiles = attachmentsFiles; + rawMail = MimeMessage(); + removeTrackingImages = false; + attachmentsFiles = attachmentsFiles; } /* @@ -189,8 +177,7 @@ class Mail extends Equatable { */ List getAttachment(String fileName) { - assert(_rawMail != null); - final List parts = _rawMail!.allPartsFlat; + final List parts = rawMail!.allPartsFlat; for (final MimePart mp in parts) { if (mp.decodeFileName() == fileName) { Uint8List? content = mp.decodeContentBinary(); @@ -228,25 +215,4 @@ class Mail extends Equatable { return "$body\n$themeScript"; } } - - MimeMessage? get rawMail => _rawMail; - - List get attachmentsFiles => _attachmentsFiles; - - @override - List get props => [ - subject, - sender, - excerpt, - body, - id, - isRead, - isFlagged, - date, - receiver, - attachments, - ]; - - @override - bool? get stringify => true; } diff --git a/packages/lyon1mailclient/lib/src/model/mail_box.dart b/packages/lyon1mailclient/lib/src/model/mail_box.dart index d88727234..5887e1fd7 100644 --- a/packages/lyon1mailclient/lib/src/model/mail_box.dart +++ b/packages/lyon1mailclient/lib/src/model/mail_box.dart @@ -1,13 +1,12 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:enough_mail/enough_mail.dart' as enough_mail; import 'package:enough_mail/highlevel.dart'; -import 'package:equatable/equatable.dart'; import 'package:lyon1mailclient/lyon1mailclient.dart'; -part 'generated/mail_box.g.dart'; +part 'generated/mail_box.mapper.dart'; -@CopyWith() -class MailBox extends Equatable { +@MappableClass() +class MailBox with MailBoxMappable { late final String name; late final SpecialMailBox? specialMailBox; late final List emails; @@ -68,14 +67,9 @@ class MailBox extends Equatable { specialMailBox = null; } } - - @override - List get props => [name, specialMailBox, emails]; - - @override - bool? get stringify => true; } +@MappableEnum() enum SpecialMailBox { inbox, sent, diff --git a/packages/lyon1mailclient/lib/src/model/mail_box_list.dart b/packages/lyon1mailclient/lib/src/model/mail_box_list.dart index d54a8fef9..f27b3bb46 100644 --- a/packages/lyon1mailclient/lib/src/model/mail_box_list.dart +++ b/packages/lyon1mailclient/lib/src/model/mail_box_list.dart @@ -1,20 +1,13 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1mailclient/lyon1mailclient.dart'; -part 'generated/mail_box_list.g.dart'; +part 'generated/mail_box_list.mapper.dart'; -@CopyWith() -class MailBoxList extends Equatable { +@MappableClass() +class MailBoxList with MailBoxListMappable { late final List mailBoxes; MailBoxList({ required this.mailBoxes, }); - - @override - List get props => [mailBoxes]; - - @override - bool? get stringify => true; } diff --git a/packages/lyon1mailclient/lib/src/sembast_helper.dart b/packages/lyon1mailclient/lib/src/sembast_helper.dart new file mode 100644 index 000000000..570186a0e --- /dev/null +++ b/packages/lyon1mailclient/lib/src/sembast_helper.dart @@ -0,0 +1,35 @@ +import 'dart:io'; + +import 'package:lyon1mailclient/lyon1mailclient.dart'; +import 'package:path/path.dart'; +import 'package:sembast/sembast_io.dart'; + +class SembastActionCache { + static Database? _db; + static final _store = StoreRef>('actions'); + static const String _key = 'cache0'; + + static Future _openDb() async { + if (_db != null) return _db!; + final dbPath = join(Directory.current.path, 'actions.db'); + _db = await databaseFactoryIo.openDatabase(dbPath); + return _db!; + } + + static Future getActions() async { + final db = await _openDb(); + final map = await _store.record(_key).get(db); + if (map == null) return ActionList(action: []); + return ActionListMapper.fromMap(map); + } + + static Future putActions(ActionList actions) async { + final db = await _openDb(); + await _store.record(_key).put(db, actions.toMap()); + } + + static Future clearActions() async { + final db = await _openDb(); + await _store.record(_key).delete(db); + } +} diff --git a/packages/lyon1mailclient/pubspec.yaml b/packages/lyon1mailclient/pubspec.yaml index 2bfb3f255..7d799c9b1 100755 --- a/packages/lyon1mailclient/pubspec.yaml +++ b/packages/lyon1mailclient/pubspec.yaml @@ -12,21 +12,19 @@ dev_dependencies: lints: ^6.0.0 test: ^1.16.0 build_runner: ^2.2.0 - hive_ce_generator: ^1.9.2 - copy_with_extension_gen: ^9.1.0 + dart_mappable_builder: + git: + url: https://github.com/hatch01/dart_mappable.git + path: packages/dart_mappable_builder dependencies: - #enough_mail: - # git: https://github.com/hatch01/enough_mail.git - #enough_mail_html: - #git: https://github.com/hatch01/enough_mail_html.git - hive_ce: ^2.2.3 requests_plus: ^4.8.3 - copy_with_extension: ^9.1.0 - equatable: ^2.0.5 enough_mail: ^2.1.2 enough_mail_html: ^2.0.1 collection: ^1.18.0 + dart_mappable: ^4.6.0 # overwritten in pubspec_overrides.yaml + sembast: ^3.8.5+1 + path: ^1.9.1 dependency_overrides: http: ^1.1.0 # needed for enough_mail diff --git a/packages/lyon1mailclient/test/lyon1mail_test.dart b/packages/lyon1mailclient/test/lyon1mail_test.dart index 14be3dc69..1d463df94 100755 --- a/packages/lyon1mailclient/test/lyon1mail_test.dart +++ b/packages/lyon1mailclient/test/lyon1mail_test.dart @@ -34,7 +34,6 @@ void main() { if (username.isEmpty || password.isEmpty) { fail("username or password were empty. check your envt variables"); } - Lyon1MailClient.registerAdapters(); mailClient = Lyon1MailClient(username, password); mailClient.cleanActions(); await mailClient.login(); diff --git a/packages/lyon1tomussclient/build.yaml b/packages/lyon1tomussclient/build.yaml index d6160f7dc..3ff8f90ad 100644 --- a/packages/lyon1tomussclient/build.yaml +++ b/packages/lyon1tomussclient/build.yaml @@ -1,9 +1,11 @@ targets: $default: builders: - source_gen|combining_builder: - generate_for: - - lib/**.dart + # only to resolve build_runner conflicts + dart_mappable_builder: options: build_extensions: - 'lib/{{path}}/{{file}}.dart': 'lib/{{path}}/generated/{{file}}.g.dart' \ No newline at end of file + 'lib/{{path}}/{{file}}.dart': + - 'lib/{{path}}/generated/{{file}}.mapper.dart' + - 'lib/{{path}}/generated/{{file}}.init.dart' + diff --git a/packages/lyon1tomussclient/lib/hive/generated/hive_adapters.g.dart b/packages/lyon1tomussclient/lib/hive/generated/hive_adapters.g.dart deleted file mode 100644 index 33bdc59b4..000000000 --- a/packages/lyon1tomussclient/lib/hive/generated/hive_adapters.g.dart +++ /dev/null @@ -1,712 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../hive_adapters.dart'; - -// ************************************************************************** -// AdaptersGenerator -// ************************************************************************** - -class GradeAdapter extends TypeAdapter { - @override - final typeId = 9; - - @override - Grade read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return Grade( - title: fields[100] as String, - author: fields[101] as String, - date: fields[102] as DateTime?, - position: (fields[103] as num).toDouble(), - numerator: fields[2] == null ? 0.0 : (fields[2] as num).toDouble(), - denominator: fields[3] == null ? 20.0 : (fields[3] as num).toDouble(), - rank: fields[4] == null ? -1 : (fields[4] as num).toInt(), - average: fields[5] == null ? 10.0 : (fields[5] as num).toDouble(), - mediane: fields[6] == null ? 10.0 : (fields[6] as num).toDouble(), - isValid: fields[8] == null ? false : fields[8] as bool, - groupeSize: fields[7] == null ? -1 : (fields[7] as num).toInt(), - children: - fields[9] == null ? const [] : (fields[9] as List).cast(), - coef: fields[10] == null ? 1.0 : (fields[10] as num).toDouble(), - ); - } - - @override - void write(BinaryWriter writer, Grade obj) { - writer - ..writeByte(13) - ..writeByte(2) - ..write(obj.numerator) - ..writeByte(3) - ..write(obj.denominator) - ..writeByte(4) - ..write(obj.rank) - ..writeByte(5) - ..write(obj.average) - ..writeByte(6) - ..write(obj.mediane) - ..writeByte(7) - ..write(obj.groupeSize) - ..writeByte(8) - ..write(obj.isValid) - ..writeByte(9) - ..write(obj.children) - ..writeByte(10) - ..write(obj.coef) - ..writeByte(100) - ..write(obj.title) - ..writeByte(101) - ..write(obj.author) - ..writeByte(102) - ..write(obj.date) - ..writeByte(103) - ..write(obj.position); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is GradeAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class TeachingUnitAdapter extends TypeAdapter { - @override - final typeId = 10; - - @override - TeachingUnit read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return TeachingUnit( - title: fields[0] == null ? "" : fields[0] as String, - masters: - fields[1] == null ? const [] : (fields[1] as List).cast(), - grades: fields[2] == null ? const [] : (fields[2] as List).cast(), - textValues: - fields[6] == null ? const [] : (fields[6] as List).cast(), - enumerations: fields[7] == null - ? const [] - : (fields[7] as List).cast(), - presences: - fields[8] == null ? const [] : (fields[8] as List).cast(), - stageCodes: - fields[9] == null ? const [] : (fields[9] as List).cast(), - uploads: - fields[10] == null ? const [] : (fields[10] as List).cast(), - urls: fields[11] == null ? const [] : (fields[11] as List).cast(), - ticket: fields[12] == null ? "" : fields[12] as String, - ue: fields[13] == null ? "" : fields[13] as String, - ); - } - - @override - void write(BinaryWriter writer, TeachingUnit obj) { - writer - ..writeByte(11) - ..writeByte(0) - ..write(obj.title) - ..writeByte(1) - ..write(obj.masters) - ..writeByte(2) - ..write(obj.grades) - ..writeByte(6) - ..write(obj.textValues) - ..writeByte(7) - ..write(obj.enumerations) - ..writeByte(8) - ..write(obj.presences) - ..writeByte(9) - ..write(obj.stageCodes) - ..writeByte(10) - ..write(obj.uploads) - ..writeByte(11) - ..write(obj.urls) - ..writeByte(12) - ..write(obj.ticket) - ..writeByte(13) - ..write(obj.ue); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is TeachingUnitAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class TeachingUnitListAdapter extends TypeAdapter { - @override - final typeId = 11; - - @override - TeachingUnitList read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return TeachingUnitList( - (fields[0] as List).cast(), - (fields[1] as num).toInt(), - ); - } - - @override - void write(BinaryWriter writer, TeachingUnitList obj) { - writer - ..writeByte(2) - ..writeByte(0) - ..write(obj.teachingUnitModels) - ..writeByte(1) - ..write(obj.semesterIndex); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is TeachingUnitListAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class TeacherAdapter extends TypeAdapter { - @override - final typeId = 12; - - @override - Teacher read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return Teacher( - name: fields[0] == null ? "" : fields[0] as String, - email: fields[1] == null ? "" : fields[1] as String, - ); - } - - @override - void write(BinaryWriter writer, Teacher obj) { - writer - ..writeByte(2) - ..writeByte(0) - ..write(obj.name) - ..writeByte(1) - ..write(obj.email); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is TeacherAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class SemesterAdapter extends TypeAdapter { - @override - final typeId = 13; - - @override - Semester read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return Semester( - title: fields[0] == null ? "" : fields[0] as String, - url: fields[1] == null ? "" : fields[1] as String, - ); - } - - @override - void write(BinaryWriter writer, Semester obj) { - writer - ..writeByte(2) - ..writeByte(0) - ..write(obj.title) - ..writeByte(1) - ..write(obj.url); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is SemesterAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class SemesterListAdapter extends TypeAdapter { - @override - final typeId = 14; - - @override - SemesterList read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return SemesterList( - (fields[0] as List).cast(), - currentSemesterIndex: fields[1] == null ? 0 : (fields[1] as num).toInt(), - ); - } - - @override - void write(BinaryWriter writer, SemesterList obj) { - writer - ..writeByte(2) - ..writeByte(0) - ..write(obj.semestres) - ..writeByte(1) - ..write(obj.currentSemesterIndex); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is SemesterListAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class EnumerationAdapter extends TypeAdapter { - @override - final typeId = 25; - - @override - Enumeration read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return Enumeration( - title: fields[100] as String, - author: fields[101] as String, - date: fields[102] as DateTime?, - position: (fields[103] as num).toDouble(), - value: fields[1] as String?, - values: fields[2] == null ? const [] : (fields[2] as List).cast(), - comment: fields[4] == null ? "" : fields[4] as String, - theId: fields[6] == null ? "" : fields[6] as String, - lineId: fields[7] == null ? "" : fields[7] as String, - ue: fields[8] == null ? "" : fields[8] as String, - semester: fields[9] == null ? "" : fields[9] as String, - year: fields[10] == null ? "" : fields[10] as String, - modifiable: fields[12] == null ? true : fields[12] as bool, - ); - } - - @override - void write(BinaryWriter writer, Enumeration obj) { - writer - ..writeByte(13) - ..writeByte(1) - ..write(obj.value) - ..writeByte(2) - ..write(obj.values) - ..writeByte(4) - ..write(obj.comment) - ..writeByte(6) - ..write(obj.theId) - ..writeByte(7) - ..write(obj.lineId) - ..writeByte(8) - ..write(obj.ue) - ..writeByte(9) - ..write(obj.semester) - ..writeByte(10) - ..write(obj.year) - ..writeByte(12) - ..write(obj.modifiable) - ..writeByte(100) - ..write(obj.title) - ..writeByte(101) - ..write(obj.author) - ..writeByte(102) - ..write(obj.date) - ..writeByte(103) - ..write(obj.position); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is EnumerationAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class PresenceColorAdapter extends TypeAdapter { - @override - final typeId = 26; - - @override - PresenceColor read(BinaryReader reader) { - switch (reader.readByte()) { - case 0: - return PresenceColor.green; - case 1: - return PresenceColor.red; - case 2: - return PresenceColor.unset; - default: - return PresenceColor.green; - } - } - - @override - void write(BinaryWriter writer, PresenceColor obj) { - switch (obj) { - case PresenceColor.green: - writer.writeByte(0); - case PresenceColor.red: - writer.writeByte(1); - case PresenceColor.unset: - writer.writeByte(2); - } - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is PresenceColorAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class PresenceAdapter extends TypeAdapter { - @override - final typeId = 27; - - @override - Presence read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return Presence( - title: fields[100] as String, - author: fields[101] as String, - date: fields[102] as DateTime?, - position: (fields[103] as num).toDouble(), - value: fields[1] == null ? "" : fields[1] as String, - emptyIs: fields[3] == null ? "" : fields[3] as String?, - color: - fields[4] == null ? PresenceColor.unset : fields[4] as PresenceColor, - visibilityDate: fields[5] as DateTime?, - visible: fields[6] as bool?, - ); - } - - @override - void write(BinaryWriter writer, Presence obj) { - writer - ..writeByte(9) - ..writeByte(1) - ..write(obj.value) - ..writeByte(3) - ..write(obj.emptyIs) - ..writeByte(4) - ..write(obj.color) - ..writeByte(5) - ..write(obj.visibilityDate) - ..writeByte(6) - ..write(obj.visible) - ..writeByte(100) - ..write(obj.title) - ..writeByte(101) - ..write(obj.author) - ..writeByte(102) - ..write(obj.date) - ..writeByte(103) - ..write(obj.position); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is PresenceAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class StageCodeAdapter extends TypeAdapter { - @override - final typeId = 28; - - @override - StageCode read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return StageCode( - title: fields[100] as String, - author: fields[101] as String, - date: fields[102] as DateTime?, - position: (fields[103] as num).toDouble(), - value: fields[1] == null ? "" : fields[1] as String, - ); - } - - @override - void write(BinaryWriter writer, StageCode obj) { - writer - ..writeByte(5) - ..writeByte(1) - ..write(obj.value) - ..writeByte(100) - ..write(obj.title) - ..writeByte(101) - ..write(obj.author) - ..writeByte(102) - ..write(obj.date) - ..writeByte(103) - ..write(obj.position); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is StageCodeAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class TomussTextAdapter extends TypeAdapter { - @override - final typeId = 29; - - @override - TomussText read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return TomussText( - title: fields[100] as String, - author: fields[101] as String, - date: fields[102] as DateTime?, - position: (fields[103] as num).toDouble(), - value: fields[1] == null ? "" : fields[1] as String, - comment: fields[3] == null ? "" : fields[3] as String, - isValidText: fields[4] == null ? false : fields[4] as bool, - isHidden: fields[6] == null ? false : fields[6] as bool, - theId: fields[7] == null ? "" : fields[7] as String, - ); - } - - @override - void write(BinaryWriter writer, TomussText obj) { - writer - ..writeByte(9) - ..writeByte(1) - ..write(obj.value) - ..writeByte(3) - ..write(obj.comment) - ..writeByte(4) - ..write(obj.isValidText) - ..writeByte(6) - ..write(obj.isHidden) - ..writeByte(7) - ..write(obj.theId) - ..writeByte(100) - ..write(obj.title) - ..writeByte(101) - ..write(obj.author) - ..writeByte(102) - ..write(obj.date) - ..writeByte(103) - ..write(obj.position); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is TomussTextAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class UploadAdapter extends TypeAdapter { - @override - final typeId = 30; - - @override - Upload read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return Upload( - title: fields[100] as String, - author: fields[101] as String, - date: fields[102] as DateTime?, - position: (fields[103] as num).toDouble(), - comment: fields[2] == null ? "" : fields[2] as String, - uploadMax: fields[3] == null ? 0 : (fields[3] as num).toInt(), - fileUrl: fields[5] == null ? "" : fields[5] as String, - ); - } - - @override - void write(BinaryWriter writer, Upload obj) { - writer - ..writeByte(7) - ..writeByte(2) - ..write(obj.comment) - ..writeByte(3) - ..write(obj.uploadMax) - ..writeByte(5) - ..write(obj.fileUrl) - ..writeByte(100) - ..write(obj.title) - ..writeByte(101) - ..write(obj.author) - ..writeByte(102) - ..write(obj.date) - ..writeByte(103) - ..write(obj.position); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is UploadAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class URLAdapter extends TypeAdapter { - @override - final typeId = 31; - - @override - URL read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return URL( - title: fields[100] as String, - author: fields[101] as String, - date: fields[102] as DateTime?, - position: (fields[103] as num).toDouble(), - value: fields[2] == null ? "" : fields[2] as String, - isModifiable: fields[3] == null ? false : fields[3] as bool, - ); - } - - @override - void write(BinaryWriter writer, URL obj) { - writer - ..writeByte(6) - ..writeByte(2) - ..write(obj.value) - ..writeByte(3) - ..write(obj.isModifiable) - ..writeByte(100) - ..write(obj.title) - ..writeByte(101) - ..write(obj.author) - ..writeByte(102) - ..write(obj.date) - ..writeByte(103) - ..write(obj.position); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is URLAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class StudentAdapter extends TypeAdapter { - @override - final typeId = 43; - - @override - Student read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return Student( - name: fields[0] == null ? "" : fields[0] as String, - surname: fields[1] == null ? "" : fields[1] as String, - email: fields[2] == null ? "" : fields[2] as String, - ); - } - - @override - void write(BinaryWriter writer, Student obj) { - writer - ..writeByte(3) - ..writeByte(0) - ..write(obj.name) - ..writeByte(1) - ..write(obj.surname) - ..writeByte(2) - ..write(obj.email); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is StudentAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} diff --git a/packages/lyon1tomussclient/lib/hive/hive_adapters.dart b/packages/lyon1tomussclient/lib/hive/hive_adapters.dart deleted file mode 100644 index 744bd284c..000000000 --- a/packages/lyon1tomussclient/lib/hive/hive_adapters.dart +++ /dev/null @@ -1,32 +0,0 @@ -import 'package:hive_ce/hive.dart'; -import 'package:lyon1tomussclient/src/model/enumeration.dart'; -import 'package:lyon1tomussclient/src/model/grade.dart'; -import 'package:lyon1tomussclient/src/model/presence.dart'; -import 'package:lyon1tomussclient/src/model/semester.dart'; -import 'package:lyon1tomussclient/src/model/semester_list.dart'; -import 'package:lyon1tomussclient/src/model/stage_code.dart'; -import 'package:lyon1tomussclient/src/model/student.dart'; -import 'package:lyon1tomussclient/src/model/teacher.dart'; -import 'package:lyon1tomussclient/src/model/teaching_unit.dart'; -import 'package:lyon1tomussclient/src/model/teaching_unit_list.dart'; -import 'package:lyon1tomussclient/src/model/tomuss_text.dart'; -import 'package:lyon1tomussclient/src/model/upload.dart'; -import 'package:lyon1tomussclient/src/model/url.dart'; - -@GenerateAdapters([ - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), -]) -part 'generated/hive_adapters.g.dart'; diff --git a/packages/lyon1tomussclient/lib/hive/hive_adapters.g.yaml b/packages/lyon1tomussclient/lib/hive/hive_adapters.g.yaml deleted file mode 100644 index 5c0743946..000000000 --- a/packages/lyon1tomussclient/lib/hive/hive_adapters.g.yaml +++ /dev/null @@ -1,235 +0,0 @@ -# Generated by Hive CE -# Manual modifications may be necessary for certain migrations -# Check in to version control -nextTypeId: 44 -types: - Grade: - typeId: 9 - nextIndex: 104 - fields: - numerator: - index: 2 - denominator: - index: 3 - rank: - index: 4 - average: - index: 5 - mediane: - index: 6 - groupeSize: - index: 7 - isValid: - index: 8 - children: - index: 9 - coef: - index: 10 - title: - index: 100 - author: - index: 101 - date: - index: 102 - position: - index: 103 - TeachingUnit: - typeId: 10 - nextIndex: 14 - fields: - title: - index: 0 - masters: - index: 1 - grades: - index: 2 - textValues: - index: 6 - enumerations: - index: 7 - presences: - index: 8 - stageCodes: - index: 9 - uploads: - index: 10 - urls: - index: 11 - ticket: - index: 12 - ue: - index: 13 - TeachingUnitList: - typeId: 11 - nextIndex: 2 - fields: - teachingUnitModels: - index: 0 - semesterIndex: - index: 1 - Teacher: - typeId: 12 - nextIndex: 2 - fields: - name: - index: 0 - email: - index: 1 - Semester: - typeId: 13 - nextIndex: 2 - fields: - title: - index: 0 - url: - index: 1 - SemesterList: - typeId: 14 - nextIndex: 2 - fields: - semestres: - index: 0 - currentSemesterIndex: - index: 1 - Enumeration: - typeId: 25 - nextIndex: 104 - fields: - value: - index: 1 - values: - index: 2 - comment: - index: 4 - theId: - index: 6 - lineId: - index: 7 - ue: - index: 8 - semester: - index: 9 - year: - index: 10 - modifiable: - index: 12 - title: - index: 100 - author: - index: 101 - date: - index: 102 - position: - index: 103 - PresenceColor: - typeId: 26 - nextIndex: 3 - fields: - green: - index: 0 - red: - index: 1 - unset: - index: 2 - Presence: - typeId: 27 - nextIndex: 104 - fields: - value: - index: 1 - emptyIs: - index: 3 - color: - index: 4 - visibilityDate: - index: 5 - visible: - index: 6 - title: - index: 100 - author: - index: 101 - date: - index: 102 - position: - index: 103 - StageCode: - typeId: 28 - nextIndex: 104 - fields: - value: - index: 1 - title: - index: 100 - author: - index: 101 - date: - index: 102 - position: - index: 103 - TomussText: - typeId: 29 - nextIndex: 104 - fields: - value: - index: 1 - comment: - index: 3 - isValidText: - index: 4 - isHidden: - index: 6 - theId: - index: 7 - title: - index: 100 - author: - index: 101 - date: - index: 102 - position: - index: 103 - Upload: - typeId: 30 - nextIndex: 104 - fields: - comment: - index: 2 - uploadMax: - index: 3 - fileUrl: - index: 5 - title: - index: 100 - author: - index: 101 - date: - index: 102 - position: - index: 103 - URL: - typeId: 31 - nextIndex: 104 - fields: - value: - index: 2 - isModifiable: - index: 3 - title: - index: 100 - author: - index: 101 - date: - index: 102 - position: - index: 103 - Student: - typeId: 43 - nextIndex: 3 - fields: - name: - index: 0 - surname: - index: 1 - email: - index: 2 diff --git a/packages/lyon1tomussclient/lib/hive/hive_registrar.g.dart b/packages/lyon1tomussclient/lib/hive/hive_registrar.g.dart deleted file mode 100644 index 4cb953113..000000000 --- a/packages/lyon1tomussclient/lib/hive/hive_registrar.g.dart +++ /dev/null @@ -1,44 +0,0 @@ -// Generated by Hive CE -// Do not modify -// Check in to version control - -import 'package:hive_ce/hive.dart'; -import 'package:lyon1tomussclient/hive/hive_adapters.dart'; - -extension HiveRegistrar on HiveInterface { - void registerAdapters() { - registerAdapter(EnumerationAdapter()); - registerAdapter(GradeAdapter()); - registerAdapter(PresenceAdapter()); - registerAdapter(PresenceColorAdapter()); - registerAdapter(SemesterAdapter()); - registerAdapter(SemesterListAdapter()); - registerAdapter(StageCodeAdapter()); - registerAdapter(StudentAdapter()); - registerAdapter(TeacherAdapter()); - registerAdapter(TeachingUnitAdapter()); - registerAdapter(TeachingUnitListAdapter()); - registerAdapter(TomussTextAdapter()); - registerAdapter(URLAdapter()); - registerAdapter(UploadAdapter()); - } -} - -extension IsolatedHiveRegistrar on IsolatedHiveInterface { - void registerAdapters() { - registerAdapter(EnumerationAdapter()); - registerAdapter(GradeAdapter()); - registerAdapter(PresenceAdapter()); - registerAdapter(PresenceColorAdapter()); - registerAdapter(SemesterAdapter()); - registerAdapter(SemesterListAdapter()); - registerAdapter(StageCodeAdapter()); - registerAdapter(StudentAdapter()); - registerAdapter(TeacherAdapter()); - registerAdapter(TeachingUnitAdapter()); - registerAdapter(TeachingUnitListAdapter()); - registerAdapter(TomussTextAdapter()); - registerAdapter(URLAdapter()); - registerAdapter(UploadAdapter()); - } -} diff --git a/packages/lyon1tomussclient/lib/src/lyon1tomussclient.dart b/packages/lyon1tomussclient/lib/src/lyon1tomussclient.dart index 15cd69756..244aaffcb 100755 --- a/packages/lyon1tomussclient/lib/src/lyon1tomussclient.dart +++ b/packages/lyon1tomussclient/lib/src/lyon1tomussclient.dart @@ -1,7 +1,5 @@ import 'package:beautiful_soup_dart/beautiful_soup.dart'; -import 'package:hive_ce/hive.dart'; import 'package:lyon1casclient/lyon1casclient.dart'; -import 'package:lyon1tomussclient/hive/hive_registrar.g.dart'; import 'package:lyon1tomussclient/lyon1tomussclient.dart'; import 'package:lyon1tomussclient/src/parser/htmlparser.dart'; import 'package:lyon1tomussclient/src/utils/urlcreator.dart'; @@ -10,20 +8,20 @@ class Lyon1TomussClient { final Lyon1CasClient _authentication; const Lyon1TomussClient(Lyon1CasClient authentication) - : _authentication = authentication; + : _authentication = authentication; Lyon1CasClient get lyon1Cas => _authentication; - static void registerAdapters() { - Hive.registerAdapters(); - } - - Future getParsedPage(final String url, - {bool autoRefresh = true}) async { + Future getParsedPage( + final String url, { + bool autoRefresh = true, + }) async { if (!_authentication.isAuthenticated) return null; - String content = - (await _authentication.serviceRequest(url, wrapUrl: false)).body; + String content = (await _authentication.serviceRequest( + url, + wrapUrl: false, + )).body; final HTMLparser parser = HTMLparser(); if (content.length < 1000) { @@ -31,17 +29,29 @@ class Lyon1TomussClient { // there is a delay if you refresh tomuss too quicky final double delay = double.tryParse(bs.find("#t")?.text ?? "") ?? 15.0; if (autoRefresh) { - return Future.delayed(Duration(seconds: delay.round() + 2), - () => getParsedPage(url, autoRefresh: false)); + return Future.delayed( + Duration(seconds: delay.round() + 2), + () => getParsedPage(url, autoRefresh: false), + ); } else { return ParsedPage( - null, null, null, true, Duration(seconds: delay.round() + 2)); + null, + null, + null, + true, + Duration(seconds: delay.round() + 2), + ); } } parser.parse(content); - return ParsedPage(parser.extractStudent(), parser.extractSemesters(), - parser.extractTeachingUnits(), false, Duration.zero); + return ParsedPage( + parser.extractStudent(), + parser.extractSemesters(), + parser.extractTeachingUnits(), + false, + Duration.zero, + ); } Future logout() async { diff --git a/packages/lyon1tomussclient/lib/src/model/enumeration.dart b/packages/lyon1tomussclient/lib/src/model/enumeration.dart index c2c03f072..fde3c5d50 100644 --- a/packages/lyon1tomussclient/lib/src/model/enumeration.dart +++ b/packages/lyon1tomussclient/lib/src/model/enumeration.dart @@ -1,12 +1,12 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1tomussclient/src/constant/constants.dart'; import 'package:lyon1tomussclient/src/model/teaching_unit_element.dart'; import 'package:requests_plus/requests_plus.dart'; -part 'generated/enumeration.g.dart'; +part 'generated/enumeration.mapper.dart'; -@CopyWith() -class Enumeration extends TeachingUnitElement { +@MappableClass() +class Enumeration extends TeachingUnitElement with EnumerationMappable { late final String? value; late final List values; late final String comment; @@ -20,8 +20,13 @@ class Enumeration extends TeachingUnitElement { late final bool modifiable; Enumeration.fromJSON( - var id, var json, var stats, var line, var column, String user) - : super.fromJson(id, json, stats, line, column, user) { + int id, + Map json, + Map stats, + List line, + Map column, + String user, + ) : super.fromJson(id, json, stats, line, column, user) { comment = json['comment'] ?? ""; if (json["type"] == "Bool") { values = ['OUI', 'NON']; @@ -55,7 +60,8 @@ class Enumeration extends TeachingUnitElement { value = null; } } - modifiable = json.keys.contains("modifiable") && + modifiable = + json.keys.contains("modifiable") && json["modifiable"] == 2 && ((line[id].length > 1 && line[id][1] == user) || line[id].length <= 1); theId = json['the_id'] ?? ""; @@ -65,6 +71,7 @@ class Enumeration extends TeachingUnitElement { year = (column['year'] ?? "").toString(); } + @MappableConstructor() Enumeration({ required super.title, required super.author, @@ -87,7 +94,7 @@ class Enumeration extends TeachingUnitElement { "${Constants.tomuss}/POST", body: { 'content': - "/$year/$semester/$ue/cell/$theId/$lineId/$value?%E2%9C%80_________________________________________________________________$ticket" + "/$year/$semester/$ue/cell/$theId/$lineId/$value?%E2%9C%80_________________________________________________________________$ticket", }, bodyEncoding: RequestBodyEncoding.FormData, ); diff --git a/packages/lyon1tomussclient/lib/src/model/generated/enumeration.g.dart b/packages/lyon1tomussclient/lib/src/model/generated/enumeration.g.dart deleted file mode 100644 index 13c499015..000000000 --- a/packages/lyon1tomussclient/lib/src/model/generated/enumeration.g.dart +++ /dev/null @@ -1,193 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../enumeration.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$EnumerationCWProxy { - Enumeration title(String title); - - Enumeration author(String author); - - Enumeration date(DateTime? date); - - Enumeration position(double position); - - Enumeration value(String? value); - - Enumeration values(List values); - - Enumeration comment(String comment); - - Enumeration theId(String theId); - - Enumeration lineId(String lineId); - - Enumeration ue(String ue); - - Enumeration semester(String semester); - - Enumeration year(String year); - - Enumeration modifiable(bool modifiable); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Enumeration(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Enumeration(...).copyWith(id: 12, name: "My name") - /// ``` - Enumeration call({ - String title, - String author, - DateTime? date, - double position, - String? value, - List values, - String comment, - String theId, - String lineId, - String ue, - String semester, - String year, - bool modifiable, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfEnumeration.copyWith(...)` or call `instanceOfEnumeration.copyWith.fieldName(value)` for a single field. -class _$EnumerationCWProxyImpl implements _$EnumerationCWProxy { - const _$EnumerationCWProxyImpl(this._value); - - final Enumeration _value; - - @override - Enumeration title(String title) => call(title: title); - - @override - Enumeration author(String author) => call(author: author); - - @override - Enumeration date(DateTime? date) => call(date: date); - - @override - Enumeration position(double position) => call(position: position); - - @override - Enumeration value(String? value) => call(value: value); - - @override - Enumeration values(List values) => call(values: values); - - @override - Enumeration comment(String comment) => call(comment: comment); - - @override - Enumeration theId(String theId) => call(theId: theId); - - @override - Enumeration lineId(String lineId) => call(lineId: lineId); - - @override - Enumeration ue(String ue) => call(ue: ue); - - @override - Enumeration semester(String semester) => call(semester: semester); - - @override - Enumeration year(String year) => call(year: year); - - @override - Enumeration modifiable(bool modifiable) => call(modifiable: modifiable); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Enumeration(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Enumeration(...).copyWith(id: 12, name: "My name") - /// ``` - Enumeration call({ - Object? title = const $CopyWithPlaceholder(), - Object? author = const $CopyWithPlaceholder(), - Object? date = const $CopyWithPlaceholder(), - Object? position = const $CopyWithPlaceholder(), - Object? value = const $CopyWithPlaceholder(), - Object? values = const $CopyWithPlaceholder(), - Object? comment = const $CopyWithPlaceholder(), - Object? theId = const $CopyWithPlaceholder(), - Object? lineId = const $CopyWithPlaceholder(), - Object? ue = const $CopyWithPlaceholder(), - Object? semester = const $CopyWithPlaceholder(), - Object? year = const $CopyWithPlaceholder(), - Object? modifiable = const $CopyWithPlaceholder(), - }) { - return Enumeration( - title: title == const $CopyWithPlaceholder() || title == null - ? _value.title - // ignore: cast_nullable_to_non_nullable - : title as String, - author: author == const $CopyWithPlaceholder() || author == null - ? _value.author - // ignore: cast_nullable_to_non_nullable - : author as String, - date: date == const $CopyWithPlaceholder() - ? _value.date - // ignore: cast_nullable_to_non_nullable - : date as DateTime?, - position: position == const $CopyWithPlaceholder() || position == null - ? _value.position - // ignore: cast_nullable_to_non_nullable - : position as double, - value: value == const $CopyWithPlaceholder() - ? _value.value - // ignore: cast_nullable_to_non_nullable - : value as String?, - values: values == const $CopyWithPlaceholder() || values == null - ? _value.values - // ignore: cast_nullable_to_non_nullable - : values as List, - comment: comment == const $CopyWithPlaceholder() || comment == null - ? _value.comment - // ignore: cast_nullable_to_non_nullable - : comment as String, - theId: theId == const $CopyWithPlaceholder() || theId == null - ? _value.theId - // ignore: cast_nullable_to_non_nullable - : theId as String, - lineId: lineId == const $CopyWithPlaceholder() || lineId == null - ? _value.lineId - // ignore: cast_nullable_to_non_nullable - : lineId as String, - ue: ue == const $CopyWithPlaceholder() || ue == null - ? _value.ue - // ignore: cast_nullable_to_non_nullable - : ue as String, - semester: semester == const $CopyWithPlaceholder() || semester == null - ? _value.semester - // ignore: cast_nullable_to_non_nullable - : semester as String, - year: year == const $CopyWithPlaceholder() || year == null - ? _value.year - // ignore: cast_nullable_to_non_nullable - : year as String, - modifiable: - modifiable == const $CopyWithPlaceholder() || modifiable == null - ? _value.modifiable - // ignore: cast_nullable_to_non_nullable - : modifiable as bool, - ); - } -} - -extension $EnumerationCopyWith on Enumeration { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfEnumeration.copyWith(...)` or `instanceOfEnumeration.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$EnumerationCWProxy get copyWith => _$EnumerationCWProxyImpl(this); -} diff --git a/packages/lyon1tomussclient/lib/src/model/generated/enumeration.mapper.dart b/packages/lyon1tomussclient/lib/src/model/generated/enumeration.mapper.dart new file mode 100644 index 000000000..2bf33c5ef --- /dev/null +++ b/packages/lyon1tomussclient/lib/src/model/generated/enumeration.mapper.dart @@ -0,0 +1,295 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../enumeration.dart'; + +class EnumerationMapper extends ClassMapperBase { + EnumerationMapper._(); + + static EnumerationMapper? _instance; + static EnumerationMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = EnumerationMapper._()); + } + return _instance!; + } + + @override + final String id = 'Enumeration'; + + static String _$title(Enumeration v) => v.title; + static const Field _f$title = Field('title', _$title); + static String _$author(Enumeration v) => v.author; + static const Field _f$author = Field('author', _$author); + static DateTime? _$date(Enumeration v) => v.date; + static const Field _f$date = Field('date', _$date); + static double _$position(Enumeration v) => v.position; + static const Field _f$position = Field( + 'position', + _$position, + ); + static String? _$value(Enumeration v) => v.value; + static const Field _f$value = Field( + 'value', + _$value, + opt: true, + ); + static List _$values(Enumeration v) => v.values; + static const Field> _f$values = Field( + 'values', + _$values, + opt: true, + def: const [], + ); + static String _$comment(Enumeration v) => v.comment; + static const Field _f$comment = Field( + 'comment', + _$comment, + opt: true, + def: "", + ); + static String _$theId(Enumeration v) => v.theId; + static const Field _f$theId = Field( + 'theId', + _$theId, + opt: true, + def: "", + ); + static String _$lineId(Enumeration v) => v.lineId; + static const Field _f$lineId = Field( + 'lineId', + _$lineId, + opt: true, + def: "", + ); + static String _$ue(Enumeration v) => v.ue; + static const Field _f$ue = Field( + 'ue', + _$ue, + opt: true, + def: "", + ); + static String _$semester(Enumeration v) => v.semester; + static const Field _f$semester = Field( + 'semester', + _$semester, + opt: true, + def: "", + ); + static String _$year(Enumeration v) => v.year; + static const Field _f$year = Field( + 'year', + _$year, + opt: true, + def: "", + ); + static bool _$modifiable(Enumeration v) => v.modifiable; + static const Field _f$modifiable = Field( + 'modifiable', + _$modifiable, + opt: true, + def: true, + ); + static bool _$isVisible(Enumeration v) => v.isVisible; + static const Field _f$isVisible = Field( + 'isVisible', + _$isVisible, + mode: FieldMode.member, + ); + static List _$customProps(Enumeration v) => v.customProps; + static const Field> _f$customProps = Field( + 'customProps', + _$customProps, + mode: FieldMode.member, + ); + + @override + final MappableFields fields = const { + #title: _f$title, + #author: _f$author, + #date: _f$date, + #position: _f$position, + #value: _f$value, + #values: _f$values, + #comment: _f$comment, + #theId: _f$theId, + #lineId: _f$lineId, + #ue: _f$ue, + #semester: _f$semester, + #year: _f$year, + #modifiable: _f$modifiable, + #isVisible: _f$isVisible, + #customProps: _f$customProps, + }; + + static Enumeration _instantiate(DecodingData data) { + return Enumeration( + title: data.dec(_f$title), + author: data.dec(_f$author), + date: data.dec(_f$date), + position: data.dec(_f$position), + value: data.dec(_f$value), + values: data.dec(_f$values), + comment: data.dec(_f$comment), + theId: data.dec(_f$theId), + lineId: data.dec(_f$lineId), + ue: data.dec(_f$ue), + semester: data.dec(_f$semester), + year: data.dec(_f$year), + modifiable: data.dec(_f$modifiable), + ); + } + + @override + final Function instantiate = _instantiate; + + static Enumeration fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static Enumeration fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin EnumerationMappable { + String toJson() { + return EnumerationMapper.ensureInitialized().encodeJson( + this as Enumeration, + ); + } + + Map toMap() { + return EnumerationMapper.ensureInitialized().encodeMap( + this as Enumeration, + ); + } + + EnumerationCopyWith get copyWith => + _EnumerationCopyWithImpl( + this as Enumeration, + $identity, + $identity, + ); + @override + String toString() { + return EnumerationMapper.ensureInitialized().stringifyValue( + this as Enumeration, + ); + } + + @override + bool operator ==(Object other) { + return EnumerationMapper.ensureInitialized().equalsValue( + this as Enumeration, + other, + ); + } + + @override + int get hashCode { + return EnumerationMapper.ensureInitialized().hashValue(this as Enumeration); + } +} + +extension EnumerationValueCopy<$R, $Out> + on ObjectCopyWith<$R, Enumeration, $Out> { + EnumerationCopyWith<$R, Enumeration, $Out> get $asEnumeration => + $base.as((v, t, t2) => _EnumerationCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class EnumerationCopyWith<$R, $In extends Enumeration, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> get values; + $R call({ + String? title, + String? author, + DateTime? date, + double? position, + String? value, + List? values, + String? comment, + String? theId, + String? lineId, + String? ue, + String? semester, + String? year, + bool? modifiable, + }); + EnumerationCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _EnumerationCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, Enumeration, $Out> + implements EnumerationCopyWith<$R, Enumeration, $Out> { + _EnumerationCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + EnumerationMapper.ensureInitialized(); + @override + ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> get values => + ListCopyWith( + $value.values, + (v, t) => ObjectCopyWith(v, $identity, t), + (v) => call(values: v), + ); + @override + $R call({ + String? title, + String? author, + Object? date = $none, + double? position, + Object? value = $none, + List? values, + String? comment, + String? theId, + String? lineId, + String? ue, + String? semester, + String? year, + bool? modifiable, + }) => $apply( + FieldCopyWithData({ + if (title != null) #title: title, + if (author != null) #author: author, + if (date != $none) #date: date, + if (position != null) #position: position, + if (value != $none) #value: value, + if (values != null) #values: values, + if (comment != null) #comment: comment, + if (theId != null) #theId: theId, + if (lineId != null) #lineId: lineId, + if (ue != null) #ue: ue, + if (semester != null) #semester: semester, + if (year != null) #year: year, + if (modifiable != null) #modifiable: modifiable, + }), + ); + @override + Enumeration $make(CopyWithData data) => Enumeration( + title: data.get(#title, or: $value.title), + author: data.get(#author, or: $value.author), + date: data.get(#date, or: $value.date), + position: data.get(#position, or: $value.position), + value: data.get(#value, or: $value.value), + values: data.get(#values, or: $value.values), + comment: data.get(#comment, or: $value.comment), + theId: data.get(#theId, or: $value.theId), + lineId: data.get(#lineId, or: $value.lineId), + ue: data.get(#ue, or: $value.ue), + semester: data.get(#semester, or: $value.semester), + year: data.get(#year, or: $value.year), + modifiable: data.get(#modifiable, or: $value.modifiable), + ); + + @override + EnumerationCopyWith<$R2, Enumeration, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _EnumerationCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1tomussclient/lib/src/model/generated/grade.g.dart b/packages/lyon1tomussclient/lib/src/model/generated/grade.g.dart deleted file mode 100644 index 9c9928dd4..000000000 --- a/packages/lyon1tomussclient/lib/src/model/generated/grade.g.dart +++ /dev/null @@ -1,194 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../grade.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$GradeCWProxy { - Grade title(String title); - - Grade author(String author); - - Grade date(DateTime? date); - - Grade position(double position); - - Grade numerator(double numerator); - - Grade denominator(double denominator); - - Grade rank(int rank); - - Grade average(double average); - - Grade mediane(double mediane); - - Grade isValid(bool isValid); - - Grade groupeSize(int groupeSize); - - Grade children(List children); - - Grade coef(double coef); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Grade(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Grade(...).copyWith(id: 12, name: "My name") - /// ``` - Grade call({ - String title, - String author, - DateTime? date, - double position, - double numerator, - double denominator, - int rank, - double average, - double mediane, - bool isValid, - int groupeSize, - List children, - double coef, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfGrade.copyWith(...)` or call `instanceOfGrade.copyWith.fieldName(value)` for a single field. -class _$GradeCWProxyImpl implements _$GradeCWProxy { - const _$GradeCWProxyImpl(this._value); - - final Grade _value; - - @override - Grade title(String title) => call(title: title); - - @override - Grade author(String author) => call(author: author); - - @override - Grade date(DateTime? date) => call(date: date); - - @override - Grade position(double position) => call(position: position); - - @override - Grade numerator(double numerator) => call(numerator: numerator); - - @override - Grade denominator(double denominator) => call(denominator: denominator); - - @override - Grade rank(int rank) => call(rank: rank); - - @override - Grade average(double average) => call(average: average); - - @override - Grade mediane(double mediane) => call(mediane: mediane); - - @override - Grade isValid(bool isValid) => call(isValid: isValid); - - @override - Grade groupeSize(int groupeSize) => call(groupeSize: groupeSize); - - @override - Grade children(List children) => call(children: children); - - @override - Grade coef(double coef) => call(coef: coef); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Grade(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Grade(...).copyWith(id: 12, name: "My name") - /// ``` - Grade call({ - Object? title = const $CopyWithPlaceholder(), - Object? author = const $CopyWithPlaceholder(), - Object? date = const $CopyWithPlaceholder(), - Object? position = const $CopyWithPlaceholder(), - Object? numerator = const $CopyWithPlaceholder(), - Object? denominator = const $CopyWithPlaceholder(), - Object? rank = const $CopyWithPlaceholder(), - Object? average = const $CopyWithPlaceholder(), - Object? mediane = const $CopyWithPlaceholder(), - Object? isValid = const $CopyWithPlaceholder(), - Object? groupeSize = const $CopyWithPlaceholder(), - Object? children = const $CopyWithPlaceholder(), - Object? coef = const $CopyWithPlaceholder(), - }) { - return Grade( - title: title == const $CopyWithPlaceholder() || title == null - ? _value.title - // ignore: cast_nullable_to_non_nullable - : title as String, - author: author == const $CopyWithPlaceholder() || author == null - ? _value.author - // ignore: cast_nullable_to_non_nullable - : author as String, - date: date == const $CopyWithPlaceholder() - ? _value.date - // ignore: cast_nullable_to_non_nullable - : date as DateTime?, - position: position == const $CopyWithPlaceholder() || position == null - ? _value.position - // ignore: cast_nullable_to_non_nullable - : position as double, - numerator: numerator == const $CopyWithPlaceholder() || numerator == null - ? _value.numerator - // ignore: cast_nullable_to_non_nullable - : numerator as double, - denominator: - denominator == const $CopyWithPlaceholder() || denominator == null - ? _value.denominator - // ignore: cast_nullable_to_non_nullable - : denominator as double, - rank: rank == const $CopyWithPlaceholder() || rank == null - ? _value.rank - // ignore: cast_nullable_to_non_nullable - : rank as int, - average: average == const $CopyWithPlaceholder() || average == null - ? _value.average - // ignore: cast_nullable_to_non_nullable - : average as double, - mediane: mediane == const $CopyWithPlaceholder() || mediane == null - ? _value.mediane - // ignore: cast_nullable_to_non_nullable - : mediane as double, - isValid: isValid == const $CopyWithPlaceholder() || isValid == null - ? _value.isValid - // ignore: cast_nullable_to_non_nullable - : isValid as bool, - groupeSize: - groupeSize == const $CopyWithPlaceholder() || groupeSize == null - ? _value.groupeSize - // ignore: cast_nullable_to_non_nullable - : groupeSize as int, - children: children == const $CopyWithPlaceholder() || children == null - ? _value.children - // ignore: cast_nullable_to_non_nullable - : children as List, - coef: coef == const $CopyWithPlaceholder() || coef == null - ? _value.coef - // ignore: cast_nullable_to_non_nullable - : coef as double, - ); - } -} - -extension $GradeCopyWith on Grade { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfGrade.copyWith(...)` or `instanceOfGrade.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$GradeCWProxy get copyWith => _$GradeCWProxyImpl(this); -} diff --git a/packages/lyon1tomussclient/lib/src/model/generated/grade.mapper.dart b/packages/lyon1tomussclient/lib/src/model/generated/grade.mapper.dart new file mode 100644 index 000000000..cf6786c57 --- /dev/null +++ b/packages/lyon1tomussclient/lib/src/model/generated/grade.mapper.dart @@ -0,0 +1,277 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../grade.dart'; + +class GradeMapper extends ClassMapperBase { + GradeMapper._(); + + static GradeMapper? _instance; + static GradeMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = GradeMapper._()); + GradeMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'Grade'; + + static String _$title(Grade v) => v.title; + static const Field _f$title = Field('title', _$title); + static String _$author(Grade v) => v.author; + static const Field _f$author = Field('author', _$author); + static DateTime? _$date(Grade v) => v.date; + static const Field _f$date = Field('date', _$date); + static double _$position(Grade v) => v.position; + static const Field _f$position = Field('position', _$position); + static double _$numerator(Grade v) => v.numerator; + static const Field _f$numerator = Field( + 'numerator', + _$numerator, + opt: true, + def: 0.0, + ); + static double _$denominator(Grade v) => v.denominator; + static const Field _f$denominator = Field( + 'denominator', + _$denominator, + opt: true, + def: 20.0, + ); + static int _$rank(Grade v) => v.rank; + static const Field _f$rank = Field( + 'rank', + _$rank, + opt: true, + def: -1, + ); + static double _$average(Grade v) => v.average; + static const Field _f$average = Field( + 'average', + _$average, + opt: true, + def: 10.0, + ); + static double _$mediane(Grade v) => v.mediane; + static const Field _f$mediane = Field( + 'mediane', + _$mediane, + opt: true, + def: 10.0, + ); + static bool _$isValid(Grade v) => v.isValid; + static const Field _f$isValid = Field( + 'isValid', + _$isValid, + opt: true, + def: false, + ); + static int _$groupeSize(Grade v) => v.groupeSize; + static const Field _f$groupeSize = Field( + 'groupeSize', + _$groupeSize, + opt: true, + def: -1, + ); + static List _$children(Grade v) => v.children; + static const Field> _f$children = Field( + 'children', + _$children, + opt: true, + def: const [], + ); + static double _$coef(Grade v) => v.coef; + static const Field _f$coef = Field( + 'coef', + _$coef, + opt: true, + def: 1.0, + ); + static bool _$isVisible(Grade v) => v.isVisible; + static const Field _f$isVisible = Field( + 'isVisible', + _$isVisible, + mode: FieldMode.member, + ); + static List _$customProps(Grade v) => v.customProps; + static const Field> _f$customProps = Field( + 'customProps', + _$customProps, + mode: FieldMode.member, + ); + + @override + final MappableFields fields = const { + #title: _f$title, + #author: _f$author, + #date: _f$date, + #position: _f$position, + #numerator: _f$numerator, + #denominator: _f$denominator, + #rank: _f$rank, + #average: _f$average, + #mediane: _f$mediane, + #isValid: _f$isValid, + #groupeSize: _f$groupeSize, + #children: _f$children, + #coef: _f$coef, + #isVisible: _f$isVisible, + #customProps: _f$customProps, + }; + + static Grade _instantiate(DecodingData data) { + return Grade( + title: data.dec(_f$title), + author: data.dec(_f$author), + date: data.dec(_f$date), + position: data.dec(_f$position), + numerator: data.dec(_f$numerator), + denominator: data.dec(_f$denominator), + rank: data.dec(_f$rank), + average: data.dec(_f$average), + mediane: data.dec(_f$mediane), + isValid: data.dec(_f$isValid), + groupeSize: data.dec(_f$groupeSize), + children: data.dec(_f$children), + coef: data.dec(_f$coef), + ); + } + + @override + final Function instantiate = _instantiate; + + static Grade fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static Grade fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin GradeMappable { + String toJson() { + return GradeMapper.ensureInitialized().encodeJson(this as Grade); + } + + Map toMap() { + return GradeMapper.ensureInitialized().encodeMap(this as Grade); + } + + GradeCopyWith get copyWith => + _GradeCopyWithImpl(this as Grade, $identity, $identity); + @override + String toString() { + return GradeMapper.ensureInitialized().stringifyValue(this as Grade); + } + + @override + bool operator ==(Object other) { + return GradeMapper.ensureInitialized().equalsValue(this as Grade, other); + } + + @override + int get hashCode { + return GradeMapper.ensureInitialized().hashValue(this as Grade); + } +} + +extension GradeValueCopy<$R, $Out> on ObjectCopyWith<$R, Grade, $Out> { + GradeCopyWith<$R, Grade, $Out> get $asGrade => + $base.as((v, t, t2) => _GradeCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class GradeCopyWith<$R, $In extends Grade, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, Grade, GradeCopyWith<$R, Grade, Grade>> get children; + $R call({ + String? title, + String? author, + DateTime? date, + double? position, + double? numerator, + double? denominator, + int? rank, + double? average, + double? mediane, + bool? isValid, + int? groupeSize, + List? children, + double? coef, + }); + GradeCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _GradeCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, Grade, $Out> + implements GradeCopyWith<$R, Grade, $Out> { + _GradeCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = GradeMapper.ensureInitialized(); + @override + ListCopyWith<$R, Grade, GradeCopyWith<$R, Grade, Grade>> get children => + ListCopyWith( + $value.children, + (v, t) => v.copyWith.$chain(t), + (v) => call(children: v), + ); + @override + $R call({ + String? title, + String? author, + Object? date = $none, + double? position, + double? numerator, + double? denominator, + int? rank, + double? average, + double? mediane, + bool? isValid, + int? groupeSize, + List? children, + double? coef, + }) => $apply( + FieldCopyWithData({ + if (title != null) #title: title, + if (author != null) #author: author, + if (date != $none) #date: date, + if (position != null) #position: position, + if (numerator != null) #numerator: numerator, + if (denominator != null) #denominator: denominator, + if (rank != null) #rank: rank, + if (average != null) #average: average, + if (mediane != null) #mediane: mediane, + if (isValid != null) #isValid: isValid, + if (groupeSize != null) #groupeSize: groupeSize, + if (children != null) #children: children, + if (coef != null) #coef: coef, + }), + ); + @override + Grade $make(CopyWithData data) => Grade( + title: data.get(#title, or: $value.title), + author: data.get(#author, or: $value.author), + date: data.get(#date, or: $value.date), + position: data.get(#position, or: $value.position), + numerator: data.get(#numerator, or: $value.numerator), + denominator: data.get(#denominator, or: $value.denominator), + rank: data.get(#rank, or: $value.rank), + average: data.get(#average, or: $value.average), + mediane: data.get(#mediane, or: $value.mediane), + isValid: data.get(#isValid, or: $value.isValid), + groupeSize: data.get(#groupeSize, or: $value.groupeSize), + children: data.get(#children, or: $value.children), + coef: data.get(#coef, or: $value.coef), + ); + + @override + GradeCopyWith<$R2, Grade, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _GradeCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1tomussclient/lib/src/model/generated/presence.g.dart b/packages/lyon1tomussclient/lib/src/model/generated/presence.g.dart deleted file mode 100644 index 5b243ebb5..000000000 --- a/packages/lyon1tomussclient/lib/src/model/generated/presence.g.dart +++ /dev/null @@ -1,149 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../presence.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$PresenceCWProxy { - Presence title(String title); - - Presence author(String author); - - Presence date(DateTime? date); - - Presence position(double position); - - Presence value(String value); - - Presence emptyIs(String? emptyIs); - - Presence color(PresenceColor color); - - Presence visibilityDate(DateTime? visibilityDate); - - Presence visible(bool? visible); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Presence(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Presence(...).copyWith(id: 12, name: "My name") - /// ``` - Presence call({ - String title, - String author, - DateTime? date, - double position, - String value, - String? emptyIs, - PresenceColor color, - DateTime? visibilityDate, - bool? visible, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfPresence.copyWith(...)` or call `instanceOfPresence.copyWith.fieldName(value)` for a single field. -class _$PresenceCWProxyImpl implements _$PresenceCWProxy { - const _$PresenceCWProxyImpl(this._value); - - final Presence _value; - - @override - Presence title(String title) => call(title: title); - - @override - Presence author(String author) => call(author: author); - - @override - Presence date(DateTime? date) => call(date: date); - - @override - Presence position(double position) => call(position: position); - - @override - Presence value(String value) => call(value: value); - - @override - Presence emptyIs(String? emptyIs) => call(emptyIs: emptyIs); - - @override - Presence color(PresenceColor color) => call(color: color); - - @override - Presence visibilityDate(DateTime? visibilityDate) => - call(visibilityDate: visibilityDate); - - @override - Presence visible(bool? visible) => call(visible: visible); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Presence(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Presence(...).copyWith(id: 12, name: "My name") - /// ``` - Presence call({ - Object? title = const $CopyWithPlaceholder(), - Object? author = const $CopyWithPlaceholder(), - Object? date = const $CopyWithPlaceholder(), - Object? position = const $CopyWithPlaceholder(), - Object? value = const $CopyWithPlaceholder(), - Object? emptyIs = const $CopyWithPlaceholder(), - Object? color = const $CopyWithPlaceholder(), - Object? visibilityDate = const $CopyWithPlaceholder(), - Object? visible = const $CopyWithPlaceholder(), - }) { - return Presence( - title: title == const $CopyWithPlaceholder() || title == null - ? _value.title - // ignore: cast_nullable_to_non_nullable - : title as String, - author: author == const $CopyWithPlaceholder() || author == null - ? _value.author - // ignore: cast_nullable_to_non_nullable - : author as String, - date: date == const $CopyWithPlaceholder() - ? _value.date - // ignore: cast_nullable_to_non_nullable - : date as DateTime?, - position: position == const $CopyWithPlaceholder() || position == null - ? _value.position - // ignore: cast_nullable_to_non_nullable - : position as double, - value: value == const $CopyWithPlaceholder() || value == null - ? _value.value - // ignore: cast_nullable_to_non_nullable - : value as String, - emptyIs: emptyIs == const $CopyWithPlaceholder() - ? _value.emptyIs - // ignore: cast_nullable_to_non_nullable - : emptyIs as String?, - color: color == const $CopyWithPlaceholder() || color == null - ? _value.color - // ignore: cast_nullable_to_non_nullable - : color as PresenceColor, - visibilityDate: visibilityDate == const $CopyWithPlaceholder() - ? _value.visibilityDate - // ignore: cast_nullable_to_non_nullable - : visibilityDate as DateTime?, - visible: visible == const $CopyWithPlaceholder() - ? _value.visible - // ignore: cast_nullable_to_non_nullable - : visible as bool?, - ); - } -} - -extension $PresenceCopyWith on Presence { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfPresence.copyWith(...)` or `instanceOfPresence.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$PresenceCWProxy get copyWith => _$PresenceCWProxyImpl(this); -} diff --git a/packages/lyon1tomussclient/lib/src/model/generated/presence.mapper.dart b/packages/lyon1tomussclient/lib/src/model/generated/presence.mapper.dart new file mode 100644 index 000000000..a47c0f69e --- /dev/null +++ b/packages/lyon1tomussclient/lib/src/model/generated/presence.mapper.dart @@ -0,0 +1,282 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../presence.dart'; + +class PresenceColorMapper extends EnumMapper { + PresenceColorMapper._(); + + static PresenceColorMapper? _instance; + static PresenceColorMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = PresenceColorMapper._()); + } + return _instance!; + } + + static PresenceColor fromValue(dynamic value) { + ensureInitialized(); + return MapperContainer.globals.fromValue(value); + } + + @override + PresenceColor decode(dynamic value) { + switch (value) { + case r'green': + return PresenceColor.green; + case r'red': + return PresenceColor.red; + case r'unset': + return PresenceColor.unset; + default: + throw MapperException.unknownEnumValue(value); + } + } + + @override + dynamic encode(PresenceColor self) { + switch (self) { + case PresenceColor.green: + return r'green'; + case PresenceColor.red: + return r'red'; + case PresenceColor.unset: + return r'unset'; + } + } +} + +extension PresenceColorMapperExtension on PresenceColor { + String toValue() { + PresenceColorMapper.ensureInitialized(); + return MapperContainer.globals.toValue(this) as String; + } +} + +class PresenceMapper extends ClassMapperBase { + PresenceMapper._(); + + static PresenceMapper? _instance; + static PresenceMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = PresenceMapper._()); + PresenceColorMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'Presence'; + + static String _$title(Presence v) => v.title; + static const Field _f$title = Field('title', _$title); + static String _$author(Presence v) => v.author; + static const Field _f$author = Field('author', _$author); + static DateTime? _$date(Presence v) => v.date; + static const Field _f$date = Field('date', _$date); + static double _$position(Presence v) => v.position; + static const Field _f$position = Field( + 'position', + _$position, + ); + static String _$value(Presence v) => v.value; + static const Field _f$value = Field( + 'value', + _$value, + opt: true, + def: "", + ); + static String? _$emptyIs(Presence v) => v.emptyIs; + static const Field _f$emptyIs = Field( + 'emptyIs', + _$emptyIs, + opt: true, + def: "", + ); + static PresenceColor _$color(Presence v) => v.color; + static const Field _f$color = Field( + 'color', + _$color, + opt: true, + def: PresenceColor.unset, + ); + static DateTime? _$visibilityDate(Presence v) => v.visibilityDate; + static const Field _f$visibilityDate = Field( + 'visibilityDate', + _$visibilityDate, + opt: true, + ); + static bool? _$visible(Presence v) => v.visible; + static const Field _f$visible = Field( + 'visible', + _$visible, + opt: true, + ); + static bool _$isVisible(Presence v) => v.isVisible; + static const Field _f$isVisible = Field( + 'isVisible', + _$isVisible, + mode: FieldMode.member, + ); + static List _$customProps(Presence v) => v.customProps; + static const Field> _f$customProps = Field( + 'customProps', + _$customProps, + mode: FieldMode.member, + ); + + @override + final MappableFields fields = const { + #title: _f$title, + #author: _f$author, + #date: _f$date, + #position: _f$position, + #value: _f$value, + #emptyIs: _f$emptyIs, + #color: _f$color, + #visibilityDate: _f$visibilityDate, + #visible: _f$visible, + #isVisible: _f$isVisible, + #customProps: _f$customProps, + }; + + static Presence _instantiate(DecodingData data) { + return Presence( + title: data.dec(_f$title), + author: data.dec(_f$author), + date: data.dec(_f$date), + position: data.dec(_f$position), + value: data.dec(_f$value), + emptyIs: data.dec(_f$emptyIs), + color: data.dec(_f$color), + visibilityDate: data.dec(_f$visibilityDate), + visible: data.dec(_f$visible), + ); + } + + @override + final Function instantiate = _instantiate; + + static Presence fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static Presence fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin PresenceMappable { + String toJson() { + return PresenceMapper.ensureInitialized().encodeJson( + this as Presence, + ); + } + + Map toMap() { + return PresenceMapper.ensureInitialized().encodeMap( + this as Presence, + ); + } + + PresenceCopyWith get copyWith => + _PresenceCopyWithImpl( + this as Presence, + $identity, + $identity, + ); + @override + String toString() { + return PresenceMapper.ensureInitialized().stringifyValue(this as Presence); + } + + @override + bool operator ==(Object other) { + return PresenceMapper.ensureInitialized().equalsValue( + this as Presence, + other, + ); + } + + @override + int get hashCode { + return PresenceMapper.ensureInitialized().hashValue(this as Presence); + } +} + +extension PresenceValueCopy<$R, $Out> on ObjectCopyWith<$R, Presence, $Out> { + PresenceCopyWith<$R, Presence, $Out> get $asPresence => + $base.as((v, t, t2) => _PresenceCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class PresenceCopyWith<$R, $In extends Presence, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({ + String? title, + String? author, + DateTime? date, + double? position, + String? value, + String? emptyIs, + PresenceColor? color, + DateTime? visibilityDate, + bool? visible, + }); + PresenceCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _PresenceCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, Presence, $Out> + implements PresenceCopyWith<$R, Presence, $Out> { + _PresenceCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + PresenceMapper.ensureInitialized(); + @override + $R call({ + String? title, + String? author, + Object? date = $none, + double? position, + String? value, + Object? emptyIs = $none, + PresenceColor? color, + Object? visibilityDate = $none, + Object? visible = $none, + }) => $apply( + FieldCopyWithData({ + if (title != null) #title: title, + if (author != null) #author: author, + if (date != $none) #date: date, + if (position != null) #position: position, + if (value != null) #value: value, + if (emptyIs != $none) #emptyIs: emptyIs, + if (color != null) #color: color, + if (visibilityDate != $none) #visibilityDate: visibilityDate, + if (visible != $none) #visible: visible, + }), + ); + @override + Presence $make(CopyWithData data) => Presence( + title: data.get(#title, or: $value.title), + author: data.get(#author, or: $value.author), + date: data.get(#date, or: $value.date), + position: data.get(#position, or: $value.position), + value: data.get(#value, or: $value.value), + emptyIs: data.get(#emptyIs, or: $value.emptyIs), + color: data.get(#color, or: $value.color), + visibilityDate: data.get(#visibilityDate, or: $value.visibilityDate), + visible: data.get(#visible, or: $value.visible), + ); + + @override + PresenceCopyWith<$R2, Presence, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _PresenceCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1tomussclient/lib/src/model/generated/semester.g.dart b/packages/lyon1tomussclient/lib/src/model/generated/semester.g.dart deleted file mode 100644 index d4f39cb91..000000000 --- a/packages/lyon1tomussclient/lib/src/model/generated/semester.g.dart +++ /dev/null @@ -1,71 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../semester.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$SemesterCWProxy { - Semester title(String title); - - Semester url(String url); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Semester(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Semester(...).copyWith(id: 12, name: "My name") - /// ``` - Semester call({ - String title, - String url, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfSemester.copyWith(...)` or call `instanceOfSemester.copyWith.fieldName(value)` for a single field. -class _$SemesterCWProxyImpl implements _$SemesterCWProxy { - const _$SemesterCWProxyImpl(this._value); - - final Semester _value; - - @override - Semester title(String title) => call(title: title); - - @override - Semester url(String url) => call(url: url); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Semester(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Semester(...).copyWith(id: 12, name: "My name") - /// ``` - Semester call({ - Object? title = const $CopyWithPlaceholder(), - Object? url = const $CopyWithPlaceholder(), - }) { - return Semester( - title: title == const $CopyWithPlaceholder() || title == null - ? _value.title - // ignore: cast_nullable_to_non_nullable - : title as String, - url: url == const $CopyWithPlaceholder() || url == null - ? _value.url - // ignore: cast_nullable_to_non_nullable - : url as String, - ); - } -} - -extension $SemesterCopyWith on Semester { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfSemester.copyWith(...)` or `instanceOfSemester.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$SemesterCWProxy get copyWith => _$SemesterCWProxyImpl(this); -} diff --git a/packages/lyon1tomussclient/lib/src/model/generated/semester.mapper.dart b/packages/lyon1tomussclient/lib/src/model/generated/semester.mapper.dart new file mode 100644 index 000000000..32eae779f --- /dev/null +++ b/packages/lyon1tomussclient/lib/src/model/generated/semester.mapper.dart @@ -0,0 +1,136 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../semester.dart'; + +class SemesterMapper extends ClassMapperBase { + SemesterMapper._(); + + static SemesterMapper? _instance; + static SemesterMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = SemesterMapper._()); + } + return _instance!; + } + + @override + final String id = 'Semester'; + + static String _$title(Semester v) => v.title; + static const Field _f$title = Field( + 'title', + _$title, + opt: true, + def: "", + ); + static String _$url(Semester v) => v.url; + static const Field _f$url = Field( + 'url', + _$url, + opt: true, + def: "", + ); + + @override + final MappableFields fields = const { + #title: _f$title, + #url: _f$url, + }; + + static Semester _instantiate(DecodingData data) { + return Semester(title: data.dec(_f$title), url: data.dec(_f$url)); + } + + @override + final Function instantiate = _instantiate; + + static Semester fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static Semester fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin SemesterMappable { + String toJson() { + return SemesterMapper.ensureInitialized().encodeJson( + this as Semester, + ); + } + + Map toMap() { + return SemesterMapper.ensureInitialized().encodeMap( + this as Semester, + ); + } + + SemesterCopyWith get copyWith => + _SemesterCopyWithImpl( + this as Semester, + $identity, + $identity, + ); + @override + String toString() { + return SemesterMapper.ensureInitialized().stringifyValue(this as Semester); + } + + @override + bool operator ==(Object other) { + return SemesterMapper.ensureInitialized().equalsValue( + this as Semester, + other, + ); + } + + @override + int get hashCode { + return SemesterMapper.ensureInitialized().hashValue(this as Semester); + } +} + +extension SemesterValueCopy<$R, $Out> on ObjectCopyWith<$R, Semester, $Out> { + SemesterCopyWith<$R, Semester, $Out> get $asSemester => + $base.as((v, t, t2) => _SemesterCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class SemesterCopyWith<$R, $In extends Semester, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({String? title, String? url}); + SemesterCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _SemesterCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, Semester, $Out> + implements SemesterCopyWith<$R, Semester, $Out> { + _SemesterCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + SemesterMapper.ensureInitialized(); + @override + $R call({String? title, String? url}) => $apply( + FieldCopyWithData({ + if (title != null) #title: title, + if (url != null) #url: url, + }), + ); + @override + Semester $make(CopyWithData data) => Semester( + title: data.get(#title, or: $value.title), + url: data.get(#url, or: $value.url), + ); + + @override + SemesterCopyWith<$R2, Semester, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _SemesterCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1tomussclient/lib/src/model/generated/semester_list.g.dart b/packages/lyon1tomussclient/lib/src/model/generated/semester_list.g.dart deleted file mode 100644 index 3f1992a62..000000000 --- a/packages/lyon1tomussclient/lib/src/model/generated/semester_list.g.dart +++ /dev/null @@ -1,75 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../semester_list.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$SemesterListCWProxy { - SemesterList semestres(List semestres); - - SemesterList currentSemesterIndex(int currentSemesterIndex); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `SemesterList(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// SemesterList(...).copyWith(id: 12, name: "My name") - /// ``` - SemesterList call({ - List semestres, - int currentSemesterIndex, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfSemesterList.copyWith(...)` or call `instanceOfSemesterList.copyWith.fieldName(value)` for a single field. -class _$SemesterListCWProxyImpl implements _$SemesterListCWProxy { - const _$SemesterListCWProxyImpl(this._value); - - final SemesterList _value; - - @override - SemesterList semestres(List semestres) => - call(semestres: semestres); - - @override - SemesterList currentSemesterIndex(int currentSemesterIndex) => - call(currentSemesterIndex: currentSemesterIndex); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `SemesterList(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// SemesterList(...).copyWith(id: 12, name: "My name") - /// ``` - SemesterList call({ - Object? semestres = const $CopyWithPlaceholder(), - Object? currentSemesterIndex = const $CopyWithPlaceholder(), - }) { - return SemesterList( - semestres == const $CopyWithPlaceholder() || semestres == null - ? _value.semestres - // ignore: cast_nullable_to_non_nullable - : semestres as List, - currentSemesterIndex: - currentSemesterIndex == const $CopyWithPlaceholder() || - currentSemesterIndex == null - ? _value.currentSemesterIndex - // ignore: cast_nullable_to_non_nullable - : currentSemesterIndex as int, - ); - } -} - -extension $SemesterListCopyWith on SemesterList { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfSemesterList.copyWith(...)` or `instanceOfSemesterList.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$SemesterListCWProxy get copyWith => _$SemesterListCWProxyImpl(this); -} diff --git a/packages/lyon1tomussclient/lib/src/model/generated/semester_list.mapper.dart b/packages/lyon1tomussclient/lib/src/model/generated/semester_list.mapper.dart new file mode 100644 index 000000000..6a1665c14 --- /dev/null +++ b/packages/lyon1tomussclient/lib/src/model/generated/semester_list.mapper.dart @@ -0,0 +1,156 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../semester_list.dart'; + +class SemesterListMapper extends ClassMapperBase { + SemesterListMapper._(); + + static SemesterListMapper? _instance; + static SemesterListMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = SemesterListMapper._()); + SemesterMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'SemesterList'; + + static List _$semestres(SemesterList v) => v.semestres; + static const Field> _f$semestres = Field( + 'semestres', + _$semestres, + ); + static int _$currentSemesterIndex(SemesterList v) => v.currentSemesterIndex; + static const Field _f$currentSemesterIndex = Field( + 'currentSemesterIndex', + _$currentSemesterIndex, + opt: true, + def: 0, + ); + + @override + final MappableFields fields = const { + #semestres: _f$semestres, + #currentSemesterIndex: _f$currentSemesterIndex, + }; + + static SemesterList _instantiate(DecodingData data) { + return SemesterList( + data.dec(_f$semestres), + currentSemesterIndex: data.dec(_f$currentSemesterIndex), + ); + } + + @override + final Function instantiate = _instantiate; + + static SemesterList fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static SemesterList fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin SemesterListMappable { + String toJson() { + return SemesterListMapper.ensureInitialized().encodeJson( + this as SemesterList, + ); + } + + Map toMap() { + return SemesterListMapper.ensureInitialized().encodeMap( + this as SemesterList, + ); + } + + SemesterListCopyWith get copyWith => + _SemesterListCopyWithImpl( + this as SemesterList, + $identity, + $identity, + ); + @override + String toString() { + return SemesterListMapper.ensureInitialized().stringifyValue( + this as SemesterList, + ); + } + + @override + bool operator ==(Object other) { + return SemesterListMapper.ensureInitialized().equalsValue( + this as SemesterList, + other, + ); + } + + @override + int get hashCode { + return SemesterListMapper.ensureInitialized().hashValue( + this as SemesterList, + ); + } +} + +extension SemesterListValueCopy<$R, $Out> + on ObjectCopyWith<$R, SemesterList, $Out> { + SemesterListCopyWith<$R, SemesterList, $Out> get $asSemesterList => + $base.as((v, t, t2) => _SemesterListCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class SemesterListCopyWith<$R, $In extends SemesterList, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, Semester, SemesterCopyWith<$R, Semester, Semester>> + get semestres; + $R call({List? semestres, int? currentSemesterIndex}); + SemesterListCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _SemesterListCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, SemesterList, $Out> + implements SemesterListCopyWith<$R, SemesterList, $Out> { + _SemesterListCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + SemesterListMapper.ensureInitialized(); + @override + ListCopyWith<$R, Semester, SemesterCopyWith<$R, Semester, Semester>> + get semestres => ListCopyWith( + $value.semestres, + (v, t) => v.copyWith.$chain(t), + (v) => call(semestres: v), + ); + @override + $R call({List? semestres, int? currentSemesterIndex}) => $apply( + FieldCopyWithData({ + if (semestres != null) #semestres: semestres, + if (currentSemesterIndex != null) + #currentSemesterIndex: currentSemesterIndex, + }), + ); + @override + SemesterList $make(CopyWithData data) => SemesterList( + data.get(#semestres, or: $value.semestres), + currentSemesterIndex: data.get( + #currentSemesterIndex, + or: $value.currentSemesterIndex, + ), + ); + + @override + SemesterListCopyWith<$R2, SemesterList, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _SemesterListCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1tomussclient/lib/src/model/generated/stage_code.g.dart b/packages/lyon1tomussclient/lib/src/model/generated/stage_code.g.dart deleted file mode 100644 index 39207de79..000000000 --- a/packages/lyon1tomussclient/lib/src/model/generated/stage_code.g.dart +++ /dev/null @@ -1,104 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../stage_code.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$StageCodeCWProxy { - StageCode title(String title); - - StageCode author(String author); - - StageCode date(DateTime? date); - - StageCode position(double position); - - StageCode value(String value); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `StageCode(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// StageCode(...).copyWith(id: 12, name: "My name") - /// ``` - StageCode call({ - String title, - String author, - DateTime? date, - double position, - String value, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfStageCode.copyWith(...)` or call `instanceOfStageCode.copyWith.fieldName(value)` for a single field. -class _$StageCodeCWProxyImpl implements _$StageCodeCWProxy { - const _$StageCodeCWProxyImpl(this._value); - - final StageCode _value; - - @override - StageCode title(String title) => call(title: title); - - @override - StageCode author(String author) => call(author: author); - - @override - StageCode date(DateTime? date) => call(date: date); - - @override - StageCode position(double position) => call(position: position); - - @override - StageCode value(String value) => call(value: value); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `StageCode(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// StageCode(...).copyWith(id: 12, name: "My name") - /// ``` - StageCode call({ - Object? title = const $CopyWithPlaceholder(), - Object? author = const $CopyWithPlaceholder(), - Object? date = const $CopyWithPlaceholder(), - Object? position = const $CopyWithPlaceholder(), - Object? value = const $CopyWithPlaceholder(), - }) { - return StageCode( - title: title == const $CopyWithPlaceholder() || title == null - ? _value.title - // ignore: cast_nullable_to_non_nullable - : title as String, - author: author == const $CopyWithPlaceholder() || author == null - ? _value.author - // ignore: cast_nullable_to_non_nullable - : author as String, - date: date == const $CopyWithPlaceholder() - ? _value.date - // ignore: cast_nullable_to_non_nullable - : date as DateTime?, - position: position == const $CopyWithPlaceholder() || position == null - ? _value.position - // ignore: cast_nullable_to_non_nullable - : position as double, - value: value == const $CopyWithPlaceholder() || value == null - ? _value.value - // ignore: cast_nullable_to_non_nullable - : value as String, - ); - } -} - -extension $StageCodeCopyWith on StageCode { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfStageCode.copyWith(...)` or `instanceOfStageCode.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$StageCodeCWProxy get copyWith => _$StageCodeCWProxyImpl(this); -} diff --git a/packages/lyon1tomussclient/lib/src/model/generated/stage_code.mapper.dart b/packages/lyon1tomussclient/lib/src/model/generated/stage_code.mapper.dart new file mode 100644 index 000000000..2269ab661 --- /dev/null +++ b/packages/lyon1tomussclient/lib/src/model/generated/stage_code.mapper.dart @@ -0,0 +1,183 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../stage_code.dart'; + +class StageCodeMapper extends ClassMapperBase { + StageCodeMapper._(); + + static StageCodeMapper? _instance; + static StageCodeMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = StageCodeMapper._()); + } + return _instance!; + } + + @override + final String id = 'StageCode'; + + static String _$title(StageCode v) => v.title; + static const Field _f$title = Field('title', _$title); + static String _$author(StageCode v) => v.author; + static const Field _f$author = Field('author', _$author); + static DateTime? _$date(StageCode v) => v.date; + static const Field _f$date = Field('date', _$date); + static double _$position(StageCode v) => v.position; + static const Field _f$position = Field( + 'position', + _$position, + ); + static String _$value(StageCode v) => v.value; + static const Field _f$value = Field( + 'value', + _$value, + opt: true, + def: "", + ); + static bool _$isVisible(StageCode v) => v.isVisible; + static const Field _f$isVisible = Field( + 'isVisible', + _$isVisible, + mode: FieldMode.member, + ); + static List _$customProps(StageCode v) => v.customProps; + static const Field> _f$customProps = Field( + 'customProps', + _$customProps, + mode: FieldMode.member, + ); + + @override + final MappableFields fields = const { + #title: _f$title, + #author: _f$author, + #date: _f$date, + #position: _f$position, + #value: _f$value, + #isVisible: _f$isVisible, + #customProps: _f$customProps, + }; + + static StageCode _instantiate(DecodingData data) { + return StageCode( + title: data.dec(_f$title), + author: data.dec(_f$author), + date: data.dec(_f$date), + position: data.dec(_f$position), + value: data.dec(_f$value), + ); + } + + @override + final Function instantiate = _instantiate; + + static StageCode fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static StageCode fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin StageCodeMappable { + String toJson() { + return StageCodeMapper.ensureInitialized().encodeJson( + this as StageCode, + ); + } + + Map toMap() { + return StageCodeMapper.ensureInitialized().encodeMap( + this as StageCode, + ); + } + + StageCodeCopyWith get copyWith => + _StageCodeCopyWithImpl( + this as StageCode, + $identity, + $identity, + ); + @override + String toString() { + return StageCodeMapper.ensureInitialized().stringifyValue( + this as StageCode, + ); + } + + @override + bool operator ==(Object other) { + return StageCodeMapper.ensureInitialized().equalsValue( + this as StageCode, + other, + ); + } + + @override + int get hashCode { + return StageCodeMapper.ensureInitialized().hashValue(this as StageCode); + } +} + +extension StageCodeValueCopy<$R, $Out> on ObjectCopyWith<$R, StageCode, $Out> { + StageCodeCopyWith<$R, StageCode, $Out> get $asStageCode => + $base.as((v, t, t2) => _StageCodeCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class StageCodeCopyWith<$R, $In extends StageCode, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({ + String? title, + String? author, + DateTime? date, + double? position, + String? value, + }); + StageCodeCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _StageCodeCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, StageCode, $Out> + implements StageCodeCopyWith<$R, StageCode, $Out> { + _StageCodeCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + StageCodeMapper.ensureInitialized(); + @override + $R call({ + String? title, + String? author, + Object? date = $none, + double? position, + String? value, + }) => $apply( + FieldCopyWithData({ + if (title != null) #title: title, + if (author != null) #author: author, + if (date != $none) #date: date, + if (position != null) #position: position, + if (value != null) #value: value, + }), + ); + @override + StageCode $make(CopyWithData data) => StageCode( + title: data.get(#title, or: $value.title), + author: data.get(#author, or: $value.author), + date: data.get(#date, or: $value.date), + position: data.get(#position, or: $value.position), + value: data.get(#value, or: $value.value), + ); + + @override + StageCodeCopyWith<$R2, StageCode, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _StageCodeCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1tomussclient/lib/src/model/generated/student.g.dart b/packages/lyon1tomussclient/lib/src/model/generated/student.g.dart deleted file mode 100644 index 7655e4a8d..000000000 --- a/packages/lyon1tomussclient/lib/src/model/generated/student.g.dart +++ /dev/null @@ -1,82 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../student.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$StudentCWProxy { - Student name(String name); - - Student surname(String surname); - - Student email(String email); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Student(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Student(...).copyWith(id: 12, name: "My name") - /// ``` - Student call({ - String name, - String surname, - String email, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfStudent.copyWith(...)` or call `instanceOfStudent.copyWith.fieldName(value)` for a single field. -class _$StudentCWProxyImpl implements _$StudentCWProxy { - const _$StudentCWProxyImpl(this._value); - - final Student _value; - - @override - Student name(String name) => call(name: name); - - @override - Student surname(String surname) => call(surname: surname); - - @override - Student email(String email) => call(email: email); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Student(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Student(...).copyWith(id: 12, name: "My name") - /// ``` - Student call({ - Object? name = const $CopyWithPlaceholder(), - Object? surname = const $CopyWithPlaceholder(), - Object? email = const $CopyWithPlaceholder(), - }) { - return Student( - name: name == const $CopyWithPlaceholder() || name == null - ? _value.name - // ignore: cast_nullable_to_non_nullable - : name as String, - surname: surname == const $CopyWithPlaceholder() || surname == null - ? _value.surname - // ignore: cast_nullable_to_non_nullable - : surname as String, - email: email == const $CopyWithPlaceholder() || email == null - ? _value.email - // ignore: cast_nullable_to_non_nullable - : email as String, - ); - } -} - -extension $StudentCopyWith on Student { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfStudent.copyWith(...)` or `instanceOfStudent.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$StudentCWProxy get copyWith => _$StudentCWProxyImpl(this); -} diff --git a/packages/lyon1tomussclient/lib/src/model/generated/student.mapper.dart b/packages/lyon1tomussclient/lib/src/model/generated/student.mapper.dart new file mode 100644 index 000000000..505b56c32 --- /dev/null +++ b/packages/lyon1tomussclient/lib/src/model/generated/student.mapper.dart @@ -0,0 +1,149 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../student.dart'; + +class StudentMapper extends ClassMapperBase { + StudentMapper._(); + + static StudentMapper? _instance; + static StudentMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = StudentMapper._()); + } + return _instance!; + } + + @override + final String id = 'Student'; + + static String _$name(Student v) => v.name; + static const Field _f$name = Field( + 'name', + _$name, + opt: true, + def: "", + ); + static String _$surname(Student v) => v.surname; + static const Field _f$surname = Field( + 'surname', + _$surname, + opt: true, + def: "", + ); + static String _$email(Student v) => v.email; + static const Field _f$email = Field( + 'email', + _$email, + opt: true, + def: "", + ); + + @override + final MappableFields fields = const { + #name: _f$name, + #surname: _f$surname, + #email: _f$email, + }; + + static Student _instantiate(DecodingData data) { + return Student( + name: data.dec(_f$name), + surname: data.dec(_f$surname), + email: data.dec(_f$email), + ); + } + + @override + final Function instantiate = _instantiate; + + static Student fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static Student fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin StudentMappable { + String toJson() { + return StudentMapper.ensureInitialized().encodeJson( + this as Student, + ); + } + + Map toMap() { + return StudentMapper.ensureInitialized().encodeMap( + this as Student, + ); + } + + StudentCopyWith get copyWith => + _StudentCopyWithImpl( + this as Student, + $identity, + $identity, + ); + @override + String toString() { + return StudentMapper.ensureInitialized().stringifyValue(this as Student); + } + + @override + bool operator ==(Object other) { + return StudentMapper.ensureInitialized().equalsValue( + this as Student, + other, + ); + } + + @override + int get hashCode { + return StudentMapper.ensureInitialized().hashValue(this as Student); + } +} + +extension StudentValueCopy<$R, $Out> on ObjectCopyWith<$R, Student, $Out> { + StudentCopyWith<$R, Student, $Out> get $asStudent => + $base.as((v, t, t2) => _StudentCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class StudentCopyWith<$R, $In extends Student, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({String? name, String? surname, String? email}); + StudentCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _StudentCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, Student, $Out> + implements StudentCopyWith<$R, Student, $Out> { + _StudentCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + StudentMapper.ensureInitialized(); + @override + $R call({String? name, String? surname, String? email}) => $apply( + FieldCopyWithData({ + if (name != null) #name: name, + if (surname != null) #surname: surname, + if (email != null) #email: email, + }), + ); + @override + Student $make(CopyWithData data) => Student( + name: data.get(#name, or: $value.name), + surname: data.get(#surname, or: $value.surname), + email: data.get(#email, or: $value.email), + ); + + @override + StudentCopyWith<$R2, Student, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _StudentCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1tomussclient/lib/src/model/generated/teacher.g.dart b/packages/lyon1tomussclient/lib/src/model/generated/teacher.g.dart deleted file mode 100644 index 74ba14b98..000000000 --- a/packages/lyon1tomussclient/lib/src/model/generated/teacher.g.dart +++ /dev/null @@ -1,71 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../teacher.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$TeacherCWProxy { - Teacher name(String name); - - Teacher email(String email); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Teacher(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Teacher(...).copyWith(id: 12, name: "My name") - /// ``` - Teacher call({ - String name, - String email, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfTeacher.copyWith(...)` or call `instanceOfTeacher.copyWith.fieldName(value)` for a single field. -class _$TeacherCWProxyImpl implements _$TeacherCWProxy { - const _$TeacherCWProxyImpl(this._value); - - final Teacher _value; - - @override - Teacher name(String name) => call(name: name); - - @override - Teacher email(String email) => call(email: email); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Teacher(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Teacher(...).copyWith(id: 12, name: "My name") - /// ``` - Teacher call({ - Object? name = const $CopyWithPlaceholder(), - Object? email = const $CopyWithPlaceholder(), - }) { - return Teacher( - name: name == const $CopyWithPlaceholder() || name == null - ? _value.name - // ignore: cast_nullable_to_non_nullable - : name as String, - email: email == const $CopyWithPlaceholder() || email == null - ? _value.email - // ignore: cast_nullable_to_non_nullable - : email as String, - ); - } -} - -extension $TeacherCopyWith on Teacher { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfTeacher.copyWith(...)` or `instanceOfTeacher.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$TeacherCWProxy get copyWith => _$TeacherCWProxyImpl(this); -} diff --git a/packages/lyon1tomussclient/lib/src/model/generated/teacher.mapper.dart b/packages/lyon1tomussclient/lib/src/model/generated/teacher.mapper.dart new file mode 100644 index 000000000..215bd8ffe --- /dev/null +++ b/packages/lyon1tomussclient/lib/src/model/generated/teacher.mapper.dart @@ -0,0 +1,135 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../teacher.dart'; + +class TeacherMapper extends ClassMapperBase { + TeacherMapper._(); + + static TeacherMapper? _instance; + static TeacherMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = TeacherMapper._()); + } + return _instance!; + } + + @override + final String id = 'Teacher'; + + static String _$name(Teacher v) => v.name; + static const Field _f$name = Field( + 'name', + _$name, + opt: true, + def: "", + ); + static String _$email(Teacher v) => v.email; + static const Field _f$email = Field( + 'email', + _$email, + opt: true, + def: "", + ); + + @override + final MappableFields fields = const { + #name: _f$name, + #email: _f$email, + }; + + static Teacher _instantiate(DecodingData data) { + return Teacher(name: data.dec(_f$name), email: data.dec(_f$email)); + } + + @override + final Function instantiate = _instantiate; + + static Teacher fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static Teacher fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin TeacherMappable { + String toJson() { + return TeacherMapper.ensureInitialized().encodeJson( + this as Teacher, + ); + } + + Map toMap() { + return TeacherMapper.ensureInitialized().encodeMap( + this as Teacher, + ); + } + + TeacherCopyWith get copyWith => + _TeacherCopyWithImpl( + this as Teacher, + $identity, + $identity, + ); + @override + String toString() { + return TeacherMapper.ensureInitialized().stringifyValue(this as Teacher); + } + + @override + bool operator ==(Object other) { + return TeacherMapper.ensureInitialized().equalsValue( + this as Teacher, + other, + ); + } + + @override + int get hashCode { + return TeacherMapper.ensureInitialized().hashValue(this as Teacher); + } +} + +extension TeacherValueCopy<$R, $Out> on ObjectCopyWith<$R, Teacher, $Out> { + TeacherCopyWith<$R, Teacher, $Out> get $asTeacher => + $base.as((v, t, t2) => _TeacherCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class TeacherCopyWith<$R, $In extends Teacher, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({String? name, String? email}); + TeacherCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _TeacherCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, Teacher, $Out> + implements TeacherCopyWith<$R, Teacher, $Out> { + _TeacherCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + TeacherMapper.ensureInitialized(); + @override + $R call({String? name, String? email}) => $apply( + FieldCopyWithData({ + if (name != null) #name: name, + if (email != null) #email: email, + }), + ); + @override + Teacher $make(CopyWithData data) => Teacher( + name: data.get(#name, or: $value.name), + email: data.get(#email, or: $value.email), + ); + + @override + TeacherCopyWith<$R2, Teacher, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _TeacherCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1tomussclient/lib/src/model/generated/teaching_unit.g.dart b/packages/lyon1tomussclient/lib/src/model/generated/teaching_unit.g.dart deleted file mode 100644 index 18b896070..000000000 --- a/packages/lyon1tomussclient/lib/src/model/generated/teaching_unit.g.dart +++ /dev/null @@ -1,177 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../teaching_unit.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$TeachingUnitCWProxy { - TeachingUnit title(String title); - - TeachingUnit masters(List masters); - - TeachingUnit grades(List grades); - - TeachingUnit textValues(List textValues); - - TeachingUnit enumerations(List enumerations); - - TeachingUnit presences(List presences); - - TeachingUnit stageCodes(List stageCodes); - - TeachingUnit uploads(List uploads); - - TeachingUnit urls(List urls); - - TeachingUnit ticket(String ticket); - - TeachingUnit ue(String ue); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `TeachingUnit(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// TeachingUnit(...).copyWith(id: 12, name: "My name") - /// ``` - TeachingUnit call({ - String title, - List masters, - List grades, - List textValues, - List enumerations, - List presences, - List stageCodes, - List uploads, - List urls, - String ticket, - String ue, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfTeachingUnit.copyWith(...)` or call `instanceOfTeachingUnit.copyWith.fieldName(value)` for a single field. -class _$TeachingUnitCWProxyImpl implements _$TeachingUnitCWProxy { - const _$TeachingUnitCWProxyImpl(this._value); - - final TeachingUnit _value; - - @override - TeachingUnit title(String title) => call(title: title); - - @override - TeachingUnit masters(List masters) => call(masters: masters); - - @override - TeachingUnit grades(List grades) => call(grades: grades); - - @override - TeachingUnit textValues(List textValues) => - call(textValues: textValues); - - @override - TeachingUnit enumerations(List enumerations) => - call(enumerations: enumerations); - - @override - TeachingUnit presences(List presences) => - call(presences: presences); - - @override - TeachingUnit stageCodes(List stageCodes) => - call(stageCodes: stageCodes); - - @override - TeachingUnit uploads(List uploads) => call(uploads: uploads); - - @override - TeachingUnit urls(List urls) => call(urls: urls); - - @override - TeachingUnit ticket(String ticket) => call(ticket: ticket); - - @override - TeachingUnit ue(String ue) => call(ue: ue); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `TeachingUnit(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// TeachingUnit(...).copyWith(id: 12, name: "My name") - /// ``` - TeachingUnit call({ - Object? title = const $CopyWithPlaceholder(), - Object? masters = const $CopyWithPlaceholder(), - Object? grades = const $CopyWithPlaceholder(), - Object? textValues = const $CopyWithPlaceholder(), - Object? enumerations = const $CopyWithPlaceholder(), - Object? presences = const $CopyWithPlaceholder(), - Object? stageCodes = const $CopyWithPlaceholder(), - Object? uploads = const $CopyWithPlaceholder(), - Object? urls = const $CopyWithPlaceholder(), - Object? ticket = const $CopyWithPlaceholder(), - Object? ue = const $CopyWithPlaceholder(), - }) { - return TeachingUnit( - title: title == const $CopyWithPlaceholder() || title == null - ? _value.title - // ignore: cast_nullable_to_non_nullable - : title as String, - masters: masters == const $CopyWithPlaceholder() || masters == null - ? _value.masters - // ignore: cast_nullable_to_non_nullable - : masters as List, - grades: grades == const $CopyWithPlaceholder() || grades == null - ? _value.grades - // ignore: cast_nullable_to_non_nullable - : grades as List, - textValues: - textValues == const $CopyWithPlaceholder() || textValues == null - ? _value.textValues - // ignore: cast_nullable_to_non_nullable - : textValues as List, - enumerations: - enumerations == const $CopyWithPlaceholder() || enumerations == null - ? _value.enumerations - // ignore: cast_nullable_to_non_nullable - : enumerations as List, - presences: presences == const $CopyWithPlaceholder() || presences == null - ? _value.presences - // ignore: cast_nullable_to_non_nullable - : presences as List, - stageCodes: - stageCodes == const $CopyWithPlaceholder() || stageCodes == null - ? _value.stageCodes - // ignore: cast_nullable_to_non_nullable - : stageCodes as List, - uploads: uploads == const $CopyWithPlaceholder() || uploads == null - ? _value.uploads - // ignore: cast_nullable_to_non_nullable - : uploads as List, - urls: urls == const $CopyWithPlaceholder() || urls == null - ? _value.urls - // ignore: cast_nullable_to_non_nullable - : urls as List, - ticket: ticket == const $CopyWithPlaceholder() || ticket == null - ? _value.ticket - // ignore: cast_nullable_to_non_nullable - : ticket as String, - ue: ue == const $CopyWithPlaceholder() || ue == null - ? _value.ue - // ignore: cast_nullable_to_non_nullable - : ue as String, - ); - } -} - -extension $TeachingUnitCopyWith on TeachingUnit { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfTeachingUnit.copyWith(...)` or `instanceOfTeachingUnit.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$TeachingUnitCWProxy get copyWith => _$TeachingUnitCWProxyImpl(this); -} diff --git a/packages/lyon1tomussclient/lib/src/model/generated/teaching_unit.mapper.dart b/packages/lyon1tomussclient/lib/src/model/generated/teaching_unit.mapper.dart new file mode 100644 index 000000000..a79a0b176 --- /dev/null +++ b/packages/lyon1tomussclient/lib/src/model/generated/teaching_unit.mapper.dart @@ -0,0 +1,363 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../teaching_unit.dart'; + +class TeachingUnitMapper extends ClassMapperBase { + TeachingUnitMapper._(); + + static TeachingUnitMapper? _instance; + static TeachingUnitMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = TeachingUnitMapper._()); + TeacherMapper.ensureInitialized(); + GradeMapper.ensureInitialized(); + TomussTextMapper.ensureInitialized(); + EnumerationMapper.ensureInitialized(); + PresenceMapper.ensureInitialized(); + StageCodeMapper.ensureInitialized(); + UploadMapper.ensureInitialized(); + URLMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'TeachingUnit'; + + static String _$title(TeachingUnit v) => v.title; + static const Field _f$title = Field( + 'title', + _$title, + opt: true, + def: "", + ); + static List _$masters(TeachingUnit v) => v.masters; + static const Field> _f$masters = Field( + 'masters', + _$masters, + opt: true, + def: const [], + ); + static List _$grades(TeachingUnit v) => v.grades; + static const Field> _f$grades = Field( + 'grades', + _$grades, + opt: true, + def: const [], + ); + static List _$textValues(TeachingUnit v) => v.textValues; + static const Field> _f$textValues = Field( + 'textValues', + _$textValues, + opt: true, + def: const [], + ); + static List _$enumerations(TeachingUnit v) => v.enumerations; + static const Field> _f$enumerations = Field( + 'enumerations', + _$enumerations, + opt: true, + def: const [], + ); + static List _$presences(TeachingUnit v) => v.presences; + static const Field> _f$presences = Field( + 'presences', + _$presences, + opt: true, + def: const [], + ); + static List _$stageCodes(TeachingUnit v) => v.stageCodes; + static const Field> _f$stageCodes = Field( + 'stageCodes', + _$stageCodes, + opt: true, + def: const [], + ); + static List _$uploads(TeachingUnit v) => v.uploads; + static const Field> _f$uploads = Field( + 'uploads', + _$uploads, + opt: true, + def: const [], + ); + static List _$urls(TeachingUnit v) => v.urls; + static const Field> _f$urls = Field( + 'urls', + _$urls, + opt: true, + def: const [], + ); + static String _$ticket(TeachingUnit v) => v.ticket; + static const Field _f$ticket = Field( + 'ticket', + _$ticket, + opt: true, + def: "", + ); + static String _$ue(TeachingUnit v) => v.ue; + static const Field _f$ue = Field( + 'ue', + _$ue, + opt: true, + def: "", + ); + static List _$children(TeachingUnit v) => v.children; + static const Field> _f$children = + Field('children', _$children, mode: FieldMode.member); + static List _$visibleChildren(TeachingUnit v) => + v.visibleChildren; + static const Field> + _f$visibleChildren = Field( + 'visibleChildren', + _$visibleChildren, + mode: FieldMode.member, + ); + + @override + final MappableFields fields = const { + #title: _f$title, + #masters: _f$masters, + #grades: _f$grades, + #textValues: _f$textValues, + #enumerations: _f$enumerations, + #presences: _f$presences, + #stageCodes: _f$stageCodes, + #uploads: _f$uploads, + #urls: _f$urls, + #ticket: _f$ticket, + #ue: _f$ue, + #children: _f$children, + #visibleChildren: _f$visibleChildren, + }; + + static TeachingUnit _instantiate(DecodingData data) { + return TeachingUnit( + title: data.dec(_f$title), + masters: data.dec(_f$masters), + grades: data.dec(_f$grades), + textValues: data.dec(_f$textValues), + enumerations: data.dec(_f$enumerations), + presences: data.dec(_f$presences), + stageCodes: data.dec(_f$stageCodes), + uploads: data.dec(_f$uploads), + urls: data.dec(_f$urls), + ticket: data.dec(_f$ticket), + ue: data.dec(_f$ue), + ); + } + + @override + final Function instantiate = _instantiate; + + static TeachingUnit fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static TeachingUnit fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin TeachingUnitMappable { + String toJson() { + return TeachingUnitMapper.ensureInitialized().encodeJson( + this as TeachingUnit, + ); + } + + Map toMap() { + return TeachingUnitMapper.ensureInitialized().encodeMap( + this as TeachingUnit, + ); + } + + TeachingUnitCopyWith get copyWith => + _TeachingUnitCopyWithImpl( + this as TeachingUnit, + $identity, + $identity, + ); + @override + String toString() { + return TeachingUnitMapper.ensureInitialized().stringifyValue( + this as TeachingUnit, + ); + } + + @override + bool operator ==(Object other) { + return TeachingUnitMapper.ensureInitialized().equalsValue( + this as TeachingUnit, + other, + ); + } + + @override + int get hashCode { + return TeachingUnitMapper.ensureInitialized().hashValue( + this as TeachingUnit, + ); + } +} + +extension TeachingUnitValueCopy<$R, $Out> + on ObjectCopyWith<$R, TeachingUnit, $Out> { + TeachingUnitCopyWith<$R, TeachingUnit, $Out> get $asTeachingUnit => + $base.as((v, t, t2) => _TeachingUnitCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class TeachingUnitCopyWith<$R, $In extends TeachingUnit, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith<$R, Teacher, TeacherCopyWith<$R, Teacher, Teacher>> get masters; + ListCopyWith<$R, Grade, GradeCopyWith<$R, Grade, Grade>> get grades; + ListCopyWith<$R, TomussText, TomussTextCopyWith<$R, TomussText, TomussText>> + get textValues; + ListCopyWith< + $R, + Enumeration, + EnumerationCopyWith<$R, Enumeration, Enumeration> + > + get enumerations; + ListCopyWith<$R, Presence, PresenceCopyWith<$R, Presence, Presence>> + get presences; + ListCopyWith<$R, StageCode, StageCodeCopyWith<$R, StageCode, StageCode>> + get stageCodes; + ListCopyWith<$R, Upload, UploadCopyWith<$R, Upload, Upload>> get uploads; + ListCopyWith<$R, URL, URLCopyWith<$R, URL, URL>> get urls; + $R call({ + String? title, + List? masters, + List? grades, + List? textValues, + List? enumerations, + List? presences, + List? stageCodes, + List? uploads, + List? urls, + String? ticket, + String? ue, + }); + TeachingUnitCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _TeachingUnitCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, TeachingUnit, $Out> + implements TeachingUnitCopyWith<$R, TeachingUnit, $Out> { + _TeachingUnitCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + TeachingUnitMapper.ensureInitialized(); + @override + ListCopyWith<$R, Teacher, TeacherCopyWith<$R, Teacher, Teacher>> + get masters => ListCopyWith( + $value.masters, + (v, t) => v.copyWith.$chain(t), + (v) => call(masters: v), + ); + @override + ListCopyWith<$R, Grade, GradeCopyWith<$R, Grade, Grade>> get grades => + ListCopyWith( + $value.grades, + (v, t) => v.copyWith.$chain(t), + (v) => call(grades: v), + ); + @override + ListCopyWith<$R, TomussText, TomussTextCopyWith<$R, TomussText, TomussText>> + get textValues => ListCopyWith( + $value.textValues, + (v, t) => v.copyWith.$chain(t), + (v) => call(textValues: v), + ); + @override + ListCopyWith< + $R, + Enumeration, + EnumerationCopyWith<$R, Enumeration, Enumeration> + > + get enumerations => ListCopyWith( + $value.enumerations, + (v, t) => v.copyWith.$chain(t), + (v) => call(enumerations: v), + ); + @override + ListCopyWith<$R, Presence, PresenceCopyWith<$R, Presence, Presence>> + get presences => ListCopyWith( + $value.presences, + (v, t) => v.copyWith.$chain(t), + (v) => call(presences: v), + ); + @override + ListCopyWith<$R, StageCode, StageCodeCopyWith<$R, StageCode, StageCode>> + get stageCodes => ListCopyWith( + $value.stageCodes, + (v, t) => v.copyWith.$chain(t), + (v) => call(stageCodes: v), + ); + @override + ListCopyWith<$R, Upload, UploadCopyWith<$R, Upload, Upload>> get uploads => + ListCopyWith( + $value.uploads, + (v, t) => v.copyWith.$chain(t), + (v) => call(uploads: v), + ); + @override + ListCopyWith<$R, URL, URLCopyWith<$R, URL, URL>> get urls => ListCopyWith( + $value.urls, + (v, t) => v.copyWith.$chain(t), + (v) => call(urls: v), + ); + @override + $R call({ + String? title, + List? masters, + List? grades, + List? textValues, + List? enumerations, + List? presences, + List? stageCodes, + List? uploads, + List? urls, + String? ticket, + String? ue, + }) => $apply( + FieldCopyWithData({ + if (title != null) #title: title, + if (masters != null) #masters: masters, + if (grades != null) #grades: grades, + if (textValues != null) #textValues: textValues, + if (enumerations != null) #enumerations: enumerations, + if (presences != null) #presences: presences, + if (stageCodes != null) #stageCodes: stageCodes, + if (uploads != null) #uploads: uploads, + if (urls != null) #urls: urls, + if (ticket != null) #ticket: ticket, + if (ue != null) #ue: ue, + }), + ); + @override + TeachingUnit $make(CopyWithData data) => TeachingUnit( + title: data.get(#title, or: $value.title), + masters: data.get(#masters, or: $value.masters), + grades: data.get(#grades, or: $value.grades), + textValues: data.get(#textValues, or: $value.textValues), + enumerations: data.get(#enumerations, or: $value.enumerations), + presences: data.get(#presences, or: $value.presences), + stageCodes: data.get(#stageCodes, or: $value.stageCodes), + uploads: data.get(#uploads, or: $value.uploads), + urls: data.get(#urls, or: $value.urls), + ticket: data.get(#ticket, or: $value.ticket), + ue: data.get(#ue, or: $value.ue), + ); + + @override + TeachingUnitCopyWith<$R2, TeachingUnit, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _TeachingUnitCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1tomussclient/lib/src/model/generated/teaching_unit_list.g.dart b/packages/lyon1tomussclient/lib/src/model/generated/teaching_unit_list.g.dart deleted file mode 100644 index 46c038903..000000000 --- a/packages/lyon1tomussclient/lib/src/model/generated/teaching_unit_list.g.dart +++ /dev/null @@ -1,74 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../teaching_unit_list.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$TeachingUnitListCWProxy { - TeachingUnitList teachingUnitModels(List teachingUnitModels); - - TeachingUnitList semesterIndex(int semesterIndex); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `TeachingUnitList(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// TeachingUnitList(...).copyWith(id: 12, name: "My name") - /// ``` - TeachingUnitList call({ - List teachingUnitModels, - int semesterIndex, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfTeachingUnitList.copyWith(...)` or call `instanceOfTeachingUnitList.copyWith.fieldName(value)` for a single field. -class _$TeachingUnitListCWProxyImpl implements _$TeachingUnitListCWProxy { - const _$TeachingUnitListCWProxyImpl(this._value); - - final TeachingUnitList _value; - - @override - TeachingUnitList teachingUnitModels(List teachingUnitModels) => - call(teachingUnitModels: teachingUnitModels); - - @override - TeachingUnitList semesterIndex(int semesterIndex) => - call(semesterIndex: semesterIndex); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `TeachingUnitList(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// TeachingUnitList(...).copyWith(id: 12, name: "My name") - /// ``` - TeachingUnitList call({ - Object? teachingUnitModels = const $CopyWithPlaceholder(), - Object? semesterIndex = const $CopyWithPlaceholder(), - }) { - return TeachingUnitList( - teachingUnitModels == const $CopyWithPlaceholder() || - teachingUnitModels == null - ? _value.teachingUnitModels - // ignore: cast_nullable_to_non_nullable - : teachingUnitModels as List, - semesterIndex == const $CopyWithPlaceholder() || semesterIndex == null - ? _value.semesterIndex - // ignore: cast_nullable_to_non_nullable - : semesterIndex as int, - ); - } -} - -extension $TeachingUnitListCopyWith on TeachingUnitList { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfTeachingUnitList.copyWith(...)` or `instanceOfTeachingUnitList.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$TeachingUnitListCWProxy get copyWith => _$TeachingUnitListCWProxyImpl(this); -} diff --git a/packages/lyon1tomussclient/lib/src/model/generated/teaching_unit_list.mapper.dart b/packages/lyon1tomussclient/lib/src/model/generated/teaching_unit_list.mapper.dart new file mode 100644 index 000000000..b24e65e4e --- /dev/null +++ b/packages/lyon1tomussclient/lib/src/model/generated/teaching_unit_list.mapper.dart @@ -0,0 +1,161 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../teaching_unit_list.dart'; + +class TeachingUnitListMapper extends ClassMapperBase { + TeachingUnitListMapper._(); + + static TeachingUnitListMapper? _instance; + static TeachingUnitListMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = TeachingUnitListMapper._()); + TeachingUnitMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'TeachingUnitList'; + + static List _$teachingUnitModels(TeachingUnitList v) => + v.teachingUnitModels; + static const Field> + _f$teachingUnitModels = Field('teachingUnitModels', _$teachingUnitModels); + static int _$semesterIndex(TeachingUnitList v) => v.semesterIndex; + static const Field _f$semesterIndex = Field( + 'semesterIndex', + _$semesterIndex, + ); + + @override + final MappableFields fields = const { + #teachingUnitModels: _f$teachingUnitModels, + #semesterIndex: _f$semesterIndex, + }; + + static TeachingUnitList _instantiate(DecodingData data) { + return TeachingUnitList( + data.dec(_f$teachingUnitModels), + data.dec(_f$semesterIndex), + ); + } + + @override + final Function instantiate = _instantiate; + + static TeachingUnitList fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static TeachingUnitList fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin TeachingUnitListMappable { + String toJson() { + return TeachingUnitListMapper.ensureInitialized() + .encodeJson(this as TeachingUnitList); + } + + Map toMap() { + return TeachingUnitListMapper.ensureInitialized() + .encodeMap(this as TeachingUnitList); + } + + TeachingUnitListCopyWith + get copyWith => + _TeachingUnitListCopyWithImpl( + this as TeachingUnitList, + $identity, + $identity, + ); + @override + String toString() { + return TeachingUnitListMapper.ensureInitialized().stringifyValue( + this as TeachingUnitList, + ); + } + + @override + bool operator ==(Object other) { + return TeachingUnitListMapper.ensureInitialized().equalsValue( + this as TeachingUnitList, + other, + ); + } + + @override + int get hashCode { + return TeachingUnitListMapper.ensureInitialized().hashValue( + this as TeachingUnitList, + ); + } +} + +extension TeachingUnitListValueCopy<$R, $Out> + on ObjectCopyWith<$R, TeachingUnitList, $Out> { + TeachingUnitListCopyWith<$R, TeachingUnitList, $Out> + get $asTeachingUnitList => + $base.as((v, t, t2) => _TeachingUnitListCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class TeachingUnitListCopyWith<$R, $In extends TeachingUnitList, $Out> + implements ClassCopyWith<$R, $In, $Out> { + ListCopyWith< + $R, + TeachingUnit, + TeachingUnitCopyWith<$R, TeachingUnit, TeachingUnit> + > + get teachingUnitModels; + $R call({List? teachingUnitModels, int? semesterIndex}); + TeachingUnitListCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ); +} + +class _TeachingUnitListCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, TeachingUnitList, $Out> + implements TeachingUnitListCopyWith<$R, TeachingUnitList, $Out> { + _TeachingUnitListCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + TeachingUnitListMapper.ensureInitialized(); + @override + ListCopyWith< + $R, + TeachingUnit, + TeachingUnitCopyWith<$R, TeachingUnit, TeachingUnit> + > + get teachingUnitModels => ListCopyWith( + $value.teachingUnitModels, + (v, t) => v.copyWith.$chain(t), + (v) => call(teachingUnitModels: v), + ); + @override + $R call({List? teachingUnitModels, int? semesterIndex}) => + $apply( + FieldCopyWithData({ + if (teachingUnitModels != null) + #teachingUnitModels: teachingUnitModels, + if (semesterIndex != null) #semesterIndex: semesterIndex, + }), + ); + @override + TeachingUnitList $make(CopyWithData data) => TeachingUnitList( + data.get(#teachingUnitModels, or: $value.teachingUnitModels), + data.get(#semesterIndex, or: $value.semesterIndex), + ); + + @override + TeachingUnitListCopyWith<$R2, TeachingUnitList, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _TeachingUnitListCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1tomussclient/lib/src/model/generated/tomuss_text.g.dart b/packages/lyon1tomussclient/lib/src/model/generated/tomuss_text.g.dart deleted file mode 100644 index e3ae5ab1c..000000000 --- a/packages/lyon1tomussclient/lib/src/model/generated/tomuss_text.g.dart +++ /dev/null @@ -1,149 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../tomuss_text.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$TomussTextCWProxy { - TomussText title(String title); - - TomussText author(String author); - - TomussText date(DateTime? date); - - TomussText position(double position); - - TomussText value(String value); - - TomussText comment(String comment); - - TomussText isValidText(bool isValidText); - - TomussText isHidden(bool isHidden); - - TomussText theId(String theId); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `TomussText(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// TomussText(...).copyWith(id: 12, name: "My name") - /// ``` - TomussText call({ - String title, - String author, - DateTime? date, - double position, - String value, - String comment, - bool isValidText, - bool isHidden, - String theId, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfTomussText.copyWith(...)` or call `instanceOfTomussText.copyWith.fieldName(value)` for a single field. -class _$TomussTextCWProxyImpl implements _$TomussTextCWProxy { - const _$TomussTextCWProxyImpl(this._value); - - final TomussText _value; - - @override - TomussText title(String title) => call(title: title); - - @override - TomussText author(String author) => call(author: author); - - @override - TomussText date(DateTime? date) => call(date: date); - - @override - TomussText position(double position) => call(position: position); - - @override - TomussText value(String value) => call(value: value); - - @override - TomussText comment(String comment) => call(comment: comment); - - @override - TomussText isValidText(bool isValidText) => call(isValidText: isValidText); - - @override - TomussText isHidden(bool isHidden) => call(isHidden: isHidden); - - @override - TomussText theId(String theId) => call(theId: theId); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `TomussText(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// TomussText(...).copyWith(id: 12, name: "My name") - /// ``` - TomussText call({ - Object? title = const $CopyWithPlaceholder(), - Object? author = const $CopyWithPlaceholder(), - Object? date = const $CopyWithPlaceholder(), - Object? position = const $CopyWithPlaceholder(), - Object? value = const $CopyWithPlaceholder(), - Object? comment = const $CopyWithPlaceholder(), - Object? isValidText = const $CopyWithPlaceholder(), - Object? isHidden = const $CopyWithPlaceholder(), - Object? theId = const $CopyWithPlaceholder(), - }) { - return TomussText( - title: title == const $CopyWithPlaceholder() || title == null - ? _value.title - // ignore: cast_nullable_to_non_nullable - : title as String, - author: author == const $CopyWithPlaceholder() || author == null - ? _value.author - // ignore: cast_nullable_to_non_nullable - : author as String, - date: date == const $CopyWithPlaceholder() - ? _value.date - // ignore: cast_nullable_to_non_nullable - : date as DateTime?, - position: position == const $CopyWithPlaceholder() || position == null - ? _value.position - // ignore: cast_nullable_to_non_nullable - : position as double, - value: value == const $CopyWithPlaceholder() || value == null - ? _value.value - // ignore: cast_nullable_to_non_nullable - : value as String, - comment: comment == const $CopyWithPlaceholder() || comment == null - ? _value.comment - // ignore: cast_nullable_to_non_nullable - : comment as String, - isValidText: - isValidText == const $CopyWithPlaceholder() || isValidText == null - ? _value.isValidText - // ignore: cast_nullable_to_non_nullable - : isValidText as bool, - isHidden: isHidden == const $CopyWithPlaceholder() || isHidden == null - ? _value.isHidden - // ignore: cast_nullable_to_non_nullable - : isHidden as bool, - theId: theId == const $CopyWithPlaceholder() || theId == null - ? _value.theId - // ignore: cast_nullable_to_non_nullable - : theId as String, - ); - } -} - -extension $TomussTextCopyWith on TomussText { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfTomussText.copyWith(...)` or `instanceOfTomussText.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$TomussTextCWProxy get copyWith => _$TomussTextCWProxyImpl(this); -} diff --git a/packages/lyon1tomussclient/lib/src/model/generated/tomuss_text.mapper.dart b/packages/lyon1tomussclient/lib/src/model/generated/tomuss_text.mapper.dart new file mode 100644 index 000000000..d30ec41ec --- /dev/null +++ b/packages/lyon1tomussclient/lib/src/model/generated/tomuss_text.mapper.dart @@ -0,0 +1,236 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../tomuss_text.dart'; + +class TomussTextMapper extends ClassMapperBase { + TomussTextMapper._(); + + static TomussTextMapper? _instance; + static TomussTextMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = TomussTextMapper._()); + } + return _instance!; + } + + @override + final String id = 'TomussText'; + + static String _$title(TomussText v) => v.title; + static const Field _f$title = Field('title', _$title); + static String _$author(TomussText v) => v.author; + static const Field _f$author = Field('author', _$author); + static DateTime? _$date(TomussText v) => v.date; + static const Field _f$date = Field('date', _$date); + static double _$position(TomussText v) => v.position; + static const Field _f$position = Field( + 'position', + _$position, + ); + static String _$value(TomussText v) => v.value; + static const Field _f$value = Field( + 'value', + _$value, + opt: true, + def: "", + ); + static String _$comment(TomussText v) => v.comment; + static const Field _f$comment = Field( + 'comment', + _$comment, + opt: true, + def: "", + ); + static bool _$isValidText(TomussText v) => v.isValidText; + static const Field _f$isValidText = Field( + 'isValidText', + _$isValidText, + opt: true, + def: false, + ); + static bool _$isHidden(TomussText v) => v.isHidden; + static const Field _f$isHidden = Field( + 'isHidden', + _$isHidden, + opt: true, + def: false, + ); + static String _$theId(TomussText v) => v.theId; + static const Field _f$theId = Field( + 'theId', + _$theId, + opt: true, + def: "", + ); + static bool _$isVisible(TomussText v) => v.isVisible; + static const Field _f$isVisible = Field( + 'isVisible', + _$isVisible, + mode: FieldMode.member, + ); + static List _$customProps(TomussText v) => v.customProps; + static const Field> _f$customProps = Field( + 'customProps', + _$customProps, + mode: FieldMode.member, + ); + + @override + final MappableFields fields = const { + #title: _f$title, + #author: _f$author, + #date: _f$date, + #position: _f$position, + #value: _f$value, + #comment: _f$comment, + #isValidText: _f$isValidText, + #isHidden: _f$isHidden, + #theId: _f$theId, + #isVisible: _f$isVisible, + #customProps: _f$customProps, + }; + + static TomussText _instantiate(DecodingData data) { + return TomussText( + title: data.dec(_f$title), + author: data.dec(_f$author), + date: data.dec(_f$date), + position: data.dec(_f$position), + value: data.dec(_f$value), + comment: data.dec(_f$comment), + isValidText: data.dec(_f$isValidText), + isHidden: data.dec(_f$isHidden), + theId: data.dec(_f$theId), + ); + } + + @override + final Function instantiate = _instantiate; + + static TomussText fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static TomussText fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin TomussTextMappable { + String toJson() { + return TomussTextMapper.ensureInitialized().encodeJson( + this as TomussText, + ); + } + + Map toMap() { + return TomussTextMapper.ensureInitialized().encodeMap( + this as TomussText, + ); + } + + TomussTextCopyWith get copyWith => + _TomussTextCopyWithImpl( + this as TomussText, + $identity, + $identity, + ); + @override + String toString() { + return TomussTextMapper.ensureInitialized().stringifyValue( + this as TomussText, + ); + } + + @override + bool operator ==(Object other) { + return TomussTextMapper.ensureInitialized().equalsValue( + this as TomussText, + other, + ); + } + + @override + int get hashCode { + return TomussTextMapper.ensureInitialized().hashValue(this as TomussText); + } +} + +extension TomussTextValueCopy<$R, $Out> + on ObjectCopyWith<$R, TomussText, $Out> { + TomussTextCopyWith<$R, TomussText, $Out> get $asTomussText => + $base.as((v, t, t2) => _TomussTextCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class TomussTextCopyWith<$R, $In extends TomussText, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({ + String? title, + String? author, + DateTime? date, + double? position, + String? value, + String? comment, + bool? isValidText, + bool? isHidden, + String? theId, + }); + TomussTextCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _TomussTextCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, TomussText, $Out> + implements TomussTextCopyWith<$R, TomussText, $Out> { + _TomussTextCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + TomussTextMapper.ensureInitialized(); + @override + $R call({ + String? title, + String? author, + Object? date = $none, + double? position, + String? value, + String? comment, + bool? isValidText, + bool? isHidden, + String? theId, + }) => $apply( + FieldCopyWithData({ + if (title != null) #title: title, + if (author != null) #author: author, + if (date != $none) #date: date, + if (position != null) #position: position, + if (value != null) #value: value, + if (comment != null) #comment: comment, + if (isValidText != null) #isValidText: isValidText, + if (isHidden != null) #isHidden: isHidden, + if (theId != null) #theId: theId, + }), + ); + @override + TomussText $make(CopyWithData data) => TomussText( + title: data.get(#title, or: $value.title), + author: data.get(#author, or: $value.author), + date: data.get(#date, or: $value.date), + position: data.get(#position, or: $value.position), + value: data.get(#value, or: $value.value), + comment: data.get(#comment, or: $value.comment), + isValidText: data.get(#isValidText, or: $value.isValidText), + isHidden: data.get(#isHidden, or: $value.isHidden), + theId: data.get(#theId, or: $value.theId), + ); + + @override + TomussTextCopyWith<$R2, TomussText, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _TomussTextCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1tomussclient/lib/src/model/generated/upload.g.dart b/packages/lyon1tomussclient/lib/src/model/generated/upload.g.dart deleted file mode 100644 index 3a8677543..000000000 --- a/packages/lyon1tomussclient/lib/src/model/generated/upload.g.dart +++ /dev/null @@ -1,126 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../upload.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$UploadCWProxy { - Upload title(String title); - - Upload author(String author); - - Upload date(DateTime? date); - - Upload position(double position); - - Upload comment(String comment); - - Upload uploadMax(int uploadMax); - - Upload fileUrl(String fileUrl); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Upload(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Upload(...).copyWith(id: 12, name: "My name") - /// ``` - Upload call({ - String title, - String author, - DateTime? date, - double position, - String comment, - int uploadMax, - String fileUrl, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfUpload.copyWith(...)` or call `instanceOfUpload.copyWith.fieldName(value)` for a single field. -class _$UploadCWProxyImpl implements _$UploadCWProxy { - const _$UploadCWProxyImpl(this._value); - - final Upload _value; - - @override - Upload title(String title) => call(title: title); - - @override - Upload author(String author) => call(author: author); - - @override - Upload date(DateTime? date) => call(date: date); - - @override - Upload position(double position) => call(position: position); - - @override - Upload comment(String comment) => call(comment: comment); - - @override - Upload uploadMax(int uploadMax) => call(uploadMax: uploadMax); - - @override - Upload fileUrl(String fileUrl) => call(fileUrl: fileUrl); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Upload(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Upload(...).copyWith(id: 12, name: "My name") - /// ``` - Upload call({ - Object? title = const $CopyWithPlaceholder(), - Object? author = const $CopyWithPlaceholder(), - Object? date = const $CopyWithPlaceholder(), - Object? position = const $CopyWithPlaceholder(), - Object? comment = const $CopyWithPlaceholder(), - Object? uploadMax = const $CopyWithPlaceholder(), - Object? fileUrl = const $CopyWithPlaceholder(), - }) { - return Upload( - title: title == const $CopyWithPlaceholder() || title == null - ? _value.title - // ignore: cast_nullable_to_non_nullable - : title as String, - author: author == const $CopyWithPlaceholder() || author == null - ? _value.author - // ignore: cast_nullable_to_non_nullable - : author as String, - date: date == const $CopyWithPlaceholder() - ? _value.date - // ignore: cast_nullable_to_non_nullable - : date as DateTime?, - position: position == const $CopyWithPlaceholder() || position == null - ? _value.position - // ignore: cast_nullable_to_non_nullable - : position as double, - comment: comment == const $CopyWithPlaceholder() || comment == null - ? _value.comment - // ignore: cast_nullable_to_non_nullable - : comment as String, - uploadMax: uploadMax == const $CopyWithPlaceholder() || uploadMax == null - ? _value.uploadMax - // ignore: cast_nullable_to_non_nullable - : uploadMax as int, - fileUrl: fileUrl == const $CopyWithPlaceholder() || fileUrl == null - ? _value.fileUrl - // ignore: cast_nullable_to_non_nullable - : fileUrl as String, - ); - } -} - -extension $UploadCopyWith on Upload { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfUpload.copyWith(...)` or `instanceOfUpload.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$UploadCWProxy get copyWith => _$UploadCWProxyImpl(this); -} diff --git a/packages/lyon1tomussclient/lib/src/model/generated/upload.mapper.dart b/packages/lyon1tomussclient/lib/src/model/generated/upload.mapper.dart new file mode 100644 index 000000000..822452848 --- /dev/null +++ b/packages/lyon1tomussclient/lib/src/model/generated/upload.mapper.dart @@ -0,0 +1,193 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../upload.dart'; + +class UploadMapper extends ClassMapperBase { + UploadMapper._(); + + static UploadMapper? _instance; + static UploadMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = UploadMapper._()); + } + return _instance!; + } + + @override + final String id = 'Upload'; + + static String _$title(Upload v) => v.title; + static const Field _f$title = Field('title', _$title); + static String _$author(Upload v) => v.author; + static const Field _f$author = Field('author', _$author); + static DateTime? _$date(Upload v) => v.date; + static const Field _f$date = Field('date', _$date); + static double _$position(Upload v) => v.position; + static const Field _f$position = Field( + 'position', + _$position, + ); + static String _$comment(Upload v) => v.comment; + static const Field _f$comment = Field( + 'comment', + _$comment, + opt: true, + def: "", + ); + static int _$uploadMax(Upload v) => v.uploadMax; + static const Field _f$uploadMax = Field( + 'uploadMax', + _$uploadMax, + opt: true, + def: 0, + ); + static String _$fileUrl(Upload v) => v.fileUrl; + static const Field _f$fileUrl = Field( + 'fileUrl', + _$fileUrl, + opt: true, + def: "", + ); + static bool _$isVisible(Upload v) => v.isVisible; + static const Field _f$isVisible = Field( + 'isVisible', + _$isVisible, + mode: FieldMode.member, + ); + static List _$customProps(Upload v) => v.customProps; + static const Field> _f$customProps = Field( + 'customProps', + _$customProps, + mode: FieldMode.member, + ); + + @override + final MappableFields fields = const { + #title: _f$title, + #author: _f$author, + #date: _f$date, + #position: _f$position, + #comment: _f$comment, + #uploadMax: _f$uploadMax, + #fileUrl: _f$fileUrl, + #isVisible: _f$isVisible, + #customProps: _f$customProps, + }; + + static Upload _instantiate(DecodingData data) { + return Upload( + title: data.dec(_f$title), + author: data.dec(_f$author), + date: data.dec(_f$date), + position: data.dec(_f$position), + comment: data.dec(_f$comment), + uploadMax: data.dec(_f$uploadMax), + fileUrl: data.dec(_f$fileUrl), + ); + } + + @override + final Function instantiate = _instantiate; + + static Upload fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static Upload fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin UploadMappable { + String toJson() { + return UploadMapper.ensureInitialized().encodeJson(this as Upload); + } + + Map toMap() { + return UploadMapper.ensureInitialized().encodeMap(this as Upload); + } + + UploadCopyWith get copyWith => + _UploadCopyWithImpl(this as Upload, $identity, $identity); + @override + String toString() { + return UploadMapper.ensureInitialized().stringifyValue(this as Upload); + } + + @override + bool operator ==(Object other) { + return UploadMapper.ensureInitialized().equalsValue(this as Upload, other); + } + + @override + int get hashCode { + return UploadMapper.ensureInitialized().hashValue(this as Upload); + } +} + +extension UploadValueCopy<$R, $Out> on ObjectCopyWith<$R, Upload, $Out> { + UploadCopyWith<$R, Upload, $Out> get $asUpload => + $base.as((v, t, t2) => _UploadCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class UploadCopyWith<$R, $In extends Upload, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({ + String? title, + String? author, + DateTime? date, + double? position, + String? comment, + int? uploadMax, + String? fileUrl, + }); + UploadCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _UploadCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, Upload, $Out> + implements UploadCopyWith<$R, Upload, $Out> { + _UploadCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = UploadMapper.ensureInitialized(); + @override + $R call({ + String? title, + String? author, + Object? date = $none, + double? position, + String? comment, + int? uploadMax, + String? fileUrl, + }) => $apply( + FieldCopyWithData({ + if (title != null) #title: title, + if (author != null) #author: author, + if (date != $none) #date: date, + if (position != null) #position: position, + if (comment != null) #comment: comment, + if (uploadMax != null) #uploadMax: uploadMax, + if (fileUrl != null) #fileUrl: fileUrl, + }), + ); + @override + Upload $make(CopyWithData data) => Upload( + title: data.get(#title, or: $value.title), + author: data.get(#author, or: $value.author), + date: data.get(#date, or: $value.date), + position: data.get(#position, or: $value.position), + comment: data.get(#comment, or: $value.comment), + uploadMax: data.get(#uploadMax, or: $value.uploadMax), + fileUrl: data.get(#fileUrl, or: $value.fileUrl), + ); + + @override + UploadCopyWith<$R2, Upload, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _UploadCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1tomussclient/lib/src/model/generated/url.g.dart b/packages/lyon1tomussclient/lib/src/model/generated/url.g.dart deleted file mode 100644 index ba8b6074f..000000000 --- a/packages/lyon1tomussclient/lib/src/model/generated/url.g.dart +++ /dev/null @@ -1,116 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../url.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$URLCWProxy { - URL title(String title); - - URL author(String author); - - URL date(DateTime? date); - - URL position(double position); - - URL value(String value); - - URL isModifiable(bool isModifiable); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `URL(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// URL(...).copyWith(id: 12, name: "My name") - /// ``` - URL call({ - String title, - String author, - DateTime? date, - double position, - String value, - bool isModifiable, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfURL.copyWith(...)` or call `instanceOfURL.copyWith.fieldName(value)` for a single field. -class _$URLCWProxyImpl implements _$URLCWProxy { - const _$URLCWProxyImpl(this._value); - - final URL _value; - - @override - URL title(String title) => call(title: title); - - @override - URL author(String author) => call(author: author); - - @override - URL date(DateTime? date) => call(date: date); - - @override - URL position(double position) => call(position: position); - - @override - URL value(String value) => call(value: value); - - @override - URL isModifiable(bool isModifiable) => call(isModifiable: isModifiable); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `URL(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// URL(...).copyWith(id: 12, name: "My name") - /// ``` - URL call({ - Object? title = const $CopyWithPlaceholder(), - Object? author = const $CopyWithPlaceholder(), - Object? date = const $CopyWithPlaceholder(), - Object? position = const $CopyWithPlaceholder(), - Object? value = const $CopyWithPlaceholder(), - Object? isModifiable = const $CopyWithPlaceholder(), - }) { - return URL( - title: title == const $CopyWithPlaceholder() || title == null - ? _value.title - // ignore: cast_nullable_to_non_nullable - : title as String, - author: author == const $CopyWithPlaceholder() || author == null - ? _value.author - // ignore: cast_nullable_to_non_nullable - : author as String, - date: date == const $CopyWithPlaceholder() - ? _value.date - // ignore: cast_nullable_to_non_nullable - : date as DateTime?, - position: position == const $CopyWithPlaceholder() || position == null - ? _value.position - // ignore: cast_nullable_to_non_nullable - : position as double, - value: value == const $CopyWithPlaceholder() || value == null - ? _value.value - // ignore: cast_nullable_to_non_nullable - : value as String, - isModifiable: - isModifiable == const $CopyWithPlaceholder() || isModifiable == null - ? _value.isModifiable - // ignore: cast_nullable_to_non_nullable - : isModifiable as bool, - ); - } -} - -extension $URLCopyWith on URL { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfURL.copyWith(...)` or `instanceOfURL.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$URLCWProxy get copyWith => _$URLCWProxyImpl(this); -} diff --git a/packages/lyon1tomussclient/lib/src/model/generated/url.mapper.dart b/packages/lyon1tomussclient/lib/src/model/generated/url.mapper.dart new file mode 100644 index 000000000..b2cf565a0 --- /dev/null +++ b/packages/lyon1tomussclient/lib/src/model/generated/url.mapper.dart @@ -0,0 +1,177 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../url.dart'; + +class URLMapper extends ClassMapperBase { + URLMapper._(); + + static URLMapper? _instance; + static URLMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = URLMapper._()); + } + return _instance!; + } + + @override + final String id = 'URL'; + + static String _$title(URL v) => v.title; + static const Field _f$title = Field('title', _$title); + static String _$author(URL v) => v.author; + static const Field _f$author = Field('author', _$author); + static DateTime? _$date(URL v) => v.date; + static const Field _f$date = Field('date', _$date); + static double _$position(URL v) => v.position; + static const Field _f$position = Field('position', _$position); + static String _$value(URL v) => v.value; + static const Field _f$value = Field( + 'value', + _$value, + opt: true, + def: "", + ); + static bool _$isModifiable(URL v) => v.isModifiable; + static const Field _f$isModifiable = Field( + 'isModifiable', + _$isModifiable, + opt: true, + def: false, + ); + static bool _$isVisible(URL v) => v.isVisible; + static const Field _f$isVisible = Field( + 'isVisible', + _$isVisible, + mode: FieldMode.member, + ); + static List _$customProps(URL v) => v.customProps; + static const Field> _f$customProps = Field( + 'customProps', + _$customProps, + mode: FieldMode.member, + ); + + @override + final MappableFields fields = const { + #title: _f$title, + #author: _f$author, + #date: _f$date, + #position: _f$position, + #value: _f$value, + #isModifiable: _f$isModifiable, + #isVisible: _f$isVisible, + #customProps: _f$customProps, + }; + + static URL _instantiate(DecodingData data) { + return URL( + title: data.dec(_f$title), + author: data.dec(_f$author), + date: data.dec(_f$date), + position: data.dec(_f$position), + value: data.dec(_f$value), + isModifiable: data.dec(_f$isModifiable), + ); + } + + @override + final Function instantiate = _instantiate; + + static URL fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static URL fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin URLMappable { + String toJson() { + return URLMapper.ensureInitialized().encodeJson(this as URL); + } + + Map toMap() { + return URLMapper.ensureInitialized().encodeMap(this as URL); + } + + URLCopyWith get copyWith => + _URLCopyWithImpl(this as URL, $identity, $identity); + @override + String toString() { + return URLMapper.ensureInitialized().stringifyValue(this as URL); + } + + @override + bool operator ==(Object other) { + return URLMapper.ensureInitialized().equalsValue(this as URL, other); + } + + @override + int get hashCode { + return URLMapper.ensureInitialized().hashValue(this as URL); + } +} + +extension URLValueCopy<$R, $Out> on ObjectCopyWith<$R, URL, $Out> { + URLCopyWith<$R, URL, $Out> get $asURL => + $base.as((v, t, t2) => _URLCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class URLCopyWith<$R, $In extends URL, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({ + String? title, + String? author, + DateTime? date, + double? position, + String? value, + bool? isModifiable, + }); + URLCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _URLCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, URL, $Out> + implements URLCopyWith<$R, URL, $Out> { + _URLCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = URLMapper.ensureInitialized(); + @override + $R call({ + String? title, + String? author, + Object? date = $none, + double? position, + String? value, + bool? isModifiable, + }) => $apply( + FieldCopyWithData({ + if (title != null) #title: title, + if (author != null) #author: author, + if (date != $none) #date: date, + if (position != null) #position: position, + if (value != null) #value: value, + if (isModifiable != null) #isModifiable: isModifiable, + }), + ); + @override + URL $make(CopyWithData data) => URL( + title: data.get(#title, or: $value.title), + author: data.get(#author, or: $value.author), + date: data.get(#date, or: $value.date), + position: data.get(#position, or: $value.position), + value: data.get(#value, or: $value.value), + isModifiable: data.get(#isModifiable, or: $value.isModifiable), + ); + + @override + URLCopyWith<$R2, URL, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _URLCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/lyon1tomussclient/lib/src/model/grade.dart b/packages/lyon1tomussclient/lib/src/model/grade.dart index da7aac1d0..ce5e2a699 100755 --- a/packages/lyon1tomussclient/lib/src/model/grade.dart +++ b/packages/lyon1tomussclient/lib/src/model/grade.dart @@ -1,11 +1,11 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1tomussclient/src/model/teaching_unit_element.dart'; import 'package:lyon1tomussclient/src/utils/roundtoprecision.dart'; -part 'generated/grade.g.dart'; +part 'generated/grade.mapper.dart'; -@CopyWith() -class Grade extends TeachingUnitElement { +@MappableClass() +class Grade extends TeachingUnitElement with GradeMappable { late final double numerator; late final double denominator; late final int rank; @@ -18,32 +18,42 @@ class Grade extends TeachingUnitElement { // ignore: preferfinalfields late final List children; - Grade.fromJSON(var id, var json, var stats, var line, var column, String user) - : super.fromJson(id, json, stats, line, column, user) { + Grade.fromJSON( + int id, + Map json, + Map stats, + List line, + Map column, + String user, + ) : super.fromJson(id, json, stats, line, column, user) { rank = stats[json['the_id']]['rank'] ?? -1; groupeSize = stats[json['the_id']]['nr'] ?? -1; isValid = (rank != -1); if (!isValid) { return; } - average = double.tryParse(stats[json['the_id']]['average'].toString()) - .roundToPrecision(); - mediane = double.tryParse(stats[json['the_id']]['mediane'].toString()) - .roundToPrecision(); + average = double.tryParse( + stats[json['the_id']]['average'].toString(), + ).roundToPrecision(); + mediane = double.tryParse( + stats[json['the_id']]['mediane'].toString(), + ).roundToPrecision(); - numerator = (line.length > 0 && id < line.length && line[id].length > 0) + numerator = (line.isNotEmpty && id < line.length && line[id].length > 0) ? double.tryParse(line[id][0].toString()).roundToPrecision() : double.nan; - denominator = double.tryParse( - (json['minmax'] ?? "").split(";").last.replaceAll("]", "") ?? - "20") ?? + denominator = + double.tryParse( + (json['minmax'] ?? "").split(";").last.replaceAll("]", "") ?? "20", + ) ?? 20; // "minmax": "[0;22]", coef = 1.0; children = []; } + @MappableConstructor() Grade({ required super.title, required super.author, @@ -73,13 +83,13 @@ class Grade extends TeachingUnitElement { @override List get customProps => [ - numerator, - denominator, - rank, - average, - mediane, - isValid, - groupeSize, - children - ]; + numerator, + denominator, + rank, + average, + mediane, + isValid, + groupeSize, + children, + ]; } diff --git a/packages/lyon1tomussclient/lib/src/model/presence.dart b/packages/lyon1tomussclient/lib/src/model/presence.dart index 6479d4ec7..4e773dffc 100644 --- a/packages/lyon1tomussclient/lib/src/model/presence.dart +++ b/packages/lyon1tomussclient/lib/src/model/presence.dart @@ -1,14 +1,15 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1tomussclient/src/model/teaching_unit_element.dart'; import 'package:lyon1tomussclient/src/parser/condition_parser.dart'; import 'package:lyon1tomussclient/src/parser/dateparser.dart'; -part 'generated/presence.g.dart'; +part 'generated/presence.mapper.dart'; +@MappableEnum() enum PresenceColor { green, red, unset } -@CopyWith() -class Presence extends TeachingUnitElement { +@MappableClass() +class Presence extends TeachingUnitElement with PresenceMappable { late final String value; late final String? emptyIs; late final PresenceColor color; @@ -16,8 +17,13 @@ class Presence extends TeachingUnitElement { late final bool? visible; Presence.fromJSON( - var id, var json, var stats, var line, var column, String user) - : super.fromJson(id, json, stats, line, column, user) { + int id, + Map json, + Map stats, + List line, + Map column, + String user, + ) : super.fromJson(id, json, stats, line, column, user) { emptyIs = json['empty_is']; if (line[id] == null || (line[id] is List && line[id].isEmpty)) { value = ""; @@ -31,8 +37,11 @@ class Presence extends TeachingUnitElement { visibilityDate = vDate.toDateTime(); visible = null; } else { - visible = - vDate.evaluateCondition(value: value, line: line, column: column); + visible = vDate.evaluateCondition( + value: value, + line: line, + column: column, + ); visibilityDate = null; } // exemple de condition: @@ -42,19 +51,27 @@ class Presence extends TeachingUnitElement { visibilityDate = null; visible = null; } - if (json['redtext'] - .toString() - .evaluateCondition(value: value, line: line, column: column) || - json['red'] - .toString() - .evaluateCondition(value: value, line: line, column: column)) { + if (json['redtext'].toString().evaluateCondition( + value: value, + line: line, + column: column, + ) || + json['red'].toString().evaluateCondition( + value: value, + line: line, + column: column, + )) { color = PresenceColor.red; - } else if (json['greentext'] - .toString() - .evaluateCondition(value: value, line: line, column: column) || - json['green'] - .toString() - .evaluateCondition(value: value, line: line, column: column)) { + } else if (json['greentext'].toString().evaluateCondition( + value: value, + line: line, + column: column, + ) || + json['green'].toString().evaluateCondition( + value: value, + line: line, + column: column, + )) { color = PresenceColor.green; } else { color = PresenceColor.unset; @@ -65,6 +82,7 @@ class Presence extends TeachingUnitElement { bool get isVisible => value != ""; //(visible != null && visible!) || //(visibilityDate != null && visibilityDate!.isBefore(DateTime.now())); + @MappableConstructor() Presence({ required super.title, required super.author, @@ -78,6 +96,11 @@ class Presence extends TeachingUnitElement { }); @override - List get customProps => - [value, emptyIs, color, visibilityDate, visible]; + List get customProps => [ + value, + emptyIs, + color, + visibilityDate, + visible, + ]; } diff --git a/packages/lyon1tomussclient/lib/src/model/semester.dart b/packages/lyon1tomussclient/lib/src/model/semester.dart index a4ffa19ad..26f2831b6 100755 --- a/packages/lyon1tomussclient/lib/src/model/semester.dart +++ b/packages/lyon1tomussclient/lib/src/model/semester.dart @@ -1,21 +1,11 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; -part 'generated/semester.g.dart'; +part 'generated/semester.mapper.dart'; -@CopyWith() -class Semester extends Equatable { +@MappableClass() +class Semester with SemesterMappable { final String title; final String url; - Semester({ - this.title = "", - this.url = "", - }); - - @override - List get props => [title, url]; - - @override - bool? get stringify => true; + Semester({this.title = "", this.url = ""}); } diff --git a/packages/lyon1tomussclient/lib/src/model/semester_list.dart b/packages/lyon1tomussclient/lib/src/model/semester_list.dart index 1c7e2e182..71e619f7c 100644 --- a/packages/lyon1tomussclient/lib/src/model/semester_list.dart +++ b/packages/lyon1tomussclient/lib/src/model/semester_list.dart @@ -1,19 +1,12 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1tomussclient/src/model/semester.dart'; -import 'package:equatable/equatable.dart'; -part 'generated/semester_list.g.dart'; +part 'generated/semester_list.mapper.dart'; -@CopyWith() -class SemesterList extends Equatable { +@MappableClass() +class SemesterList with SemesterListMappable { final List semestres; final int currentSemesterIndex; SemesterList(this.semestres, {this.currentSemesterIndex = 0}); - - @override - List get props => [semestres, currentSemesterIndex]; - - @override - bool? get stringify => true; } diff --git a/packages/lyon1tomussclient/lib/src/model/stage_code.dart b/packages/lyon1tomussclient/lib/src/model/stage_code.dart index b616b254c..35f38ded6 100644 --- a/packages/lyon1tomussclient/lib/src/model/stage_code.dart +++ b/packages/lyon1tomussclient/lib/src/model/stage_code.dart @@ -1,18 +1,24 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1tomussclient/src/model/teaching_unit_element.dart'; -part 'generated/stage_code.g.dart'; +part 'generated/stage_code.mapper.dart'; -@CopyWith() -class StageCode extends TeachingUnitElement { +@MappableClass() +class StageCode extends TeachingUnitElement with StageCodeMappable { late final String value; StageCode.fromJSON( - var id, var json, var stats, var line, var column, String user) - : super.fromJson(id, json, stats, line, column, user) { + int id, + Map json, + Map stats, + List line, + Map column, + String user, + ) : super.fromJson(id, json, stats, line, column, user) { value = line[id][0].toString(); } + @MappableConstructor() StageCode({ required super.title, required super.author, diff --git a/packages/lyon1tomussclient/lib/src/model/student.dart b/packages/lyon1tomussclient/lib/src/model/student.dart index f13e04e9f..66365b9b2 100644 --- a/packages/lyon1tomussclient/lib/src/model/student.dart +++ b/packages/lyon1tomussclient/lib/src/model/student.dart @@ -1,31 +1,19 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; -part 'generated/student.g.dart'; +part 'generated/student.mapper.dart'; -@CopyWith() -class Student extends Equatable { +@MappableClass() +class Student with StudentMappable { late final String name; - late final String surname; - late final String email; - Student.fromJSON(var json) { + Student.fromJSON(List json) { name = json[0] ?? ""; surname = json[1] ?? ""; email = json[2] ?? ""; } - Student({ - this.name = "", - this.surname = "", - this.email = "", - }); - - @override - List get props => [name, surname, email]; - - @override - bool? get stringify => true; + @MappableConstructor() + Student({this.name = "", this.surname = "", this.email = ""}); } diff --git a/packages/lyon1tomussclient/lib/src/model/teacher.dart b/packages/lyon1tomussclient/lib/src/model/teacher.dart index c00a52a5f..a93fac12e 100755 --- a/packages/lyon1tomussclient/lib/src/model/teacher.dart +++ b/packages/lyon1tomussclient/lib/src/model/teacher.dart @@ -1,28 +1,19 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1tomussclient/src/utils/stringcasing.dart'; -part 'generated/teacher.g.dart'; +part 'generated/teacher.mapper.dart'; -@CopyWith() -class Teacher extends Equatable { +@MappableClass() +class Teacher with TeacherMappable { late final String name; late final String email; - Teacher.fromJSON(var json) { + Teacher.fromJSON(List json) { name = "${json[0].toString().capitalize} ${json[1] ?? ''}"; // Firstname LASTNAME email = json[2] ?? ""; // firstname.lastname@domain.ext } - Teacher({ - this.name = "", - this.email = "", - }); - - @override - List get props => [name, email]; - - @override - bool? get stringify => true; + @MappableConstructor() + Teacher({this.name = "", this.email = ""}); } diff --git a/packages/lyon1tomussclient/lib/src/model/teaching_unit.dart b/packages/lyon1tomussclient/lib/src/model/teaching_unit.dart index 9b5d8c1af..e38ae3a8c 100755 --- a/packages/lyon1tomussclient/lib/src/model/teaching_unit.dart +++ b/packages/lyon1tomussclient/lib/src/model/teaching_unit.dart @@ -1,11 +1,10 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1tomussclient/lyon1tomussclient.dart'; -part 'generated/teaching_unit.g.dart'; +part 'generated/teaching_unit.mapper.dart'; -@CopyWith() -class TeachingUnit extends Equatable { +@MappableClass() +class TeachingUnit with TeachingUnitMappable { final String title; final List masters; final List grades; @@ -32,33 +31,15 @@ class TeachingUnit extends Equatable { this.ue = "", }); - @override - List get props => [ - title, - masters, - grades, - textValues, - enumerations, - presences, - stageCodes, - uploads, - urls, - ticket, - ue - ]; - - @override - bool? get stringify => true; - List get children => [ - ...grades, - ...textValues, - ...enumerations, - ...presences, - ...stageCodes, - ...uploads, - ...urls, - ]; + ...grades, + ...textValues, + ...enumerations, + ...presences, + ...stageCodes, + ...uploads, + ...urls, + ]; List get visibleChildren => children.where((element) => element.isVisible).toList(); diff --git a/packages/lyon1tomussclient/lib/src/model/teaching_unit_element.dart b/packages/lyon1tomussclient/lib/src/model/teaching_unit_element.dart index b2ac148db..1c544a9cb 100644 --- a/packages/lyon1tomussclient/lib/src/model/teaching_unit_element.dart +++ b/packages/lyon1tomussclient/lib/src/model/teaching_unit_element.dart @@ -1,12 +1,13 @@ -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1tomussclient/src/parser/dateparser.dart'; -abstract class TeachingUnitElement extends Equatable { +abstract class TeachingUnitElement { late final String title; late final String author; late final DateTime? date; late final double position; + @MappableConstructor() TeachingUnitElement({ this.title = "", this.author = "", @@ -15,7 +16,13 @@ abstract class TeachingUnitElement extends Equatable { }); TeachingUnitElement.fromJson( - var id, var json, var stats, var line, var column, String user) { + int id, + Map json, + Map stats, + List line, + Map column, + String user, + ) { title = json['title'] ?? ""; author = json['author'] ?? ""; if (line[id].length > 2) { @@ -30,26 +37,4 @@ abstract class TeachingUnitElement extends Equatable { bool get isVisible; List get customProps; - - @override - List get props => [title, author, date, position, ...customProps]; - - @override - bool? get stringify => true; } - -// class CustomElement extends TeachingUnitElement { -// // Ajoutez ici les propriétés spécifiques à CustomElement -// -// CustomElement.fromJson(Map json) : super.fromJson(json) { -// coucou = json['coucou']; -// } -// -// CustomElement({required super.name, required this.coucou}); -// -// @override -// bool get isVisible => false; -// -// @override -// List get customProps => [coucou]; -// } diff --git a/packages/lyon1tomussclient/lib/src/model/teaching_unit_list.dart b/packages/lyon1tomussclient/lib/src/model/teaching_unit_list.dart index 2dbf2a564..80679ce60 100644 --- a/packages/lyon1tomussclient/lib/src/model/teaching_unit_list.dart +++ b/packages/lyon1tomussclient/lib/src/model/teaching_unit_list.dart @@ -1,19 +1,12 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1tomussclient/src/model/teaching_unit.dart'; -import 'package:equatable/equatable.dart'; -part 'generated/teaching_unit_list.g.dart'; +part 'generated/teaching_unit_list.mapper.dart'; -@CopyWith() -class TeachingUnitList extends Equatable { +@MappableClass() +class TeachingUnitList with TeachingUnitListMappable { final List teachingUnitModels; final int semesterIndex; TeachingUnitList(this.teachingUnitModels, this.semesterIndex); - - @override - List get props => [teachingUnitModels, semesterIndex]; - - @override - bool? get stringify => true; } diff --git a/packages/lyon1tomussclient/lib/src/model/tomuss_text.dart b/packages/lyon1tomussclient/lib/src/model/tomuss_text.dart index 3649c540b..12cd9afe4 100755 --- a/packages/lyon1tomussclient/lib/src/model/tomuss_text.dart +++ b/packages/lyon1tomussclient/lib/src/model/tomuss_text.dart @@ -1,10 +1,10 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1tomussclient/src/model/teaching_unit_element.dart'; -part 'generated/tomuss_text.g.dart'; +part 'generated/tomuss_text.mapper.dart'; -@CopyWith() -class TomussText extends TeachingUnitElement { +@MappableClass() +class TomussText extends TeachingUnitElement with TomussTextMappable { late final String value; late final String comment; late final bool isValidText; @@ -12,11 +12,16 @@ class TomussText extends TeachingUnitElement { late final String theId; TomussText.fromJSON( - var id, var json, var stats, var line, var column, String user) - : super.fromJson(id, json, stats, line, column, user) { + int id, + Map json, + Map stats, + List line, + Map column, + String user, + ) : super.fromJson(id, json, stats, line, column, user) { comment = json['comment'] ?? ""; - value = (line.length > 0 && id < line.length && line[id].length > 0) + value = (line.isNotEmpty && id < line.length && line[id].length > 0) ? line[id][0].toString() : ""; isValidText = value.isNotEmpty; @@ -24,6 +29,7 @@ class TomussText extends TeachingUnitElement { theId = json['the_id'] ?? ""; } + @MappableConstructor() TomussText({ required super.title, required super.author, @@ -40,6 +46,11 @@ class TomussText extends TeachingUnitElement { bool get isVisible => !isHidden && !["0_0", "0_1", "0_2"].contains(theId); @override - List get customProps => - [value, comment, isValidText, theId, isHidden]; + List get customProps => [ + value, + comment, + isValidText, + theId, + isHidden, + ]; } diff --git a/packages/lyon1tomussclient/lib/src/model/upload.dart b/packages/lyon1tomussclient/lib/src/model/upload.dart index 222094b9e..ba5807a9d 100644 --- a/packages/lyon1tomussclient/lib/src/model/upload.dart +++ b/packages/lyon1tomussclient/lib/src/model/upload.dart @@ -1,19 +1,24 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1tomussclient/src/constant/constants.dart'; import 'package:lyon1tomussclient/src/model/teaching_unit_element.dart'; import 'package:requests_plus/requests_plus.dart'; -part 'generated/upload.g.dart'; +part 'generated/upload.mapper.dart'; -@CopyWith() -class Upload extends TeachingUnitElement { +@MappableClass() +class Upload extends TeachingUnitElement with UploadMappable { late final String comment; late final int uploadMax; late final String fileUrl; Upload.fromJSON( - var id, var json, var stats, var line, var column, String user) - : super.fromJson(id, json, stats, line, column, user) { + int id, + Map json, + Map stats, + List line, + Map column, + String user, + ) : super.fromJson(id, json, stats, line, column, user) { comment = json['comment'] ?? ""; uploadMax = int.tryParse(json['upload_max'] ?? "") ?? 0; //https://tomuss.univ-lyon1.fr/2023/Printemps/codeUE/upload_get/theId/lineId/codeUE_uploadName_filename?unsafe=1&ticket=ST-6037266-YbrFlIZeqewEEE1TjBgy-cas.univ-lyon1.fr @@ -25,6 +30,7 @@ class Upload extends TeachingUnitElement { } } + @MappableConstructor() Upload({ required super.title, required super.author, @@ -36,9 +42,7 @@ class Upload extends TeachingUnitElement { }); Future> getContent(String ticket) async { - var response = await RequestsPlus.get( - "$fileUrl?unsafe=1&ticket=$ticket", - ); + var response = await RequestsPlus.get("$fileUrl?unsafe=1&ticket=$ticket"); if (response.statusCode == 200) { return response.bytes().toList(); } diff --git a/packages/lyon1tomussclient/lib/src/model/url.dart b/packages/lyon1tomussclient/lib/src/model/url.dart index dbb481c61..5bc1c18b6 100644 --- a/packages/lyon1tomussclient/lib/src/model/url.dart +++ b/packages/lyon1tomussclient/lib/src/model/url.dart @@ -1,15 +1,21 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:lyon1tomussclient/src/model/teaching_unit_element.dart'; -part 'generated/url.g.dart'; +part 'generated/url.mapper.dart'; -@CopyWith() -class URL extends TeachingUnitElement { +@MappableClass() +class URL extends TeachingUnitElement with URLMappable { late final String value; late final bool isModifiable; - URL.fromJSON(var id, Map json, var stats, var line, var column, String user) - : super.fromJson(id, json, stats, line, column, user) { + URL.fromJSON( + int id, + Map json, + Map stats, + List line, + Map column, + String user, + ) : super.fromJson(id, json, stats, line, column, user) { var props = line[id]; bool isModifiable; if (json.containsKey("modifiable")) { @@ -29,6 +35,7 @@ class URL extends TeachingUnitElement { this.isModifiable = isModifiable; } + @MappableConstructor() URL({ required super.title, required super.author, diff --git a/packages/lyon1tomussclient/pubspec.yaml b/packages/lyon1tomussclient/pubspec.yaml index 484ca3ef9..5a510632e 100755 --- a/packages/lyon1tomussclient/pubspec.yaml +++ b/packages/lyon1tomussclient/pubspec.yaml @@ -4,22 +4,19 @@ version: 1.0.12 repository: https://github.com/onyx-lyon1/onxy/packages/lyon1tomussclient environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.8.0 <4.0.0" dev_dependencies: dotenv: ^4.0.1 lints: ^6.0.0 test: ^1.20.1 build_runner: ^2.3.3 - hive_ce_generator: ^1.9.2 - copy_with_extension_gen: ^9.1.0 + dart_mappable_builder: ^4.6.0 dependencies: beautiful_soup_dart: ^0.3.0 - copy_with_extension: ^9.1.0 - equatable: ^2.0.5 - hive_ce: ^2.2.3 requests_plus: ^4.8.5 lyon1casclient: ^1.0.6 + dart_mappable: ^4.6.0 #dependency_overrides: # requests: diff --git a/packages/lyon1tomussclient/test/tomussclient_test.dart b/packages/lyon1tomussclient/test/tomussclient_test.dart index 0fc55c5f7..193ecfd08 100755 --- a/packages/lyon1tomussclient/test/tomussclient_test.dart +++ b/packages/lyon1tomussclient/test/tomussclient_test.dart @@ -10,8 +10,6 @@ void main() async { DotEnv env = DotEnv(includePlatformEnvironment: true); setUpAll(() async { - Lyon1TomussClient.registerAdapters(); - Lyon1CasClient.registerAdapters(); env.load(); final String username = env['USERNAME'] ?? ""; final String password = env['PASSWORD'] ?? ""; @@ -26,8 +24,9 @@ void main() async { }); test('TomussClient.getPage', () async { - final ParsedPage? parsedPageOpt = - await tomussOK.getParsedPage(URLCreator.basic()); + final ParsedPage? parsedPageOpt = await tomussOK.getParsedPage( + URLCreator.basic(), + ); expect(parsedPageOpt == null, equals(false)); final ParsedPage parsedPage = parsedPageOpt ?? ParsedPage.empty(); @@ -38,17 +37,21 @@ void main() async { }); test('Dartus.getPage x2', () async { - final ParsedPage? parsedPageOpt = - await tomussOK.getParsedPage(URLCreator.basic()); + final ParsedPage? parsedPageOpt = await tomussOK.getParsedPage( + URLCreator.basic(), + ); expect(parsedPageOpt == null, equals(false)); }, timeout: Timeout.parse("5m")); test('Dartus.getPage timeout', () async { - ParsedPage? parsedPageOpt = - await tomussOK.getParsedPage(URLCreator.basic()); + ParsedPage? parsedPageOpt = await tomussOK.getParsedPage( + URLCreator.basic(), + ); for (int i = 0; i < 5; i++) { - parsedPageOpt = - await tomussOK.getParsedPage(URLCreator.basic(), autoRefresh: false); + parsedPageOpt = await tomussOK.getParsedPage( + URLCreator.basic(), + autoRefresh: false, + ); } expect(parsedPageOpt == null, equals(false)); expect(parsedPageOpt!.isTimedOut, equals(true)); @@ -57,8 +60,9 @@ void main() async { }); test("change un enum", () async { - final ParsedPage? parsedPageOpt = await tomussOK - .getParsedPage(URLCreator.currentSemester(DateTime.now())); + final ParsedPage? parsedPageOpt = await tomussOK.getParsedPage( + URLCreator.currentSemester(DateTime.now()), + ); expect(parsedPageOpt == null, equals(false)); final ParsedPage parsedPage = parsedPageOpt ?? ParsedPage.empty(); expect(parsedPage.semesters, isNotNull); @@ -79,16 +83,17 @@ void main() async { expect(enumeration == null, equals(false)); String prevValue = enumeration!.value!; Enumeration newEnumeration = await enumeration.updateValue( - enumeration.values[ - (enumeration.values.indexOf(enumeration.value!) + 1) % - enumeration.values.length], - parsedPage.teachingunits!.first.ticket); + enumeration.values[(enumeration.values.indexOf(enumeration.value!) + 1) % + enumeration.values.length], + parsedPage.teachingunits!.first.ticket, + ); expect(newEnumeration.value == prevValue, equals(false)); }); test('download an upload', () async { - final ParsedPage? parsedPageOpt = await tomussOK - .getParsedPage(URLCreator.currentSemester(DateTime.now())); + final ParsedPage? parsedPageOpt = await tomussOK.getParsedPage( + URLCreator.currentSemester(DateTime.now()), + ); expect(parsedPageOpt == null, equals(false)); final ParsedPage parsedPage = parsedPageOpt ?? ParsedPage.empty(); expect(parsedPage.semesters, isNotNull); @@ -100,22 +105,31 @@ void main() async { } } expect(upload == null, equals(false)); - List file = - await upload!.getContent(parsedPage.teachingunits!.first.ticket); + List file = await upload!.getContent( + parsedPage.teachingunits!.first.ticket, + ); expect(file.isNotEmpty, equals(true)); }); test('Dartus.currentSemester()', () async { - expect(URLCreator.currentSemester(DateTime.parse("20220124")), - "https://tomuss.univ-lyon1.fr/S/2022/Printemps"); + expect( + URLCreator.currentSemester(DateTime.parse("20220124")), + "https://tomuss.univ-lyon1.fr/S/2022/Printemps", + ); - expect(URLCreator.currentSemester(DateTime.parse("20211129")), - "https://tomuss.univ-lyon1.fr/S/2021/Automne"); + expect( + URLCreator.currentSemester(DateTime.parse("20211129")), + "https://tomuss.univ-lyon1.fr/S/2021/Automne", + ); - expect(URLCreator.previousSemester(DateTime.parse("20220124")), - "https://tomuss.univ-lyon1.fr/S/2021/Automne"); + expect( + URLCreator.previousSemester(DateTime.parse("20220124")), + "https://tomuss.univ-lyon1.fr/S/2021/Automne", + ); - expect(URLCreator.previousSemester(DateTime.parse("20211129")), - "https://tomuss.univ-lyon1.fr/S/2021/Printemps"); + expect( + URLCreator.previousSemester(DateTime.parse("20211129")), + "https://tomuss.univ-lyon1.fr/S/2021/Printemps", + ); }); } diff --git a/packages/polytechcolloscopeclient/build.yaml b/packages/polytechcolloscopeclient/build.yaml index d6160f7dc..3ff8f90ad 100644 --- a/packages/polytechcolloscopeclient/build.yaml +++ b/packages/polytechcolloscopeclient/build.yaml @@ -1,9 +1,11 @@ targets: $default: builders: - source_gen|combining_builder: - generate_for: - - lib/**.dart + # only to resolve build_runner conflicts + dart_mappable_builder: options: build_extensions: - 'lib/{{path}}/{{file}}.dart': 'lib/{{path}}/generated/{{file}}.g.dart' \ No newline at end of file + 'lib/{{path}}/{{file}}.dart': + - 'lib/{{path}}/generated/{{file}}.mapper.dart' + - 'lib/{{path}}/generated/{{file}}.init.dart' + diff --git a/packages/polytechcolloscopeclient/lib/hive/generated/hive_adapters.g.dart b/packages/polytechcolloscopeclient/lib/hive/generated/hive_adapters.g.dart deleted file mode 100644 index 055eb8716..000000000 --- a/packages/polytechcolloscopeclient/lib/hive/generated/hive_adapters.g.dart +++ /dev/null @@ -1,170 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../hive_adapters.dart'; - -// ************************************************************************** -// AdaptersGenerator -// ************************************************************************** - -class StudentAdapter extends TypeAdapter { - @override - final typeId = 44; - - @override - Student read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return Student( - fields[0] as Year, - fields[1] as String, - (fields[2] as num).toInt(), - ); - } - - @override - void write(BinaryWriter writer, Student obj) { - writer - ..writeByte(3) - ..writeByte(0) - ..write(obj.year) - ..writeByte(1) - ..write(obj.name) - ..writeByte(2) - ..write(obj.id); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is StudentAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class KholleAdapter extends TypeAdapter { - @override - final typeId = 45; - - @override - Kholle read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return Kholle( - fields[0] as DateTime, - fields[1] as String, - fields[2] as String, - fields[3] as String?, - fields[4] as String?, - ); - } - - @override - void write(BinaryWriter writer, Kholle obj) { - writer - ..writeByte(5) - ..writeByte(0) - ..write(obj.date) - ..writeByte(1) - ..write(obj.subject) - ..writeByte(2) - ..write(obj.kholleur) - ..writeByte(3) - ..write(obj.message) - ..writeByte(4) - ..write(obj.room); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is KholleAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class StudentColloscopeAdapter extends TypeAdapter { - @override - final typeId = 46; - - @override - StudentColloscope read(BinaryReader reader) { - final numOfFields = reader.readByte(); - final fields = { - for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), - }; - return StudentColloscope( - fields[0] as Student, - (fields[1] as num).toInt(), - (fields[2] as List).cast(), - ); - } - - @override - void write(BinaryWriter writer, StudentColloscope obj) { - writer - ..writeByte(3) - ..writeByte(0) - ..write(obj.student) - ..writeByte(1) - ..write(obj.trinomeId) - ..writeByte(2) - ..write(obj.kholles); - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is StudentColloscopeAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} - -class YearAdapter extends TypeAdapter { - @override - final typeId = 47; - - @override - Year read(BinaryReader reader) { - switch (reader.readByte()) { - case 0: - return Year.first; - case 1: - return Year.second; - default: - return Year.first; - } - } - - @override - void write(BinaryWriter writer, Year obj) { - switch (obj) { - case Year.first: - writer.writeByte(0); - case Year.second: - writer.writeByte(1); - } - } - - @override - int get hashCode => typeId.hashCode; - - @override - bool operator ==(Object other) => - identical(this, other) || - other is YearAdapter && - runtimeType == other.runtimeType && - typeId == other.typeId; -} diff --git a/packages/polytechcolloscopeclient/lib/hive/hive_adapters.dart b/packages/polytechcolloscopeclient/lib/hive/hive_adapters.dart deleted file mode 100644 index 86f3425bc..000000000 --- a/packages/polytechcolloscopeclient/lib/hive/hive_adapters.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:hive_ce/hive.dart'; -import 'package:polytechcolloscopeclient/src/models/kholle.dart'; -import 'package:polytechcolloscopeclient/src/models/student.dart'; -import 'package:polytechcolloscopeclient/src/models/student_colloscope.dart'; -import 'package:polytechcolloscopeclient/src/models/year.dart'; - -@GenerateAdapters([ - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), - AdapterSpec(), -]) -part 'generated/hive_adapters.g.dart'; diff --git a/packages/polytechcolloscopeclient/lib/hive/hive_adapters.g.yaml b/packages/polytechcolloscopeclient/lib/hive/hive_adapters.g.yaml deleted file mode 100644 index 48750376b..000000000 --- a/packages/polytechcolloscopeclient/lib/hive/hive_adapters.g.yaml +++ /dev/null @@ -1,47 +0,0 @@ -# Generated by Hive CE -# Manual modifications may be necessary for certain migrations -# Check in to version control -nextTypeId: 48 -types: - Student: - typeId: 44 - nextIndex: 3 - fields: - year: - index: 0 - name: - index: 1 - id: - index: 2 - Kholle: - typeId: 45 - nextIndex: 5 - fields: - date: - index: 0 - subject: - index: 1 - kholleur: - index: 2 - message: - index: 3 - room: - index: 4 - StudentColloscope: - typeId: 46 - nextIndex: 3 - fields: - student: - index: 0 - trinomeId: - index: 1 - kholles: - index: 2 - Year: - typeId: 47 - nextIndex: 2 - fields: - first: - index: 0 - second: - index: 1 diff --git a/packages/polytechcolloscopeclient/lib/hive/hive_registrar.g.dart b/packages/polytechcolloscopeclient/lib/hive/hive_registrar.g.dart deleted file mode 100644 index 56c9fdddc..000000000 --- a/packages/polytechcolloscopeclient/lib/hive/hive_registrar.g.dart +++ /dev/null @@ -1,24 +0,0 @@ -// Generated by Hive CE -// Do not modify -// Check in to version control - -import 'package:hive_ce/hive.dart'; -import 'package:polytechcolloscopeclient/hive/hive_adapters.dart'; - -extension HiveRegistrar on HiveInterface { - void registerAdapters() { - registerAdapter(KholleAdapter()); - registerAdapter(StudentAdapter()); - registerAdapter(StudentColloscopeAdapter()); - registerAdapter(YearAdapter()); - } -} - -extension IsolatedHiveRegistrar on IsolatedHiveInterface { - void registerAdapters() { - registerAdapter(KholleAdapter()); - registerAdapter(StudentAdapter()); - registerAdapter(StudentColloscopeAdapter()); - registerAdapter(YearAdapter()); - } -} diff --git a/packages/polytechcolloscopeclient/lib/src/models/generated/kholle.g.dart b/packages/polytechcolloscopeclient/lib/src/models/generated/kholle.g.dart deleted file mode 100644 index 3708eab4f..000000000 --- a/packages/polytechcolloscopeclient/lib/src/models/generated/kholle.g.dart +++ /dev/null @@ -1,104 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../kholle.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$KholleCWProxy { - Kholle date(DateTime date); - - Kholle subject(String subject); - - Kholle kholleur(String kholleur); - - Kholle message(String? message); - - Kholle room(String? room); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Kholle(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Kholle(...).copyWith(id: 12, name: "My name") - /// ``` - Kholle call({ - DateTime date, - String subject, - String kholleur, - String? message, - String? room, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfKholle.copyWith(...)` or call `instanceOfKholle.copyWith.fieldName(value)` for a single field. -class _$KholleCWProxyImpl implements _$KholleCWProxy { - const _$KholleCWProxyImpl(this._value); - - final Kholle _value; - - @override - Kholle date(DateTime date) => call(date: date); - - @override - Kholle subject(String subject) => call(subject: subject); - - @override - Kholle kholleur(String kholleur) => call(kholleur: kholleur); - - @override - Kholle message(String? message) => call(message: message); - - @override - Kholle room(String? room) => call(room: room); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Kholle(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Kholle(...).copyWith(id: 12, name: "My name") - /// ``` - Kholle call({ - Object? date = const $CopyWithPlaceholder(), - Object? subject = const $CopyWithPlaceholder(), - Object? kholleur = const $CopyWithPlaceholder(), - Object? message = const $CopyWithPlaceholder(), - Object? room = const $CopyWithPlaceholder(), - }) { - return Kholle( - date == const $CopyWithPlaceholder() || date == null - ? _value.date - // ignore: cast_nullable_to_non_nullable - : date as DateTime, - subject == const $CopyWithPlaceholder() || subject == null - ? _value.subject - // ignore: cast_nullable_to_non_nullable - : subject as String, - kholleur == const $CopyWithPlaceholder() || kholleur == null - ? _value.kholleur - // ignore: cast_nullable_to_non_nullable - : kholleur as String, - message == const $CopyWithPlaceholder() - ? _value.message - // ignore: cast_nullable_to_non_nullable - : message as String?, - room == const $CopyWithPlaceholder() - ? _value.room - // ignore: cast_nullable_to_non_nullable - : room as String?, - ); - } -} - -extension $KholleCopyWith on Kholle { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfKholle.copyWith(...)` or `instanceOfKholle.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$KholleCWProxy get copyWith => _$KholleCWProxyImpl(this); -} diff --git a/packages/polytechcolloscopeclient/lib/src/models/generated/kholle.mapper.dart b/packages/polytechcolloscopeclient/lib/src/models/generated/kholle.mapper.dart new file mode 100644 index 000000000..fe543c757 --- /dev/null +++ b/packages/polytechcolloscopeclient/lib/src/models/generated/kholle.mapper.dart @@ -0,0 +1,148 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../kholle.dart'; + +class KholleMapper extends ClassMapperBase { + KholleMapper._(); + + static KholleMapper? _instance; + static KholleMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = KholleMapper._()); + } + return _instance!; + } + + @override + final String id = 'Kholle'; + + static DateTime _$date(Kholle v) => v.date; + static const Field _f$date = Field('date', _$date); + static String _$subject(Kholle v) => v.subject; + static const Field _f$subject = Field('subject', _$subject); + static String _$kholleur(Kholle v) => v.kholleur; + static const Field _f$kholleur = Field( + 'kholleur', + _$kholleur, + ); + static String? _$message(Kholle v) => v.message; + static const Field _f$message = Field('message', _$message); + static String? _$room(Kholle v) => v.room; + static const Field _f$room = Field('room', _$room); + + @override + final MappableFields fields = const { + #date: _f$date, + #subject: _f$subject, + #kholleur: _f$kholleur, + #message: _f$message, + #room: _f$room, + }; + + static Kholle _instantiate(DecodingData data) { + return Kholle( + data.dec(_f$date), + data.dec(_f$subject), + data.dec(_f$kholleur), + data.dec(_f$message), + data.dec(_f$room), + ); + } + + @override + final Function instantiate = _instantiate; + + static Kholle fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static Kholle fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin KholleMappable { + String toJson() { + return KholleMapper.ensureInitialized().encodeJson(this as Kholle); + } + + Map toMap() { + return KholleMapper.ensureInitialized().encodeMap(this as Kholle); + } + + KholleCopyWith get copyWith => + _KholleCopyWithImpl(this as Kholle, $identity, $identity); + @override + String toString() { + return KholleMapper.ensureInitialized().stringifyValue(this as Kholle); + } + + @override + bool operator ==(Object other) { + return KholleMapper.ensureInitialized().equalsValue(this as Kholle, other); + } + + @override + int get hashCode { + return KholleMapper.ensureInitialized().hashValue(this as Kholle); + } +} + +extension KholleValueCopy<$R, $Out> on ObjectCopyWith<$R, Kholle, $Out> { + KholleCopyWith<$R, Kholle, $Out> get $asKholle => + $base.as((v, t, t2) => _KholleCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class KholleCopyWith<$R, $In extends Kholle, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({ + DateTime? date, + String? subject, + String? kholleur, + String? message, + String? room, + }); + KholleCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _KholleCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, Kholle, $Out> + implements KholleCopyWith<$R, Kholle, $Out> { + _KholleCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = KholleMapper.ensureInitialized(); + @override + $R call({ + DateTime? date, + String? subject, + String? kholleur, + Object? message = $none, + Object? room = $none, + }) => $apply( + FieldCopyWithData({ + if (date != null) #date: date, + if (subject != null) #subject: subject, + if (kholleur != null) #kholleur: kholleur, + if (message != $none) #message: message, + if (room != $none) #room: room, + }), + ); + @override + Kholle $make(CopyWithData data) => Kholle( + data.get(#date, or: $value.date), + data.get(#subject, or: $value.subject), + data.get(#kholleur, or: $value.kholleur), + data.get(#message, or: $value.message), + data.get(#room, or: $value.room), + ); + + @override + KholleCopyWith<$R2, Kholle, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _KholleCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/polytechcolloscopeclient/lib/src/models/generated/student.g.dart b/packages/polytechcolloscopeclient/lib/src/models/generated/student.g.dart deleted file mode 100644 index ff4752cde..000000000 --- a/packages/polytechcolloscopeclient/lib/src/models/generated/student.g.dart +++ /dev/null @@ -1,82 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../student.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$StudentCWProxy { - Student year(Year year); - - Student name(String name); - - Student id(int id); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Student(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Student(...).copyWith(id: 12, name: "My name") - /// ``` - Student call({ - Year year, - String name, - int id, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfStudent.copyWith(...)` or call `instanceOfStudent.copyWith.fieldName(value)` for a single field. -class _$StudentCWProxyImpl implements _$StudentCWProxy { - const _$StudentCWProxyImpl(this._value); - - final Student _value; - - @override - Student year(Year year) => call(year: year); - - @override - Student name(String name) => call(name: name); - - @override - Student id(int id) => call(id: id); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Student(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// Student(...).copyWith(id: 12, name: "My name") - /// ``` - Student call({ - Object? year = const $CopyWithPlaceholder(), - Object? name = const $CopyWithPlaceholder(), - Object? id = const $CopyWithPlaceholder(), - }) { - return Student( - year == const $CopyWithPlaceholder() || year == null - ? _value.year - // ignore: cast_nullable_to_non_nullable - : year as Year, - name == const $CopyWithPlaceholder() || name == null - ? _value.name - // ignore: cast_nullable_to_non_nullable - : name as String, - id == const $CopyWithPlaceholder() || id == null - ? _value.id - // ignore: cast_nullable_to_non_nullable - : id as int, - ); - } -} - -extension $StudentCopyWith on Student { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfStudent.copyWith(...)` or `instanceOfStudent.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$StudentCWProxy get copyWith => _$StudentCWProxyImpl(this); -} diff --git a/packages/polytechcolloscopeclient/lib/src/models/generated/student.mapper.dart b/packages/polytechcolloscopeclient/lib/src/models/generated/student.mapper.dart new file mode 100644 index 000000000..663862222 --- /dev/null +++ b/packages/polytechcolloscopeclient/lib/src/models/generated/student.mapper.dart @@ -0,0 +1,131 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../student.dart'; + +class StudentMapper extends ClassMapperBase { + StudentMapper._(); + + static StudentMapper? _instance; + static StudentMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = StudentMapper._()); + YearMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'Student'; + + static Year _$year(Student v) => v.year; + static const Field _f$year = Field('year', _$year); + static String _$name(Student v) => v.name; + static const Field _f$name = Field('name', _$name); + static int _$id(Student v) => v.id; + static const Field _f$id = Field('id', _$id); + + @override + final MappableFields fields = const { + #year: _f$year, + #name: _f$name, + #id: _f$id, + }; + + static Student _instantiate(DecodingData data) { + return Student(data.dec(_f$year), data.dec(_f$name), data.dec(_f$id)); + } + + @override + final Function instantiate = _instantiate; + + static Student fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static Student fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin StudentMappable { + String toJson() { + return StudentMapper.ensureInitialized().encodeJson( + this as Student, + ); + } + + Map toMap() { + return StudentMapper.ensureInitialized().encodeMap( + this as Student, + ); + } + + StudentCopyWith get copyWith => + _StudentCopyWithImpl( + this as Student, + $identity, + $identity, + ); + @override + String toString() { + return StudentMapper.ensureInitialized().stringifyValue(this as Student); + } + + @override + bool operator ==(Object other) { + return StudentMapper.ensureInitialized().equalsValue( + this as Student, + other, + ); + } + + @override + int get hashCode { + return StudentMapper.ensureInitialized().hashValue(this as Student); + } +} + +extension StudentValueCopy<$R, $Out> on ObjectCopyWith<$R, Student, $Out> { + StudentCopyWith<$R, Student, $Out> get $asStudent => + $base.as((v, t, t2) => _StudentCopyWithImpl<$R, $Out>(v, t, t2)); +} + +abstract class StudentCopyWith<$R, $In extends Student, $Out> + implements ClassCopyWith<$R, $In, $Out> { + $R call({Year? year, String? name, int? id}); + StudentCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t); +} + +class _StudentCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, Student, $Out> + implements StudentCopyWith<$R, Student, $Out> { + _StudentCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + StudentMapper.ensureInitialized(); + @override + $R call({Year? year, String? name, int? id}) => $apply( + FieldCopyWithData({ + if (year != null) #year: year, + if (name != null) #name: name, + if (id != null) #id: id, + }), + ); + @override + Student $make(CopyWithData data) => Student( + data.get(#year, or: $value.year), + data.get(#name, or: $value.name), + data.get(#id, or: $value.id), + ); + + @override + StudentCopyWith<$R2, Student, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => + _StudentCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/polytechcolloscopeclient/lib/src/models/generated/student_colloscope.g.dart b/packages/polytechcolloscopeclient/lib/src/models/generated/student_colloscope.g.dart deleted file mode 100644 index e90dfb26e..000000000 --- a/packages/polytechcolloscopeclient/lib/src/models/generated/student_colloscope.g.dart +++ /dev/null @@ -1,83 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of '../student_colloscope.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$StudentColloscopeCWProxy { - StudentColloscope student(Student student); - - StudentColloscope trinomeId(int trinomeId); - - StudentColloscope kholles(List kholles); - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `StudentColloscope(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// StudentColloscope(...).copyWith(id: 12, name: "My name") - /// ``` - StudentColloscope call({ - Student student, - int trinomeId, - List kholles, - }); -} - -/// Callable proxy for `copyWith` functionality. -/// Use as `instanceOfStudentColloscope.copyWith(...)` or call `instanceOfStudentColloscope.copyWith.fieldName(value)` for a single field. -class _$StudentColloscopeCWProxyImpl implements _$StudentColloscopeCWProxy { - const _$StudentColloscopeCWProxyImpl(this._value); - - final StudentColloscope _value; - - @override - StudentColloscope student(Student student) => call(student: student); - - @override - StudentColloscope trinomeId(int trinomeId) => call(trinomeId: trinomeId); - - @override - StudentColloscope kholles(List kholles) => call(kholles: kholles); - - @override - - /// Creates a new instance with the provided field values. - /// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `StudentColloscope(...).copyWith.fieldName(value)`. - /// - /// Example: - /// ```dart - /// StudentColloscope(...).copyWith(id: 12, name: "My name") - /// ``` - StudentColloscope call({ - Object? student = const $CopyWithPlaceholder(), - Object? trinomeId = const $CopyWithPlaceholder(), - Object? kholles = const $CopyWithPlaceholder(), - }) { - return StudentColloscope( - student == const $CopyWithPlaceholder() || student == null - ? _value.student - // ignore: cast_nullable_to_non_nullable - : student as Student, - trinomeId == const $CopyWithPlaceholder() || trinomeId == null - ? _value.trinomeId - // ignore: cast_nullable_to_non_nullable - : trinomeId as int, - kholles == const $CopyWithPlaceholder() || kholles == null - ? _value.kholles - // ignore: cast_nullable_to_non_nullable - : kholles as List, - ); - } -} - -extension $StudentColloscopeCopyWith on StudentColloscope { - /// Returns a callable class used to build a new instance with modified fields. - /// Example: `instanceOfStudentColloscope.copyWith(...)` or `instanceOfStudentColloscope.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$StudentColloscopeCWProxy get copyWith => - _$StudentColloscopeCWProxyImpl(this); -} diff --git a/packages/polytechcolloscopeclient/lib/src/models/generated/student_colloscope.mapper.dart b/packages/polytechcolloscopeclient/lib/src/models/generated/student_colloscope.mapper.dart new file mode 100644 index 000000000..f95fc2dee --- /dev/null +++ b/packages/polytechcolloscopeclient/lib/src/models/generated/student_colloscope.mapper.dart @@ -0,0 +1,174 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../student_colloscope.dart'; + +class StudentColloscopeMapper extends ClassMapperBase { + StudentColloscopeMapper._(); + + static StudentColloscopeMapper? _instance; + static StudentColloscopeMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = StudentColloscopeMapper._()); + StudentMapper.ensureInitialized(); + KholleMapper.ensureInitialized(); + } + return _instance!; + } + + @override + final String id = 'StudentColloscope'; + + static Student _$student(StudentColloscope v) => v.student; + static const Field _f$student = Field( + 'student', + _$student, + ); + static int _$trinomeId(StudentColloscope v) => v.trinomeId; + static const Field _f$trinomeId = Field( + 'trinomeId', + _$trinomeId, + ); + static List _$kholles(StudentColloscope v) => v.kholles; + static const Field> _f$kholles = Field( + 'kholles', + _$kholles, + ); + + @override + final MappableFields fields = const { + #student: _f$student, + #trinomeId: _f$trinomeId, + #kholles: _f$kholles, + }; + + static StudentColloscope _instantiate(DecodingData data) { + return StudentColloscope( + data.dec(_f$student), + data.dec(_f$trinomeId), + data.dec(_f$kholles), + ); + } + + @override + final Function instantiate = _instantiate; + + static StudentColloscope fromMap(Map map) { + return ensureInitialized().decodeMap(map); + } + + static StudentColloscope fromJson(String json) { + return ensureInitialized().decodeJson(json); + } +} + +mixin StudentColloscopeMappable { + String toJson() { + return StudentColloscopeMapper.ensureInitialized() + .encodeJson(this as StudentColloscope); + } + + Map toMap() { + return StudentColloscopeMapper.ensureInitialized() + .encodeMap(this as StudentColloscope); + } + + StudentColloscopeCopyWith< + StudentColloscope, + StudentColloscope, + StudentColloscope + > + get copyWith => + _StudentColloscopeCopyWithImpl( + this as StudentColloscope, + $identity, + $identity, + ); + @override + String toString() { + return StudentColloscopeMapper.ensureInitialized().stringifyValue( + this as StudentColloscope, + ); + } + + @override + bool operator ==(Object other) { + return StudentColloscopeMapper.ensureInitialized().equalsValue( + this as StudentColloscope, + other, + ); + } + + @override + int get hashCode { + return StudentColloscopeMapper.ensureInitialized().hashValue( + this as StudentColloscope, + ); + } +} + +extension StudentColloscopeValueCopy<$R, $Out> + on ObjectCopyWith<$R, StudentColloscope, $Out> { + StudentColloscopeCopyWith<$R, StudentColloscope, $Out> + get $asStudentColloscope => $base.as( + (v, t, t2) => _StudentColloscopeCopyWithImpl<$R, $Out>(v, t, t2), + ); +} + +abstract class StudentColloscopeCopyWith< + $R, + $In extends StudentColloscope, + $Out +> + implements ClassCopyWith<$R, $In, $Out> { + StudentCopyWith<$R, Student, Student> get student; + ListCopyWith<$R, Kholle, KholleCopyWith<$R, Kholle, Kholle>> get kholles; + $R call({Student? student, int? trinomeId, List? kholles}); + StudentColloscopeCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ); +} + +class _StudentColloscopeCopyWithImpl<$R, $Out> + extends ClassCopyWithBase<$R, StudentColloscope, $Out> + implements StudentColloscopeCopyWith<$R, StudentColloscope, $Out> { + _StudentColloscopeCopyWithImpl(super.value, super.then, super.then2); + + @override + late final ClassMapperBase $mapper = + StudentColloscopeMapper.ensureInitialized(); + @override + StudentCopyWith<$R, Student, Student> get student => + $value.student.copyWith.$chain((v) => call(student: v)); + @override + ListCopyWith<$R, Kholle, KholleCopyWith<$R, Kholle, Kholle>> get kholles => + ListCopyWith( + $value.kholles, + (v, t) => v.copyWith.$chain(t), + (v) => call(kholles: v), + ); + @override + $R call({Student? student, int? trinomeId, List? kholles}) => $apply( + FieldCopyWithData({ + if (student != null) #student: student, + if (trinomeId != null) #trinomeId: trinomeId, + if (kholles != null) #kholles: kholles, + }), + ); + @override + StudentColloscope $make(CopyWithData data) => StudentColloscope( + data.get(#student, or: $value.student), + data.get(#trinomeId, or: $value.trinomeId), + data.get(#kholles, or: $value.kholles), + ); + + @override + StudentColloscopeCopyWith<$R2, StudentColloscope, $Out2> $chain<$R2, $Out2>( + Then<$Out2, $R2> t, + ) => _StudentColloscopeCopyWithImpl<$R2, $Out2>($value, $cast, t); +} + diff --git a/packages/polytechcolloscopeclient/lib/src/models/generated/year.mapper.dart b/packages/polytechcolloscopeclient/lib/src/models/generated/year.mapper.dart new file mode 100644 index 000000000..9525a6ec2 --- /dev/null +++ b/packages/polytechcolloscopeclient/lib/src/models/generated/year.mapper.dart @@ -0,0 +1,55 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// dart format off +// ignore_for_file: type=lint +// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member +// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter + +part of '../year.dart'; + +class YearMapper extends EnumMapper { + YearMapper._(); + + static YearMapper? _instance; + static YearMapper ensureInitialized() { + if (_instance == null) { + MapperContainer.globals.use(_instance = YearMapper._()); + } + return _instance!; + } + + static Year fromValue(dynamic value) { + ensureInitialized(); + return MapperContainer.globals.fromValue(value); + } + + @override + Year decode(dynamic value) { + switch (value) { + case r'first': + return Year.first; + case r'second': + return Year.second; + default: + throw MapperException.unknownEnumValue(value); + } + } + + @override + dynamic encode(Year self) { + switch (self) { + case Year.first: + return r'first'; + case Year.second: + return r'second'; + } + } +} + +extension YearMapperExtension on Year { + String toValue() { + YearMapper.ensureInitialized(); + return MapperContainer.globals.toValue(this) as String; + } +} + diff --git a/packages/polytechcolloscopeclient/lib/src/models/kholle.dart b/packages/polytechcolloscopeclient/lib/src/models/kholle.dart index 7a419eaf9..3ab4b6898 100644 --- a/packages/polytechcolloscopeclient/lib/src/models/kholle.dart +++ b/packages/polytechcolloscopeclient/lib/src/models/kholle.dart @@ -1,10 +1,9 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; -part 'generated/kholle.g.dart'; +part 'generated/kholle.mapper.dart'; -@CopyWith() -class Kholle extends Equatable { +@MappableClass() +class Kholle with KholleMappable { final DateTime date; final String subject; final String kholleur; @@ -12,10 +11,4 @@ class Kholle extends Equatable { final String? room; Kholle(this.date, this.subject, this.kholleur, this.message, this.room); - - @override - List get props => [date, subject, kholleur, message, room]; - - @override - bool? get stringify => true; } diff --git a/packages/polytechcolloscopeclient/lib/src/models/student.dart b/packages/polytechcolloscopeclient/lib/src/models/student.dart index 7a847c14a..d20b3a107 100644 --- a/packages/polytechcolloscopeclient/lib/src/models/student.dart +++ b/packages/polytechcolloscopeclient/lib/src/models/student.dart @@ -1,11 +1,10 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:polytechcolloscopeclient/src/models/year.dart'; -part 'generated/student.g.dart'; +part 'generated/student.mapper.dart'; -@CopyWith() -class Student extends Equatable { +@MappableClass() +class Student with StudentMappable { final Year year; final String name; final int id; @@ -15,10 +14,4 @@ class Student extends Equatable { static Student empty() { return Student(Year.first, "", 0); } - - @override - List get props => [year, name, id]; - - @override - bool? get stringify => true; } diff --git a/packages/polytechcolloscopeclient/lib/src/models/student_colloscope.dart b/packages/polytechcolloscopeclient/lib/src/models/student_colloscope.dart index e14ffe9f0..0654d5b6b 100644 --- a/packages/polytechcolloscopeclient/lib/src/models/student_colloscope.dart +++ b/packages/polytechcolloscopeclient/lib/src/models/student_colloscope.dart @@ -1,11 +1,10 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; +import 'package:dart_mappable/dart_mappable.dart'; import 'package:polytechcolloscopeclient/polytechcolloscopeclient.dart'; -part 'generated/student_colloscope.g.dart'; +part 'generated/student_colloscope.mapper.dart'; -@CopyWith() -class StudentColloscope extends Equatable { +@MappableClass() +class StudentColloscope with StudentColloscopeMappable { final Student student; final int trinomeId; final List kholles; @@ -15,10 +14,4 @@ class StudentColloscope extends Equatable { static StudentColloscope empty() { return StudentColloscope(Student.empty(), 0, []); } - - @override - List get props => [student, trinomeId, kholles]; - - @override - bool? get stringify => true; } diff --git a/packages/polytechcolloscopeclient/lib/src/models/year.dart b/packages/polytechcolloscopeclient/lib/src/models/year.dart index 416699589..f03535ba1 100644 --- a/packages/polytechcolloscopeclient/lib/src/models/year.dart +++ b/packages/polytechcolloscopeclient/lib/src/models/year.dart @@ -1,3 +1,8 @@ +import 'package:dart_mappable/dart_mappable.dart'; + +part 'generated/year.mapper.dart'; + +@MappableEnum() enum Year { first, second, diff --git a/packages/polytechcolloscopeclient/lib/src/polytechcolloscopeclient_base.dart b/packages/polytechcolloscopeclient/lib/src/polytechcolloscopeclient_base.dart index dab85df38..45571761a 100644 --- a/packages/polytechcolloscopeclient/lib/src/polytechcolloscopeclient_base.dart +++ b/packages/polytechcolloscopeclient/lib/src/polytechcolloscopeclient_base.dart @@ -1,9 +1,7 @@ import 'package:beautiful_soup_dart/beautiful_soup.dart'; import 'package:collection/collection.dart'; import 'package:diacritic/diacritic.dart'; -import 'package:hive_ce/hive.dart'; import 'package:html/dom.dart'; -import 'package:polytechcolloscopeclient/hive/hive_registrar.g.dart'; import 'package:requests_plus/requests_plus.dart'; import 'consts.dart'; @@ -18,8 +16,11 @@ class PolytechColloscopeClient { } Future> fetchStudents(Year year) async { - var page = await RequestsPlus.get(Consts.kholleURL[year]!, - userName: _username, password: _password); + var page = await RequestsPlus.get( + Consts.kholleURL[year]!, + userName: _username, + password: _password, + ); BeautifulSoup bs = BeautifulSoup(page.body); @@ -50,15 +51,19 @@ class PolytechColloscopeClient { var students = await fetchStudents(year); return students.firstWhereOrNull( - (s) => removeDiacritics(s.name) == removeDiacritics(match)); + (s) => removeDiacritics(s.name) == removeDiacritics(match), + ); } Future getColloscope(Student student) async { var page = await RequestsPlus.get( - Consts.khollesStudentURL[student.year]! - .replaceFirst(":id", student.id.toString()), - userName: _username, - password: _password); + Consts.khollesStudentURL[student.year]!.replaceFirst( + ":id", + student.id.toString(), + ), + userName: _username, + password: _password, + ); BeautifulSoup bs = BeautifulSoup(page.body); @@ -68,8 +73,9 @@ class PolytechColloscopeClient { throw StateError("Invalid student id"); } - var trinomeStr = - RegExp(r"trinôme (\d+)").firstMatch(header.innerHtml)!.group(1)!; + var trinomeStr = RegExp( + r"trinôme (\d+)", + ).firstMatch(header.innerHtml)!.group(1)!; var trinome = int.parse(trinomeStr); @@ -90,14 +96,16 @@ class PolytechColloscopeClient { var date = e.children.first.innerHtml.trim(); var secondTd = e.children.elementAtOrNull(1)!; - var hourAndMinute = - secondTd.children.first.innerHtml.replaceFirst(" ", "").trim(); + var hourAndMinute = secondTd.children.first.innerHtml + .replaceFirst(" ", "") + .trim(); var secondDiv = secondTd.children.elementAtOrNull(1)!; var kholleur = secondDiv.find("a")!.text.trim(); - var divText = - secondDiv.nodes.where((element) => element.runtimeType == Text); + var divText = secondDiv.nodes.where( + (element) => element.runtimeType == Text, + ); var subject = divText.first.text!.replaceAll(RegExp(r'[()]'), "").trim(); @@ -110,30 +118,37 @@ class PolytechColloscopeClient { String? room; if (message != null) { room = RegExp(r"salle(.*)", caseSensitive: false) - .firstMatch(message.replaceAll( - RegExp(r"\b(salle\s*)+\b", caseSensitive: false), "Salle")) + .firstMatch( + message.replaceAll( + RegExp(r"\b(salle\s*)+\b", caseSensitive: false), + "Salle", + ), + ) ?.group(1) ?.trim(); } - var dateParsed = - RegExp(r"(\d{1,2})\s*(\S{3,9})\s*(\d{4})?").firstMatch(date)!; + var dateParsed = RegExp( + r"(\d{1,2})\s*(\S{3,9})\s*(\d{4})?", + ).firstMatch(date)!; var day = dateParsed.group(1)!; var month = dateParsed.group(2)!.asMonthNumber; var year = int.parse(dateParsed.group(3) ?? DateTime.now().year.toString()); - var hourAndMinutesParsed = - RegExp(r"(\d{1,2}) h (\d{2})").firstMatch(hourAndMinute)!; + var hourAndMinutesParsed = RegExp( + r"(\d{1,2}) h (\d{2})", + ).firstMatch(hourAndMinute)!; var hour = hourAndMinutesParsed.group(1)!; var minutes = hourAndMinutesParsed.group(2)!; var dateTime = DateTime( - year, month, int.parse(day), int.parse(hour), int.parse(minutes)); + year, + month, + int.parse(day), + int.parse(hour), + int.parse(minutes), + ); return Kholle(dateTime, subject, kholleur, message, room); } - - static void registerAdapters() { - Hive.registerAdapters(); - } } diff --git a/packages/polytechcolloscopeclient/pubspec.yaml b/packages/polytechcolloscopeclient/pubspec.yaml index 62c01b011..9da19bd5e 100644 --- a/packages/polytechcolloscopeclient/pubspec.yaml +++ b/packages/polytechcolloscopeclient/pubspec.yaml @@ -4,23 +4,20 @@ version: 1.0.11 repository: https://github.com/onyx-lyon1/onyx/tree/main/packages/polytechcolloscopeclient environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.8.0 <4.0.0" # Add regular dependencies here. dependencies: beautiful_soup_dart: ^0.3.0 collection: ^1.17.2 dotenv: ^4.2.0 - equatable: ^2.0.5 - hive_ce: ^2.2.3 - copy_with_extension: ^9.1.0 html: ^0.15.4 requests_plus: ^4.8.4 diacritic: ^0.1.5 + dart_mappable: ^4.6.0 dev_dependencies: lints: ^6.0.0 test: ^1.21.0 build_runner: ^2.2.0 - hive_ce_generator: ^1.9.2 - copy_with_extension_gen: ^9.1.0 + dart_mappable_builder: ^4.6.0