selamlar. bir uygulama yapmak istiyorum tüm platformlarda tek seferde yayınlanabilirse daha iyi olacağını düşündüğümden Flutter ya da React Native'i tercih ederim
OpenAI dan API çekilerek üretilecek basit bir uygulama olacak. istediğimiz kısa bilgileri girince otomatik olarak istediğim chatgpt yorumunu yapacak. hepsi bu. 4-5 adet kısa bilgi var girilecek. sonrasında butona basınca yorum yapacak. başka bir şeyi yok uygulamanın.
LÜtfen sadce pM
API eklentilerin lisanslı olarak var ise buyur..
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(OpenAICommentApp());
}
class OpenAICommentApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'OpenAI Comment Generator',
theme: ThemeData(
brightness: Brightness.light,
primarySwatch: Colors.indigo,
textTheme: GoogleFonts.poppinsTextTheme(
Theme.of(context).textTheme,
),
scaffoldBackgroundColor: Colors.white,
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
padding: EdgeInsets.symmetric(vertical: 14, horizontal: 24),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
textStyle: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
),
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: Colors.grey[100],
contentPadding: EdgeInsets.symmetric(vertical: 14, horizontal: 16),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
floatingLabelBehavior: FloatingLabelBehavior.auto,
),
),
home: CommentFormPage(),
);
}
}
class CommentFormPage extends StatefulWidget {
@override
_CommentFormPageState createState() => _CommentFormPageState();
}
class _CommentFormPageState extends State<CommentFormPage> {
final _formKey = GlobalKey<FormState>();
final TextEditingController _info1Controller = TextEditingController();
final TextEditingController _info2Controller = TextEditingController();
final TextEditingController _info3Controller = TextEditingController();
final TextEditingController _info4Controller = TextEditingController();
final TextEditingController _info5Controller = TextEditingController();
String? _responseText;
bool _isLoading = false;
String? _errorText;
// TODO: Replace with your actual OpenAI API key
static const String openaiApiKey = 'YOUR_OPENAI_API_KEY_HERE';
Future<void> _generateComment() async {
if (!_formKey.currentState!.validate()) return;
setState(() {
_isLoading = true;
_responseText = null;
_errorText = null;
});
final prompt = '''
Arka plandaki bilgiler:
1. ${_info1Controller.text.trim()}
2. ${_info2Controller.text.trim()}
3. ${_info3Controller.text.trim()}
4. ${_info4Controller.text.trim()}
5. ${_info5Controller.text.trim()}
Bu bilgilere dayanarak kısa ve açıklayıcı bir yorum yapınız.
''';
try {
final response = await http.post(
Uri.parse('https://api.openai.com/v1/chat/completions'),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $openaiApiKey',
},
body: jsonEncode({
"model": "gpt-3.5-turbo",
"messages": [
{"role": "system", "content": "Sen akıllı ve bilgilendirici bir yorumcusun."},
{"role": "user", "content": prompt}
],
"max_tokens": 150,
"temperature": 0.7,
"n": 1,
"stop": null
}),
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
final generatedText = data['choices'][0]['message']['content'];
setState(() {
_responseText = generatedText.trim();
});
} else {
setState(() {
_errorText = 'API hatası: ${response.statusCode}';
});
}
} catch (e) {
setState(() {
_errorText = 'Bir hata oluştu: $e';
});
} finally {
setState(() {
_isLoading = false;
});
}
}
@override
void dispose() {
_info1Controller.dispose();
_info2Controller.dispose();
_info3Controller.dispose();
_info4Controller.dispose();
_info5Controller.dispose();
super.dispose();
}
Widget _buildTextField(TextEditingController controller, String label) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: TextFormField(
controller: controller,
decoration: InputDecoration(
labelText: label,
),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Lütfen bu alanı doldurun';
}
return null;
},
),
);
}
@override
Widget build(BuildContext context) {
final spacing = SizedBox(height: 24);
return Scaffold(
appBar: AppBar(
title: Text('OpenAI Yorum Oluşturucu'),
centerTitle: true,
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(bottom: Radius.circular(12)),
),
),
body: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 32),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'Bilgileri Girin',
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.w700,
color: Colors.indigo[900],
),
textAlign: TextAlign.center,
),
spacing,
_buildTextField(_info1Controller, 'Bilgi 1'),
_buildTextField(_info2Controller, 'Bilgi 2'),
_buildTextField(_info3Controller, 'Bilgi 3'),
_buildTextField(_info4Controller, 'Bilgi 4'),
_buildTextField(_info5Controller, 'Bilgi 5'),
SizedBox(height: 32),
ElevatedButton(
onPressed: _isLoading ? null : _generateComment,
child: _isLoading
? SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 3,
color: Colors.white,
),
)
: Text('Yorum Oluştur'),
),
spacing,
if (_responseText != null)
Container(
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.indigo.shade50,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: Colors.indigo.shade100,
blurRadius: 8,
offset: Offset(0, 4),
),
],
),
child: Text(
_responseText!,
style: TextStyle(
fontSize: 16,
color: Colors.indigo[900],
height: 1.4,
),
),
),
if (_errorText != null) ...[
SizedBox(height: 16),
Text(
_errorText!,
style: TextStyle(color: Colors.red[700], fontWeight: FontWeight.w600),
textAlign: TextAlign.center,
),
],
],
),
),
),
);
}
}