forked from eatvio/eatvio_app
feat(feed): Dio, retrofit and freezed model stump
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/locator_service.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'dart:convert';
|
||||
import '/core/app_export.dart';
|
||||
@@ -39,7 +39,7 @@ class BlogPostCreateBloc
|
||||
blog_postModelObj: currentState.blog_postModelObj,
|
||||
title: currentState.title,
|
||||
description: currentState.description,
|
||||
youtube_url: currentState.youtube_url,
|
||||
youtubeURL: currentState.youtubeURL,
|
||||
token: currentState.token,
|
||||
),
|
||||
);
|
||||
@@ -49,7 +49,7 @@ class BlogPostCreateBloc
|
||||
token: token,
|
||||
title: TextEditingController(),
|
||||
description: TextEditingController(),
|
||||
youtube_url: TextEditingController(),
|
||||
youtubeURL: TextEditingController(),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -64,8 +64,9 @@ class BlogPostCreateBloc
|
||||
|
||||
var response = await sendBlogPost(
|
||||
currentState.title?.text,
|
||||
currentState.youtube_url?.text,
|
||||
currentState.youtubeURL?.text,
|
||||
currentState.description?.text,
|
||||
currentState.image,
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
@@ -78,34 +79,35 @@ class BlogPostCreateBloc
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<http.Response> sendBlogPost(
|
||||
String? title,
|
||||
String? youtube_url,
|
||||
String? description,
|
||||
) async {
|
||||
String url = '${dotenv.env['SERVER_ROOT']!}/feed/create';
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
sendBlogPost(String? title, String? youtubeURL, String? description,
|
||||
XFile? image) async {
|
||||
String url = '/blog_post/create';
|
||||
|
||||
final Map<String, dynamic> credentials = {
|
||||
'title': title,
|
||||
'description': description,
|
||||
'youtube_url': youtube_url,
|
||||
'youtube_url': youtubeURL,
|
||||
'status': 'active',
|
||||
'image': image,
|
||||
};
|
||||
|
||||
var response = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
body: json.encode(credentials),
|
||||
encoding: utf8,
|
||||
var response = await sl<Dio>().post(
|
||||
url,
|
||||
data: json.encode(credentials),
|
||||
);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
FutureOr<void> _uploadImages(
|
||||
UploadImages event, Emitter<BlogPostCreateState> emit) {}
|
||||
UploadImages event, Emitter<BlogPostCreateState> emit) {
|
||||
if (state is BlogPostCreateLoadedState) {
|
||||
var currentState = state as BlogPostCreateLoadedState;
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
image: event.image,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,33 +27,37 @@ class BlogPostCreateLoadedState extends BlogPostCreateState {
|
||||
this.blog_postModelObj,
|
||||
this.title,
|
||||
this.description,
|
||||
this.youtube_url,
|
||||
this.youtubeURL,
|
||||
this.image,
|
||||
this.isLoading = false,
|
||||
});
|
||||
|
||||
BlogPostCreateModel? blog_postModelObj;
|
||||
TextEditingController? title;
|
||||
TextEditingController? description;
|
||||
TextEditingController? youtube_url;
|
||||
TextEditingController? youtubeURL;
|
||||
String? token;
|
||||
bool isLoading;
|
||||
XFile? image;
|
||||
@override
|
||||
List<Object?> get props =>
|
||||
[blog_postModelObj, title, description, youtube_url];
|
||||
[blog_postModelObj, title, description, youtubeURL];
|
||||
BlogPostCreateLoadedState copyWith({
|
||||
BlogPostCreateModel? blog_postModelObj,
|
||||
TextEditingController? title,
|
||||
TextEditingController? description,
|
||||
TextEditingController? youtube_url,
|
||||
TextEditingController? youtubeURL,
|
||||
String? token,
|
||||
XFile? image,
|
||||
bool isLoading = false,
|
||||
}) {
|
||||
return BlogPostCreateLoadedState(
|
||||
blog_postModelObj: blog_postModelObj ?? this.blog_postModelObj,
|
||||
title: title ?? this.title,
|
||||
description: description ?? this.description,
|
||||
youtube_url: youtube_url ?? this.youtube_url,
|
||||
youtubeURL: youtubeURL ?? this.youtubeURL,
|
||||
token: token ?? this.token,
|
||||
image: image ?? this.image,
|
||||
isLoading: this.isLoading,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user