Anasayfa kodum bu
import 'dart:convert';
import 'package:BestOtomasyon/json/DetailPage.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
Future<List<Photo>> fetchPhotos(http.Client client) async {
final response =
await client.get(Uri.parse('https://api.npoint.io/f22fe0c4d9648253f79b'));
return compute(parsePhotos, response.body);
}
List<Photo> parsePhotos(String responseBody) {
final parsed = jsonDecode(responseBody).cast<Map<String, dynamic>>();
return parsed.map<Photo>((json) => Photo.fromJson(json)).toList();
}
class Photo {
final String title;
final String photo;
final String date;
final String content;
const Photo({
required this.title,
required this.photo,
required this.date,
required this.content,
});
factory Photo.fromJson(Map<String, dynamic> json) {
return Photo(
title: json['title'] as String,
photo: json['photo'] as String,
date: json['date'] as String,
content: json['content'] as String,
);
}
}
class Anasayfa extends StatefulWidget {
const Anasayfa({Key? key}) : super(key: key);
@override
_AnasayfaState createState() => _AnasayfaState();
}
class _AnasayfaState extends State<Anasayfa> {
int _selectedIndex = 0;
final secili = [
Center(child:
null),
Center(
child: FutureBuilder<List<Photo>>(
future: fetchPhotos(http.Client()),
builder: (context, snapshot) {
if (snapshot.hasError) {
return const Center(
child: Text('Beklenmeyen bir hata oluştu.'),
);
} else if (snapshot.hasData) {
return PhotosList(photos: snapshot.data!);
} else {
return const Center(
child: CircularProgressIndicator(
strokeWidth: 10,
backgroundColor: Colors.green,
),
);
}
},
),
),
ListView(
children: [
Center(
child: Text(
"DENEME",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 25,
fontStyle: FontStyle.italic,
height: 1.5,
),
),
),
Text(
"TEST DENEME",
style: TextStyle(height: 2),textAlign: TextAlign.justify,
)
],
)
];
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text("HOŞGELDİNİZ"),
backgroundColor: Colors.grey,
),
body: secili[_selectedIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedIndex,
type: BottomNavigationBarType.fixed,
fixedColor: Colors.yellowAccent,
backgroundColor: Colors.blue[200],
items: [
BottomNavigationBarItem(
tooltip: 'Giriş',
icon: Icon(Icons.home),
label: 'Giriş',
backgroundColor: Colors.orange),
BottomNavigationBarItem(
tooltip: 'TEST',
icon: Icon(Icons.account_balance),
label: 'TEST',
backgroundColor: Colors.grey),
BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'Hakkımızda',
backgroundColor: Colors.teal,
)
],
onTap: (index) {
setState(() {
_selectedIndex = index;
});
},
),
));
}
}
class PhotosList extends StatelessWidget {
const PhotosList({Key? key, required this.photos}) : super(key: key);
final List<Photo> photos;
@override
Widget build(BuildContext context) {
return GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount:
MediaQuery.of(context).orientation == Orientation.landscape
? 1
: 1),
itemCount: photos.length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailPage(
data: photos[index],
)));
},
child: Card(
semanticContainer: true,
child: Stack(
fit: StackFit.expand,
children: [
Image.network(
photos[index].photo,
fit: BoxFit.cover,
),
Positioned(
left: 10,
top: 10,
child: Text(
photos[index].title,
style: TextStyle(
fontSize: 35,
fontWeight: FontWeight.bold,
color: Colors.white,
shadows: [
Shadow(
blurRadius: 10.0,
color: Colors.black,
offset: Offset(5.0, 5.0),
),
]),
))
],
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
elevation: 5,
margin: EdgeInsets.all(10),
));
});
}
}