Skip to content

Commit

Permalink
Freezed
Browse files Browse the repository at this point in the history
  • Loading branch information
Carapacik committed Nov 14, 2023
1 parent e5fa385 commit dc11b96
Show file tree
Hide file tree
Showing 13 changed files with 638 additions and 253 deletions.
9 changes: 9 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
targets:
$default:
builders:
freezed:
options:
when:
when: false
maybe_when: false
when_or_null: false
103 changes: 103 additions & 0 deletions lib/src/core/assets/generated/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions lib/src/core/bloc/app_bloc_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import 'package:wordly/src/core/utils/logger.dart';

/// [BlocObserver] which logs all bloc state changes, errors and events.
class AppBlocObserver extends BlocObserver {
/// [BlocObserver] which logs all bloc state changes, errors and events.
const AppBlocObserver();

@override
void onTransition(
Bloc<Object?, Object?> bloc,
Transition<Object?, Object?> transition,
) {
void onTransition(Bloc<Object?, Object?> bloc, Transition<Object?, Object?> transition) {
final buffer = StringBuffer()
..writeln('Bloc: ${bloc.runtimeType} | ${transition.event.runtimeType}')
..write('Transition: ${transition.currentState.runtimeType}')
Expand All @@ -27,11 +27,7 @@ class AppBlocObserver extends BlocObserver {
}

@override
void onError(
BlocBase<Object?> bloc,
Object error,
StackTrace stackTrace,
) {
void onError(BlocBase<Object?> bloc, Object error, StackTrace stackTrace) {
logger.error(
'Bloc: ${bloc.runtimeType} | $error',
stackTrace: stackTrace,
Expand Down
4 changes: 1 addition & 3 deletions lib/src/core/localization/localization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import 'package:wordly/src/core/localization/generated/l10n.dart';
/// {@endtemplate}
final class Localization extends GeneratedLocalization {
/// {@macro localization}
Localization._({
required this.locale,
});
Localization._({required this.locale});

/// {@macro localization}
static const localizationDelegate = _LocalizationDelegate(
Expand Down
12 changes: 0 additions & 12 deletions lib/src/core/utils/extensions/build_context.dart

This file was deleted.

17 changes: 11 additions & 6 deletions lib/src/core/utils/extensions/context_extension.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'package:flutter/material.dart';
import 'package:wordly/src/core/localization/localization.dart';
import 'package:wordly/src/feature/initialization/model/dependencies.dart';
import 'package:wordly/src/feature/initialization/widget/dependencies_scope.dart';

/// List of extensions for [BuildContext]
extension ContextExtension on BuildContext {
Expand All @@ -8,9 +11,7 @@ extension ContextExtension on BuildContext {
/// when that widget changes (or a new widget of that type is introduced,
/// or the widget goes away), this build context is rebuilt so that it can
/// obtain new values from that widget.
T? inhMaybeOf<T extends InheritedWidget>({
bool listen = true,
}) =>
T? inhMaybeOf<T extends InheritedWidget>({bool listen = true}) =>
listen ? dependOnInheritedWidgetOfExactType<T>() : getInheritedWidgetOfExactType<T>();

/// Obtain the nearest widget of the given type T,
Expand All @@ -19,13 +20,17 @@ extension ContextExtension on BuildContext {
/// when that widget changes (or a new widget of that type is introduced,
/// or the widget goes away), this build context is rebuilt so that it can
/// obtain new values from that widget.
T inhOf<T extends InheritedWidget>({
bool listen = true,
}) =>
T inhOf<T extends InheritedWidget>({bool listen = true}) =>
inhMaybeOf<T>(listen: listen) ??
(throw ArgumentError(
'Out of scope, not found inherited widget '
'a $T of the exact type',
'out_of_scope',
));

Dependencies get dependencies => DependenciesScope.of(this);

ThemeData get theme => Theme.of(this);

Localization get r => Localization.of(this);
}
1 change: 0 additions & 1 deletion lib/src/core/utils/extensions/extensions.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// Extensions
library app_extensions;

export 'build_context.dart';
export 'context_extension.dart';
export 'theme_data.dart';
24 changes: 6 additions & 18 deletions lib/src/core/utils/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ abstract base class Logger {
void verbose(String message);

/// Set up the logger
L runLogging<L>(
L Function() fn, [
LogOptions options = const LogOptions(),
]);
L runLogging<L>(L Function() fn, [LogOptions options = const LogOptions()]);

/// Stream of logs
Stream<LogMessage> get logs;
Expand All @@ -141,7 +138,7 @@ abstract base class Logger {

/// Default logger using logging package
final class LoggerLogging extends Logger {
final _logger = logging.Logger('WordlyPlusLogger');
final _logger = logging.Logger('SizzleLogger');

@override
void debug(String message) => _logger.fine(message);
Expand All @@ -164,25 +161,16 @@ final class LoggerLogging extends Logger {
);

@override
L runLogging<L>(
L Function() fn, [
LogOptions options = const LogOptions(),
]) {
L runLogging<L>(L Function() fn, [LogOptions options = const LogOptions()]) {
if (kReleaseMode && !options.logInRelease) {
return fn();
}
logging.hierarchicalLoggingEnabled = true;

_logger.onRecord.where((event) => event.loggerName == 'WordlyPlusLogger').listen((event) {
_logger.onRecord.where((event) => event.loggerName == 'SizzleLogger').listen((event) {
final logMessage = event.toLogMessage();
final message = options.formatter?.call(
logMessage,
options,
) ??
_formatLoggerMessage(
log: logMessage,
options: options,
);
final message =
options.formatter?.call(logMessage, options) ?? _formatLoggerMessage(log: logMessage, options: options);

if (logMessage.logLevel.compareTo(options.level) < 0) {
return;
Expand Down
Loading

0 comments on commit dc11b96

Please sign in to comment.