Kodlarım aşağıda. Haber Detay sayfasına galeri tablosundan haberidleri eşit resimleri bir türlü çekemedim. Yardımcı olursanız sevinirim.
List<Welcome> welcomeFromJson(String str) =>
List<Welcome>.from(json.decode(str).map((x) => Welcome.fromJson(x)));
String welcomeToJson(List<Welcome> data) =>
json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
class Welcome {
Welcome({
this.galeriId,
this.haberId,
this.haberResimBaslik,
this.haberResim,
});
int galeriId;
int haberId;
String haberResimBaslik;
String haberResim;
factory Welcome.fromJson(Map<String, dynamic> json) => Welcome(
galeriId: json["GaleriId"],
haberId: json["HaberId"],
haberResimBaslik: json["HaberResimBaslik"],
haberResim: json["HaberResim"],
);
Map<String, dynamic> toJson() => {
"GaleriId": galeriId,
"HaberId": haberId,
"HaberResimBaslik": haberResimBaslik,
"HaberResim": haberResim,
};
}
class HaberDetay extends StatelessWidget {
@override
int haberid;
String haberbaslik;
String haberresim;
String haberdetay;
String habertarih;
HaberDetay(
{this.haberid,
this.haberbaslik,
this.haberdetay,
this.haberresim,
this.habertarih});
@override
Widget build(BuildContext context) {
Future<List<Welcome>> getProductList() async {
var productURl =
Uri.parse('https://api......./api/Category/GetAllHaberResim');
final response =
await http.get(productURl, headers: {'charset': 'utf-8'});
List jsonResponse = json.decode(utf8.decode(response.bodyBytes));
List profilList =
jsonResponse.map((job) => new Welcome.fromJson(job)).toList();
profilList.sort((a, b) => b.haberId.compareTo(a.haberId));
profilList.where((i) => i.haberId == haberid);
return profilList;
}
return Scaffold(
appBar: AppBar(
title: Text(haberbaslik),
backgroundColor: Color(0xffdf2d3c),
),
resizeToAvoidBottomInset: false,
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Image.network(
haberresim,
width: double.infinity,
fit: BoxFit.cover,
),
),
Padding(
padding: EdgeInsets.fromLTRB(10.0, 20.0, 0.0, 0.0),
child: Text(
haberbaslik,
textAlign: TextAlign.left,
style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 13,
color: Colors.black),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 5.0),
child: Html(data: haberdetay, style: {
'Html': Style(
textAlign: TextAlign.justify,
fontSize: FontSize(13),
)
}),
),
Padding(
padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 5.0),
child: FutureBuilder<List<Welcome>>(
future: getProductList(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Container(
child: CarouselSlider.builder(
itemBuilder: (context, index, realIdx) {
Welcome veri = snapshot.data[index];
return Container(
child: Center(
child: Image.network(veri.haberResim,
fit: BoxFit.cover, width: 800)),
);
},
itemCount: snapshot.data.length,
options: CarouselOptions(
autoPlay: true,
aspectRatio: 2.0,
enlargeCenterPage: true,
),
),
);
} else {
return Center(child: CircularProgressIndicator());
}
},
),
),
],
),
),
);
}
}