Untitled
unknown
plain_text
a year ago
7.3 kB
3
Indexable
Never
// ignore_for_file: avoid_unnecessary_containers, prefer_const_constructors, non_constant_identifier_names, camel_case_types import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', debugShowCheckedModeBanner: false, theme: ThemeData.dark(), home: const HomePage(), ); } } class HomePage extends StatefulWidget { const HomePage({super.key}); @override State<HomePage> createState() => _HomePageState(); } class _HomePageState extends State<HomePage> { List items = []; TextEditingController adcontroller = TextEditingController(); TextEditingController soyadcontroller = TextEditingController(); TextEditingController yascontroller = TextEditingController(); bool isLoading = false; void fetchData() async { setState(() { isLoading = true; // İstek atıldığında isLoading'i true yaparak döngü çizgisini göster }); String ad = adcontroller.text; String soyad = soyadcontroller.text; String yas = yascontroller.text; var url = 'http://5.180.81.117/?ad=$ad&soyad=$soyad&yas=$yas'; var response = await http.get(Uri.parse(url)); if (response.statusCode == 200) { // Başarılı istek durumunda verileri al var data = jsonDecode(response.body); items.clear(); items.add(data); // alınan verileri kullanarak işlemleri gerçekleştir print("Ad: $data"); setState(() { isLoading = false; // İstek tamamlandığında isLoading'i false yaparak döngü çizgisini gizle }); } else { // Hata durumunda hata mesajını göster print('Hata: ${response.statusCode}'); } } @override Widget build(BuildContext context) { return Scaffold( body: SafeArea( child: Padding( padding: EdgeInsets.all(16.0), child: Column( children: [ TextFormField( controller: adcontroller, decoration: InputDecoration( labelText: 'Ad', labelStyle: TextStyle(color: Colors.grey), focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.blue, width: 2.0), ), enabledBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.grey, width: 1.0), ), errorBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.red, width: 1.0), ), focusedErrorBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.red, width: 2.0), ), suffixIcon: Icon(Icons.person), ), ), SizedBox(height: 16.0), TextFormField( controller: soyadcontroller, decoration: InputDecoration( labelText: 'Soyad', labelStyle: TextStyle(color: Colors.grey), focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.blue, width: 2.0), ), enabledBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.grey, width: 1.0), ), errorBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.red, width: 1.0), ), focusedErrorBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.red, width: 2.0), ), suffixIcon: Icon(Icons.person), ), ), SizedBox(height: 16.0), TextFormField( controller: yascontroller, decoration: InputDecoration( labelText: 'Yaş', labelStyle: TextStyle(color: Colors.grey), focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.blue, width: 2.0), ), enabledBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.grey, width: 1.0), ), errorBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.red, width: 1.0), ), focusedErrorBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.red, width: 2.0), ), suffixIcon: Icon(Icons.email), ), ), SizedBox(height: 16.0), ElevatedButton( onPressed: () { fetchData(); }, child: Text('Sorgula'), ), isLoading ? CircularProgressIndicator() // isLoading true ise döngü çizgisini göster : Expanded( child: ListView.builder( itemCount: items.length, itemBuilder: (BuildContext context, index) { return Card( child: ListTile( title: Text("${items[index][2]}"), onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => DetailPage( data: items[index], ))); }, ), ); })) ], ), ), ), ); } } class DetailPage extends StatelessWidget { final Map data; const DetailPage({super.key, required this.data}); @override Widget build(BuildContext context) { return Scaffold( body: SafeArea( child: Column( children: [ Card( child: ListTile( title: Text(data["ad"]), onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => DetailPage( data: data, ))); }, ), ), ElevatedButton( onPressed: () { Navigator.pop(context); }, child: Text('Geri Dön')), ], )), ); } }