Spaces:
Sleeping
Add layout_type support for generating 4 DIFFERENT home screen structures
Browse filesThe problem: All 4 variants had the same vertical list structure
The solution: AI now generates different layout_type for each variant
Changes:
- Added layout_type field to AI prompt (grid_2x2, vertical_list, hero_card, timeline, featured_grid)
- Updated JSON output to include layout_type
- Added layout_type to fitness fallback variants
- Created _generate_body_content() method that generates different Dart layouts:
* grid_2x2: GridView with 2 columns for dashboards/metrics
* hero_card: Large featured card + smaller cards below
* timeline: ListView for chronological events
* vertical_list: Classic scrollable column (default)
- Replaced hardcoded Expanded(SingleChildScrollView(...)) with dynamic body_content
Now each variant has a DIFFERENT visual structure, not just different colors!
Example for fitness app:
1. "Dashboard" → Grid 2x2 with metrics
2. "Focus Mode" → Hero card with large workout info
3. "Progress" → Timeline of achievements
4. "Social" → Vertical list of activities
- agents/flutter_screen_generator.py +100 -17
|
@@ -635,7 +635,14 @@ FOOTERS:
|
|
| 635 |
- classic_expanded (icons + labels, traditional)
|
| 636 |
- gesture_bar (iOS-style swipe, minimal)
|
| 637 |
|
| 638 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 639 |
{cards_str}
|
| 640 |
|
| 641 |
Generate 4 DIFFERENT variants, each optimized for different use cases.
|
|
@@ -643,10 +650,11 @@ Consider theme style + app type to make smart combinations.
|
|
| 643 |
|
| 644 |
IMPORTANT RULES:
|
| 645 |
1. Use a DIFFERENT background for each variant (choose from 30 options above)
|
| 646 |
-
2.
|
| 647 |
-
3.
|
| 648 |
-
4.
|
| 649 |
-
5. **
|
|
|
|
| 650 |
|
| 651 |
Output ONLY valid JSON:
|
| 652 |
{{
|
|
@@ -654,6 +662,7 @@ Output ONLY valid JSON:
|
|
| 654 |
{{
|
| 655 |
"name": "Variant Name",
|
| 656 |
"description": "Short description",
|
|
|
|
| 657 |
"background": "waves_smooth",
|
| 658 |
"header": "stats_header",
|
| 659 |
"footer": "floating_fab",
|
|
@@ -668,6 +677,7 @@ Output ONLY valid JSON:
|
|
| 668 |
{{
|
| 669 |
"name": "Another Variant",
|
| 670 |
"description": "Different approach",
|
|
|
|
| 671 |
"background": "gradient_mesh",
|
| 672 |
"header": "minimal",
|
| 673 |
"footer": "animated_pills",
|
|
@@ -679,7 +689,7 @@ Output ONLY valid JSON:
|
|
| 679 |
}},
|
| 680 |
"reasoning": "Different background and components"
|
| 681 |
}},
|
| 682 |
-
...2 more variants with DIFFERENT backgrounds, cards and personalized texts
|
| 683 |
]
|
| 684 |
}}
|
| 685 |
|
|
@@ -721,6 +731,7 @@ JSON:"""
|
|
| 721 |
{
|
| 722 |
"name": "High Energy Action",
|
| 723 |
"description": "Dynamic design for active users",
|
|
|
|
| 724 |
"background": "waves_smooth",
|
| 725 |
"header": "stats_header",
|
| 726 |
"footer": "floating_fab",
|
|
@@ -735,6 +746,7 @@ JSON:"""
|
|
| 735 |
{
|
| 736 |
"name": "Focus Mode",
|
| 737 |
"description": "Minimal UI during workout",
|
|
|
|
| 738 |
"background": "gradient_linear",
|
| 739 |
"header": "minimal",
|
| 740 |
"footer": "gesture_bar",
|
|
@@ -749,6 +761,7 @@ JSON:"""
|
|
| 749 |
{
|
| 750 |
"name": "Progress Dashboard",
|
| 751 |
"description": "Data-focused tracking",
|
|
|
|
| 752 |
"background": "geometric_circles",
|
| 753 |
"header": "tabs",
|
| 754 |
"footer": "animated_pills",
|
|
@@ -763,6 +776,7 @@ JSON:"""
|
|
| 763 |
{
|
| 764 |
"name": "Gamified Tracker",
|
| 765 |
"description": "Playful achievement system",
|
|
|
|
| 766 |
"background": "abstract_particles",
|
| 767 |
"header": "avatar_search",
|
| 768 |
"footer": "classic_expanded",
|
|
@@ -2799,6 +2813,81 @@ class _BackgroundPainter extends CustomPainter {{
|
|
| 2799 |
return cards_with_spacing
|
| 2800 |
|
| 2801 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2802 |
def _generate_complete_screen(
|
| 2803 |
self,
|
| 2804 |
theme: Dict[str, Any],
|
|
@@ -2891,6 +2980,10 @@ class _BackgroundPainter extends CustomPainter {{
|
|
| 2891 |
cards_list = variant.get("cards", [])
|
| 2892 |
cards_code = self._generate_cards_code(cards_list, theme_data, app_type)
|
| 2893 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2894 |
# Build complete Dart code
|
| 2895 |
code = f'''import 'package:flutter/material.dart';
|
| 2896 |
|
|
@@ -2949,17 +3042,7 @@ class HomePage extends StatelessWidget {{
|
|
| 2949 |
const _FakeNotch(),
|
| 2950 |
const SizedBox(height: 8),
|
| 2951 |
{header_code},
|
| 2952 |
-
|
| 2953 |
-
child: SingleChildScrollView(
|
| 2954 |
-
padding: EdgeInsets.all({spacing_unit * 2.5}),
|
| 2955 |
-
child: Column(
|
| 2956 |
-
crossAxisAlignment: CrossAxisAlignment.start,
|
| 2957 |
-
children: [
|
| 2958 |
-
{cards_code}
|
| 2959 |
-
],
|
| 2960 |
-
),
|
| 2961 |
-
),
|
| 2962 |
-
),
|
| 2963 |
],
|
| 2964 |
),
|
| 2965 |
),
|
|
|
|
| 635 |
- classic_expanded (icons + labels, traditional)
|
| 636 |
- gesture_bar (iOS-style swipe, minimal)
|
| 637 |
|
| 638 |
+
LAYOUT TYPES (choose 1 per variant - MUST be different for each variant):
|
| 639 |
+
- grid_2x2: 2-column grid layout, perfect for metrics/stats/dashboards
|
| 640 |
+
- vertical_list: Classic vertical scrollable list of cards (default)
|
| 641 |
+
- hero_card: ONE large featured card at top + 2-3 smaller cards below
|
| 642 |
+
- timeline: Vertical timeline with events/activities chronologically
|
| 643 |
+
- featured_grid: ONE large featured item + grid of 4-6 smaller items below
|
| 644 |
+
|
| 645 |
+
CARDS for {app_type} app (choose 3-6 per variant based on layout):
|
| 646 |
{cards_str}
|
| 647 |
|
| 648 |
Generate 4 DIFFERENT variants, each optimized for different use cases.
|
|
|
|
| 650 |
|
| 651 |
IMPORTANT RULES:
|
| 652 |
1. Use a DIFFERENT background for each variant (choose from 30 options above)
|
| 653 |
+
2. Use a DIFFERENT layout_type for each variant (grid_2x2, vertical_list, hero_card, timeline, featured_grid)
|
| 654 |
+
3. Vary the complexity: mix simple, medium, and complex backgrounds
|
| 655 |
+
4. Match background category to use case (gradients=clean, waves=dynamic, geometric=modern, organic=creative, patterns=structured, abstract=premium)
|
| 656 |
+
5. **SELECT 3-6 CARDS** from the list above based on layout_type (grid needs 4-6, hero needs 3-4, timeline needs 4-5)
|
| 657 |
+
6. **PERSONALIZE TEXT** content based on app_type (e.g., fitness="Workout Tracker", banking="Account Overview")
|
| 658 |
|
| 659 |
Output ONLY valid JSON:
|
| 660 |
{{
|
|
|
|
| 662 |
{{
|
| 663 |
"name": "Variant Name",
|
| 664 |
"description": "Short description",
|
| 665 |
+
"layout_type": "grid_2x2",
|
| 666 |
"background": "waves_smooth",
|
| 667 |
"header": "stats_header",
|
| 668 |
"footer": "floating_fab",
|
|
|
|
| 677 |
{{
|
| 678 |
"name": "Another Variant",
|
| 679 |
"description": "Different approach",
|
| 680 |
+
"layout_type": "hero_card",
|
| 681 |
"background": "gradient_mesh",
|
| 682 |
"header": "minimal",
|
| 683 |
"footer": "animated_pills",
|
|
|
|
| 689 |
}},
|
| 690 |
"reasoning": "Different background and components"
|
| 691 |
}},
|
| 692 |
+
...2 more variants with DIFFERENT layout_type, backgrounds, cards and personalized texts
|
| 693 |
]
|
| 694 |
}}
|
| 695 |
|
|
|
|
| 731 |
{
|
| 732 |
"name": "High Energy Action",
|
| 733 |
"description": "Dynamic design for active users",
|
| 734 |
+
"layout_type": "grid_2x2",
|
| 735 |
"background": "waves_smooth",
|
| 736 |
"header": "stats_header",
|
| 737 |
"footer": "floating_fab",
|
|
|
|
| 746 |
{
|
| 747 |
"name": "Focus Mode",
|
| 748 |
"description": "Minimal UI during workout",
|
| 749 |
+
"layout_type": "hero_card",
|
| 750 |
"background": "gradient_linear",
|
| 751 |
"header": "minimal",
|
| 752 |
"footer": "gesture_bar",
|
|
|
|
| 761 |
{
|
| 762 |
"name": "Progress Dashboard",
|
| 763 |
"description": "Data-focused tracking",
|
| 764 |
+
"layout_type": "timeline",
|
| 765 |
"background": "geometric_circles",
|
| 766 |
"header": "tabs",
|
| 767 |
"footer": "animated_pills",
|
|
|
|
| 776 |
{
|
| 777 |
"name": "Gamified Tracker",
|
| 778 |
"description": "Playful achievement system",
|
| 779 |
+
"layout_type": "vertical_list",
|
| 780 |
"background": "abstract_particles",
|
| 781 |
"header": "avatar_search",
|
| 782 |
"footer": "classic_expanded",
|
|
|
|
| 2813 |
return cards_with_spacing
|
| 2814 |
|
| 2815 |
|
| 2816 |
+
def _generate_body_content(
|
| 2817 |
+
self,
|
| 2818 |
+
layout_type: str,
|
| 2819 |
+
cards_code: str,
|
| 2820 |
+
spacing_unit: int
|
| 2821 |
+
) -> str:
|
| 2822 |
+
"""
|
| 2823 |
+
Generate body content layout based on layout_type
|
| 2824 |
+
|
| 2825 |
+
Args:
|
| 2826 |
+
layout_type: grid_2x2, vertical_list, hero_card, timeline, featured_grid
|
| 2827 |
+
cards_code: Pre-generated card widgets code
|
| 2828 |
+
spacing_unit: Spacing value from theme
|
| 2829 |
+
|
| 2830 |
+
Returns:
|
| 2831 |
+
Dart code for the Expanded body section
|
| 2832 |
+
"""
|
| 2833 |
+
layout_type = layout_type or "vertical_list" # Default
|
| 2834 |
+
|
| 2835 |
+
if layout_type == "grid_2x2":
|
| 2836 |
+
# 2-column grid layout
|
| 2837 |
+
return f"""Expanded(
|
| 2838 |
+
child: Padding(
|
| 2839 |
+
padding: EdgeInsets.all({spacing_unit * 2.5}),
|
| 2840 |
+
child: GridView.count(
|
| 2841 |
+
crossAxisCount: 2,
|
| 2842 |
+
crossAxisSpacing: {spacing_unit * 2.0},
|
| 2843 |
+
mainAxisSpacing: {spacing_unit * 2.0},
|
| 2844 |
+
childAspectRatio: 1.0,
|
| 2845 |
+
children: [
|
| 2846 |
+
{cards_code}
|
| 2847 |
+
],
|
| 2848 |
+
),
|
| 2849 |
+
),
|
| 2850 |
+
)"""
|
| 2851 |
+
|
| 2852 |
+
elif layout_type == "hero_card":
|
| 2853 |
+
# One large hero card + smaller cards below
|
| 2854 |
+
return f"""Expanded(
|
| 2855 |
+
child: SingleChildScrollView(
|
| 2856 |
+
padding: EdgeInsets.all({spacing_unit * 2.5}),
|
| 2857 |
+
child: Column(
|
| 2858 |
+
crossAxisAlignment: CrossAxisAlignment.start,
|
| 2859 |
+
children: [
|
| 2860 |
+
{cards_code}
|
| 2861 |
+
],
|
| 2862 |
+
),
|
| 2863 |
+
),
|
| 2864 |
+
)"""
|
| 2865 |
+
|
| 2866 |
+
elif layout_type == "timeline":
|
| 2867 |
+
# Vertical timeline layout
|
| 2868 |
+
return f"""Expanded(
|
| 2869 |
+
child: ListView(
|
| 2870 |
+
padding: EdgeInsets.all({spacing_unit * 2.5}),
|
| 2871 |
+
children: [
|
| 2872 |
+
{cards_code}
|
| 2873 |
+
],
|
| 2874 |
+
),
|
| 2875 |
+
)"""
|
| 2876 |
+
|
| 2877 |
+
else: # vertical_list (default) or featured_grid
|
| 2878 |
+
# Classic vertical scrollable list
|
| 2879 |
+
return f"""Expanded(
|
| 2880 |
+
child: SingleChildScrollView(
|
| 2881 |
+
padding: EdgeInsets.all({spacing_unit * 2.5}),
|
| 2882 |
+
child: Column(
|
| 2883 |
+
crossAxisAlignment: CrossAxisAlignment.start,
|
| 2884 |
+
children: [
|
| 2885 |
+
{cards_code}
|
| 2886 |
+
],
|
| 2887 |
+
),
|
| 2888 |
+
),
|
| 2889 |
+
)"""
|
| 2890 |
+
|
| 2891 |
def _generate_complete_screen(
|
| 2892 |
self,
|
| 2893 |
theme: Dict[str, Any],
|
|
|
|
| 2980 |
cards_list = variant.get("cards", [])
|
| 2981 |
cards_code = self._generate_cards_code(cards_list, theme_data, app_type)
|
| 2982 |
|
| 2983 |
+
# Generate body content based on layout_type
|
| 2984 |
+
layout_type = variant.get("layout_type", "vertical_list")
|
| 2985 |
+
body_content = self._generate_body_content(layout_type, cards_code, spacing_unit)
|
| 2986 |
+
|
| 2987 |
# Build complete Dart code
|
| 2988 |
code = f'''import 'package:flutter/material.dart';
|
| 2989 |
|
|
|
|
| 3042 |
const _FakeNotch(),
|
| 3043 |
const SizedBox(height: 8),
|
| 3044 |
{header_code},
|
| 3045 |
+
{body_content}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3046 |
],
|
| 3047 |
),
|
| 3048 |
),
|