Skip to content

Commit 6141060

Browse files
committed
modified blog
1 parent 41d3aca commit 6141060

File tree

10 files changed

+291
-165
lines changed

10 files changed

+291
-165
lines changed

lib/controllers/app_controller.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import '/exports/exports.dart';
33
class AppController with ChangeNotifier {
44
// SharedPreferences _prefs = SharedPreferences.getInstance();
55
// AppController() {}
6-
bool _isDarkMode = false;
6+
bool _isDarkMode = true;
77
bool get isDarkMode => _isDarkMode;
88
set isDarkMode(bool mode) {
99
_isDarkMode = mode;
@@ -14,7 +14,6 @@ class AppController with ChangeNotifier {
1414
Map<String, dynamic> _homeTeamData = {};
1515
Map<String, dynamic> get homeTeamData => _homeTeamData;
1616
set homeTeamData(Map<String, dynamic> data) {
17-
print("Home Data: $data");
1817
_homeTeamData = data;
1918
notifyListeners();
2019
}
@@ -24,7 +23,6 @@ class AppController with ChangeNotifier {
2423
Map<String, dynamic> get awayTeamData => _awayTeamData;
2524
set awayTeamData(Map<String, dynamic> data) {
2625
_awayTeamData = data;
27-
print("Away Data: $data");
2826
notifyListeners();
2927
}
3028

@@ -33,7 +31,6 @@ class AppController with ChangeNotifier {
3331
Map<String, dynamic> get matchDateId => _matchDateId;
3432
set matchDateId(Map<String, dynamic> id) {
3533
_matchDateId = id;
36-
print("MatchDate : $id");
3734
notifyListeners();
3835
}
3936
}

lib/models/blogs_model.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import 'dart:convert';
32

43
List<BlogsModel> blogsModelFromJson(String str) =>
@@ -11,6 +10,7 @@ class BlogsModel {
1110
final String id;
1211
final String league;
1312
final String title;
13+
final String summary;
1414
final String content;
1515
final String image;
1616
final DateTime createdAt;
@@ -21,6 +21,7 @@ class BlogsModel {
2121
required this.id,
2222
required this.league,
2323
required this.title,
24+
required this.summary,
2425
required this.content,
2526
required this.image,
2627
required this.createdAt,
@@ -32,6 +33,7 @@ class BlogsModel {
3233
id: json["_id"],
3334
league: json["league"],
3435
title: json["title"],
36+
summary: json["summary"],
3537
content: json["content"],
3638
image: json["image"],
3739
createdAt: DateTime.parse(json["createdAt"]),
@@ -43,6 +45,7 @@ class BlogsModel {
4345
"_id": id,
4446
"league": league,
4547
"title": title,
48+
"summary": summary,
4649
"content": content,
4750
"image": image,
4851
"createdAt": createdAt.toIso8601String(),

lib/services/blog_service.dart

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class BlogService {
2424
var request = MultipartRequest('POST', Uri.parse(Apis.addBlog));
2525
request.fields['title'] = data['title'];
2626
request.fields['content'] = data['content'];
27+
request.fields['summary'] = data['summary'];
2728
request.fields['league'] = data['league'];
2829
request.fields['action'] = "Blogs";
2930
// handle file upload
@@ -41,6 +42,7 @@ class BlogService {
4142
msg: result['message'],
4243
color: Colors.green[900],
4344
);
45+
Routes.popPage();
4446
} else {
4547
context.read<LoaderController>().isLoading = false;
4648
showMessage(msg: response.reasonPhrase ?? "Error adding a blog");
@@ -57,6 +59,7 @@ class BlogService {
5759
showLoader(text: "Deleting blog");
5860
var response = await Client().delete(Uri.parse("${Apis.deleteBlog}/$id"));
5961
if (response.statusCode == 200) {
62+
Routes.popPage();
6063
Routes.popPage();
6164
var result = json.decode(response.body);
6265
showMessage(
@@ -79,17 +82,27 @@ class BlogService {
7982
context.read<LoaderController>().isLoading = true;
8083
var request = MultipartRequest(
8184
'PUT', Uri.parse("${Apis.updateBlog}/${data['id']}"));
85+
86+
request.headers.addAll({
87+
'Content-Type': 'multipart/form-data',
88+
'Accept': 'application/json',
89+
});
8290
request.fields['title'] = data['title'];
8391
request.fields['content'] = data['content'];
92+
request.fields['summary'] = data['summary'];
8493
request.fields['league'] = data['league'];
8594
request.fields['action'] = "Blogs";
8695
// handle file upload
87-
request.files.add(
88-
await MultipartFile.fromPath(
89-
'blog',
90-
data['image'],
91-
),
92-
);
96+
if (data['stream'] != null) {
97+
request.files.add(
98+
MultipartFile(
99+
"blog",
100+
data["stream"],
101+
data["length"],
102+
filename: data["filename"],
103+
),
104+
);
105+
}
93106
StreamedResponse response = await request.send();
94107
if (response.statusCode == 200) {
95108
context.read<LoaderController>().isLoading = false;
@@ -101,12 +114,11 @@ class BlogService {
101114
);
102115
} else {
103116
context.read<LoaderController>().isLoading = false;
104-
Routes.popPage();
105-
showMessage(msg: response.reasonPhrase ?? "Error updating a blog");
117+
var result = json.decode(await response.stream.bytesToString());
118+
showMessage(msg: result['message']);
106119
}
107120
} on Exception catch (e, _) {
108121
context.read<LoaderController>().isLoading = false;
109-
Routes.popPage();
110122
debugPrint("Error $_");
111123
}
112124
}

lib/views/pages/blogs/add_blog.dart

Lines changed: 79 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class AddBlog extends StatefulWidget {
1313

1414
class _AddBlogState extends State<AddBlog> {
1515
final titleController = TextEditingController();
16+
final summaryController = TextEditingController();
1617
final contentController = TextEditingController();
1718
String? image;
1819
@override
@@ -25,59 +26,101 @@ class _AddBlogState extends State<AddBlog> {
2526
return ListView(
2627
padding: const EdgeInsets.fromLTRB(15, 10, 15, 10),
2728
children: [
28-
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
29-
CircleAvatar(
30-
backgroundImage: image == null
31-
? const AssetImage("assets/images/logo.jpeg")
32-
as ImageProvider<Object>
33-
: FileImage(
34-
File(image!),
35-
),
36-
radius: 70,
29+
TapEffect(
30+
onClick: () async {
31+
final pickedFile =
32+
await ImagePicker.platform.getImageFromSource(
33+
source: ImageSource.gallery,
34+
);
35+
if (pickedFile != null) {
36+
setState(() {
37+
image = pickedFile.path;
38+
});
39+
}
40+
},
41+
child: Card(
42+
shape: RoundedRectangleBorder(
43+
borderRadius: BorderRadius.circular(10),
44+
side: BorderSide(
45+
color: Colors.grey.shade400,
46+
),
47+
),
48+
child: SizedBox.square(
49+
dimension: MediaQuery.of(context).size.width / 2.3,
50+
child: image != null
51+
? Image.file(
52+
File(image!),
53+
fit: BoxFit.cover,
54+
)
55+
: Row(
56+
mainAxisAlignment: MainAxisAlignment.center,
57+
children: [
58+
const Icon(Icons.add),
59+
const SizedBox.square(dimension: 10),
60+
Text(
61+
"Add a banner",
62+
style: Theme.of(context).textTheme.bodyLarge,
63+
),
64+
],
65+
),
66+
),
3767
),
38-
IconButton(
39-
iconSize: 40,
40-
icon: const Icon(
41-
Icons.add_a_photo_rounded,
68+
),
69+
const SizedBox.square(dimension: 10),
70+
TextFormField(
71+
maxLines: 1,
72+
controller: titleController,
73+
readOnly: controller.isLoading,
74+
decoration: InputDecoration(
75+
labelText: "Blog title",
76+
labelStyle: Theme.of(context).textTheme.bodyMedium,
77+
hintText: "Enter blog title",
78+
border: OutlineInputBorder(
79+
borderRadius: BorderRadius.circular(10),
80+
borderSide: BorderSide(
81+
color: Colors.grey.shade200,
82+
),
4283
),
43-
onPressed: () async {
44-
final pickedFile =
45-
await ImagePicker.platform.getImageFromSource(
46-
source: ImageSource.gallery,
47-
);
48-
if (pickedFile != null) {
49-
setState(() {
50-
image = pickedFile.path;
51-
});
52-
}
53-
},
5484
),
55-
]),
56-
CommonTextField(
57-
titleText: "Title",
58-
enableBorder: true,
59-
hintText: "Enter title",
85+
),
86+
const SizedBox.square(dimension: 10),
87+
TextFormField(
88+
maxLines: 3,
89+
controller: summaryController,
6090
readOnly: controller.isLoading,
61-
controller: titleController,
91+
decoration: InputDecoration(
92+
labelText: "Blog summary",
93+
labelStyle: Theme.of(context).textTheme.bodyMedium,
94+
hintText: "Enter blog summary",
95+
border: OutlineInputBorder(
96+
borderRadius: BorderRadius.circular(10),
97+
borderSide: BorderSide(
98+
color: Colors.grey.shade200,
99+
),
100+
),
101+
),
62102
),
63-
const SizedBox.square(dimension: 20),
103+
const SizedBox.square(dimension: 10),
64104
TextFormField(
65-
maxLines: 15,
105+
maxLines: 9,
66106
controller: contentController,
67107
readOnly: controller.isLoading,
68108
decoration: InputDecoration(
69-
// helperText: "Description",
109+
labelText: "Description",
110+
labelStyle: Theme.of(context).textTheme.bodyMedium,
70111
hintText: "Enter description",
71112
border: OutlineInputBorder(
113+
borderRadius: BorderRadius.circular(10),
72114
borderSide: BorderSide(
73115
color: Colors.grey.shade200,
74116
),
75117
),
76118
),
77119
),
78-
const SizedBox.square(dimension: 20),
120+
const SizedBox.square(dimension: 10),
79121
CustomButton(
80-
text: "Add Blog Post",
122+
text: "Publish",
123+
buttonRadius: 10,
81124
loading: controller.isLoading,
82125
buttonColor: controller.isLoading
83126
? null
@@ -105,6 +148,7 @@ class _AddBlogState extends State<AddBlog> {
105148
BlogService.createBlog({
106149
"title": titleController.text,
107150
"content": contentController.text,
151+
"summary": summaryController.text,
108152
"league": widget.league,
109153
"image": image,
110154
});

0 commit comments

Comments
 (0)