Line data Source code
1 : import 'package:flutter/material.dart'; 2 : 3 : import 'models/model.dart'; 4 : 5 : class ControllerBootstrap { 6 : final List<Component> components; 7 2 : ControllerBootstrap(this.components); 8 : 9 2 : Map<TypeScreen, Organization> mountOrganizations(String style) { 10 : final regExp = 11 2 : RegExp(r'(xs|md|lg|sm)|([-][0-9]*)|([:]{0}[h]{1}[\/*][0-9]*)'); 12 2 : final matches = regExp.allMatches(style); 13 4 : final items = matches.map((match) { 14 2 : return match.group(0) ?? ""; 15 2 : }).toList(); 16 2 : final organizations = <TypeScreen, Organization>{}; 17 8 : for (var i = 0; i + 1 < items.length; i++) { 18 6 : if ((i + 1) % 2 != 0) { 19 4 : var typeScreen = items[i].parseScreen; 20 4 : var height = organizations[typeScreen]?.height ?? 1.0; 21 4 : var division = organizations[typeScreen]?.division ?? 12; 22 6 : if (items[i + 1].contains("h")) { 23 6 : height = items[i + 1].parseHeight; 24 : } else { 25 8 : division = int.parse(items[i + 1]).abs(); 26 : } 27 4 : organizations.addAll({ 28 6 : items[i].parseScreen: Organization( 29 : division: division, 30 : height: height, 31 : ) 32 : }); 33 : } 34 : } 35 : return organizations; 36 : } 37 : 38 2 : void createComponents() { 39 8 : for (var i = 0; i < components.length; i++) { 40 8 : final organizations = mountOrganizations(components[i].style); 41 10 : components[i] = components[i].copyWith( 42 : organizations: organizations, 43 : ); 44 : } 45 : } 46 : }