Skip to content

Flutter pattern

create_page

create_page(path, module, page, isResponsive=False) -> dict[list[str], list[str]]

Create the necessary files for a new page in a Flutter module.

This function creates Dart files for UI, binding, and controller layers of a new page in the specified module. It returns the status of each file creation.

Args: - path (str): The file system path where the Flutter project is located. - module (str): The module in which the page will be created. - page (str): The name of the page to be created.

Returns: - dict: A dictionary with two lists, 'File' and 'Status', indicating the names of created files and their creation status respectively.

Source code in izio_cli/pattern/flutter_pattern.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
def create_page(path, module, page, isResponsive=False) -> dict[list[str], list[str]]:
    """
    Create the necessary files for a new page in a Flutter module.

    This function creates Dart files for UI, binding, and controller layers of a new page in the specified module. It returns the status of each file creation.

    Args:
    - path (str): The file system path where the Flutter project is located.
    - module (str): The module in which the page will be created.
    - page (str): The name of the page to be created.

    Returns:
    - dict: A dictionary with two lists, 'File' and 'Status', indicating the names of created files and their creation status respectively.
    """


    files = []
    status = []


    pageSnake = to_snake_case(page)

    if pageSnake.endswith("_page"):
        pageSnake = pageSnake[:-5]

    result = create_file(f"{path}{os.sep}lib{os.sep}{module}{os.sep}ui", f"{pageSnake}_page.dart", responsivePagePayload(page=page) if isResponsive else pagePayload(page=page))
    files.append(f"{result["file"]}")
    status.append(result["status"])

    result = create_file(f"{path}{os.sep}lib{os.sep}{module}{os.sep}binding", f"{pageSnake}_binding.dart", bindingPayload(page=page))
    files.append(f"{result["file"]}")
    status.append(result["status"])

    result = create_file(f"{path}{os.sep}lib{os.sep}{module}{os.sep}controller", f"{pageSnake}_controller.dart", controllerPayload(page=page))
    files.append(f"{result["file"]}")
    status.append(result["status"])

    return {"File": files, "Status": status}

getFlutterFlavors

getFlutterFlavors(root: str, flutterProject='loyalty2_0')

Retrieve the list of Flutter modules excluding certain predefined directories.

This function checks for the existence of 'pubspec.yaml' and 'lib' folder in the specified path and then lists all the directories that are considered Flutter modules.

Args: - path (str): The file system path where the Flutter project is located.

Returns: - list: A sorted list of Flutter module names.

Raises: - Exception: If 'pubspec.yaml' or 'lib' folder is not found in the given path.

Source code in izio_cli/pattern/flutter_pattern.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
def getFlutterFlavors(root: str, flutterProject="loyalty2_0"):
    """
    Retrieve the list of Flutter modules excluding certain predefined directories.

    This function checks for the existence of 'pubspec.yaml' and 'lib' folder in the specified path and then lists all the directories that are considered Flutter modules.

    Args:
    - path (str): The file system path where the Flutter project is located.

    Returns:
    - list: A sorted list of Flutter module names.

    Raises:
    - Exception: If 'pubspec.yaml' or 'lib' folder is not found in the given path.
    """

    # Verify if the path is a flutter project
    path = root + f"{os.sep}{flutterProject}{os.sep}envs"

    if not os.path.exists(path):
        raise Exception("envs folder not found, this is a izio project?")

    # list .env files inside envs folder
    flavors = [ f for f in os.listdir(path) if f.endswith(".env")]
    # remove .env extension
    flavors = [f[:-4] for f in flavors]

    flavors.sort()
    return flavors

getFlutterModules

getFlutterModules(path: str)

Retrieve the list of Flutter modules excluding certain predefined directories.

This function checks for the existence of 'pubspec.yaml' and 'lib' folder in the specified path and then lists all the directories that are considered Flutter modules.

Args: - path (str): The file system path where the Flutter project is located.

Returns: - list: A sorted list of Flutter module names.

Raises: - Exception: If 'pubspec.yaml' or 'lib' folder is not found in the given path.

Source code in izio_cli/pattern/flutter_pattern.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def getFlutterModules(path: str):
    """
    Retrieve the list of Flutter modules excluding certain predefined directories.

    This function checks for the existence of 'pubspec.yaml' and 'lib' folder in the specified path and then lists all the directories that are considered Flutter modules.

    Args:
    - path (str): The file system path where the Flutter project is located.

    Returns:
    - list: A sorted list of Flutter module names.

    Raises:
    - Exception: If 'pubspec.yaml' or 'lib' folder is not found in the given path.
    """

    # Verify if the path is a flutter project
    if not os.path.exists(path + f"{os.sep}pubspec.yaml"):
        raise Exception("pubspec.yaml not found, this is a flutter project?")

    # Verify if the path contains a lib folder
    if not os.path.exists(path + f"{os.sep}lib"):
        raise Exception("lib folder not found")

    modules = [
        d
        for d in os.listdir(path + f"{os.sep}lib")
        if os.path.isdir(os.path.join(path + f"{os.sep}lib", d))
    ]
    modules = [m for m in modules if m not in _dirFilter]
    modules.sort()
    return modules

getFlutterPages

getFlutterPages(path: str, module: str)

Retrieve the list of Flutter pages from a specified module.

This function lists all Dart files that end with '_page.dart' in the 'ui' directory of a given module.

Args: - path (str): The file system path where the Flutter project is located. - module (str): The name of the module to search for pages.

Returns: - list: A sorted list of Flutter page names.

Source code in izio_cli/pattern/flutter_pattern.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def getFlutterPages(path: str, module: str):
    """
    Retrieve the list of Flutter pages from a specified module.

    This function lists all Dart files that end with '_page.dart' in the 'ui' directory of a given module.

    Args:
    - path (str): The file system path where the Flutter project is located.
    - module (str): The name of the module to search for pages.

    Returns:
    - list: A sorted list of Flutter page names.
    """
    pages = [
        d
        for d in os.listdir(path + f"{os.sep}lib{os.sep}" + module + f"{os.sep}ui")
        if os.path.isfile(os.path.join(path + f"{os.sep}lib{os.sep}" + module + f"{os.sep}ui", d))
    ]
    pages = [p for p in pages if p.endswith("_page.dart")]
    pages.sort()
    return pages

getModules

getModules(path: str)

Retrieve the list of Flutter modules from a given path.

This function gets all Flutter module directories in the specified path, as a module. It adds "Cancel" and "New Module" options to the list of modules for user interaction.

Args: - path (str): The file system path where Flutter modules are located.

Returns: - list: A list of module names including "Cancel" and "New Module" options.

Source code in izio_cli/pattern/flutter_pattern.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def getModules(path: str):
    """
    Retrieve the list of Flutter modules from a given path.

    This function gets all Flutter module directories in the specified path, as a module. It adds "Cancel" and "New Module" options to the list of modules for user interaction.

    Args:
    - path (str): The file system path where Flutter modules are located.

    Returns:
    - list: A list of module names including "Cancel" and "New Module" options.
    """

    modules = getFlutterModules(path)
    modules.append("Cancel")
    modules.insert(0, "New Module")
    return modules

new_module

new_module(path, module) -> dict[list[str], list[str]]

Create a new module with subdirectories for a Flutter project.

This function creates a new module directory and all the required subdirectories in the Flutter project. It returns the status of each directory creation.

Args: - path (str): The file system path where the Flutter project is located. - module (str): The name of the module to be created.

Returns: - dict: A dictionary with two lists, 'Directory' and 'status', indicating the names of created directories and their creation status respectively.

Source code in izio_cli/pattern/flutter_pattern.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def new_module(path, module) -> dict[list[str], list[str]]:
    """
    Create a new module with subdirectories for a Flutter project.

    This function creates a new module directory and all the required subdirectories in the Flutter project. It returns the status of each directory creation.

    Args:
    - path (str): The file system path where the Flutter project is located.
    - module (str): The name of the module to be created.

    Returns:
    - dict: A dictionary with two lists, 'Directory' and 'status', indicating the names of created directories and their creation status respectively.
    """
    directories = []
    status = []

    result = create_directory(f"{path}{os.sep}lib{os.sep}{module}")
    directories.append(f"{result["directory"]} (module)")
    status.append(result["status"])

    for subdirectory in _subdirectories:
        result = create_directory(f"{path}{os.sep}lib{os.sep}{module}{os.sep}{subdirectory}")
        directories.append(f"{os.sep}" + subdirectory)
        status.append(result["status"])

    return {"Directory": directories, "status": status}