Skip to content

Commit fb5e70e

Browse files
committed
Own Blog fetched and showed
1 parent 897cd99 commit fb5e70e

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

lib/Blog/Blogs.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,32 @@ class Blogs extends StatefulWidget {
1515
class _BlogsState extends State<Blogs> {
1616
NetworkHandler networkHandler = NetworkHandler();
1717
SuperModel superModel = SuperModel();
18+
List<AddBlogModel> data = [];
1819

1920
@override
2021
void initState() {
2122
// TODO: implement initState
2223
super.initState();
24+
fetchData();
2325
}
2426

2527
void fetchData() async {
2628
var response = await networkHandler.get(widget.url);
2729
superModel = SuperModel.fromJson(response);
30+
setState(() {
31+
data = superModel.data;
32+
});
2833
}
2934

3035
@override
3136
Widget build(BuildContext context) {
32-
return ListView.builder(
33-
itemBuilder: (BuildContext context, int index) => BlogCard(),
34-
itemCount: superModel.data.length,
37+
return Column(
38+
children: data
39+
.map((item) => BlogCard(
40+
addBlogModel: item,
41+
networkHandler: networkHandler,
42+
))
43+
.toList(),
3544
);
3645
}
3746
}

lib/CustumWidget/BlogCard.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import 'dart:io';
22

3+
import 'package:blogapp/Model/addBlogModels.dart';
4+
import 'package:blogapp/NetworkHandler.dart';
35
import 'package:flutter/material.dart';
46
import 'package:image_picker/image_picker.dart';
57

68
class BlogCard extends StatelessWidget {
7-
const BlogCard({
8-
Key key,
9-
}) : super(key: key);
9+
const BlogCard({Key key, this.addBlogModel, this.networkHandler})
10+
: super(key: key);
11+
12+
final AddBlogModel addBlogModel;
13+
final NetworkHandler networkHandler;
1014

1115
@override
1216
Widget build(BuildContext context) {
@@ -21,9 +25,7 @@ class BlogCard extends StatelessWidget {
2125
width: MediaQuery.of(context).size.width,
2226
decoration: BoxDecoration(
2327
image: DecorationImage(
24-
image: FileImage(
25-
File(imagefile.path),
26-
),
28+
image: networkHandler.getImage(addBlogModel.id),
2729
fit: BoxFit.fitWidth),
2830
),
2931
),
@@ -36,7 +38,7 @@ class BlogCard extends StatelessWidget {
3638
decoration: BoxDecoration(
3739
color: Colors.white, borderRadius: BorderRadius.circular(8)),
3840
child: Text(
39-
title,
41+
addBlogModel.title,
4042
style: TextStyle(
4143
fontWeight: FontWeight.bold,
4244
fontSize: 15,

lib/Profile/MainProfile.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ class _MainProfileState extends State<MainProfile> {
6666
SizedBox(
6767
height: 20,
6868
),
69-
Blogs(),
69+
Blogs(
70+
url: "/blogpost/getOwnBlog",
71+
),
7072
],
7173
),
7274
);

0 commit comments

Comments
 (0)