@@ -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