File size: 5,319 Bytes
71f2499
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d535ad0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71f2499
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
81
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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
161
162
163
164
165
166
167
168
169
170
171
172
173
"""
Simple Flutter Generator - Direct prompt to DeepSeek
No presets, no themes, just raw AI code generation
"""

import os
import requests
from typing import Dict, Any


class SimpleFlutterGenerator:
    """
    Ultra-simple Flutter code generator
    Takes a prompt, calls DeepSeek, returns Flutter code
    """

    def __init__(self):
        self.deepseek_api_key = os.getenv("DEEPSEEK_API_KEY", "")
        self.deepseek_base_url = "https://api.deepseek.com/v1/chat/completions"
        self.model = "deepseek-coder"

    def generate(self, prompt: str) -> Dict[str, Any]:
        """
        Generate Flutter code from user prompt

        Args:
            prompt: User description (e.g., "Create a login screen with email and password")

        Returns:
            {
                "code": "complete Flutter/Dart code",
                "prompt": "original user prompt",
                "success": True/False,
                "error": "error message if failed"
            }
        """

        if not self.deepseek_api_key:
            return {
                "success": False,
                "error": "DEEPSEEK_API_KEY not configured",
                "code": "",
                "prompt": prompt
            }

        if not prompt or not prompt.strip():
            return {
                "success": False,
                "error": "Empty prompt",
                "code": "",
                "prompt": prompt
            }

        try:
            # Simple, direct prompt to DeepSeek
            system_prompt = """You are an expert Flutter/Dart developer.
Generate complete, runnable Flutter code that can be pasted directly into DartPad.

REQUIREMENTS:
1. Complete code with imports, main(), MaterialApp, and all widgets
2. Use Material 3 design (useMaterial3: true)
3. Include realistic mock data
4. Make it visually appealing with proper colors, spacing, shadows
5. Code must be between 200-1000 lines
6. No external packages - only flutter/material.dart
7. Format code properly with indentation

IMPORTANT - IPHONE DEVICE FRAME:
8. Wrap the entire app in an iPhone device frame with these exact specifications:
   - Use a Container with width: 393, height: 852 (iPhone 15 Pro dimensions)
   - Add rounded corners (borderRadius: 50)
   - Add a subtle shadow and border to simulate device frame
   - Center the container on a light gray background
   - The user's requested app should render INSIDE this frame

Example structure:
```dart
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        backgroundColor: Color(0xFFE5E5E5),
        body: Center(
          child: Container(
            width: 393,
            height: 852,
            decoration: BoxDecoration(
              color: Colors.black,
              borderRadius: BorderRadius.circular(50),
              boxShadow: [
                BoxShadow(
                  color: Colors.black26,
                  blurRadius: 30,
                  spreadRadius: 5,
                )
              ],
            ),
            clipBehavior: Clip.antiAlias,
            child: MaterialApp(
              // User's actual app goes here
              home: [USER_REQUESTED_WIDGET],
            ),
          ),
        ),
      ),
    );
  }
}
```

Output ONLY the Dart code, no explanations."""

            user_message = f"Generate Flutter code for: {prompt}"

            print(f"📝 Prompt: {prompt}")
            print(f"🤖 Calling DeepSeek API...")

            headers = {
                "Authorization": f"Bearer {self.deepseek_api_key}",
                "Content-Type": "application/json"
            }

            payload = {
                "model": self.model,
                "messages": [
                    {"role": "system", "content": system_prompt},
                    {"role": "user", "content": user_message}
                ],
                "max_tokens": 4000,  # Enough for ~1000 lines of code
                "temperature": 0.7
            }

            response = requests.post(
                self.deepseek_base_url,
                headers=headers,
                json=payload,
                timeout=60
            )

            response.raise_for_status()
            result = response.json()

            generated_code = result["choices"][0]["message"]["content"]

            # Clean up code (remove markdown fences if present)
            if "```dart" in generated_code:
                generated_code = generated_code.split("```dart")[1].split("```")[0].strip()
            elif "```" in generated_code:
                generated_code = generated_code.split("```")[1].split("```")[0].strip()

            print(f"✅ Generated {len(generated_code)} characters of code")

            return {
                "success": True,
                "code": generated_code,
                "prompt": prompt,
                "error": None,
                "lines": len(generated_code.split('\n'))
            }

        except Exception as e:
            print(f"❌ Error: {e}")
            return {
                "success": False,
                "error": str(e),
                "code": "",
                "prompt": prompt
            }