File tree Expand file tree Collapse file tree 3 files changed +24
-11
lines changed Expand file tree Collapse file tree 3 files changed +24
-11
lines changed Original file line number Diff line number Diff line change @@ -15,23 +15,32 @@ class Blogs extends StatefulWidget {
15
15
class _BlogsState extends State <Blogs > {
16
16
NetworkHandler networkHandler = NetworkHandler ();
17
17
SuperModel superModel = SuperModel ();
18
+ List <AddBlogModel > data = [];
18
19
19
20
@override
20
21
void initState () {
21
22
// TODO: implement initState
22
23
super .initState ();
24
+ fetchData ();
23
25
}
24
26
25
27
void fetchData () async {
26
28
var response = await networkHandler.get (widget.url);
27
29
superModel = SuperModel .fromJson (response);
30
+ setState (() {
31
+ data = superModel.data;
32
+ });
28
33
}
29
34
30
35
@override
31
36
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 (),
35
44
);
36
45
}
37
46
}
Original file line number Diff line number Diff line change 1
1
import 'dart:io' ;
2
2
3
+ import 'package:blogapp/Model/addBlogModels.dart' ;
4
+ import 'package:blogapp/NetworkHandler.dart' ;
3
5
import 'package:flutter/material.dart' ;
4
6
import 'package:image_picker/image_picker.dart' ;
5
7
6
8
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;
10
14
11
15
@override
12
16
Widget build (BuildContext context) {
@@ -21,9 +25,7 @@ class BlogCard extends StatelessWidget {
21
25
width: MediaQuery .of (context).size.width,
22
26
decoration: BoxDecoration (
23
27
image: DecorationImage (
24
- image: FileImage (
25
- File (imagefile.path),
26
- ),
28
+ image: networkHandler.getImage (addBlogModel.id),
27
29
fit: BoxFit .fitWidth),
28
30
),
29
31
),
@@ -36,7 +38,7 @@ class BlogCard extends StatelessWidget {
36
38
decoration: BoxDecoration (
37
39
color: Colors .white, borderRadius: BorderRadius .circular (8 )),
38
40
child: Text (
39
- title,
41
+ addBlogModel. title,
40
42
style: TextStyle (
41
43
fontWeight: FontWeight .bold,
42
44
fontSize: 15 ,
Original file line number Diff line number Diff line change @@ -66,7 +66,9 @@ class _MainProfileState extends State<MainProfile> {
66
66
SizedBox (
67
67
height: 20 ,
68
68
),
69
- Blogs (),
69
+ Blogs (
70
+ url: "/blogpost/getOwnBlog" ,
71
+ ),
70
72
],
71
73
),
72
74
);
You can’t perform that action at this time.
0 commit comments