Untitled
unknown
plain_text
a month ago
3.6 kB
2
Indexable
Never
import 'package:flutter/material.dart'; import 'package:curved_navigation_bar/curved_navigation_bar.dart'; import 'package:generator/screens/mainscreen/display_image_screen.dart'; import 'package:generator/screens/settingsscreen/settings.dart'; import 'package:get/get.dart'; import 'package:generator/api/api_service.dart'; import 'package:generator/screens/mainscreen/custom_model_loader.dart'; import 'package:generator/screens/mainscreen/text_field_controller.dart'; class HomePage extends StatefulWidget { HomePage({Key? key}) : super(key: key); @override State<HomePage> createState() => _HomePageState(); } class _HomePageState extends State<HomePage> { final textFieldController = Get.put(TextFieldController()); late bool loading; late String _textButton; late String imageId; int _currentIndex = 1; final List<String> sizes = [ "768 x 768", "1024 x 768", "1280 x 720", ]; late String selectedStyle; String selectedSize = "768 x 768"; @override void initState() { loading = false; selectedStyle = 'Leonardo Lightning XL'; imageId = 'b24e16ff-06e3-43eb-8d33-4416c2d75876'; _textButton = 'Generate'; super.initState(); } void generateButtonPressed() { setState(() { loading = true; if (loading) { _textButton = 'Generating'; } }); final prompt = textFieldController.textEditingController.value.text; ApiService.makeRequest(prompt, selectedStyle, imageId, selectedSize) .then((imageUrl) { setState(() { loading = false; _textButton = 'Generate'; Navigator.push( context, MaterialPageRoute( builder: (context) => DisplayImageScreen( imageUrl: imageUrl, prompt: prompt, selectedStyle: selectedStyle, imageId: imageId, selectedSize: selectedSize, ), ), ); }); }).catchError((error) { setState(() { loading = false; _textButton = 'Generate'; }); print(error); }); } void onTabTapped(int index) { setState(() { _currentIndex = index; }); } final List<Widget> _children = [ HomeScreen(), VipSubcribe(), ]; @override Widget build(BuildContext context) { return Scaffold( body: Container( width: double.infinity, height: double.infinity, decoration: const BoxDecoration( gradient: LinearGradient( colors: [ Color(0xFF3D335C), Color(0xFF201838), ], begin: Alignment.topCenter, end: Alignment.bottomCenter, ), ), child: CustomModelLoader( textFieldController: textFieldController, sizes: sizes, selectedSize: selectedSize, onSizeSelected: (size) { setState(() { selectedSize = size; }); }, selectedStyle: selectedStyle, onStyleSelected: (style) { setState(() { selectedStyle = style; print('Selected style: $selectedStyle'); }); }, onStyleSelectedid: (id) { setState(() { imageId = id; print('Selected $imageId'); }); }, loading: loading, textButton: _textButton, onGeneratePressed: generateButtonPressed, imageId: imageId, customModels: const [], // Pass imageId to CustomModelLoader ), ), ); } }
Leave a Comment