Skip to content

Commit 6e8ec8d

Browse files
authored
Merge pull request #1906 from EnsembleUI/fix/device-context
[Fix] context problem with device changes
2 parents 456990b + dd3a8f6 commit 6e8ec8d

File tree

2 files changed

+6
-49
lines changed

2 files changed

+6
-49
lines changed

modules/ensemble/lib/framework/data_context.dart

+4-8
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,15 @@ class DataContext implements Context {
8888
_contextMap['auth'] = GetIt.instance<AuthContextManager>();
8989
}
9090

91-
_addLegacyDataContext(buildContext);
91+
_addLegacyDataContext();
9292
}
9393

9494

9595
// device is a common name. If user already uses that, don't override it
9696
// This is now in ensemble.device.*
97-
void _addLegacyDataContext(BuildContext? newBuildContext) {
97+
void _addLegacyDataContext() {
9898
if (_contextMap['device'] == null) {
99-
_contextMap['device'] = Device(newBuildContext);
100-
} else {
101-
// If device exists, update its context
102-
final device = _contextMap['device'];
103-
device.updateContext(newBuildContext);
99+
_contextMap['device'] = Device();
104100
}
105101
}
106102

@@ -472,7 +468,7 @@ class NativeInvokable extends ActionInvokable {
472468
'user': () => UserInfo(),
473469
'formatter': () => Formatter(),
474470
'utils': () => _EnsembleUtils(),
475-
'device': () => Device(buildContext),
471+
'device': () => Device(),
476472
'version': () => _cache['version'],
477473
};
478474
}

modules/ensemble/lib/framework/device.dart

+2-41
Original file line numberDiff line numberDiff line change
@@ -27,52 +27,13 @@ class Device
2727
DeviceInfoCapability,
2828
WidgetsBindingObserver {
2929
static final Device _instance = Device._internal();
30-
static late BuildContext context;
3130

32-
Device._internal() {
33-
WidgetsBinding.instance.addObserver(this);
34-
}
31+
Device._internal();
3532

36-
factory Device([BuildContext? buildContext]) {
37-
if (buildContext != null) {
38-
context = buildContext;
39-
}
33+
factory Device() {
4034
return _instance;
4135
}
4236

43-
// method to update context
44-
void updateContext(BuildContext? newContext) {
45-
if (newContext != null) {
46-
context = newContext;
47-
}
48-
}
49-
50-
@override
51-
void didChangeMetrics() {
52-
WidgetsBinding.instance
53-
.addPostFrameCallback((_) => _handleMediaQueryChange());
54-
}
55-
56-
void _handleMediaQueryChange() {
57-
final newData = MediaQuery.of(context);
58-
59-
// Compare with existing static data
60-
if (MediaQueryCapability.data?.orientation != newData.orientation ||
61-
MediaQueryCapability.data?.size != newData.size) {
62-
MediaQueryCapability.data = newData;
63-
64-
// Dispatch individual property changes
65-
ScreenController().dispatchDeviceChanges(context, 'width', screenWidth);
66-
ScreenController().dispatchDeviceChanges(context, 'height', screenHeight);
67-
ScreenController()
68-
.dispatchDeviceChanges(context, 'orientation', screenOrientation);
69-
ScreenController()
70-
.dispatchDeviceChanges(context, 'safeAreaTop', safeAreaTop);
71-
ScreenController()
72-
.dispatchDeviceChanges(context, 'safeAreaBottom', safeAreaBottom);
73-
}
74-
}
75-
7637
@override
7738
Map<String, Function> getters() {
7839
return {

0 commit comments

Comments
 (0)