Skip to content

Commit b214df6

Browse files
committed
Cloud UI #52
1 parent a922f3d commit b214df6

File tree

3 files changed

+41
-36
lines changed

3 files changed

+41
-36
lines changed

lib/src/data/data_manager.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,14 +656,23 @@ class DataManager {
656656
log('Layout ID map changed. Updating...');
657657
}
658658

659+
final bool disabledLayoutsChanged = !(const ListEquality()
660+
.equals(localModel.disabledLayouts, serverModel.disabledLayouts));
661+
if (disabledLayoutsChanged) {
662+
localModel =
663+
localModel.copyWith(disabledLayouts: serverModel.disabledLayouts);
664+
log('Disabled layouts changed. Updating...');
665+
}
666+
659667
if (layoutUpdates.isEmpty &&
660668
fontUpdates.isEmpty &&
661669
apiUpdates.isEmpty &&
662670
variableUpdates.isEmpty &&
663671
conditionUpdates.isEmpty &&
664672
!templateChanged &&
665673
!entryChanged &&
666-
!didLayoutIDMapChange) {
674+
!didLayoutIDMapChange &&
675+
!disabledLayoutsChanged) {
667676
log('No updates to process.');
668677
return;
669678
} else {
@@ -675,6 +684,8 @@ class DataManager {
675684
log(' | ${conditionUpdates.length} condition updates.');
676685
log(' | ${templateChanged ? 1 : 0} template update${templateChanged ? '' : 's'}.');
677686
log(' | ${entryChanged ? 1 : 0} entry id update${entryChanged ? '' : 's'}.');
687+
log(' | ${didLayoutIDMapChange ? 'Layout ID map changed.' : 'No layout ID map changes.'}');
688+
log(' | ${disabledLayoutsChanged ? 'Disabled layout IDs changed.' : 'No disabled layout IDs changed.'}');
678689
}
679690

680691
for (final String layoutID in layoutUpdates.keys) {
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import 'package:flutter/cupertino.dart';
22
import 'package:flutter/material.dart';
33

4-
class CodelesslyLoadingScreen extends StatefulWidget {
4+
class CodelesslyLoadingScreen extends StatelessWidget {
55
const CodelesslyLoadingScreen({super.key});
66

7-
@override
8-
State<CodelesslyLoadingScreen> createState() =>
9-
_CodelesslyLoadingScreenState();
10-
}
11-
12-
class _CodelesslyLoadingScreenState extends State<CodelesslyLoadingScreen> {
137
@override
148
Widget build(BuildContext context) => const SizedBox.shrink();
159
}

lib/src/ui/codelessly_widget.dart

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,34 @@ class _CodelesslyWidgetState extends State<CodelesslyWidget> {
446446
super.dispose();
447447
}
448448

449+
/// Retrieves a canvas ID for a layout group based on the current screen size.
450+
/// Returns null if the layout group does not have a canvas for the current
451+
/// screen size or if the layout group does not exist.
452+
String? _getCanvasIDForLayoutGroup(
453+
String? layoutID, SDKPublishModel model, Size screenSize) {
454+
if (layoutID != null && model.layouts.containsKey(layoutID)) {
455+
final SDKPublishLayout? layout = model.layouts[layoutID];
456+
if (layout != null) {
457+
if (layout.canvases.length == 1) {
458+
// standalone layout. No need to check breakpoints.
459+
return layout.canvases.keys.first;
460+
}
461+
// this layout belongs to a layout group. Load correct layout
462+
// for the current breakpoint.
463+
final width = screenSize.width;
464+
final breakpoints = layout.breakpoints;
465+
// Get a breakpoint for the current width.
466+
final breakpoint = breakpoints.findForWidth(width);
467+
if (breakpoint != null) {
468+
// print(
469+
// 'Found breakpoint for width ${width.toInt()}: ${breakpoint.nodeId}');
470+
return breakpoint.nodeId;
471+
}
472+
}
473+
}
474+
return null;
475+
}
476+
449477
/// Once the SDK is successfully initialized, we can build the layout.
450478
/// A [StreamBuilder] is used to listen to layout changes whenever a user
451479
/// publishes a new update through the Codelessly publish menu, the changes
@@ -641,31 +669,3 @@ class _NavigationBuilderState extends State<_NavigationBuilder> {
641669
@override
642670
Widget build(BuildContext context) => widget.builder(context);
643671
}
644-
645-
/// Retrieves a canvas ID for a layout group based on the current screen size.
646-
/// Returns null if the layout group does not have a canvas for the current
647-
/// screen size or if the layout group does not exist.
648-
String? _getCanvasIDForLayoutGroup(
649-
String? layoutID, SDKPublishModel model, Size screenSize) {
650-
if (layoutID != null && model.layouts.containsKey(layoutID)) {
651-
final SDKPublishLayout? layout = model.layouts[layoutID];
652-
if (layout != null) {
653-
if (layout.canvases.length == 1) {
654-
// standalone layout. No need to check breakpoints.
655-
return layout.canvases.keys.first;
656-
}
657-
// this layout belongs to a layout group. Load correct layout
658-
// for the current breakpoint.
659-
final width = screenSize.width;
660-
final breakpoints = layout.breakpoints;
661-
// Get a breakpoint for the current width.
662-
final breakpoint = breakpoints.findForWidth(width);
663-
if (breakpoint != null) {
664-
// print(
665-
// 'Found breakpoint for width ${width.toInt()}: ${breakpoint.nodeId}');
666-
return breakpoint.nodeId;
667-
}
668-
}
669-
}
670-
return null;
671-
}

0 commit comments

Comments
 (0)