JanadaSroor commited on
Commit
7f5e4f2
·
1 Parent(s): 1f671ba

Demo version

Browse files
Files changed (1) hide show
  1. app.py +210 -236
app.py CHANGED
@@ -3,6 +3,73 @@ import zipfile
3
  import io
4
  import os
5
  from datetime import datetime
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  def generate_flutter_code(description):
8
  """
@@ -89,20 +156,22 @@ def generate_flutter_code(description):
89
 
90
 
91
  def generate_main_dart(description):
92
- """Generate the main.dart file content."""
93
- return f"""// AI-Generated Flutter Application
94
- // Description: {description}
95
- // Generated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
96
 
 
 
 
 
 
 
 
97
  import 'package:flutter/material.dart';
98
- import 'widgets.dart';
99
 
100
  void main() {{
101
  runApp(const MyApp());
102
  }}
103
 
104
- /// Main application widget
105
- /// This is the root of your Flutter application
106
  class MyApp extends StatelessWidget {{
107
  const MyApp({{super.key}});
108
 
@@ -110,22 +179,15 @@ class MyApp extends StatelessWidget {{
110
  Widget build(BuildContext context) {{
111
  return MaterialApp(
112
  title: 'Flutter App',
113
- debugShowCheckedModeBanner: false,
114
  theme: ThemeData(
115
- colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
116
  useMaterial3: true,
117
- appBarTheme: const AppBarTheme(
118
- centerTitle: true,
119
- elevation: 2,
120
- ),
121
  ),
122
  home: const HomePage(),
123
  );
124
  }}
125
  }}
126
 
127
- /// Home page widget
128
- /// Main screen of the application
129
  class HomePage extends StatefulWidget {{
130
  const HomePage({{super.key}});
131
 
@@ -134,66 +196,44 @@ class HomePage extends StatefulWidget {{
134
  }}
135
 
136
  class _HomePageState extends State<HomePage> {{
137
- int _counter = 0;
138
-
139
- void _incrementCounter() {{
140
- setState(() {{
141
- _counter++;
142
- }});
143
- }}
144
-
145
  @override
146
  Widget build(BuildContext context) {{
147
  return Scaffold(
148
- appBar: AppBar(
149
- backgroundColor: Theme.of(context).colorScheme.inversePrimary,
150
- title: const Text('Flutter App'),
151
- ),
152
- body: Center(
153
- child: Column(
154
- mainAxisAlignment: MainAxisAlignment.center,
155
- children: <Widget>[
156
- // Custom widget from widgets.dart
157
- const CustomInfoCard(
158
- title: 'Welcome',
159
- description: '{description[:50]}...',
160
- ),
161
- const SizedBox(height: 24),
162
- const Text(
163
- 'You have pushed the button this many times:',
164
- style: TextStyle(fontSize: 16),
165
- ),
166
- Text(
167
- '$_counter',
168
- style: Theme.of(context).textTheme.headlineMedium?.copyWith(
169
- fontWeight: FontWeight.bold,
170
- color: Theme.of(context).colorScheme.primary,
171
- ),
172
- ),
173
- ],
174
- ),
175
- ),
176
- floatingActionButton: FloatingActionButton(
177
- onPressed: _incrementCounter,
178
- tooltip: 'Increment',
179
- child: const Icon(Icons.add),
180
- ),
181
  );
182
  }}
183
  }}
184
- """
185
 
 
186
 
187
- def generate_widgets_dart(description):
188
- """Generate the widgets.dart file content."""
189
- return f"""// Custom Widgets for the Flutter Application
190
  // Description: {description}
191
  // Generated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
 
 
 
 
 
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  import 'package:flutter/material.dart';
194
 
195
  /// Custom info card widget
196
- /// Displays a title and description in a styled card
197
  class CustomInfoCard extends StatelessWidget {{
198
  final String title;
199
  final String description;
@@ -216,26 +256,11 @@ class CustomInfoCard extends StatelessWidget {{
216
  child: Column(
217
  mainAxisSize: MainAxisSize.min,
218
  children: [
219
- if (icon != null)
220
- Icon(
221
- icon,
222
- size: 48,
223
- color: Theme.of(context).colorScheme.primary,
224
- ),
225
  if (icon != null) const SizedBox(height: 12),
226
- Text(
227
- title,
228
- style: Theme.of(context).textTheme.headlineSmall?.copyWith(
229
- fontWeight: FontWeight.bold,
230
- ),
231
- textAlign: TextAlign.center,
232
- ),
233
  const SizedBox(height: 8),
234
- Text(
235
- description,
236
- style: Theme.of(context).textTheme.bodyMedium,
237
- textAlign: TextAlign.center,
238
- ),
239
  ],
240
  ),
241
  ),
@@ -243,105 +268,65 @@ class CustomInfoCard extends StatelessWidget {{
243
  }}
244
  }}
245
 
246
- /// Custom button widget with loading state
247
  class CustomButton extends StatelessWidget {{
248
  final String text;
249
  final VoidCallback? onPressed;
250
  final bool isLoading;
251
- final IconData? icon;
252
 
253
  const CustomButton({{
254
  super.key,
255
  required this.text,
256
  this.onPressed,
257
  this.isLoading = false,
258
- this.icon,
259
  }});
260
 
261
  @override
262
  Widget build(BuildContext context) {{
263
  return ElevatedButton(
264
  onPressed: isLoading ? null : onPressed,
265
- style: ElevatedButton.styleFrom(
266
- padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
267
- shape: RoundedRectangleBorder(
268
- borderRadius: BorderRadius.circular(8),
269
- ),
270
- ),
271
  child: isLoading
272
- ? const SizedBox(
273
- width: 20,
274
- height: 20,
275
- child: CircularProgressIndicator(strokeWidth: 2),
276
- )
277
- : Row(
278
- mainAxisSize: MainAxisSize.min,
279
- children: [
280
- if (icon != null) ...[
281
- Icon(icon, size: 20),
282
- const SizedBox(width: 8),
283
- ],
284
- Text(text),
285
- ],
286
- ),
287
  );
288
  }}
289
  }}
 
290
 
291
- /// Custom text input field widget
292
- class CustomTextField extends StatelessWidget {{
293
- final String label;
294
- final String? hint;
295
- final TextEditingController? controller;
296
- final int maxLines;
297
- final TextInputType? keyboardType;
298
 
299
- const CustomTextField({{
300
- super.key,
301
- required this.label,
302
- this.hint,
303
- this.controller,
304
- this.maxLines = 1,
305
- this.keyboardType,
306
- }});
307
 
308
- @override
309
- Widget build(BuildContext context) {{
310
- return TextField(
311
- controller: controller,
312
- maxLines: maxLines,
313
- keyboardType: keyboardType,
314
- decoration: InputDecoration(
315
- labelText: label,
316
- hintText: hint,
317
- border: OutlineInputBorder(
318
- borderRadius: BorderRadius.circular(8),
319
- ),
320
- filled: true,
321
- fillColor: Theme.of(context).colorScheme.surface,
322
- ),
323
- );
324
- }}
325
- }}
326
  """
327
 
 
 
328
 
329
  def generate_models_dart(description):
330
- """Generate the models.dart file content."""
331
- return f"""// Data Models for the Flutter Application
332
- // Description: {description}
333
- // Generated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
 
 
 
 
 
334
 
 
335
  /// Base item model
336
- /// Represents a generic item in the application
337
  class Item {{
338
  final String id;
339
  final String title;
340
  final String description;
341
  final DateTime createdAt;
342
- bool isCompleted;
343
 
344
- Item({{
345
  required this.id,
346
  required this.title,
347
  required this.description,
@@ -349,108 +334,101 @@ class Item {{
349
  this.isCompleted = false,
350
  }});
351
 
352
- /// Convert item to JSON
353
- Map<String, dynamic> toJson() {{
354
- return {{
355
- 'id': id,
356
- 'title': title,
357
- 'description': description,
358
- 'createdAt': createdAt.toIso8601String(),
359
- 'isCompleted': isCompleted,
360
- }};
361
- }}
 
 
 
 
 
362
 
363
- /// Create item from JSON
364
- factory Item.fromJson(Map<String, dynamic> json) {{
365
- return Item(
366
- id: json['id'] as String,
367
- title: json['title'] as String,
368
- description: json['description'] as String,
369
- createdAt: DateTime.parse(json['createdAt'] as String),
370
- isCompleted: json['isCompleted'] as bool? ?? false,
371
- );
372
- }}
373
-
374
- /// Create a copy with updated fields
375
  Item copyWith({{
376
  String? id,
377
  String? title,
378
  String? description,
379
  DateTime? createdAt,
380
  bool? isCompleted,
381
- }}) {{
382
- return Item(
383
- id: id ?? this.id,
384
- title: title ?? this.title,
385
- description: description ?? this.description,
386
- createdAt: createdAt ?? this.createdAt,
387
- isCompleted: isCompleted ?? this.isCompleted,
388
- );
389
- }}
390
  }}
391
 
392
  /// User model
393
- /// Represents a user in the application
394
  class User {{
395
  final String id;
396
  final String name;
397
  final String email;
398
- final String? avatarUrl;
399
 
400
  const User({{
401
  required this.id,
402
  required this.name,
403
  required this.email,
404
- this.avatarUrl,
405
  }});
406
 
407
- /// Convert user to JSON
408
- Map<String, dynamic> toJson() {{
409
- return {{
410
- 'id': id,
411
- 'name': name,
412
- 'email': email,
413
- 'avatarUrl': avatarUrl,
414
- }};
415
- }}
416
-
417
- /// Create user from JSON
418
- factory User.fromJson(Map<String, dynamic> json) {{
419
- return User(
420
- id: json['id'] as String,
421
- name: json['name'] as String,
422
- email: json['email'] as String,
423
- avatarUrl: json['avatarUrl'] as String?,
424
- );
425
- }}
426
  }}
427
- """
428
 
 
429
 
430
- def generate_services_dart(description):
431
- """Generate the services.dart file content."""
432
- return f"""// Business Logic and Services
433
  // Description: {description}
434
  // Generated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
 
435
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436
  import 'models.dart';
437
 
438
- /// Data service for managing items
439
- /// This service handles CRUD operations for items
440
- class ItemService {{
441
  final List<Item> _items = [];
442
 
443
  /// Get all items
444
- List<Item> getAllItems() {{
445
- return List.unmodifiable(_items);
446
- }}
447
 
448
- /// Add a new item
449
- void addItem(Item item) {{
450
- _items.add(item);
451
- }}
452
 
453
- /// Update an existing item
454
  bool updateItem(String id, Item updatedItem) {{
455
  final index = _items.indexWhere((item) => item.id == id);
456
  if (index != -1) {{
@@ -460,7 +438,7 @@ class ItemService {{
460
  return false;
461
  }}
462
 
463
- /// Delete an item
464
  bool deleteItem(String id) {{
465
  final index = _items.indexWhere((item) => item.id == id);
466
  if (index != -1) {{
@@ -470,8 +448,8 @@ class ItemService {{
470
  return false;
471
  }}
472
 
473
- /// Toggle item completion status
474
- bool toggleItemCompletion(String id) {{
475
  final index = _items.indexWhere((item) => item.id == id);
476
  if (index != -1) {{
477
  _items[index].isCompleted = !_items[index].isCompleted;
@@ -479,41 +457,36 @@ class ItemService {{
479
  }}
480
  return false;
481
  }}
482
-
483
- /// Get completed items
484
- List<Item> getCompletedItems() {{
485
- return _items.where((item) => item.isCompleted).toList();
486
- }}
487
-
488
- /// Get pending items
489
- List<Item> getPendingItems() {{
490
- return _items.where((item) => !item.isCompleted).toList();
491
- }}
492
  }}
493
 
494
- /// Validation service
495
- /// Provides validation utilities
496
  class ValidationService {{
497
- /// Validate email format
498
  static bool isValidEmail(String email) {{
499
- final emailRegex = RegExp(
500
- r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{{2,}}$',
501
- );
502
- return emailRegex.hasMatch(email);
503
  }}
504
 
505
- /// Validate string is not empty
506
  static bool isNotEmpty(String? value) {{
507
  return value != null && value.trim().isNotEmpty;
508
  }}
509
 
510
- /// Validate minimum length
511
  static bool hasMinLength(String value, int minLength) {{
512
  return value.length >= minLength;
513
  }}
514
  }}
 
 
 
 
 
 
 
 
 
 
515
  """
516
 
 
 
517
 
518
  def generate_pubspec(description):
519
  """Generate the pubspec.yaml file content."""
@@ -748,10 +721,11 @@ def create_interface():
748
  - **README.md** - Setup and usage instructions
749
 
750
  ### ⚠️ Important Notes:
751
- - This is a **placeholder implementation** for demonstration
752
- - In production, this would integrate with an AI model API (Claude, GPT, etc.)
753
  - Always review and test generated code before production use
754
- - Customize the code to match your specific requirements
 
755
 
756
  ### 🔧 Next Steps After Download:
757
  1. Extract the ZIP file
 
3
  import io
4
  import os
5
  from datetime import datetime
6
+ from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
7
+ import torch
8
+
9
+ # Global model variables
10
+ model = None
11
+ tokenizer = None
12
+
13
+ def load_model():
14
+ """Load the small AI model for code generation."""
15
+ global model, tokenizer
16
+ if model is None:
17
+ try:
18
+ # Use a very small model that can run on Hugging Face Spaces free tier
19
+ model_name = "distilgpt2"
20
+
21
+ print("Loading AI model...")
22
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
23
+ model = AutoModelForCausalLM.from_pretrained(model_name)
24
+
25
+ # Set padding token to EOS token for GPT-2
26
+ tokenizer.pad_token = tokenizer.eos_token
27
+
28
+ print("Model loaded successfully!")
29
+ except Exception as e:
30
+ print(f"Error loading model: {e}")
31
+ return False
32
+ return True
33
+
34
+ def generate_code_with_ai(prompt, max_length=500):
35
+ """Generate code using the AI model."""
36
+ if not load_model():
37
+ return "// Error: Could not load AI model\n// Using fallback template instead"
38
+
39
+ try:
40
+ # Create a more specific prompt for Flutter/Dart code
41
+ full_prompt = f"Write Flutter Dart code for: {prompt}\n\n"
42
+
43
+ inputs = tokenizer(full_prompt, return_tensors="pt", padding=True, truncation=True, max_length=100)
44
+
45
+ with torch.no_grad():
46
+ outputs = model.generate(
47
+ inputs["input_ids"],
48
+ attention_mask=inputs["attention_mask"],
49
+ max_length=max_length,
50
+ num_return_sequences=1,
51
+ temperature=0.7,
52
+ do_sample=True,
53
+ pad_token_id=tokenizer.eos_token_id,
54
+ eos_token_id=tokenizer.eos_token_id,
55
+ )
56
+
57
+ generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
58
+
59
+ # Extract the code part (remove the prompt)
60
+ code = generated_text[len(full_prompt):].strip()
61
+
62
+ # Basic cleanup - try to extract Dart-like code
63
+ if "```dart" in code:
64
+ code = code.split("```dart")[1].split("```")[0]
65
+ elif "```" in code:
66
+ code = code.split("```")[1].split("```")[0]
67
+
68
+ return code if code else "// AI-generated placeholder code"
69
+
70
+ except Exception as e:
71
+ print(f"Error generating code with AI: {e}")
72
+ return "// Error generating code\n// Using fallback template"
73
 
74
  def generate_flutter_code(description):
75
  """
 
156
 
157
 
158
  def generate_main_dart(description):
159
+ """Generate the main.dart file content using AI."""
160
+ prompt = f"""Create a Flutter main.dart file for an app described as: {description}
 
 
161
 
162
+ The main.dart should include:
163
+ - Material Design theme
164
+ - A basic home page
165
+ - Proper imports
166
+ - Clean, modern Flutter code structure
167
+
168
+ ```dart
169
  import 'package:flutter/material.dart';
 
170
 
171
  void main() {{
172
  runApp(const MyApp());
173
  }}
174
 
 
 
175
  class MyApp extends StatelessWidget {{
176
  const MyApp({{super.key}});
177
 
 
179
  Widget build(BuildContext context) {{
180
  return MaterialApp(
181
  title: 'Flutter App',
 
182
  theme: ThemeData(
183
+ primarySwatch: Colors.blue,
184
  useMaterial3: true,
 
 
 
 
185
  ),
186
  home: const HomePage(),
187
  );
188
  }}
189
  }}
190
 
 
 
191
  class HomePage extends StatefulWidget {{
192
  const HomePage({{super.key}});
193
 
 
196
  }}
197
 
198
  class _HomePageState extends State<HomePage> {{
 
 
 
 
 
 
 
 
199
  @override
200
  Widget build(BuildContext context) {{
201
  return Scaffold(
202
+ appBar: AppBar(title: const Text('Home')),
203
+ body: const Center(child: Text('Hello World')),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  );
205
  }}
206
  }}
207
+ ```"""
208
 
209
+ ai_generated_code = generate_code_with_ai(prompt, max_length=800)
210
 
211
+ # Add header comment
212
+ header = f"""// AI-Generated Flutter Application
 
213
  // Description: {description}
214
  // Generated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
215
+ // Note: This is AI-generated code - review and test before production use
216
+
217
+ """
218
+
219
+ return header + ai_generated_code
220
 
221
+
222
+ def generate_widgets_dart(description):
223
+ """Generate the widgets.dart file content using AI."""
224
+ prompt = f"""Create Flutter custom widgets for an app described as: {description}
225
+
226
+ Create at least 3 reusable widgets including:
227
+ - A custom card/info widget
228
+ - A custom button widget
229
+ - A custom input field widget
230
+ - Follow Material Design guidelines
231
+ - Include proper documentation
232
+
233
+ ```dart
234
  import 'package:flutter/material.dart';
235
 
236
  /// Custom info card widget
 
237
  class CustomInfoCard extends StatelessWidget {{
238
  final String title;
239
  final String description;
 
256
  child: Column(
257
  mainAxisSize: MainAxisSize.min,
258
  children: [
259
+ if (icon != null) Icon(icon, size: 48),
 
 
 
 
 
260
  if (icon != null) const SizedBox(height: 12),
261
+ Text(title, style: Theme.of(context).textTheme.headlineSmall),
 
 
 
 
 
 
262
  const SizedBox(height: 8),
263
+ Text(description, style: Theme.of(context).textTheme.bodyMedium),
 
 
 
 
264
  ],
265
  ),
266
  ),
 
268
  }}
269
  }}
270
 
271
+ /// Custom button with loading state
272
  class CustomButton extends StatelessWidget {{
273
  final String text;
274
  final VoidCallback? onPressed;
275
  final bool isLoading;
 
276
 
277
  const CustomButton({{
278
  super.key,
279
  required this.text,
280
  this.onPressed,
281
  this.isLoading = false,
 
282
  }});
283
 
284
  @override
285
  Widget build(BuildContext context) {{
286
  return ElevatedButton(
287
  onPressed: isLoading ? null : onPressed,
 
 
 
 
 
 
288
  child: isLoading
289
+ ? const CircularProgressIndicator()
290
+ : Text(text),
 
 
 
 
 
 
 
 
 
 
 
 
 
291
  );
292
  }}
293
  }}
294
+ ```"""
295
 
296
+ ai_generated_code = generate_code_with_ai(prompt, max_length=1000)
 
 
 
 
 
 
297
 
298
+ # Add header comment
299
+ header = f"""// Custom Widgets for the Flutter Application
300
+ // Description: {description}
301
+ // Generated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
302
+ // Note: This is AI-generated code - review and test before production use
 
 
 
303
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
  """
305
 
306
+ return header + ai_generated_code
307
+
308
 
309
  def generate_models_dart(description):
310
+ """Generate the models.dart file content using AI."""
311
+ prompt = f"""Create Flutter data models for an app described as: {description}
312
+
313
+ Create data models with:
314
+ - Proper Dart class structure
315
+ - JSON serialization methods (toJson/fromJson)
316
+ - CopyWith methods for immutability
317
+ - Proper type annotations
318
+ - At least 2-3 relevant models based on the app description
319
 
320
+ ```dart
321
  /// Base item model
 
322
  class Item {{
323
  final String id;
324
  final String title;
325
  final String description;
326
  final DateTime createdAt;
327
+ final bool isCompleted;
328
 
329
+ const Item({{
330
  required this.id,
331
  required this.title,
332
  required this.description,
 
334
  this.isCompleted = false,
335
  }});
336
 
337
+ Map<String, dynamic> toJson() => {{
338
+ 'id': id,
339
+ 'title': title,
340
+ 'description': description,
341
+ 'createdAt': createdAt.toIso8601String(),
342
+ 'isCompleted': isCompleted,
343
+ }};
344
+
345
+ factory Item.fromJson(Map<String, dynamic> json) => Item(
346
+ id: json['id'],
347
+ title: json['title'],
348
+ description: json['description'],
349
+ createdAt: DateTime.parse(json['createdAt']),
350
+ isCompleted: json['isCompleted'] ?? false,
351
+ );
352
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  Item copyWith({{
354
  String? id,
355
  String? title,
356
  String? description,
357
  DateTime? createdAt,
358
  bool? isCompleted,
359
+ }}) => Item(
360
+ id: id ?? this.id,
361
+ title: title ?? this.title,
362
+ description: description ?? this.description,
363
+ createdAt: createdAt ?? this.createdAt,
364
+ isCompleted: isCompleted ?? this.isCompleted,
365
+ );
 
 
366
  }}
367
 
368
  /// User model
 
369
  class User {{
370
  final String id;
371
  final String name;
372
  final String email;
 
373
 
374
  const User({{
375
  required this.id,
376
  required this.name,
377
  required this.email,
 
378
  }});
379
 
380
+ Map<String, dynamic> toJson() => {{
381
+ 'id': id,
382
+ 'name': name,
383
+ 'email': email,
384
+ }};
385
+
386
+ factory User.fromJson(Map<String, dynamic> json) => User(
387
+ id: json['id'],
388
+ name: json['name'],
389
+ email: json['email'],
390
+ );
 
 
 
 
 
 
 
 
391
  }}
392
+ ```"""
393
 
394
+ ai_generated_code = generate_code_with_ai(prompt, max_length=800)
395
 
396
+ # Add header comment
397
+ header = f"""// Data Models for the Flutter Application
 
398
  // Description: {description}
399
  // Generated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
400
+ // Note: This is AI-generated code - review and test before production use
401
 
402
+ """
403
+
404
+ return header + ai_generated_code
405
+
406
+
407
+ def generate_services_dart(description):
408
+ """Generate the services.dart file content using AI."""
409
+ prompt = f"""Create Flutter service classes for an app described as: {description}
410
+
411
+ Create service classes with:
412
+ - Business logic methods
413
+ - Data management operations (CRUD)
414
+ - Validation utilities
415
+ - Proper error handling
416
+ - Based on the app requirements from the description
417
+
418
+ ```dart
419
  import 'models.dart';
420
 
421
+ /// Data service for managing application data
422
+ class DataService {{
 
423
  final List<Item> _items = [];
424
 
425
  /// Get all items
426
+ List<Item> getAllItems() => List.unmodifiable(_items);
 
 
427
 
428
+ /// Add new item
429
+ void addItem(Item item) => _items.add(item);
 
 
430
 
431
+ /// Update existing item
432
  bool updateItem(String id, Item updatedItem) {{
433
  final index = _items.indexWhere((item) => item.id == id);
434
  if (index != -1) {{
 
438
  return false;
439
  }}
440
 
441
+ /// Delete item
442
  bool deleteItem(String id) {{
443
  final index = _items.indexWhere((item) => item.id == id);
444
  if (index != -1) {{
 
448
  return false;
449
  }}
450
 
451
+ /// Toggle completion status
452
+ bool toggleCompletion(String id) {{
453
  final index = _items.indexWhere((item) => item.id == id);
454
  if (index != -1) {{
455
  _items[index].isCompleted = !_items[index].isCompleted;
 
457
  }}
458
  return false;
459
  }}
 
 
 
 
 
 
 
 
 
 
460
  }}
461
 
462
+ /// Validation service with utility methods
 
463
  class ValidationService {{
 
464
  static bool isValidEmail(String email) {{
465
+ return RegExp(r'^[^@]+@[^@]+\\.[^@]+').hasMatch(email);
 
 
 
466
  }}
467
 
 
468
  static bool isNotEmpty(String? value) {{
469
  return value != null && value.trim().isNotEmpty;
470
  }}
471
 
 
472
  static bool hasMinLength(String value, int minLength) {{
473
  return value.length >= minLength;
474
  }}
475
  }}
476
+ ```"""
477
+
478
+ ai_generated_code = generate_code_with_ai(prompt, max_length=800)
479
+
480
+ # Add header comment
481
+ header = f"""// Business Logic and Services
482
+ // Description: {description}
483
+ // Generated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
484
+ // Note: This is AI-generated code - review and test before production use
485
+
486
  """
487
 
488
+ return header + ai_generated_code
489
+
490
 
491
  def generate_pubspec(description):
492
  """Generate the pubspec.yaml file content."""
 
721
  - **README.md** - Setup and usage instructions
722
 
723
  ### ⚠️ Important Notes:
724
+ - This uses a **small AI model** (DistilGPT-2) running directly on Hugging Face Spaces
725
+ - The AI generates Flutter/Dart code based on your description
726
  - Always review and test generated code before production use
727
+ - The model may produce varying quality results - iterate on your descriptions
728
+ - Customize the generated code to match your specific requirements
729
 
730
  ### 🔧 Next Steps After Download:
731
  1. Extract the ZIP file