Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/src/registry_api/components/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export "component_registry.dart";
export "component_registry_impl.dart";
export "component_description.dart";
export "value_reference.dart";
export "reference_target.dart";
4 changes: 2 additions & 2 deletions lib/src/registry_api/index.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export 'registry.dart';
export 'model_factory.dart';
export 'build_factory.dart';
export 'reference_target.dart';
export "components/index.dart" show ComponentDescription, ValueReference;
export "components/index.dart"
show ComponentDescription, ValueReference, RefWithTarget;
24 changes: 3 additions & 21 deletions lib/src/registry_api/registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,21 @@ sealed class DuitRegistry {
static final Map<String, FactoryRecord> _customComponentRegistry = {};
static DebugLogger _logger = DefaultLogger.instance;
static ComponentRegistry _componentRegistry = DefaultComponentRegistry();
static late final ResourceLoader<DuitTheme> _themeLoader;
static DuitTheme _theme = const DuitTheme({});

static FutureOr<void> configure({
static FutureOr<void> initialize({
DebugLogger? logger,
ResourceLoader<DuitTheme>? themeLoader,
DuitTheme? theme,
ComponentRegistry? componentRegistry,
}) async {
Comment on lines +15 to 19

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Consider if async signature is still necessary.

The method is still marked as async and returns FutureOr<void>, but the theme assignment is now synchronous. The async behavior might only be needed for the component registry initialization. Consider whether the signature can be simplified further.

🤖 Prompt for AI Agents
In lib/src/registry_api/registry.dart around lines 15 to 19, the initialize
method is marked async and returns FutureOr<void>, but since theme assignment is
synchronous and only componentRegistry initialization might be async, review if
the method can be simplified by removing async and returning Future<void> only
if necessary. Adjust the method signature and implementation accordingly to
reflect the actual async needs, possibly by returning a Future only when
componentRegistry initialization is awaited.

_logger = logger ?? _logger;
_componentRegistry = componentRegistry ?? _componentRegistry;

_theme = theme ?? _theme;
await _componentRegistry.init();

if (themeLoader != null) {
_themeLoader = themeLoader;
}
}

static DuitTheme get theme => _theme;

static Future<void> initTheme() async {
try {
_theme = await _themeLoader.load();
} catch (e, s) {
_logger.error(
"Theme initialization failed",
error: e,
stackTrace: s,
);
rethrow;
}
}

/// Registers a list of component descriptions.
static FutureOr<void> registerComponents(
List<Map<String, dynamic>> components,
Expand Down
1 change: 0 additions & 1 deletion lib/src/ui/theme/index.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export 'theme.dart';
export 'theme_override_rule.dart';
export 'theme_loader.dart';
export 'preprocessor.dart';
export "theme_token.dart";
87 changes: 7 additions & 80 deletions lib/src/ui/theme/preprocessor.dart
Original file line number Diff line number Diff line change
@@ -1,97 +1,24 @@
import 'package:duit_kernel/src/ui/theme/index.dart';

/// Function for custom tokenization of themes.
typedef CustomTokenizer = ThemeToken? Function(
typedef TokenizationCallback = ThemeToken? Function(
String type,
Map<String, dynamic> themeData,
);

final class ThemePreprocessor {
final CustomTokenizer? customWidgetTokenizer, overrideWidgetTokenizer;
abstract class ThemePreprocessor {
final TokenizationCallback? customWidgetTokenizer, overrideWidgetTokenizer;

const ThemePreprocessor({
this.customWidgetTokenizer,
this.overrideWidgetTokenizer,
});

///Creates token for default cases
ThemeToken _createToken(
ThemeToken createToken(
String widgetType,
Map<String, dynamic> themeData,
) {
return switch (widgetType) {
"Text" => TextThemeToken(
themeData,
),
"Image" => ImageThemeToken(
themeData,
),
"Align" ||
"BackdropFilter" ||
"ColoredBox" ||
"ConstrainedBox" ||
"DecoratedBox" ||
"Expanded" ||
"FittedBox" ||
"Row" ||
"Column" ||
"SizedBox" ||
"Container" ||
"OverflowBox" ||
"Padding" ||
"Positioned" ||
"Opacity" ||
"RotatedBox" ||
"Stack" ||
"Wrap" ||
"Transform" ||
"Card" =>
AnimatedPropOwnerThemeToken(
themeData,
widgetType,
),
"AnimatedOpacity" => ImplicitAnimatableThemeToken(
themeData,
widgetType,
),
"GestureDetector" || "InkWell" => ExcludeGestureCallbacksThemeToken(
themeData,
widgetType,
),
"AppBar" || "Scaffold" => ExcludeChildThemeToken(
themeData,
widgetType,
),
"GridView" || "ListView" => DynamicChildHolderThemeToken(
themeData,
widgetType,
),
"ElevatedButton" ||
"Center" ||
"IgnorePointer" ||
"RepaintBoundary" ||
"SingleChildScrollView" =>
DefaultThemeToken(
themeData,
widgetType,
),
"Checkbox" || "Switch" || "TextField" => AttendedWidgetThemeToken(
themeData,
widgetType,
),
"RadioGroupContext" => RadioGroupContextThemeToken(
themeData,
),
"Radio" => RadioThemeToken(
themeData,
),
"Slider" => SliderThemeToken(
themeData,
),
_ => customWidgetTokenizer?.call(widgetType, themeData) ??
const UnknownThemeToken(),
};
}
);

DuitTheme tokenize(Map<String, dynamic> theme) {
final errors = <String>{};
Expand All @@ -113,13 +40,13 @@ final class ThemePreprocessor {
if (overridedToken != null) {
token = overridedToken;
} else {
token = _createToken(
token = createToken(
widgetType,
themeData,
);
}
} else {
token = _createToken(
token = createToken(
widgetType,
themeData,
);
Expand Down
29 changes: 0 additions & 29 deletions lib/src/ui/theme/theme_loader.dart

This file was deleted.

Loading