Initial commit: Penyerahan final Source code Tugas Akhir
This commit is contained in:
0
lib/providers/.gitkeep
Normal file
0
lib/providers/.gitkeep
Normal file
98
lib/providers/announcement_provider.dart
Normal file
98
lib/providers/announcement_provider.dart
Normal file
@ -0,0 +1,98 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:initial_folder/models/announcement_model.dart';
|
||||
import 'package:initial_folder/services/announcement_service.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
enum ResultState { loading, noData, hasData, error }
|
||||
|
||||
enum ResultStateLike { loading, error }
|
||||
|
||||
class AnnouncementProvider with ChangeNotifier {
|
||||
final _service = AnnouncementService();
|
||||
|
||||
StreamController<AnnouncementModel> streamController = BehaviorSubject();
|
||||
String _message = '';
|
||||
String get message => _message;
|
||||
|
||||
ResultState? _state;
|
||||
ResultState? get state => _state;
|
||||
|
||||
AnnouncementModel? _announcementModel;
|
||||
AnnouncementModel? get result => _announcementModel;
|
||||
|
||||
set annoucementModel(AnnouncementModel? announcementModel) {
|
||||
_announcementModel = announcementModel;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Stream<AnnouncementModel> get announcementStream {
|
||||
return streamController.stream;
|
||||
}
|
||||
|
||||
Future<void> getAnnouncement(String id) async {
|
||||
try {
|
||||
AnnouncementModel announcementModel = await _service.getAnnouncement(id);
|
||||
if (announcementModel.error == true && announcementModel.status == 404) {
|
||||
// Jika respons adalah 404 (tidak ditemukan), tangani objek dummy di sini
|
||||
// Misalnya, menampilkan pesan kepada pengguna bahwa tidak ada data yang ditemukan
|
||||
// Atau menampilkan UI yang sesuai
|
||||
print('masuk rerror dsiinii');
|
||||
streamController.add(announcementModel);
|
||||
} else {
|
||||
// Jika respons adalah 200 (berhasil), tambahkan data ke dalam stream
|
||||
streamController.add(announcementModel);
|
||||
}
|
||||
} catch (e) {
|
||||
throw Error;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> likeAnnouncement(String tokenAnnouncement) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
|
||||
bool response =
|
||||
await AnnouncementService().likeAnnouncement(tokenAnnouncement);
|
||||
if (response) {
|
||||
_state = ResultState.hasData;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_state = ResultState.noData;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.error;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> replyAnnouncement(String textBody, String idAnnouncmenet,
|
||||
String tokenAnnouncement, String idAnnouncement) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
|
||||
bool response = await AnnouncementService()
|
||||
.replyAnnouncement(tokenAnnouncement, textBody, idAnnouncement);
|
||||
if (response) {
|
||||
_state = ResultState.hasData;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_state = ResultState.noData;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.error;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
53
lib/providers/auth_provider.dart
Normal file
53
lib/providers/auth_provider.dart
Normal file
@ -0,0 +1,53 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/user_model.dart';
|
||||
import 'package:initial_folder/services/auth_service.dart';
|
||||
|
||||
class AuthProvider with ChangeNotifier {
|
||||
UserModel? _user;
|
||||
UserModel? get user => _user;
|
||||
|
||||
set user(UserModel? user) {
|
||||
_user = user;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<bool> register({
|
||||
required String name,
|
||||
required String email,
|
||||
required String password,
|
||||
required String phoneNumber,
|
||||
}) async {
|
||||
try {
|
||||
UserModel? user = await AuthService().register(
|
||||
name: name,
|
||||
email: email,
|
||||
password: password,
|
||||
phoneNumber: phoneNumber,
|
||||
);
|
||||
|
||||
_user = user;
|
||||
return true;
|
||||
} catch (e) {
|
||||
print("Exception: $e");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> login({
|
||||
required String email,
|
||||
required String password,
|
||||
}) async {
|
||||
try {
|
||||
UserModel user = await AuthService().login(
|
||||
email: email,
|
||||
password: password,
|
||||
);
|
||||
|
||||
_user = user;
|
||||
return true;
|
||||
} catch (e) {
|
||||
print("EXception: $e");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
53
lib/providers/banners_provider.dart
Normal file
53
lib/providers/banners_provider.dart
Normal file
@ -0,0 +1,53 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/banners_model.dart';
|
||||
import 'package:initial_folder/services/banners_service.dart';
|
||||
|
||||
enum ResultState { Loading, NoData, HasData, Error }
|
||||
|
||||
class BannersProvider with ChangeNotifier {
|
||||
final BannersService bannersService;
|
||||
BannersProvider({required this.bannersService}) {
|
||||
getAllBanners();
|
||||
}
|
||||
List<BannersModel> _banners = [];
|
||||
|
||||
ResultState? _state;
|
||||
|
||||
String _message = '';
|
||||
String _status = '';
|
||||
|
||||
List<BannersModel> get result => _banners;
|
||||
|
||||
ResultState? get state => _state;
|
||||
|
||||
String get message => _message;
|
||||
String get status => _status;
|
||||
|
||||
set banners(List<BannersModel> banners) {
|
||||
_banners = banners;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getAllBanners() async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
var result = await bannersService.getAllBanners();
|
||||
if (result['status'] == 404) {
|
||||
_state = ResultState.NoData;
|
||||
print("Harusnya ke sini");
|
||||
notifyListeners();
|
||||
return _message = 'Banner kosong';
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
notifyListeners();
|
||||
return _banners = result['data'];
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
print('Gagal banner provider $e');
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
62
lib/providers/cart_provider.dart
Normal file
62
lib/providers/cart_provider.dart
Normal file
@ -0,0 +1,62 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:initial_folder/models/cart_model.dart';
|
||||
import 'package:initial_folder/services/cart_service.dart';
|
||||
|
||||
enum ResultState { loading, succes, failed }
|
||||
|
||||
class CartProvider with ChangeNotifier {
|
||||
final CartService cartService;
|
||||
CartProvider({required this.cartService});
|
||||
CartModel? _cartModel;
|
||||
CartModel? get cartModel => _cartModel;
|
||||
ResultState? _state;
|
||||
ResultState? get state => _state;
|
||||
set cartModel(CartModel? cartModel) {
|
||||
_cartModel = cartModel;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<bool> addCart(_idCourse) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
bool cart = await cartService.addCart(_idCourse);
|
||||
if (cart) {
|
||||
_state = ResultState.succes;
|
||||
notifyListeners();
|
||||
} else if (!cart) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
}
|
||||
return true;
|
||||
} on SocketException {
|
||||
return false;
|
||||
} catch (e) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
print("Exceptions: $e");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> deleteCart(_idCart) async {
|
||||
try {
|
||||
bool cart = await cartService.deleteCart(_idCart);
|
||||
if (cart) {
|
||||
_state = ResultState.succes;
|
||||
notifyListeners();
|
||||
} else if (!cart) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
}
|
||||
return true;
|
||||
} on SocketException {
|
||||
return false;
|
||||
} catch (e) {
|
||||
print("Exceptions: $e");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
78
lib/providers/carts_provider.dart
Normal file
78
lib/providers/carts_provider.dart
Normal file
@ -0,0 +1,78 @@
|
||||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/carts_model.dart';
|
||||
import 'package:initial_folder/services/cart_service.dart';
|
||||
|
||||
enum ResultState { Loading, NoData, HasData, Error }
|
||||
|
||||
class CartsProvider with ChangeNotifier {
|
||||
final CartService cartService;
|
||||
CartsProvider({required this.cartService}) {
|
||||
getCarts();
|
||||
}
|
||||
|
||||
CartsModel? _cartsModel;
|
||||
CartsModel? get result => _cartsModel;
|
||||
|
||||
ResultState? _state;
|
||||
ResultState? get state => _state;
|
||||
|
||||
String _message = '';
|
||||
String _finalPrice = '';
|
||||
|
||||
String get message => _message;
|
||||
String get finalPrice => _finalPrice;
|
||||
|
||||
int _length = 0;
|
||||
int get lenght => _length;
|
||||
|
||||
set lengthCarts(int v) {
|
||||
_length = v;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
List _data = [];
|
||||
List get data => _data;
|
||||
|
||||
// StreamController<List<DataCartsModel>> dataStream = StreamController.broadcast();
|
||||
|
||||
set carts(CartsModel carts) {
|
||||
_cartsModel = carts;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_length = 0;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getCarts() async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
_data = [];
|
||||
notifyListeners();
|
||||
CartsModel carts = await cartService.getCarts();
|
||||
_length = carts.data.length;
|
||||
notifyListeners();
|
||||
if (carts.data.isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
_data = carts.data.map((e) => e.courseId).toList();
|
||||
_state = ResultState.HasData;
|
||||
print(_data);
|
||||
print("ini dari getcatsrs");
|
||||
notifyListeners();
|
||||
return _cartsModel = carts;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
log('$e');
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
76
lib/providers/categories_provider.dart
Normal file
76
lib/providers/categories_provider.dart
Normal file
@ -0,0 +1,76 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/catagories_model.dart';
|
||||
import 'package:initial_folder/models/subcategories_model.dart';
|
||||
import 'package:initial_folder/services/categories_service.dart';
|
||||
|
||||
enum ResultState { Loading, NoData, HasData, Error }
|
||||
|
||||
class CategoriesProvider with ChangeNotifier {
|
||||
final CategoriesService categoriesService;
|
||||
CategoriesProvider({required this.categoriesService}) {
|
||||
getAllCategories();
|
||||
}
|
||||
List<CategoriesModel> _categories = [];
|
||||
Map<String, List<SubCategoryModel>> _subCategoriesMap = {};
|
||||
|
||||
ResultState? _state;
|
||||
|
||||
String _message = '';
|
||||
|
||||
List<String?> get ids {
|
||||
return _categories.map((category) => category.id).toList();
|
||||
}
|
||||
|
||||
List<String?> get nameCategories {
|
||||
return _categories.map((category) => category.nameCategory).toList();
|
||||
}
|
||||
|
||||
List<CategoriesModel> get result => _categories;
|
||||
|
||||
ResultState? get state => _state;
|
||||
|
||||
String get message => _message;
|
||||
|
||||
String _selectedSubcategoryId = '';
|
||||
|
||||
set categories(List<CategoriesModel> categories) {
|
||||
_categories = categories;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Map<String, List<SubCategoryModel>> get subCategoriesMap => _subCategoriesMap;
|
||||
|
||||
String get selectedSubcategoryId => _selectedSubcategoryId;
|
||||
|
||||
set selectedSubcategoryId(String value) {
|
||||
_selectedSubcategoryId = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getAllCategories() async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
List<CategoriesModel> categories =
|
||||
await categoriesService.getAllCategories();
|
||||
if (categories.isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
for (var category in categories) {
|
||||
List<SubCategoryModel> subCategories =
|
||||
await categoriesService.getSubCategories(category.id!);
|
||||
category.subCategories = subCategories;
|
||||
}
|
||||
_categories = categories;
|
||||
_state = ResultState.HasData;
|
||||
notifyListeners();
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
181
lib/providers/certificate_provider.dart
Normal file
181
lib/providers/certificate_provider.dart
Normal file
@ -0,0 +1,181 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/certificate_model.dart';
|
||||
import 'package:initial_folder/models/check_certificate.model.dart';
|
||||
import 'package:initial_folder/models/my_certificate.dart';
|
||||
import 'package:initial_folder/services/all_certificate_service.dart';
|
||||
|
||||
enum ResultState { Loading, NoData, HasData, Error }
|
||||
|
||||
class CertificateProvider with ChangeNotifier {
|
||||
final AllCertificateServices certificateServices;
|
||||
CertificateProvider({required this.certificateServices}) {
|
||||
getAllCertif();
|
||||
}
|
||||
|
||||
bool _isChecked = true;
|
||||
bool get isChecked => _isChecked;
|
||||
|
||||
ResultState? _state;
|
||||
|
||||
List<DataMyCertificateModel?>? _allCertificate;
|
||||
|
||||
String? _userId;
|
||||
String? _idPayment;
|
||||
String? _certificateNo;
|
||||
String? _username;
|
||||
String? _title;
|
||||
String? _idCourse;
|
||||
int? _progress;
|
||||
dynamic _finishDate;
|
||||
int _allCertificateCount = 0;
|
||||
bool _isSearch = false;
|
||||
|
||||
List<DataMyCertificateModel?>? get allCertificate => _allCertificate;
|
||||
|
||||
int? get allCertificateCount => _allCertificateCount;
|
||||
dynamic get finishDate => _finishDate;
|
||||
String? get idPayment => _idPayment;
|
||||
String? get certificateNo => _certificateNo;
|
||||
String? get name => _username;
|
||||
String? get title => _title;
|
||||
String? get userId => _userId;
|
||||
String? get idCourse => _idCourse;
|
||||
int? get progress => _progress;
|
||||
bool get isSearch => _isSearch;
|
||||
|
||||
ResultState? get state => _state;
|
||||
|
||||
Future uploadCertificate(String idPayment, File pdfFile) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
await certificateServices.uploadCertificate(idPayment, pdfFile);
|
||||
_state = ResultState.HasData;
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
print(
|
||||
"Error download sertifikat $e",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future getCertif(String idCourse) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
List<CertificateModel> certif =
|
||||
await certificateServices.getSertif(idCourse);
|
||||
|
||||
if (certif.isEmpty) {
|
||||
print("Jangan loading terus");
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
notifyListeners();
|
||||
_idPayment = certif[0].idPayment;
|
||||
_certificateNo = certif[0].certificateNo;
|
||||
_username = certif[0].name;
|
||||
_title = certif[0].title;
|
||||
_finishDate = certif[0].finishDate;
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
} catch (e) {
|
||||
print("Ini gagal pas pindah ke certif cuy ${e}");
|
||||
}
|
||||
}
|
||||
|
||||
Future getAllCertif() async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
List<DataMyCertificateModel> allCertificate =
|
||||
await AllCertificateServices().getAllCertificate();
|
||||
|
||||
allCertificate.sort((a, b) => b.progress!.compareTo(a.progress!));
|
||||
|
||||
_allCertificateCount = 0;
|
||||
if (allCertificate.isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
_isSearch = false;
|
||||
notifyListeners();
|
||||
_allCertificate = allCertificate;
|
||||
for (var data in allCertificate) {
|
||||
if (data.progress == 100) _allCertificateCount++;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
} catch (e) {
|
||||
print("Jangan loading terus ${e}");
|
||||
}
|
||||
}
|
||||
|
||||
Future checkSertif(String text) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
CheckCertificateData certif = await certificateServices.checkSertif(text);
|
||||
if (certif.certificateNo!.isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
_idCourse = certif.courseId;
|
||||
_idPayment = certif.idPayment;
|
||||
_certificateNo = certif.certificateNo;
|
||||
_username = certif.name;
|
||||
_title = certif.title;
|
||||
_finishDate = certif.finishDate;
|
||||
_progress = certif.progress;
|
||||
notifyListeners();
|
||||
}
|
||||
} catch (e) {
|
||||
print("Ini error input no sertif${e}");
|
||||
}
|
||||
}
|
||||
|
||||
Future clearCheckSertif() async {
|
||||
_idPayment = null;
|
||||
}
|
||||
|
||||
Future searchCertif(String keyword) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
List<DataMyCertificateModel> allCertificate =
|
||||
await AllCertificateServices().searchCertif(keyword);
|
||||
_allCertificateCount = 0;
|
||||
if (allCertificate.isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
_isSearch = true;
|
||||
notifyListeners();
|
||||
_allCertificate = allCertificate;
|
||||
for (var data in allCertificate) {
|
||||
if (data.progress == 100) {
|
||||
_allCertificateCount++;
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
bool toggleCheckbox([bool value = false]) {
|
||||
_isChecked = !_isChecked;
|
||||
notifyListeners();
|
||||
return _isChecked;
|
||||
}
|
||||
}
|
12
lib/providers/checkbox_provider.dart
Normal file
12
lib/providers/checkbox_provider.dart
Normal file
@ -0,0 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CheckboxProvider with ChangeNotifier {
|
||||
bool _isChecked = false;
|
||||
|
||||
bool get isChecked => _isChecked;
|
||||
|
||||
set isChecked(bool value) {
|
||||
_isChecked = value;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
52
lib/providers/counter_qna_comment_provider.dart
Normal file
52
lib/providers/counter_qna_comment_provider.dart
Normal file
@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/counter_qna_comment_model.dart';
|
||||
import 'package:initial_folder/services/qna_service.dart';
|
||||
|
||||
enum ResultState { loading, noData, hasData, error }
|
||||
enum ResultStateLike { loading, error }
|
||||
|
||||
class CounterQnaCommentProvider with ChangeNotifier {
|
||||
final String idQna;
|
||||
|
||||
CounterQnaCommentProvider({required this.idQna}) {
|
||||
getCounterComment(idQna);
|
||||
}
|
||||
String _message = '';
|
||||
String get message => _message;
|
||||
ResultState? _state;
|
||||
ResultState? get state => _state;
|
||||
CounterCommentModel? _counterCommentModel;
|
||||
CounterCommentModel? get result => _counterCommentModel;
|
||||
set counterComment(CounterCommentModel? counterCommentModel) {
|
||||
_counterCommentModel = counterCommentModel;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
//Get Counter Comment QNA
|
||||
Future<dynamic> getCounterComment(String idQna) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
CounterCommentModel counterCommentModel =
|
||||
await QnaService().getCounterComment(idQna);
|
||||
// print("Ini Cunter : ${counterCommentModel.data}");
|
||||
// ignore: unnecessary_null_comparison
|
||||
if (counterCommentModel.data != null) {
|
||||
print("ADA DATA");
|
||||
_state = ResultState.hasData;
|
||||
notifyListeners();
|
||||
return _counterCommentModel = counterCommentModel;
|
||||
} else {
|
||||
print("TIDAK ADA DATA");
|
||||
_state = ResultState.noData;
|
||||
notifyListeners();
|
||||
return _message = 'Tidak ada Data';
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.error;
|
||||
print(e);
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
52
lib/providers/counter_qna_like_provider.dart
Normal file
52
lib/providers/counter_qna_like_provider.dart
Normal file
@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/counter_qna_like_model.dart';
|
||||
import 'package:initial_folder/services/qna_service.dart';
|
||||
|
||||
enum ResultState { loading, noData, hasData, error }
|
||||
enum ResultStateLike { loading, error }
|
||||
|
||||
class CounterQnaLikeProvider with ChangeNotifier {
|
||||
final String idQna;
|
||||
|
||||
CounterQnaLikeProvider({required this.idQna}) {
|
||||
getLikeComment(idQna);
|
||||
}
|
||||
String _message = '';
|
||||
String get message => _message;
|
||||
ResultState? _state;
|
||||
ResultState? get state => _state;
|
||||
CounterLikeModel? _counterLikeModel;
|
||||
CounterLikeModel? get result => _counterLikeModel;
|
||||
set counterComment(CounterLikeModel? counterLikeModel) {
|
||||
_counterLikeModel = counterLikeModel;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
//Get Counter Like QNA
|
||||
Future<dynamic> getLikeComment(String idQna) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
CounterLikeModel counterLikeModel =
|
||||
await QnaService().getCounterLike(idQna);
|
||||
// print("Ini Cunter : ${counterLikeModel.data}");
|
||||
// ignore: unnecessary_null_comparison
|
||||
if (counterLikeModel.data != null) {
|
||||
print("ADA DATA");
|
||||
_state = ResultState.hasData;
|
||||
notifyListeners();
|
||||
return _counterLikeModel = counterLikeModel;
|
||||
} else {
|
||||
print("TIDAK ADA DATA");
|
||||
_state = ResultState.noData;
|
||||
notifyListeners();
|
||||
return _message = 'Tidak ada Data';
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.error;
|
||||
print(e);
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
53
lib/providers/coupon_course_provider.dart
Normal file
53
lib/providers/coupon_course_provider.dart
Normal file
@ -0,0 +1,53 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/services/coupon_service.dart';
|
||||
|
||||
enum ResultState { Loading, NoData, HasData, Error }
|
||||
|
||||
class CouponCourseProvider with ChangeNotifier {
|
||||
final CouponService couponService;
|
||||
String coupon;
|
||||
CouponCourseProvider({required this.couponService, required this.coupon}) {
|
||||
getDiscountCourse(coupon);
|
||||
}
|
||||
dynamic _data;
|
||||
|
||||
ResultState? _state;
|
||||
|
||||
String _message = '';
|
||||
|
||||
dynamic get result => _data;
|
||||
|
||||
ResultState? get state => _state;
|
||||
|
||||
String get message => _message;
|
||||
|
||||
set data(dynamic data) {
|
||||
_data = data;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getDiscountCourse(coupon) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
dynamic data = await couponService.getDiscountCourse(coupon);
|
||||
if (data.isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
print("ini berhasil provider kupon ${_data}");
|
||||
notifyListeners();
|
||||
return _data = data;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
print("Gagal kupon ${e}");
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
85
lib/providers/course_by_category_provider.dart
Normal file
85
lib/providers/course_by_category_provider.dart
Normal file
@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/course_model.dart';
|
||||
import 'package:initial_folder/services/course_by_category_service.dart';
|
||||
|
||||
enum ResultState { Loading, NoData, HasData, Error }
|
||||
|
||||
class CourseByCategoryProvider with ChangeNotifier {
|
||||
final CourseByCategoryService courseByCategoryService;
|
||||
final String id;
|
||||
final String subId;
|
||||
final bool fetchBySubcategory;
|
||||
CourseByCategoryProvider({
|
||||
required this.courseByCategoryService,
|
||||
required this.id,
|
||||
required this.subId,
|
||||
this.fetchBySubcategory = false,
|
||||
}) {
|
||||
if (fetchBySubcategory) {
|
||||
getCourseByCategory(id, subId);
|
||||
} else {
|
||||
getCourseOnlyCategory(id);
|
||||
}
|
||||
}
|
||||
List<CourseModel> _courseByCategory = [];
|
||||
|
||||
ResultState? _state;
|
||||
|
||||
String _message = '';
|
||||
|
||||
List<CourseModel> get result => _courseByCategory;
|
||||
|
||||
ResultState? get state => _state;
|
||||
|
||||
String get message => _message;
|
||||
|
||||
set courseByCategory(List<CourseModel> courseByCategory) {
|
||||
_courseByCategory = courseByCategory;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getCourseByCategory(_id, subId) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
List<CourseModel> courseByCategory =
|
||||
await courseByCategoryService.getCourseCategoryAndSub(_id, subId);
|
||||
if (courseByCategory.isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
print(_courseByCategory);
|
||||
notifyListeners();
|
||||
return _courseByCategory = courseByCategory;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> getCourseOnlyCategory(_id) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
List<CourseModel> courseByCategory =
|
||||
await courseByCategoryService.getCourseOnlyCategory(_id);
|
||||
if (courseByCategory.isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
notifyListeners();
|
||||
return _courseByCategory = courseByCategory;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
27
lib/providers/current_lesson_provider.dart
Normal file
27
lib/providers/current_lesson_provider.dart
Normal file
@ -0,0 +1,27 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:initial_folder/models/lesson_model.dart';
|
||||
import 'package:initial_folder/providers/lesson_course_provider.dart';
|
||||
import 'package:initial_folder/services/current_lesson_service.dart';
|
||||
|
||||
class CurrentLessonProvider extends ChangeNotifier {
|
||||
late LessonModel _currentLesson;
|
||||
LessonModel get payload => _currentLesson;
|
||||
|
||||
ResultState _state = ResultState.loading;
|
||||
ResultState get state => _state;
|
||||
|
||||
Future<dynamic> fetchCurrentLesson(String lessonId) async {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final data = await CurrentLessonService().getCurrentLesson(lessonId);
|
||||
_currentLesson = data;
|
||||
_state = ResultState.hasData;
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
_state = ResultState.error;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
137
lib/providers/data_diri_provider.dart
Normal file
137
lib/providers/data_diri_provider.dart
Normal file
@ -0,0 +1,137 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/data_diri_model.dart';
|
||||
import 'package:initial_folder/services/user_info_service.dart';
|
||||
|
||||
enum ResultStateData { Loading, NoData, HasData, Error }
|
||||
|
||||
class DataDiriProvider with ChangeNotifier {
|
||||
final UserInfoService userInfoService;
|
||||
|
||||
DataDiriProvider({
|
||||
required this.userInfoService,
|
||||
}) {
|
||||
getDataDiri();
|
||||
}
|
||||
|
||||
DataDiriModel? _dataDiriModel;
|
||||
|
||||
ResultStateData? _state;
|
||||
|
||||
String _message = '';
|
||||
|
||||
DataDiriModel? get result => _dataDiriModel;
|
||||
|
||||
ResultStateData? get state => _state;
|
||||
|
||||
String get message => _message;
|
||||
|
||||
bool _isNewBirthDate = false;
|
||||
bool get isNewBirthDate => _isNewBirthDate;
|
||||
|
||||
bool _newName = false;
|
||||
bool get newName => _newName;
|
||||
|
||||
bool _newHeadline = false;
|
||||
bool get newHeadline => _newHeadline;
|
||||
|
||||
bool _newBiograpy = false;
|
||||
bool get newBiograpy => _newBiograpy;
|
||||
|
||||
bool _newEmail = false;
|
||||
bool get newEmail => _newEmail;
|
||||
|
||||
bool _newPhone = false;
|
||||
bool get newPhone => _newPhone;
|
||||
|
||||
bool _newGender = false;
|
||||
bool get newGender => _newGender;
|
||||
|
||||
bool _newInstagram = false;
|
||||
bool get newInstagram => _newInstagram;
|
||||
|
||||
bool _newTwitter = false;
|
||||
bool get newTwitter => _newTwitter;
|
||||
|
||||
bool _newFacebook = false;
|
||||
bool get newFacebook => _newFacebook;
|
||||
|
||||
bool _newLinkedin = false;
|
||||
bool get newLinkedin => _newLinkedin;
|
||||
|
||||
set isNewBirthDate(bool value) {
|
||||
_isNewBirthDate = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set newName(bool value) {
|
||||
_newName = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set newHeadline(bool value) {
|
||||
_newHeadline = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set newBiograpy(bool value) {
|
||||
_newBiograpy = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set newEmail(bool value) {
|
||||
_newEmail = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set newPhone(bool value) {
|
||||
_newPhone = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set newGender(bool value) {
|
||||
_newGender = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set newInstagram(bool value) {
|
||||
_newInstagram = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set newTwitter(bool value) {
|
||||
_newTwitter = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set newFacebook(bool value) {
|
||||
_newFacebook = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set newLinkedin(bool value) {
|
||||
_newLinkedin = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set dataDiri(DataDiriModel dataDiri) {
|
||||
_dataDiriModel = dataDiri;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getDataDiri() async {
|
||||
try {
|
||||
_state = ResultStateData.Loading;
|
||||
notifyListeners();
|
||||
DataDiriModel dataDiri = await userInfoService.getDataDiri();
|
||||
|
||||
_state = ResultStateData.HasData;
|
||||
notifyListeners();
|
||||
_dataDiriModel = dataDiri;
|
||||
return _dataDiriModel;
|
||||
} catch (e) {
|
||||
_state = ResultStateData.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
12
lib/providers/description_provider.dart
Normal file
12
lib/providers/description_provider.dart
Normal file
@ -0,0 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DescriptionProvider with ChangeNotifier {
|
||||
bool isExpanded;
|
||||
|
||||
DescriptionProvider({this.isExpanded = true});
|
||||
|
||||
void expanded() {
|
||||
isExpanded = !isExpanded;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
87
lib/providers/detail_course_coupon_provider.dart
Normal file
87
lib/providers/detail_course_coupon_provider.dart
Normal file
@ -0,0 +1,87 @@
|
||||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:initial_folder/models/detail_course_model.dart';
|
||||
import 'package:initial_folder/services/course_service.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
enum ResultState { Loading, HasData, Error, NoData }
|
||||
|
||||
class DetailCourseCouponProvider with ChangeNotifier {
|
||||
final CourseService courseService;
|
||||
final String id;
|
||||
final String coupon;
|
||||
DetailCourseCouponProvider(
|
||||
{required this.courseService, required this.id, required this.coupon}) {
|
||||
getDetailCourseCoupon(id, coupon);
|
||||
}
|
||||
|
||||
DataDetailCourseModel? _detailCourse;
|
||||
|
||||
DataDetailCourseModel? get result => _detailCourse;
|
||||
|
||||
ResultState? _state;
|
||||
|
||||
String _message = '';
|
||||
|
||||
ResultState? get state => _state;
|
||||
|
||||
String get message => _message;
|
||||
|
||||
set detailCourse(DataDetailCourseModel? detail) {
|
||||
_detailCourse = detail;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getDetailCourseCoupon(_id, String coupon) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
DataDetailCourseModel? detail =
|
||||
await courseService.getDetailCourseCoupon(_id, coupon);
|
||||
|
||||
_state = ResultState.HasData;
|
||||
print("Berhasil detail kupon di provider ${_detailCourse}");
|
||||
notifyListeners();
|
||||
return _detailCourse = detail;
|
||||
} catch (e) {
|
||||
print("Gagal detail kupon di provider ${e}");
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DetailCouponProvider with ChangeNotifier {
|
||||
DataDetailCourseModel? _detailCourse;
|
||||
|
||||
DataDetailCourseModel? get result => _detailCourse;
|
||||
|
||||
StreamController<DataDetailCourseModel> streamController = BehaviorSubject();
|
||||
|
||||
String _message = '';
|
||||
|
||||
String get message => _message;
|
||||
|
||||
set detailCourse(DataDetailCourseModel? detail) {
|
||||
_detailCourse = detail;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Stream<DataDetailCourseModel> get detailStream {
|
||||
return streamController.stream;
|
||||
}
|
||||
|
||||
Future<void> getDetail(id, coupon) async {
|
||||
try {
|
||||
print("Berhasil detail kupon di provider");
|
||||
DataDetailCourseModel? detail =
|
||||
await CourseService().getDetailCourseCoupon(id, coupon);
|
||||
streamController.add(detail);
|
||||
} catch (e) {
|
||||
print("Gagal detail kupon di provider 2 ${e}");
|
||||
}
|
||||
}
|
||||
}
|
109
lib/providers/detail_course_provider.dart
Normal file
109
lib/providers/detail_course_provider.dart
Normal file
@ -0,0 +1,109 @@
|
||||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:initial_folder/models/detail_course_model.dart';
|
||||
import 'package:initial_folder/screens/splash/splash_screen_login.dart';
|
||||
import 'package:initial_folder/services/course_service.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
enum ResultState { Loading, HasData, Error, NoData }
|
||||
|
||||
class DetailCourseProvider with ChangeNotifier {
|
||||
final CourseService courseService;
|
||||
final String id;
|
||||
DetailCourseProvider({required this.courseService, required this.id}) {
|
||||
Condition.loginEmail ? getDetailCourseLogin(id) : getDetailCourse(id);
|
||||
}
|
||||
|
||||
DetailCourseModel? _detailCourse;
|
||||
DetailCourseModel? get result => _detailCourse;
|
||||
|
||||
ResultState? _state;
|
||||
ResultState? get state => _state;
|
||||
|
||||
String _message = '';
|
||||
String get message => _message;
|
||||
int? get checkoutPrice => _detailCourse?.data[0][0].checkoutPrice;
|
||||
|
||||
set detailCourse(DetailCourseModel? detail) {
|
||||
_detailCourse = detail;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getDetailCourse(_id) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
DetailCourseModel? detail = await courseService.getDetailCourse(_id);
|
||||
|
||||
if (detail.data[0].isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Tidak ada data';
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
notifyListeners();
|
||||
return _detailCourse = detail;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
print(e);
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> getDetailCourseLogin(id) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
DetailCourseModel? detail = await courseService.getDetailCourseLogin(id);
|
||||
|
||||
if (detail.data[0].isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Tidak ada data';
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
notifyListeners();
|
||||
return _detailCourse = detail;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
print(e);
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DetailProvider with ChangeNotifier {
|
||||
DetailCourseModel? _detailCourse;
|
||||
DetailCourseModel? get result => _detailCourse;
|
||||
|
||||
StreamController<DetailCourseModel> streamController = BehaviorSubject();
|
||||
|
||||
String _message = '';
|
||||
String get message => _message;
|
||||
int? get checkoutPrice => _detailCourse?.data[0][0].checkoutPrice ?? 0;
|
||||
|
||||
set detailCourse(DetailCourseModel? detail) {
|
||||
_detailCourse = detail;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Stream<DetailCourseModel> get detailStream {
|
||||
return streamController.stream;
|
||||
}
|
||||
|
||||
Future<void> getDetail(id) async {
|
||||
try {
|
||||
DetailCourseModel? detail =
|
||||
await CourseService().getDetailCourseLogin(id);
|
||||
streamController.add(detail);
|
||||
} catch (e) {
|
||||
log(e as String);
|
||||
}
|
||||
}
|
||||
}
|
44
lib/providers/detail_invoice_provider.dart
Normal file
44
lib/providers/detail_invoice_provider.dart
Normal file
@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/detail_invoice_model.dart';
|
||||
import 'package:initial_folder/services/detail_invoice_service.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
enum ResultState { loading, noData, hasData, error }
|
||||
|
||||
class DetailInvoiceProvider extends ChangeNotifier {
|
||||
final DetailInvoiceService _detailInvoiceService = DetailInvoiceService();
|
||||
|
||||
List<DataDetailInvoiceModel>? _detailInvoice;
|
||||
String? _message;
|
||||
String? _thumbnail;
|
||||
ResultState? _state;
|
||||
|
||||
String? get message => _message;
|
||||
String? get thumbnail => _thumbnail;
|
||||
List<DataDetailInvoiceModel>? get detailInvoice => _detailInvoice;
|
||||
ResultState? get state => _state;
|
||||
|
||||
set selectedThumbnail(String? value) {
|
||||
_thumbnail = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> fetchDetailInvoice(String? orderId) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
final data = await _detailInvoiceService.detailInvoice(orderId);
|
||||
if (data.isEmpty) {
|
||||
_state = ResultState.noData;
|
||||
_message = 'Invoice Detail is Empty';
|
||||
} else {
|
||||
_state = ResultState.hasData;
|
||||
_detailInvoice = data;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.error;
|
||||
_message = 'Error -> $e';
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
79
lib/providers/detail_rating_course_provider.dart
Normal file
79
lib/providers/detail_rating_course_provider.dart
Normal file
@ -0,0 +1,79 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:initial_folder/models/detail_rating_course_model.dart';
|
||||
import 'package:initial_folder/services/course_service.dart';
|
||||
|
||||
enum ResultState { Loading, HasData, Error, NoData }
|
||||
|
||||
class DetailRatingCourseProvider with ChangeNotifier {
|
||||
final CourseService courseService;
|
||||
final String id;
|
||||
DetailRatingCourseProvider({required this.courseService, required this.id}) {
|
||||
getDetailCourse(id);
|
||||
}
|
||||
|
||||
RatingCourseDetailModel? _detailRatingCourse;
|
||||
|
||||
RatingCourseDetailModel? get result => _detailRatingCourse;
|
||||
List<DataReview>? _review;
|
||||
List<DataReview>? get review => _review;
|
||||
ResultState? _state;
|
||||
|
||||
String _message = '';
|
||||
|
||||
ResultState? get state => _state;
|
||||
|
||||
String get message => _message;
|
||||
|
||||
set detailCourse(RatingCourseDetailModel detail) {
|
||||
_detailRatingCourse = detail;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
int _currentIndex = 0;
|
||||
|
||||
int get currentIndex => _currentIndex;
|
||||
|
||||
set currentIndex(int index) {
|
||||
_currentIndex = index;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getDetailCourse([_id]) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
RatingCourseDetailModel detail =
|
||||
await courseService.getRatingDetailCourse((_id != null) ? _id : id );
|
||||
|
||||
_state = ResultState.HasData;
|
||||
_review = detail.dataReview;
|
||||
notifyListeners();
|
||||
return _detailRatingCourse = detail;
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> filterCourse(int rating) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
RatingCourseDetailModel detail =
|
||||
await courseService.getRatingDetailCourse(id);
|
||||
|
||||
_state = ResultState.HasData;
|
||||
_review = detail.dataReview.where((element) => element.rating == rating.toString()).toList();
|
||||
notifyListeners();
|
||||
|
||||
return _detailRatingCourse = detail;
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
19
lib/providers/email_provider.dart
Normal file
19
lib/providers/email_provider.dart
Normal file
@ -0,0 +1,19 @@
|
||||
// import 'package:flutter/material.dart';
|
||||
|
||||
// class EmailProvider with ChangeNotifier {
|
||||
// String? _currentEmail = '';
|
||||
// String? _currentName = '';
|
||||
|
||||
// String? get currentEmail => _currentEmail;
|
||||
// String? get currentName => _currentName;
|
||||
|
||||
// set currentEmail(String? email) {
|
||||
// _currentEmail = email;
|
||||
// notifyListeners();
|
||||
// }
|
||||
|
||||
// set currentName(String? name) {
|
||||
// _currentName = name;
|
||||
// notifyListeners();
|
||||
// }
|
||||
// }
|
133
lib/providers/filters_course_provider.dart
Normal file
133
lib/providers/filters_course_provider.dart
Normal file
@ -0,0 +1,133 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:initial_folder/models/course_model.dart';
|
||||
import 'package:initial_folder/services/search_service.dart';
|
||||
|
||||
enum ResultState { loading, noData, hasData, error }
|
||||
|
||||
class FilterCourseProvider with ChangeNotifier {
|
||||
final SearchService searchService;
|
||||
FilterCourseProvider({required this.searchService});
|
||||
|
||||
List<CourseModel> _filteredCourse = [];
|
||||
ResultState? _state;
|
||||
String _message = '';
|
||||
|
||||
List<CourseModel> get filterResult => [..._filteredCourse];
|
||||
ResultState? get state => _state;
|
||||
String get message => _message;
|
||||
|
||||
List<String> _categories = [''];
|
||||
List<String> get categories => [..._categories];
|
||||
void addCategory(String id) {
|
||||
_categories.add(id);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void removeCategory(String id) {
|
||||
_categories.removeWhere((item) => item == id);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void allCategories() {
|
||||
_categories = [];
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
List<String> _levels = [''];
|
||||
List<String> get levels => [..._levels];
|
||||
void addLevel(String level) {
|
||||
_levels.add(level);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void removeLevel(String level) {
|
||||
_levels.removeWhere((item) => item == level);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void allLevel() {
|
||||
_levels = [];
|
||||
}
|
||||
|
||||
String _currentIndexRating = '';
|
||||
String get currentIndexRating => _currentIndexRating;
|
||||
set currentIndexRating(String index) {
|
||||
_currentIndexRating = index;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
String _currentIndexPrice = '';
|
||||
String get currentIndexPrice => _currentIndexPrice;
|
||||
set currentIndexPrice(String index) {
|
||||
_currentIndexPrice = index;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
String _currentIndexLevelCheckBox = '';
|
||||
String get currentIndexLevelCheckBox => _currentIndexLevelCheckBox;
|
||||
set currentIndexLevelCheckBox(String index) {
|
||||
_currentIndexLevelCheckBox = index;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void resetFilter() {
|
||||
_currentIndexPrice = '';
|
||||
_currentIndexRating = '';
|
||||
_categories = [''];
|
||||
_levels = [''];
|
||||
_filteredCourse = [];
|
||||
}
|
||||
|
||||
void resetState() {
|
||||
_state = null;
|
||||
}
|
||||
|
||||
bool _isSearch = false;
|
||||
bool get isSearch => _isSearch;
|
||||
void isSearchsTrue() {
|
||||
_isSearch = true;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void isSearchsFalse() {
|
||||
_isSearch = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> filter({
|
||||
String category = '',
|
||||
String price = '',
|
||||
String level = '',
|
||||
String language = '',
|
||||
String rating = '',
|
||||
String keyword = '',
|
||||
}) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
List<CourseModel> course = await searchService.filter(
|
||||
price: price,
|
||||
level: level,
|
||||
language: language,
|
||||
rating: rating,
|
||||
keyword: keyword,
|
||||
);
|
||||
print("Ini keyword filter search ${keyword}");
|
||||
|
||||
if (course.isEmpty) {
|
||||
_state = ResultState.noData;
|
||||
notifyListeners();
|
||||
return _message = 'No Data';
|
||||
} else {
|
||||
_state = ResultState.hasData;
|
||||
notifyListeners();
|
||||
return _filteredCourse = course;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.error;
|
||||
print(e);
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
161
lib/providers/firebase_authentication_provider.dart
Normal file
161
lib/providers/firebase_authentication_provider.dart
Normal file
@ -0,0 +1,161 @@
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
// import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/models/user_model.dart';
|
||||
import 'package:initial_folder/services/auth_service.dart';
|
||||
|
||||
class FirebaseAuthenticationProvider extends ChangeNotifier {
|
||||
final googleSignIn = GoogleSignIn();
|
||||
GoogleSignInAccount? _user;
|
||||
GoogleSignInAccount get user => _user!;
|
||||
|
||||
UserModel? _userModel;
|
||||
UserModel? get userModel => _userModel;
|
||||
|
||||
set userModel(UserModel? userModel) {
|
||||
_userModel = userModel;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future googleSignUp() async {
|
||||
final googleUser = await googleSignIn.signIn();
|
||||
if (googleUser == null) return;
|
||||
_user = googleUser;
|
||||
final googleAuth = await googleUser.authentication;
|
||||
final credential =
|
||||
GoogleAuthProvider.credential(accessToken: googleAuth.idToken);
|
||||
await FirebaseAuth.instance.signInWithCredential(credential);
|
||||
await AuthService().googleSignInAuth(
|
||||
idToken: googleAuth.idToken ?? '',
|
||||
// email: googleUser.email,
|
||||
// password: '',
|
||||
);
|
||||
// _userModel = userModel;
|
||||
await UsersInfo().setEmail(googleUser.email);
|
||||
notifyListeners();
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<bool> googleLogin() async {
|
||||
try {
|
||||
print('Preparing');
|
||||
final googleUser = await googleSignIn.signIn();
|
||||
print('Start');
|
||||
if (googleUser == null) {
|
||||
print('Failed');
|
||||
await logout();
|
||||
return false;
|
||||
}
|
||||
|
||||
print('State 1');
|
||||
final GoogleSignInAuthentication googleAuth =
|
||||
await googleUser.authentication;
|
||||
|
||||
final credential = GoogleAuthProvider.credential(
|
||||
accessToken: googleAuth.accessToken,
|
||||
idToken: googleAuth.idToken,
|
||||
);
|
||||
|
||||
print('State 2');
|
||||
final userCredential =
|
||||
await FirebaseAuth.instance.signInWithCredential(credential);
|
||||
|
||||
print("ID Token: ${googleAuth.idToken}");
|
||||
|
||||
await AuthService().googleSignInAuth(
|
||||
idToken: googleAuth.idToken ?? '',
|
||||
);
|
||||
// _userModel = userModel;
|
||||
|
||||
print('State 3');
|
||||
await UsersInfo().setEmail(googleUser.email);
|
||||
|
||||
print('Login sukses');
|
||||
notifyListeners();
|
||||
return true;
|
||||
} catch (e) {
|
||||
// print(e);
|
||||
// return false;
|
||||
if (e.toString() == 'Exception: Akun anda belum terdaftar') {
|
||||
await logout();
|
||||
throw Exception('Akun anda belum terdaftar');
|
||||
} else {
|
||||
print(e);
|
||||
await logout();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Future facebookLogin() async {
|
||||
// try {
|
||||
// final LoginResult facebookSignIn = await FacebookAuth.instance.login();
|
||||
// if (facebookSignIn.accessToken == null) {
|
||||
// await logout();
|
||||
// return false;
|
||||
// }
|
||||
// switch (facebookSignIn.status) {
|
||||
// case LoginStatus.success:
|
||||
// try {
|
||||
// final facebookAuthCredential = FacebookAuthProvider.credential(
|
||||
// facebookSignIn.accessToken!.token);
|
||||
// await FirebaseAuth.instance
|
||||
// .signInWithCredential(facebookAuthCredential);
|
||||
|
||||
// String name = await FacebookAuth.instance
|
||||
// .getUserData()
|
||||
// .then((data) => data['name']);
|
||||
// String email = await FacebookAuth.instance
|
||||
// .getUserData()
|
||||
// .then((data) => data['email']);
|
||||
// String pictureUrl = await FacebookAuth.instance
|
||||
// .getUserData()
|
||||
// .then((data) => data['picture']['data']['url']);
|
||||
|
||||
// UserModel userModel = await AuthService().facebookSignInAuth(
|
||||
// name: name,
|
||||
// email: email,
|
||||
// password: '',
|
||||
// pictureUrl: pictureUrl,
|
||||
// );
|
||||
// _userModel = userModel;
|
||||
|
||||
// await UsersInfo().setEmail(email);
|
||||
|
||||
// notifyListeners();
|
||||
// return true;
|
||||
// } catch (e) {
|
||||
// await logout();
|
||||
// return false;
|
||||
// }
|
||||
// case LoginStatus.cancelled:
|
||||
// await logout();
|
||||
// return false;
|
||||
// case LoginStatus.failed:
|
||||
// await logout();
|
||||
// return false;
|
||||
// default:
|
||||
// await logout();
|
||||
// return false;
|
||||
// }
|
||||
// } catch (e) {
|
||||
// await logout();
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
Future logout() async {
|
||||
try {
|
||||
if (googleSignIn.currentUser != null) {
|
||||
await googleSignIn.disconnect();
|
||||
} // else if (await FacebookAuth.instance.accessToken != null) {
|
||||
// await FacebookAuth.instance.logOut();
|
||||
// }
|
||||
} finally {
|
||||
FirebaseAuth.instance.signOut();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
19
lib/providers/forgot_password_provider.dart
Normal file
19
lib/providers/forgot_password_provider.dart
Normal file
@ -0,0 +1,19 @@
|
||||
import 'package:initial_folder/services/forgot_password_service.dart';
|
||||
|
||||
import '../models/forgot_password_model.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class ForgotPasswordProvider extends ChangeNotifier {
|
||||
final ForgotService _apiService = ForgotService();
|
||||
ForgotPasswordModel? _forgotPasswordModel;
|
||||
ForgotPasswordModel? get forgotPasswordModel => _forgotPasswordModel;
|
||||
|
||||
Future<void> forgotPassword(String email) async {
|
||||
try {
|
||||
_forgotPasswordModel = await _apiService.forgotPassword(email: email);
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
84
lib/providers/history_transactions_provider.dart
Normal file
84
lib/providers/history_transactions_provider.dart
Normal file
@ -0,0 +1,84 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:initial_folder/models/history_transaction_model.dart';
|
||||
import 'package:initial_folder/services/history_transactions_service.dart';
|
||||
|
||||
enum ResultState { loading, noData, hasData, error }
|
||||
|
||||
class HistoryTranscationsProvider with ChangeNotifier {
|
||||
HistoryTranscationsProvider({required this.historyTransactionService}) {
|
||||
getHistoryTransaction();
|
||||
}
|
||||
|
||||
final HistoryTransactionService historyTransactionService;
|
||||
|
||||
ResultState? _state;
|
||||
String _message = '';
|
||||
List<HistoryTransactionModel>? _historyTransactionsModel;
|
||||
List<HistoryTransactionModel>? get historyPayment {
|
||||
return _historyTransactionsModel == null
|
||||
? []
|
||||
: _historyTransactionsModel!
|
||||
.where((element) => element.statusPayment != '2')
|
||||
.toList();
|
||||
}
|
||||
|
||||
List<HistoryTransactionModel>? get paymentPending {
|
||||
return _historyTransactionsModel == null
|
||||
? []
|
||||
: _historyTransactionsModel!
|
||||
.where((element) => element.statusPayment == '2')
|
||||
.toList();
|
||||
}
|
||||
|
||||
// transaksi dengan status "-5"
|
||||
List<HistoryTransactionModel>? get paymentAwaitingMethod {
|
||||
return _historyTransactionsModel == null
|
||||
? []
|
||||
: _historyTransactionsModel!
|
||||
.where((element) => element.statusPayment == '-5')
|
||||
.toList();
|
||||
}
|
||||
|
||||
ResultState? get state => _state;
|
||||
String get message => _message;
|
||||
|
||||
set histtoryTranscation(List<HistoryTransactionModel> historyTr) {
|
||||
_historyTransactionsModel = historyTr;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Stream<List<HistoryTransactionModel>> getHistoryTransactionStream() async* {
|
||||
while (true) {
|
||||
List<HistoryTransactionModel>? response =
|
||||
await historyTransactionService.historyTransactions();
|
||||
|
||||
if (response.isNotEmpty) {
|
||||
yield response
|
||||
.where((transaction) => transaction.statusPayment == '2')
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> getHistoryTransaction() async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
List<HistoryTransactionModel>? response =
|
||||
await historyTransactionService.historyTransactions();
|
||||
if (response.isEmpty) {
|
||||
_state = ResultState.noData;
|
||||
notifyListeners();
|
||||
return _message = 'Tidak Ada data';
|
||||
} else {
|
||||
_state = ResultState.hasData;
|
||||
notifyListeners();
|
||||
return _historyTransactionsModel = response;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.error;
|
||||
notifyListeners();
|
||||
return _message = 'Data transaksi gagal diambil';
|
||||
}
|
||||
}
|
||||
}
|
93
lib/providers/incomplete_profile_provider.dart
Normal file
93
lib/providers/incomplete_profile_provider.dart
Normal file
@ -0,0 +1,93 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/update_incomplete_profile_model.dart';
|
||||
import 'package:initial_folder/models/user_info_incomplete_model.dart';
|
||||
import 'package:initial_folder/services/user_info_service.dart';
|
||||
|
||||
enum ResultState { Loading, Success, NoData, HasData, Error }
|
||||
|
||||
class IncompleteProfileProvider with ChangeNotifier {
|
||||
final UserInfoService userInfoService;
|
||||
|
||||
IncompleteProfileProvider({
|
||||
required this.userInfoService,
|
||||
});
|
||||
|
||||
UpdateIncompleteProfileModel? _updateIncompleteProfileModel;
|
||||
UserInfoIncompleteModel? _userInfoIncompleteModel;
|
||||
ResultState? _state;
|
||||
bool? _isUserInfoComplete;
|
||||
String _message = '';
|
||||
|
||||
UpdateIncompleteProfileModel? get updateIncompleteProfileModel =>
|
||||
_updateIncompleteProfileModel;
|
||||
UserInfoIncompleteModel? get userInfoIncompleteModel =>
|
||||
_userInfoIncompleteModel;
|
||||
ResultState? get state => _state;
|
||||
bool? get isUserInfoComplete => _isUserInfoComplete;
|
||||
String get message => _message;
|
||||
|
||||
Future<bool> getUserInfoIncomplete() async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
UserInfoIncompleteModel userInfoIncomplete =
|
||||
await userInfoService.getUserInfoIncomplete();
|
||||
|
||||
if (userInfoIncomplete.data == null) {
|
||||
_state = ResultState.NoData;
|
||||
_isUserInfoComplete = null;
|
||||
notifyListeners();
|
||||
return false;
|
||||
} else {
|
||||
if (userInfoIncomplete.status == 202) {
|
||||
_isUserInfoComplete = false;
|
||||
} else if (userInfoIncomplete.status == 200) {
|
||||
_isUserInfoComplete = true;
|
||||
}
|
||||
notifyListeners();
|
||||
_userInfoIncompleteModel = userInfoIncomplete;
|
||||
return true;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
_message = 'Error --> $e';
|
||||
_userInfoIncompleteModel = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> updateIncompleteProfile({
|
||||
String? fullname,
|
||||
String? phone,
|
||||
String? email,
|
||||
String? newPassword,
|
||||
String? newConfirmPassword,
|
||||
}) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
_updateIncompleteProfileModel =
|
||||
await UserInfoService().updateIncompleteProfile(
|
||||
fullname: fullname,
|
||||
phone: phone,
|
||||
email: email,
|
||||
newPassword: newPassword,
|
||||
newConfirmPassword: newConfirmPassword,
|
||||
);
|
||||
if (_updateIncompleteProfileModel != null) {
|
||||
if (_updateIncompleteProfileModel!.status == 200) {
|
||||
_state = ResultState.Success;
|
||||
notifyListeners();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (e) {
|
||||
print("Exception: $e");
|
||||
_updateIncompleteProfileModel = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
45
lib/providers/instructor_provider.dart
Normal file
45
lib/providers/instructor_provider.dart
Normal file
@ -0,0 +1,45 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:initial_folder/models/instructor_model.dart';
|
||||
import 'package:initial_folder/services/instructor_service.dart';
|
||||
|
||||
enum ResultState { Loading, HasData, NoData, Error }
|
||||
|
||||
class InstructorProvider with ChangeNotifier {
|
||||
final InstructorService instructorService;
|
||||
final int id;
|
||||
InstructorProvider({required this.instructorService, required this.id}) {
|
||||
getProfileInstructor(id);
|
||||
}
|
||||
InstructorModel? _instructorModel;
|
||||
ResultState? _state;
|
||||
String _message = '';
|
||||
InstructorModel? get result => _instructorModel;
|
||||
ResultState? get state => _state;
|
||||
String get message => _message;
|
||||
set instruktur(InstructorModel instruktur) {
|
||||
_instructorModel = instruktur;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getProfileInstructor(_id) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
InstructorModel instruktur =
|
||||
await instructorService.getInstructorProfile(_id);
|
||||
if (instruktur.data.isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Tidak Ada Data';
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
notifyListeners();
|
||||
return _instructorModel = instruktur;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
50
lib/providers/latest_course_provider.dart
Normal file
50
lib/providers/latest_course_provider.dart
Normal file
@ -0,0 +1,50 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/course_model.dart';
|
||||
import 'package:initial_folder/services/course_service.dart';
|
||||
|
||||
enum ResultState { Loading, NoData, HasData, Error }
|
||||
|
||||
class LatestCourseProvider with ChangeNotifier {
|
||||
final CourseService courseService;
|
||||
LatestCourseProvider({required this.courseService}) {
|
||||
getLatestCourse();
|
||||
}
|
||||
|
||||
List<CourseModel> _course = [];
|
||||
|
||||
ResultState? _state;
|
||||
|
||||
String _message = '';
|
||||
|
||||
List<CourseModel> get result => _course;
|
||||
|
||||
ResultState? get state => _state;
|
||||
|
||||
String get message => _message;
|
||||
|
||||
set course(List<CourseModel> course) {
|
||||
_course = course;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getLatestCourse() async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
List<CourseModel> course = await courseService.getLatestCourse();
|
||||
if (course.isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
notifyListeners();
|
||||
return _course = course;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
109
lib/providers/lesson_course_provider.dart
Normal file
109
lib/providers/lesson_course_provider.dart
Normal file
@ -0,0 +1,109 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:initial_folder/models/lesson_course_model.dart';
|
||||
import 'package:initial_folder/models/section_model.dart';
|
||||
import 'package:initial_folder/services/lesson_course_service.dart';
|
||||
|
||||
enum ResultState { loading, hasData, noData, error }
|
||||
// enum ResultStateUpdate { uninitialized, loading, success, eror }
|
||||
|
||||
class LessonCourseProvider with ChangeNotifier {
|
||||
final LessonCourseService lessonCourseService;
|
||||
final int id;
|
||||
LessonCourseProvider({required this.lessonCourseService, required this.id}) {
|
||||
getLessonCourse(id);
|
||||
}
|
||||
|
||||
bool switchbutton = false;
|
||||
|
||||
LessonCourseModel? _lessonCourseModel;
|
||||
SectionModel? _sectionModel;
|
||||
ResultState? _state;
|
||||
// ResultStateUpdate _stateUpdate = ResultStateUpdate.uninitialized;
|
||||
String _message = '';
|
||||
|
||||
LessonCourseModel? get result => _lessonCourseModel;
|
||||
SectionModel? get sectionResult => _sectionModel;
|
||||
|
||||
ResultState? get state => _state;
|
||||
// ResultStateUpdate get stateUpdate => _stateUpdate;
|
||||
String get message => _message;
|
||||
|
||||
String _url = '';
|
||||
|
||||
String get url => _url;
|
||||
|
||||
set uri(String urlVideo) {
|
||||
_url = urlVideo;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
indexUri(String indexUri) {
|
||||
_url = indexUri;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set lessonCourse(LessonCourseModel lesson) {
|
||||
_lessonCourseModel = lesson;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set sectionCourse(SectionModel section) {
|
||||
_sectionModel = section;
|
||||
notifyListeners();
|
||||
}
|
||||
// set newMap(NewMap lesson) {
|
||||
// _newMap = lesson;
|
||||
// notifyListeners();
|
||||
// }
|
||||
|
||||
void autoplay() {
|
||||
switchbutton = !switchbutton;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getLessonCourse(int _id) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
LessonCourseModel lesson = await lessonCourseService.getLessonCourse(_id);
|
||||
SectionModel section = await lessonCourseService.getSectionCourse(_id);
|
||||
|
||||
if (lesson.data[0].isEmpty && section.data[0].isEmpty) {
|
||||
_state = ResultState.noData;
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
_state = ResultState.hasData;
|
||||
|
||||
notifyListeners();
|
||||
_sectionModel = section;
|
||||
return _lessonCourseModel = lesson;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.error;
|
||||
notifyListeners();
|
||||
print('masuk sini');
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> updateLessonCourse(String _courseId, String _lessonId) async {
|
||||
try {
|
||||
// _stateUpdate = ResultStateUpdate.loading;
|
||||
// notifyListeners();
|
||||
bool update = await lessonCourseService.updateLessonCourse(_lessonId);
|
||||
|
||||
if (update) {
|
||||
// _stateUpdate = ResultStateUpdate.success;
|
||||
// notifyListeners();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (e) {
|
||||
// _stateUpdate = ResultStateUpdate.eror;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
33
lib/providers/like_announcement.dart
Normal file
33
lib/providers/like_announcement.dart
Normal file
@ -0,0 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/services/announcement_service.dart';
|
||||
|
||||
enum ResultState { uninitilized, loading, failed, success }
|
||||
|
||||
class LikeOrAnnouncementProvider with ChangeNotifier {
|
||||
ResultState _state = ResultState.uninitilized;
|
||||
|
||||
ResultState get state => _state;
|
||||
|
||||
Future<bool> likeOrAnnouncement(String tokenAnnouncement) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
|
||||
bool response =
|
||||
await AnnouncementService().likeAnnouncement(tokenAnnouncement);
|
||||
if (response) {
|
||||
_state = ResultState.success;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
32
lib/providers/like_or_unlike_provider.dart
Normal file
32
lib/providers/like_or_unlike_provider.dart
Normal file
@ -0,0 +1,32 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/services/qna_service.dart';
|
||||
|
||||
enum ResultState { uninitilized, loading, failed, success }
|
||||
|
||||
class LikeOrUnlikeProvider with ChangeNotifier {
|
||||
ResultState _state = ResultState.uninitilized;
|
||||
|
||||
ResultState get state => _state;
|
||||
//Posting QNA
|
||||
Future<bool> likeOrUnlike(int idQna) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
|
||||
bool response = await QnaService().likeOrLike(idQna);
|
||||
if (response) {
|
||||
_state = ResultState.success;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
18
lib/providers/login_provider.dart
Normal file
18
lib/providers/login_provider.dart
Normal file
@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LoginProvider with ChangeNotifier {
|
||||
bool _loadGoogle = false;
|
||||
bool _loadFacebook = false;
|
||||
bool get loadGoogle => _loadGoogle;
|
||||
bool get loadFacebook => _loadFacebook;
|
||||
|
||||
loadGoogleActive(bool value) {
|
||||
_loadGoogle = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
loadFacebookActive(bool value) {
|
||||
_loadFacebook= value;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
14
lib/providers/metode_provider.dart
Normal file
14
lib/providers/metode_provider.dart
Normal file
@ -0,0 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
enum MetodePembayaran { kreditdebit, mandiri, bni, permata, lainnya, gopay }
|
||||
|
||||
class MetodeProvider with ChangeNotifier {
|
||||
MetodePembayaran? _character = MetodePembayaran.kreditdebit;
|
||||
|
||||
MetodePembayaran? get character => _character;
|
||||
|
||||
set character(MetodePembayaran? value) {
|
||||
_character = value;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
87
lib/providers/my_course_provider.dart
Normal file
87
lib/providers/my_course_provider.dart
Normal file
@ -0,0 +1,87 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/my_course_model.dart';
|
||||
import 'package:initial_folder/services/course_service.dart';
|
||||
|
||||
enum ResultState { Loading, NoData, HasData, Error }
|
||||
|
||||
enum SearchResultState { Loading, NoData, HasData, Error }
|
||||
|
||||
class MyCourseProvider with ChangeNotifier {
|
||||
final CourseService courseService;
|
||||
MyCourseProvider({required this.courseService}) {
|
||||
getMyCourse();
|
||||
}
|
||||
MyCourseModel? _myCourseModel;
|
||||
MyCourseModel? _searchCourseModel;
|
||||
ResultState? _state;
|
||||
SearchResultState? _searchResultState;
|
||||
String _message = '';
|
||||
|
||||
MyCourseModel? get result => _myCourseModel;
|
||||
MyCourseModel? get searchResult => _searchCourseModel;
|
||||
ResultState? get state => _state;
|
||||
SearchResultState? get searchResultState => _searchResultState;
|
||||
|
||||
String get message => _message;
|
||||
|
||||
set myCourse(MyCourseModel myCourse) {
|
||||
_myCourseModel = myCourse;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getMyCourse() async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
MyCourseModel myCourse = await courseService.getMyCourse();
|
||||
|
||||
if (myCourse.data[0].isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
notifyListeners();
|
||||
return _myCourseModel = myCourse;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
print('resultstate mycourse eror');
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> getSearchMyCourse(String courseName) async {
|
||||
try {
|
||||
_searchResultState = SearchResultState.Loading;
|
||||
|
||||
notifyListeners();
|
||||
MyCourseModel myCourse =
|
||||
await courseService.getSearchMyCourse(courseName);
|
||||
if (myCourse.data[0].isEmpty) {
|
||||
_searchResultState = SearchResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
_searchResultState = SearchResultState.HasData;
|
||||
notifyListeners();
|
||||
|
||||
return _searchCourseModel = myCourse;
|
||||
}
|
||||
} catch (e) {
|
||||
_searchResultState = SearchResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
|
||||
clearSearch() {
|
||||
_searchResultState = null;
|
||||
Future.delayed(Duration(seconds: 2), () {
|
||||
if (_searchCourseModel != null && _searchCourseModel!.data.isNotEmpty) {
|
||||
_searchCourseModel!.data[0].clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
127
lib/providers/notification_provider.dart
Normal file
127
lib/providers/notification_provider.dart
Normal file
@ -0,0 +1,127 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:initial_folder/models/notification.dart';
|
||||
import 'package:initial_folder/services/notification_service.dart';
|
||||
|
||||
enum resultState { Loading, NoData, HasData, Error }
|
||||
|
||||
enum countState { Loading, NoData, HasData, Error }
|
||||
|
||||
class NotificationProvider with ChangeNotifier {
|
||||
final NotificationServices notificationServices;
|
||||
NotificationProvider({required this.notificationServices}) {
|
||||
getMyNotification();
|
||||
}
|
||||
|
||||
List<NotificationData> _notificationData = [];
|
||||
List<NotificationDataAnnouncementUser> _notificationDataAnnouncementUser = [];
|
||||
|
||||
resultState? _state;
|
||||
countState? _cState;
|
||||
|
||||
int _notificationCount = 0;
|
||||
String _message = '';
|
||||
|
||||
List<NotificationData> get result => _notificationData;
|
||||
List<NotificationDataAnnouncementUser> get resultAnnouncement =>
|
||||
_notificationDataAnnouncementUser;
|
||||
|
||||
int get notificationCount => _notificationCount;
|
||||
String get message => _message;
|
||||
|
||||
resultState? get state => _state;
|
||||
countState? get cState => _cState;
|
||||
|
||||
changeIsRead(List<NotificationData> list, int index) {
|
||||
list[index].isRead = "1";
|
||||
if (_notificationCount > 0) {
|
||||
_notificationCount--;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
changeAllRead() {
|
||||
if (_state == resultState.HasData) {
|
||||
for (final notif in _notificationData) {
|
||||
notif.isRead = "1";
|
||||
}
|
||||
_notificationCount = 0;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> getMyNotification() async {
|
||||
try {
|
||||
_state = resultState.Loading;
|
||||
notifyListeners();
|
||||
var notifications = await notificationServices.getNotification();
|
||||
List<NotificationData> myNotification = notifications[0];
|
||||
List<NotificationDataAnnouncementUser> myNotificationAnnouncement =
|
||||
notifications[1];
|
||||
|
||||
if (myNotification.isEmpty && myNotificationAnnouncement.isEmpty) {
|
||||
_state = resultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
_state = resultState.HasData;
|
||||
_notificationData = myNotification;
|
||||
_notificationDataAnnouncementUser = myNotificationAnnouncement;
|
||||
_notificationData
|
||||
.sort((a, b) => b.timestamps!.compareTo(a.timestamps!));
|
||||
_notificationDataAnnouncementUser
|
||||
.sort((a, b) => b.timestamps!.compareTo(a.timestamps!));
|
||||
_notificationCount =
|
||||
_notificationData.where((notif) => notif.isRead == "0").length;
|
||||
notifyListeners();
|
||||
return [_notificationData, _notificationDataAnnouncementUser];
|
||||
}
|
||||
} catch (e, stacktrace) {
|
||||
print(stacktrace.toString());
|
||||
_state = resultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
|
||||
Future markAsRead() async {
|
||||
try {
|
||||
await notificationServices.readAllNotification();
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print("Error: --> $e");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future getNotificationCount() async {
|
||||
try {
|
||||
_cState = countState.Loading;
|
||||
notifyListeners();
|
||||
|
||||
int notificationCount =
|
||||
_notificationData.where((notif) => notif.isRead == "0").length;
|
||||
if (notificationCount == 0) {
|
||||
_cState = countState.NoData;
|
||||
_notificationCount = 0;
|
||||
notifyListeners();
|
||||
} else {
|
||||
_cState = countState.HasData;
|
||||
_notificationCount = notificationCount;
|
||||
notifyListeners();
|
||||
}
|
||||
} catch (e) {
|
||||
_cState = countState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
|
||||
decreaseNotificationCount() {
|
||||
if (_notificationCount > 0) {
|
||||
_notificationCount--;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
118
lib/providers/order_provider.dart
Normal file
118
lib/providers/order_provider.dart
Normal file
@ -0,0 +1,118 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:initial_folder/models/order_model.dart';
|
||||
|
||||
enum ResultState { loading, succes, failed }
|
||||
|
||||
class OrderProvider with ChangeNotifier {
|
||||
ResultState? _state;
|
||||
ResultState? get state => _state;
|
||||
|
||||
String? _totalPrice;
|
||||
String? _discountPrice;
|
||||
String? _idCourse;
|
||||
String? _thumbnail;
|
||||
String? _title;
|
||||
String? _instructor;
|
||||
|
||||
String? get totalPrice => _totalPrice;
|
||||
String? get discountPrice => _discountPrice;
|
||||
String? get idCourse => _idCourse;
|
||||
String? get thumbnail => _thumbnail;
|
||||
String? get title => _title;
|
||||
String? get instructor => _instructor;
|
||||
|
||||
set selectedThumbnail(String value) {
|
||||
_thumbnail = value;
|
||||
}
|
||||
|
||||
set selectedTitle(String value) {
|
||||
_title = value;
|
||||
}
|
||||
|
||||
set selectedInstructor(String value) {
|
||||
_instructor = value;
|
||||
}
|
||||
|
||||
void getTotalPrice(String total) {
|
||||
_totalPrice = total;
|
||||
}
|
||||
|
||||
void getdiscountPrice(String discountPrice) {
|
||||
_discountPrice = discountPrice;
|
||||
}
|
||||
|
||||
void getIdCourse(String idCourse) {
|
||||
_idCourse = idCourse;
|
||||
}
|
||||
|
||||
List<OrderModel> _orders = [];
|
||||
List<OrderModel> get orders => _orders;
|
||||
|
||||
List<Map<String, String>> _invoice = [];
|
||||
List<Map<String, String>> get invoice => _invoice;
|
||||
|
||||
void addOrder({
|
||||
String? id,
|
||||
String? title,
|
||||
String? price,
|
||||
String? imageUrl,
|
||||
String? discountPrice,
|
||||
String? instructor,
|
||||
}) {
|
||||
_orders.add(
|
||||
OrderModel(
|
||||
idCourse: id as String,
|
||||
title: title as String,
|
||||
price: price as String,
|
||||
instructor: instructor as String,
|
||||
imageUrl: imageUrl!,
|
||||
discountPrice: discountPrice as String,
|
||||
),
|
||||
);
|
||||
_invoice.add({
|
||||
"id_kursus": id,
|
||||
"title_kursus": title,
|
||||
"qty": "1",
|
||||
"harga": discountPrice == "0" ? price : discountPrice
|
||||
});
|
||||
}
|
||||
|
||||
void removeOrder(
|
||||
{String? id,
|
||||
String? title,
|
||||
String? price,
|
||||
String? imageUrl,
|
||||
String? discountPrice,
|
||||
String? instructor}) {
|
||||
_orders.remove(OrderModel(
|
||||
idCourse: id ?? '',
|
||||
title: title ?? '',
|
||||
price: price ?? '',
|
||||
instructor: instructor ?? '',
|
||||
imageUrl: imageUrl ?? '',
|
||||
discountPrice: discountPrice ?? '',
|
||||
));
|
||||
_invoice.remove({
|
||||
"id_kursus": id ?? '',
|
||||
"title_kursus": title ?? '',
|
||||
"qty": "1",
|
||||
"harga": (discountPrice == "0" || discountPrice == null)
|
||||
? price
|
||||
: discountPrice
|
||||
});
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_orders = [];
|
||||
_invoice = [];
|
||||
}
|
||||
|
||||
// void addInvoice({
|
||||
// required String id,
|
||||
// required String title,
|
||||
// required String price,
|
||||
// }) {
|
||||
// _invoice.add(
|
||||
// {"id_kursus": id, "title_kursus": title, "qty": "1", "harga": price});
|
||||
// }
|
||||
}
|
75
lib/providers/others_course_provider.dart
Normal file
75
lib/providers/others_course_provider.dart
Normal file
@ -0,0 +1,75 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/course_model.dart';
|
||||
import 'package:initial_folder/services/course_service.dart';
|
||||
|
||||
enum ResultState { Loading, NoData, HasData, Error }
|
||||
|
||||
class OthersCourseProvider with ChangeNotifier {
|
||||
final CourseService otherCourseService;
|
||||
OthersCourseProvider({required this.otherCourseService}) {
|
||||
getOthersCourse();
|
||||
}
|
||||
List<CourseModel> _othersCourse = [];
|
||||
|
||||
ResultState? _state;
|
||||
|
||||
String _message = '';
|
||||
|
||||
List<CourseModel> get result => _othersCourse;
|
||||
|
||||
ResultState? get state => _state;
|
||||
|
||||
String get message => _message;
|
||||
int _page = 1;
|
||||
int get page => _page;
|
||||
bool _loading = true;
|
||||
bool get loading => _loading;
|
||||
set course(List<CourseModel> course) {
|
||||
_othersCourse = course;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getOthersCourse() async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
List<CourseModel> course =
|
||||
await otherCourseService.getOthersCourse(_page);
|
||||
|
||||
if (course.isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
course.shuffle();
|
||||
_state = ResultState.HasData;
|
||||
notifyListeners();
|
||||
return _othersCourse = course;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> getOthersCourses() async {
|
||||
try {
|
||||
List<CourseModel> res =
|
||||
await otherCourseService.getOthersCourse(_page + 1);
|
||||
if (res.isNotEmpty) {
|
||||
res.shuffle();
|
||||
_page += 1;
|
||||
notifyListeners();
|
||||
return _othersCourse.addAll(res);
|
||||
} else {
|
||||
_loading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
16
lib/providers/page_provider.dart
Normal file
16
lib/providers/page_provider.dart
Normal file
@ -0,0 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PageProvider with ChangeNotifier {
|
||||
int _currentIndex = 0;
|
||||
|
||||
int get currentIndex => _currentIndex;
|
||||
|
||||
set currentIndex(int index) {
|
||||
_currentIndex = index;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
remove() {
|
||||
_currentIndex = 0;
|
||||
}
|
||||
}
|
167
lib/providers/payments_provider.dart
Normal file
167
lib/providers/payments_provider.dart
Normal file
@ -0,0 +1,167 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/detail_order_model.dart';
|
||||
import 'package:initial_folder/models/detail_order_model_underscore.dart';
|
||||
import 'package:initial_folder/models/zero_price_model.dart';
|
||||
import 'package:initial_folder/services/payment_service.dart';
|
||||
|
||||
import '../screens/checkout/snap_payment_page.dart';
|
||||
|
||||
enum ResultState { error, success, gagal, loading }
|
||||
|
||||
enum Process { uninitialized, loading }
|
||||
|
||||
class PaymentsProvider with ChangeNotifier {
|
||||
PaymentsProvider({required this.paymentServices});
|
||||
final PaymentServices paymentServices;
|
||||
|
||||
ResultState? _state;
|
||||
Process _stateProcess = Process.uninitialized;
|
||||
bool _paymentModel = false;
|
||||
ZeroPrice? _zeroPrice;
|
||||
String? _idOrders;
|
||||
List<DetailOrderModel> _detailOrder = [];
|
||||
List<DetailOrderModelUnderscore> _detailOrderUnderscore = [];
|
||||
|
||||
ResultState? get state => _state;
|
||||
Process get stateProcess => _stateProcess;
|
||||
bool get result => _paymentModel;
|
||||
String? get idOrders => _idOrders;
|
||||
ZeroPrice? get zeroPrice => _zeroPrice;
|
||||
List<DetailOrderModel> get detailOrder => _detailOrder;
|
||||
List<DetailOrderModelUnderscore> get detailOrderUnderscore => _detailOrderUnderscore;
|
||||
|
||||
String get orderId {
|
||||
if (_detailOrder.isNotEmpty) {
|
||||
return _detailOrder[0].idOrder;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
set selectedIdOrders(String value) {
|
||||
_idOrders = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// mulai Snap Payment
|
||||
Future<Map<String, String>?> startSnapPayment({
|
||||
required String orderId,
|
||||
required int grossAmount,
|
||||
required List<Map<String, dynamic>> dataInvoice,
|
||||
}) async {
|
||||
try {
|
||||
_stateProcess = Process.loading;
|
||||
notifyListeners();
|
||||
|
||||
Map<String, String> transactionToken = await paymentServices.getSnapTransactionToken(
|
||||
orderId: orderId,
|
||||
grossAmount: grossAmount,
|
||||
dataInvoice: dataInvoice,
|
||||
);
|
||||
|
||||
if (transactionToken.isNotEmpty) {
|
||||
_stateProcess = Process.uninitialized;
|
||||
_state = ResultState.success;
|
||||
print('Transaction token didapatkan: $transactionToken');
|
||||
notifyListeners();
|
||||
return transactionToken;
|
||||
} else {
|
||||
_state = ResultState.gagal;
|
||||
_stateProcess = Process.uninitialized;
|
||||
notifyListeners();
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error Snap Payment -> $e');
|
||||
_state = ResultState.error;
|
||||
_stateProcess = Process.uninitialized;
|
||||
notifyListeners();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, String>> getSnapTransactionToken({
|
||||
required String orderId,
|
||||
required int grossAmount,
|
||||
required List<Map<String, dynamic>> dataInvoice,
|
||||
}) async {
|
||||
return await paymentServices.getSnapTransactionToken(
|
||||
orderId: orderId,
|
||||
grossAmount: grossAmount,
|
||||
dataInvoice: dataInvoice,
|
||||
);
|
||||
}
|
||||
|
||||
// kursus gratis
|
||||
Future<bool> freeCourse(int _idCourse) async {
|
||||
try {
|
||||
_stateProcess = Process.loading;
|
||||
notifyListeners();
|
||||
bool result = await paymentServices.freeCoure(_idCourse);
|
||||
if (result) {
|
||||
_stateProcess = Process.uninitialized;
|
||||
_state = ResultState.success;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_state = ResultState.gagal;
|
||||
_stateProcess = Process.uninitialized;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error -> $e');
|
||||
_state = ResultState.error;
|
||||
_stateProcess = Process.uninitialized;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// kursus dengan kupon gratis
|
||||
Future<bool> freeCourseCoupon(int _idCourse, String coupon) async {
|
||||
try {
|
||||
_stateProcess = Process.loading;
|
||||
notifyListeners();
|
||||
bool result = await paymentServices.freeCoureCoupon(_idCourse, coupon);
|
||||
if (result) {
|
||||
_stateProcess = Process.uninitialized;
|
||||
_state = ResultState.success;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_state = ResultState.gagal;
|
||||
_stateProcess = Process.uninitialized;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error -> $e');
|
||||
_state = ResultState.error;
|
||||
_stateProcess = Process.uninitialized;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//pembayaran dengan harga 0 (ZeroPrice)
|
||||
Future<dynamic> zeroPayment(List<Map<String, String>> dataInvoice, String totalPayment) async {
|
||||
try {
|
||||
notifyListeners();
|
||||
var result = await paymentServices.zeroPayment(
|
||||
dataInvoice: dataInvoice, totalPayment: totalPayment);
|
||||
if (result.isNotEmpty) {
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error -> $e');
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
17
lib/providers/play_video_course_provider.dart
Normal file
17
lib/providers/play_video_course_provider.dart
Normal file
@ -0,0 +1,17 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class PlayVideoCourseProvider with ChangeNotifier {
|
||||
String _url = '';
|
||||
|
||||
String get url => _url;
|
||||
|
||||
set uri(String videoUrl) {
|
||||
_url = videoUrl;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
indexUri(String indexUri) {
|
||||
_url = indexUri;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
34
lib/providers/posting_announcement_reply_provider.dart
Normal file
34
lib/providers/posting_announcement_reply_provider.dart
Normal file
@ -0,0 +1,34 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:initial_folder/services/announcement_service.dart';
|
||||
|
||||
enum ResultState { uninitilized, loading, failed, success }
|
||||
|
||||
class PostingAnnouncementReplyProvider with ChangeNotifier {
|
||||
ResultState _state = ResultState.uninitilized;
|
||||
|
||||
ResultState get state => _state;
|
||||
|
||||
Future<bool> postAnnouncementReply(String textBody, String idAnnouncmenet,
|
||||
String tokenAnnouncement, String idAnnouncement) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
|
||||
bool response = await AnnouncementService()
|
||||
.replyAnnouncement(tokenAnnouncement, textBody, idAnnouncement);
|
||||
if (response) {
|
||||
_state = ResultState.success;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
94
lib/providers/posting_qna_provider.dart
Normal file
94
lib/providers/posting_qna_provider.dart
Normal file
@ -0,0 +1,94 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/qna_model.dart';
|
||||
import 'package:initial_folder/services/qna_service.dart';
|
||||
|
||||
enum ResultState { uninitilized, loading, failed, success }
|
||||
|
||||
class PostingQnaProvider with ChangeNotifier {
|
||||
QnaDataModel? _qnaDataModel;
|
||||
QnaDataModel? get wishlistPostModel => _qnaDataModel;
|
||||
|
||||
setwishlistPostModel(QnaDataModel? qnaDataModel) {
|
||||
_qnaDataModel = qnaDataModel;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
ResultState _state = ResultState.uninitilized;
|
||||
|
||||
ResultState get state => _state;
|
||||
|
||||
//Posting QNA
|
||||
Future<bool> postingQna(
|
||||
String title,
|
||||
String quest,
|
||||
String idCourse,
|
||||
String idLesson,
|
||||
) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
|
||||
bool response =
|
||||
await QnaService().postingQna(title, quest, idCourse, idLesson);
|
||||
if (response) {
|
||||
_state = ResultState.success;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Update QNA
|
||||
Future<bool> editQna(String idCourse, String quest, int idQna, String title, String idLesson) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
|
||||
bool response = await QnaService().updateQna(idCourse, quest, idQna, title, idLesson);
|
||||
if (response) {
|
||||
_state = ResultState.success;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Delete QNA
|
||||
Future<bool> deleteQna(int idQna) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
|
||||
bool response = await QnaService().deleteQna(idQna);
|
||||
if (response) {
|
||||
_state = ResultState.success;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
79
lib/providers/posting_qna_reply_provider.dart
Normal file
79
lib/providers/posting_qna_reply_provider.dart
Normal file
@ -0,0 +1,79 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/services/qna_service.dart';
|
||||
|
||||
enum ResultState { uninitilized, loading, failed, success }
|
||||
|
||||
class PostingQnaReplyProvider with ChangeNotifier {
|
||||
ResultState _state = ResultState.uninitilized;
|
||||
|
||||
ResultState get state => _state;
|
||||
|
||||
//Post Qna Reply
|
||||
Future<bool> postQnaReply(String textRep, String idQna) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
|
||||
bool response = await QnaService().postQnaReply(textRep, idQna);
|
||||
if (response) {
|
||||
_state = ResultState.success;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Update QNA Reply
|
||||
Future<bool> editQnaReply(String textRep, int idRep, String idQna) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
|
||||
bool response = await QnaService().editQnaReply(idRep, textRep, idQna);
|
||||
if (response) {
|
||||
_state = ResultState.success;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete Qna Reply
|
||||
Future<bool> deleteReplyQna(int idRep) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
|
||||
bool response = await QnaService().deleteReplyQna(idRep);
|
||||
if (response) {
|
||||
_state = ResultState.success;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
41
lib/providers/posting_review_provider.dart
Normal file
41
lib/providers/posting_review_provider.dart
Normal file
@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/services/course_service.dart';
|
||||
|
||||
enum ResultState { uninitilized, loading, failed, successAdd, successUpdate }
|
||||
|
||||
class PostingReviewProvider with ChangeNotifier {
|
||||
final CourseService courseService;
|
||||
|
||||
PostingReviewProvider({required this.courseService});
|
||||
|
||||
ResultState _state = ResultState.uninitilized;
|
||||
|
||||
ResultState get state => _state;
|
||||
|
||||
Future<bool> postingReview(
|
||||
String _review, int _courseId, int _valueRating) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
List response = await courseService.postingReviewCourse(
|
||||
_review, _courseId, _valueRating);
|
||||
if (response[0] == true && response[1] == 201) {
|
||||
_state = ResultState.successAdd;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else if (response[0] == true && response[1] == 200) {
|
||||
_state = ResultState.successUpdate;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
34
lib/providers/profile_image_provider.dart
Normal file
34
lib/providers/profile_image_provider.dart
Normal file
@ -0,0 +1,34 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/profile_image_post_model.dart';
|
||||
import 'package:initial_folder/services/profile_image_service.dart';
|
||||
|
||||
class ProfileImageProvider with ChangeNotifier {
|
||||
ProfileImagePostModel? _imageModel;
|
||||
File? _imageFile;
|
||||
|
||||
ProfileImagePostModel? get imageModel => _imageModel;
|
||||
File? get imageFile => _imageFile;
|
||||
|
||||
set imageModel(ProfileImagePostModel? _imageModel) {
|
||||
_imageModel = imageModel;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setImageFile(File? file) {
|
||||
_imageFile = file;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<bool> addProfileImage({required File pckFile}) async {
|
||||
try {
|
||||
ProfileImagePostModel? imageModel =
|
||||
await ProfileImageService().addProfileImage(pckFile: pckFile);
|
||||
_imageModel = imageModel;
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
12
lib/providers/profile_provider.dart
Normal file
12
lib/providers/profile_provider.dart
Normal file
@ -0,0 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ProfileProvider with ChangeNotifier {
|
||||
int _currentIndex = 0;
|
||||
|
||||
int get currentIndex => _currentIndex;
|
||||
|
||||
set currentIndex(int index) {
|
||||
_currentIndex = index;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
51
lib/providers/promo_course_provider.dart
Normal file
51
lib/providers/promo_course_provider.dart
Normal file
@ -0,0 +1,51 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/course_model.dart';
|
||||
import 'package:initial_folder/services/course_service.dart';
|
||||
|
||||
enum ResultState { Loading, NoData, HasData, Error }
|
||||
|
||||
class PromoCourseProvider with ChangeNotifier {
|
||||
final CourseService courseService;
|
||||
PromoCourseProvider({required this.courseService}) {
|
||||
getPromoCourse();
|
||||
}
|
||||
|
||||
List<CourseModel> _course = [];
|
||||
|
||||
ResultState? _state;
|
||||
|
||||
String _message = '';
|
||||
|
||||
List<CourseModel> get result => _course;
|
||||
|
||||
ResultState? get state => _state;
|
||||
|
||||
String get message => _message;
|
||||
|
||||
set course(List<CourseModel> course) {
|
||||
_course = course;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getPromoCourse() async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
List<CourseModel> course = await courseService.getPromoCourse();
|
||||
if (course.isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
print("Tidak ada data promo dri api");
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
notifyListeners();
|
||||
return _course = course;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
50
lib/providers/qna_provider.dart
Normal file
50
lib/providers/qna_provider.dart
Normal file
@ -0,0 +1,50 @@
|
||||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/qna_model.dart';
|
||||
import 'package:initial_folder/services/qna_service.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
enum ResultState { loading, noData, hasData, error }
|
||||
|
||||
enum ResultStateLike { loading, error }
|
||||
|
||||
class QnaProvider with ChangeNotifier {
|
||||
final _service = QnaService();
|
||||
StreamController<QnaModel> streamController = BehaviorSubject();
|
||||
String _message = '';
|
||||
String get message => _message;
|
||||
ResultState? _state;
|
||||
ResultState? get state => _state;
|
||||
QnaModel? _qnaModel;
|
||||
QnaModel? get result => _qnaModel;
|
||||
set qnaModel(QnaModel? qnaModel) {
|
||||
_qnaModel = qnaModel;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Stream<QnaModel> get qnaStream {
|
||||
return streamController.stream;
|
||||
}
|
||||
|
||||
//Get QNA
|
||||
Future<void> getQna(String idCourse) async {
|
||||
try {
|
||||
QnaModel qnaModel = await _service.getMyQna(idCourse);
|
||||
if (qnaModel.error == true && qnaModel.status == 404) {
|
||||
// Jika respons adalah 404 (tidak ditemukan), tangani objek dummy di sini
|
||||
// Misalnya, menampilkan pesan kepada pengguna bahwa tidak ada data yang ditemukan
|
||||
// Atau menampilkan UI yang sesuai
|
||||
print('masuk rerror dsiinii');
|
||||
streamController.add(qnaModel);
|
||||
} else {
|
||||
// Jika respons adalah 200 (berhasil), tambahkan data ke dalam stream
|
||||
streamController.add(qnaModel);
|
||||
}
|
||||
} catch (error) {
|
||||
// Tangani jenis error lain jika diperlukan
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
103
lib/providers/radeem_voucher_provider.dart
Normal file
103
lib/providers/radeem_voucher_provider.dart
Normal file
@ -0,0 +1,103 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/voucher_model.dart';
|
||||
import 'package:initial_folder/services/voucher_service.dart';
|
||||
|
||||
enum ResultState { loading, failed, success, empty }
|
||||
|
||||
class RadeemVoucherProvider with ChangeNotifier {
|
||||
ResultState _state = ResultState.loading;
|
||||
String? _message;
|
||||
String? _messageCart;
|
||||
String? _messageCancel;
|
||||
|
||||
ResultState get state => _state;
|
||||
String? get message => _message;
|
||||
String? get messageCart => _messageCart;
|
||||
String? get messageCancel => _messageCancel;
|
||||
|
||||
VoucherModel? _detailKupon;
|
||||
|
||||
VoucherModel? get result => _detailKupon;
|
||||
|
||||
set detailKupon(VoucherModel? detail) {
|
||||
_detailKupon = detail;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void clearState() {
|
||||
_state = ResultState.empty;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> radeemVoucher(int? idCourse, String voucher) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
|
||||
VoucherModel? response =
|
||||
await VoucherService().radeemVoucher(idCourse, voucher);
|
||||
if (response.status == 200) {
|
||||
_state = ResultState.success;
|
||||
print("Berhasil kupon di provider ${_detailKupon}");
|
||||
notifyListeners();
|
||||
return _detailKupon = response;
|
||||
// notifyListeners();
|
||||
} else {
|
||||
_state = ResultState.failed;
|
||||
print("Gagal kupon di provider 1 ${_detailKupon}");
|
||||
notifyListeners();
|
||||
return _detailKupon = response;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.failed;
|
||||
print("Gagal kupon di provider ${e}");
|
||||
_message = 'Error --> $e';
|
||||
notifyListeners();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future redeemVoucherCart(List<String> idCourse, String voucher) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
|
||||
VoucherModel response =
|
||||
await VoucherService().redeemVoucherCart(idCourse, voucher);
|
||||
if (response.status == 200) {
|
||||
_state = ResultState.success;
|
||||
|
||||
notifyListeners();
|
||||
return true;
|
||||
// notifyListeners();
|
||||
} else {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> deleteCoupon(_coupon) async {
|
||||
try {
|
||||
VoucherModel deleteCoupon = await VoucherService().cancelCoupon(_coupon);
|
||||
if (deleteCoupon.status == 200) {
|
||||
_state = ResultState.success;
|
||||
notifyListeners();
|
||||
|
||||
notifyListeners();
|
||||
} else if (deleteCoupon.status == 404) {
|
||||
_state = ResultState.failed;
|
||||
notifyListeners();
|
||||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
print("Exceptions: $e");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
15
lib/providers/registrasi_google_provider.dart
Normal file
15
lib/providers/registrasi_google_provider.dart
Normal file
@ -0,0 +1,15 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class RegistrasiGoogleProvider extends ChangeNotifier {
|
||||
String? _name;
|
||||
String? _email;
|
||||
|
||||
String? get name => _name;
|
||||
String? get email => _email;
|
||||
|
||||
void setNameAndEmail(String name, String email) {
|
||||
_name = name;
|
||||
_email = email;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
40
lib/providers/reply_announcement_provider.dart
Normal file
40
lib/providers/reply_announcement_provider.dart
Normal file
@ -0,0 +1,40 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:initial_folder/models/announcement_model.dart';
|
||||
import 'package:initial_folder/services/announcement_service.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
enum DataState { loading, noData, hasData, error }
|
||||
|
||||
enum ResultStateLike { loading, error }
|
||||
|
||||
class ReplyAnnouncementProvider with ChangeNotifier {
|
||||
final _service = AnnouncementService();
|
||||
|
||||
StreamController<AnnouncementModel> streamController = BehaviorSubject();
|
||||
|
||||
String _message = '';
|
||||
String get message => _message;
|
||||
|
||||
DataState? _state;
|
||||
DataState? get state => _state;
|
||||
|
||||
AnnouncementModel? _announcementModel;
|
||||
AnnouncementModel? get result => _announcementModel;
|
||||
|
||||
set announcementModel(AnnouncementModel? announcementModel) {
|
||||
_announcementModel = announcementModel;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Stream<AnnouncementModel> get replyAnnouncementStream {
|
||||
return streamController.stream;
|
||||
}
|
||||
|
||||
Future<void> getReplyAnnouncement(String idCourse, int index) async {
|
||||
AnnouncementModel announcementModel =
|
||||
await _service.getAnnouncement(idCourse);
|
||||
streamController.add(announcementModel);
|
||||
}
|
||||
}
|
65
lib/providers/reply_qna_provider.dart
Normal file
65
lib/providers/reply_qna_provider.dart
Normal file
@ -0,0 +1,65 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/qna_model.dart';
|
||||
import 'package:initial_folder/services/qna_service.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
enum DataState { loading, noData, hasData, error }
|
||||
enum ResultStateLike { loading, error }
|
||||
|
||||
class ReplyQnaProvider with ChangeNotifier {
|
||||
final _service = QnaService();
|
||||
StreamController<QnaModel> streamController = BehaviorSubject();
|
||||
String _message = '';
|
||||
String get message => _message;
|
||||
DataState? _state;
|
||||
DataState? get state => _state;
|
||||
QnaModel? _qnaModel;
|
||||
QnaModel? get result => _qnaModel;
|
||||
|
||||
set qnaModel(QnaModel? qnaModel) {
|
||||
_qnaModel = qnaModel;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Stream<QnaModel> get replyQnaStream {
|
||||
return streamController.stream;
|
||||
}
|
||||
|
||||
Future<void> getReplyQna(String idCourse, int index) async {
|
||||
QnaModel qnaModel = await _service.getMyQna(idCourse);
|
||||
streamController.add(qnaModel);
|
||||
}
|
||||
|
||||
Future<void> getReplyQnaById(String idCourse, String idQna) async {
|
||||
try {
|
||||
_state = DataState.loading;
|
||||
QnaModel qnaModel = await _service.getMyQna(idCourse);
|
||||
|
||||
// Filter untuk mencari item dengan idQna yang sesuai dalam List<List<QnaDataModel>>
|
||||
var filteredQna = qnaModel.data.expand((innerList) => innerList)
|
||||
.where((qna) => qna.idQna == idQna).toList();
|
||||
|
||||
if (filteredQna.isNotEmpty) {
|
||||
// Set data yang sudah terfilter ke dalam streamController
|
||||
streamController.add(QnaModel(data: [filteredQna]));
|
||||
_state = DataState.hasData;
|
||||
} else {
|
||||
// Jika tidak ada data, set status noData
|
||||
_state = DataState.noData;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = DataState.error;
|
||||
_message = "Terjadi kesalahan saat mengambil data balasan.";
|
||||
streamController.addError(_message);
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
streamController.close();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
29
lib/providers/reset_provider.dart
Normal file
29
lib/providers/reset_provider.dart
Normal file
@ -0,0 +1,29 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/reset_model.dart';
|
||||
import 'package:initial_folder/services/reset_service.dart';
|
||||
|
||||
class ResetProvider with ChangeNotifier {
|
||||
ResetModel? _reset;
|
||||
ResetModel? get reset => _reset;
|
||||
|
||||
set reset(ResetModel? reset) {
|
||||
_reset = reset;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<bool> resetPassword({
|
||||
required String email,
|
||||
}) async {
|
||||
try {
|
||||
ResetModel? reset = await ResetService().kirimEmail(
|
||||
email: email,
|
||||
);
|
||||
|
||||
_reset = reset;
|
||||
return true;
|
||||
} catch (e) {
|
||||
print("EXception: $e");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
99
lib/providers/search_provider.dart
Normal file
99
lib/providers/search_provider.dart
Normal file
@ -0,0 +1,99 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:initial_folder/models/course_model.dart';
|
||||
import 'package:initial_folder/services/search_service.dart';
|
||||
|
||||
enum ResultState { loading, noData, hasData, error }
|
||||
|
||||
class SearchProvider with ChangeNotifier {
|
||||
final SearchService searchService;
|
||||
SearchProvider({required this.searchService});
|
||||
|
||||
ResultState? _state;
|
||||
String _message = '';
|
||||
List<CourseModel> _searchCourse = [];
|
||||
String _search = '';
|
||||
String _searchFilter = '';
|
||||
|
||||
ResultState? get state => _state;
|
||||
List<CourseModel> get result => _searchCourse;
|
||||
String get message => _message;
|
||||
String get search => _search;
|
||||
String get searchFilter => _searchFilter;
|
||||
String get searchText => _search;
|
||||
String get searchTextFilter => _searchFilter;
|
||||
|
||||
void resetState() {
|
||||
_state = null;
|
||||
}
|
||||
|
||||
set searchText(String text) {
|
||||
_search = text;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set searchTextFilter(String text) {
|
||||
_searchFilter = text;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void clearSearchBox() {
|
||||
_search = '';
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
initSearchCourse({
|
||||
String price = '',
|
||||
String level = '',
|
||||
String language = '',
|
||||
String rating = '',
|
||||
}) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
|
||||
List<CourseModel> course = await searchService.filter(
|
||||
price: price,
|
||||
level: level,
|
||||
language: language,
|
||||
rating: rating,
|
||||
keyword: _search,
|
||||
);
|
||||
|
||||
if (course.isEmpty) {
|
||||
_state = ResultState.noData;
|
||||
notifyListeners();
|
||||
_message = 'Empty Data';
|
||||
} else {
|
||||
_state = ResultState.hasData;
|
||||
|
||||
_searchCourse = course;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.error;
|
||||
|
||||
_message = 'Error --> $e';
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> searchCourse(judul) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
List<CourseModel> course = await searchService.search(judul);
|
||||
|
||||
if (course.isEmpty) {
|
||||
_state = ResultState.noData;
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
_state = ResultState.hasData;
|
||||
notifyListeners();
|
||||
return _searchCourse = course;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
54
lib/providers/section_lesson_course_provider.dart
Normal file
54
lib/providers/section_lesson_course_provider.dart
Normal file
@ -0,0 +1,54 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:initial_folder/models/section_lesson_model.dart';
|
||||
import 'package:initial_folder/services/section_lesson_service.dart';
|
||||
|
||||
enum ResultState { Loading, HasData, Error, NoData }
|
||||
|
||||
class SectionLessonCourseProvider with ChangeNotifier {
|
||||
final SectionLessonService sectionLessonService;
|
||||
final String id;
|
||||
SectionLessonCourseProvider(
|
||||
{required this.sectionLessonService, required this.id}) {
|
||||
getDetailCourse(id);
|
||||
}
|
||||
|
||||
SectionLessonModel? _sectionLessonModel;
|
||||
|
||||
SectionLessonModel? get result => _sectionLessonModel;
|
||||
|
||||
ResultState? _state;
|
||||
|
||||
String _message = '';
|
||||
|
||||
ResultState? get state => _state;
|
||||
|
||||
String get message => _message;
|
||||
|
||||
set detailCourse(SectionLessonModel detail) {
|
||||
_sectionLessonModel = detail;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getDetailCourse(_id) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
SectionLessonModel detail =
|
||||
await sectionLessonService.getSectionLessonCourse(_id);
|
||||
if (detail.data![0].isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Tidak ada data';
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
notifyListeners();
|
||||
return _sectionLessonModel = detail;
|
||||
}
|
||||
} catch (e) {
|
||||
print('ini erroprnyaa' + e.toString());
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
41
lib/providers/section_lesson_provider.dart
Normal file
41
lib/providers/section_lesson_provider.dart
Normal file
@ -0,0 +1,41 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class SectionLessonProvider with ChangeNotifier {
|
||||
bool isExpanded;
|
||||
bool isCheckBoxLesson;
|
||||
bool isOutcomes;
|
||||
bool isDescription;
|
||||
bool isDescriptionInstruktur;
|
||||
SectionLessonProvider({
|
||||
this.isExpanded = true,
|
||||
this.isCheckBoxLesson = false,
|
||||
this.isOutcomes = false,
|
||||
this.isDescription = true,
|
||||
this.isDescriptionInstruktur = false,
|
||||
});
|
||||
|
||||
void expanded() {
|
||||
isExpanded = !isExpanded;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void checkBoxLesson() {
|
||||
isCheckBoxLesson = !isCheckBoxLesson;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void detailPlayCourseOutcomes() {
|
||||
isOutcomes = !isOutcomes;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void descriptionPlayCourse() {
|
||||
isDescription = !isDescription;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void descriptionInstrukturPlayCourse() {
|
||||
isDescriptionInstruktur = !isDescriptionInstruktur;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
12
lib/providers/selected_title_provider.dart
Normal file
12
lib/providers/selected_title_provider.dart
Normal file
@ -0,0 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SelectedTitleProvider extends ChangeNotifier {
|
||||
String? _selectedTitle;
|
||||
|
||||
String? get selectedTitle => _selectedTitle;
|
||||
|
||||
set selectedTitle(String? value) {
|
||||
_selectedTitle = value;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
11
lib/providers/show_hide_pw/show_hide_prov1.dart
Normal file
11
lib/providers/show_hide_pw/show_hide_prov1.dart
Normal file
@ -0,0 +1,11 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class ShowHidePassword1 with ChangeNotifier {
|
||||
bool password;
|
||||
ShowHidePassword1({this.password = false});
|
||||
|
||||
void showPassword() {
|
||||
password = !password;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
11
lib/providers/show_hide_pw/show_hide_prov2.dart
Normal file
11
lib/providers/show_hide_pw/show_hide_prov2.dart
Normal file
@ -0,0 +1,11 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class ShowHidePassword2 with ChangeNotifier {
|
||||
bool password;
|
||||
ShowHidePassword2({this.password = false});
|
||||
|
||||
void showPassword() {
|
||||
password = !password;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
11
lib/providers/show_hide_pw/show_hide_provider.dart
Normal file
11
lib/providers/show_hide_pw/show_hide_provider.dart
Normal file
@ -0,0 +1,11 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class ShowHidePassword with ChangeNotifier {
|
||||
bool password;
|
||||
ShowHidePassword({this.password = false});
|
||||
|
||||
void showPassword() {
|
||||
password = !password;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
61
lib/providers/stream_invoice_provider.dart
Normal file
61
lib/providers/stream_invoice_provider.dart
Normal file
@ -0,0 +1,61 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/detail_invoice_model.dart';
|
||||
import 'package:initial_folder/services/detail_invoice_service.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
enum ResultState { loading, noData, hasData, error }
|
||||
|
||||
class StreamInvoiceProvider extends ChangeNotifier {
|
||||
final DetailInvoiceService _detailInvoiceService = DetailInvoiceService();
|
||||
List<DataDetailInvoiceModel>? _detailInvoice;
|
||||
String? _message;
|
||||
String? _thumbnail;
|
||||
ResultState? _state;
|
||||
final StreamController<String> _transactionStatusController =
|
||||
StreamController<String>.broadcast();
|
||||
|
||||
Stream<String> get transactionStatusStream =>
|
||||
_transactionStatusController.stream;
|
||||
String? get message => _message;
|
||||
String? get thumbnail => _thumbnail;
|
||||
List<DataDetailInvoiceModel>? get detailInvoice => _detailInvoice;
|
||||
ResultState? get state => _state;
|
||||
|
||||
set selectedThumbnail(String? value) {
|
||||
_thumbnail = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> fetchDetailInvoice(String? orderId) async {
|
||||
print("Fetching detail invoice for order ID: $orderId");
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
final data = await _detailInvoiceService.detailInvoice(orderId);
|
||||
if (data.isEmpty) {
|
||||
_state = ResultState.noData;
|
||||
_message = 'Invoice Detail is Empty';
|
||||
print("Invoice detail is empty");
|
||||
} else {
|
||||
_state = ResultState.hasData;
|
||||
_detailInvoice = data;
|
||||
print(
|
||||
"Invoice detail fetched, updating transaction status to: ${data[0].transactionStatus}");
|
||||
_transactionStatusController.sink.add(data[0].transactionStatus!);
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.error;
|
||||
_message = 'Error -> $e';
|
||||
print("Error fetching invoice detail: $e");
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_transactionStatusController.close();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
12
lib/providers/tab_play_course_provider.dart
Normal file
12
lib/providers/tab_play_course_provider.dart
Normal file
@ -0,0 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TabPlayCourseProvider with ChangeNotifier {
|
||||
int _currentIndex = 0;
|
||||
|
||||
int get currentIndex => _currentIndex;
|
||||
|
||||
set currentIndex(int index) {
|
||||
_currentIndex = index;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
12
lib/providers/tab_provider.dart
Normal file
12
lib/providers/tab_provider.dart
Normal file
@ -0,0 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TabProvider with ChangeNotifier {
|
||||
int _currentIndex = 0;
|
||||
|
||||
int get currentIndex => _currentIndex;
|
||||
|
||||
set currentIndex(int index) {
|
||||
_currentIndex = index;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
60
lib/providers/theme_provider.dart
Normal file
60
lib/providers/theme_provider.dart
Normal file
@ -0,0 +1,60 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/theme.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class ThemeProvider with ChangeNotifier {
|
||||
ThemeData _themeData = ThemeClass.darkmode;
|
||||
|
||||
ThemeProvider() {
|
||||
loadTheme();
|
||||
}
|
||||
|
||||
ThemeData get themeData => _themeData;
|
||||
|
||||
set themeData(ThemeData themeData) {
|
||||
_themeData = themeData;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void toggleTheme() {
|
||||
if (_themeData == ThemeClass.lightmode) {
|
||||
themeData = ThemeClass.darkmode;
|
||||
_saveTheme('dark');
|
||||
} else {
|
||||
themeData = ThemeClass.lightmode;
|
||||
_saveTheme('light');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadTheme() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
String? theme = prefs.getString('theme');
|
||||
if (theme == null) {
|
||||
var brightness =
|
||||
WidgetsBinding.instance.platformDispatcher.platformBrightness;
|
||||
|
||||
if (brightness == Brightness.light) {
|
||||
themeData = ThemeClass.lightmode;
|
||||
_saveTheme('light');
|
||||
} else {
|
||||
themeData = ThemeClass.darkmode;
|
||||
_saveTheme('dark');
|
||||
}
|
||||
} else if (theme == 'dark') {
|
||||
themeData = ThemeClass.darkmode;
|
||||
} else {
|
||||
themeData = ThemeClass.lightmode;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> saveCurrentTheme() async {
|
||||
String theme = _themeData == ThemeClass.darkmode ? 'dark' : 'light';
|
||||
await _saveTheme(theme);
|
||||
}
|
||||
|
||||
Future<void> _saveTheme(String theme) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('theme', theme);
|
||||
}
|
||||
}
|
50
lib/providers/top_course_provider.dart
Normal file
50
lib/providers/top_course_provider.dart
Normal file
@ -0,0 +1,50 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/course_model.dart';
|
||||
import 'package:initial_folder/services/course_service.dart';
|
||||
|
||||
enum ResultState { Loading, NoData, HasData, Error }
|
||||
|
||||
class TopCourseProvider with ChangeNotifier {
|
||||
final CourseService courseService;
|
||||
TopCourseProvider({required this.courseService}) {
|
||||
getTopCourse();
|
||||
}
|
||||
|
||||
List<CourseModel> _course = [];
|
||||
|
||||
ResultState? _state;
|
||||
|
||||
String _message = '';
|
||||
|
||||
List<CourseModel> get result => _course;
|
||||
|
||||
ResultState? get state => _state;
|
||||
|
||||
String get message => _message;
|
||||
|
||||
set course(List<CourseModel> course) {
|
||||
_course = course;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getTopCourse() async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
List<CourseModel> course = await courseService.getTopCourse();
|
||||
if (course.isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
notifyListeners();
|
||||
return _course = course;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
75
lib/providers/total_price_provider.dart
Normal file
75
lib/providers/total_price_provider.dart
Normal file
@ -0,0 +1,75 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TotalPriceProvider with ChangeNotifier {
|
||||
int? _totalPrice;
|
||||
int? _totalPrices;
|
||||
int? _priceCoupon;
|
||||
int? _finalPriceCoupon;
|
||||
int? _potonganKupon;
|
||||
int? _penguranganHarga;
|
||||
String? _typeCoupon;
|
||||
String? _couponText;
|
||||
String? _valuePrice;
|
||||
String? _subTotal;
|
||||
|
||||
int? get totalPrice => _totalPrice;
|
||||
int? get totalPrices => _totalPrices;
|
||||
int? get priceCoupon => _priceCoupon;
|
||||
int? get finalPriceCoupon => _finalPriceCoupon;
|
||||
int? get potonganKupon => _potonganKupon;
|
||||
int? get penguranganHarga => _penguranganHarga;
|
||||
String? get typeCoupon => _typeCoupon;
|
||||
String? get couponText => _couponText;
|
||||
String? get valuePrice => _valuePrice;
|
||||
String? get subTotal => _subTotal;
|
||||
|
||||
set selectedTotalPrice(int value) {
|
||||
_totalPrice = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set selectedTotalPrices(int value) {
|
||||
_totalPrices = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set selectedPriceCoupon(int value) {
|
||||
_priceCoupon = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set selectedTypeCoupon(String value) {
|
||||
_typeCoupon = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set selectedFinalPriceCoupon(int value) {
|
||||
_finalPriceCoupon = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set selectedCouponText(String value) {
|
||||
_couponText = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set selectedPotonganKupon(int value) {
|
||||
_potonganKupon = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set selectedValuePrice(String value) {
|
||||
_valuePrice = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set selectedPenguranganHarga(int value) {
|
||||
_penguranganHarga = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
set selectedSubTotal(String value) {
|
||||
_subTotal = value;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
61
lib/providers/update_data_diri_provider.dart
Normal file
61
lib/providers/update_data_diri_provider.dart
Normal file
@ -0,0 +1,61 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/update_data_diri_model.dart';
|
||||
import 'package:initial_folder/services/user_info_service.dart';
|
||||
|
||||
enum ResultState { loading, succes }
|
||||
|
||||
class UpdateDataDiriProvider with ChangeNotifier {
|
||||
UpdateDataDiriModel? _updateDataDiriModel;
|
||||
|
||||
UpdateDataDiriModel? get updateDataDiriModel => _updateDataDiriModel;
|
||||
ResultState? _state;
|
||||
ResultState? get state => _state;
|
||||
set updateDataDiriModel(UpdateDataDiriModel? _updateDataDiriModel) {
|
||||
_updateDataDiriModel = updateDataDiriModel;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<bool> dataDiriUpdate(
|
||||
{String? fullname,
|
||||
String? biograph,
|
||||
String? twitter,
|
||||
String? facebook,
|
||||
String? linkedin,
|
||||
String? instagram,
|
||||
String? datebirth,
|
||||
String? phone,
|
||||
String? gender,
|
||||
String? headline,
|
||||
String? email}) async {
|
||||
try {
|
||||
_state = ResultState.loading;
|
||||
notifyListeners();
|
||||
_updateDataDiriModel = await UserInfoService().updateDataDiri(
|
||||
fullname: fullname,
|
||||
biograph: biograph,
|
||||
phone: phone,
|
||||
// datebirth: datebirth,
|
||||
// gender: gender,
|
||||
facebook: facebook,
|
||||
linkedin: linkedin,
|
||||
twitter: twitter,
|
||||
instagram: instagram,
|
||||
headline: headline,
|
||||
email: email,
|
||||
);
|
||||
if (_updateDataDiriModel != null) {
|
||||
if (_updateDataDiriModel!.status == 200) {
|
||||
_state = ResultState.succes;
|
||||
notifyListeners();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (e) {
|
||||
print("Exception: $e");
|
||||
_updateDataDiriModel = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
39
lib/providers/update_password_provider.dart
Normal file
39
lib/providers/update_password_provider.dart
Normal file
@ -0,0 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/update_password_model.dart';
|
||||
import 'package:initial_folder/services/user_info_service.dart';
|
||||
|
||||
class UpdatePasswordProvider with ChangeNotifier {
|
||||
UpdatePasswordModel? _updatePasswordModel;
|
||||
|
||||
UpdatePasswordModel? get updatePasswordModel => _updatePasswordModel;
|
||||
|
||||
set updatePasswordModel(UpdatePasswordModel? _updatePasswordModel) {
|
||||
_updatePasswordModel = updatePasswordModel;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<bool> passwordUpdate({
|
||||
required idUser,
|
||||
required String? email,
|
||||
required String? oldPassword,
|
||||
required String? password,
|
||||
required String? newPasswordConfirm,
|
||||
}) async {
|
||||
try {
|
||||
UpdatePasswordModel? updatePasswordModel = await UserInfoService()
|
||||
.updatePassword(
|
||||
idUser: idUser,
|
||||
email: email,
|
||||
oldPassword: oldPassword,
|
||||
password: password,
|
||||
newPasswordConfirm: newPasswordConfirm);
|
||||
|
||||
_updatePasswordModel = updatePasswordModel;
|
||||
//print(user);
|
||||
return true;
|
||||
} catch (e) {
|
||||
print("excecptiasd gagal: $e");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
54
lib/providers/user_info_provider.dart
Normal file
54
lib/providers/user_info_provider.dart
Normal file
@ -0,0 +1,54 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/user_info_model.dart';
|
||||
import 'package:initial_folder/services/user_info_service.dart';
|
||||
|
||||
enum ResultState { Loading, NoData, HasData, Error }
|
||||
|
||||
class UserInfoProvider with ChangeNotifier {
|
||||
final UserInfoService userInfoService;
|
||||
|
||||
UserInfoProvider({
|
||||
required this.userInfoService,
|
||||
});
|
||||
|
||||
UserInfoModel? _userInfoModel;
|
||||
|
||||
ResultState? _state;
|
||||
|
||||
String _message = '';
|
||||
|
||||
UserInfoModel? get result => _userInfoModel;
|
||||
|
||||
ResultState? get state => _state;
|
||||
|
||||
String get message => _message;
|
||||
|
||||
String get fullName => _userInfoModel?.data[0].fullname ?? '';
|
||||
|
||||
set userInfo(UserInfoModel userInfo) {
|
||||
_userInfoModel = userInfo;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getUserInfo(_email) async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
UserInfoModel userInfo = await userInfoService.getUserInfo(_email);
|
||||
//print(userInfo.data[0].id_user);
|
||||
if (userInfo.data.isEmpty) {
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
_state = ResultState.HasData;
|
||||
notifyListeners();
|
||||
return _userInfoModel = userInfo;
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
68
lib/providers/whislist_provider.dart
Normal file
68
lib/providers/whislist_provider.dart
Normal file
@ -0,0 +1,68 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/wishlist_model.dart';
|
||||
import 'package:initial_folder/services/wishlist_service.dart';
|
||||
|
||||
enum ResultState { Loading, NoData, HasData, Error }
|
||||
|
||||
class WishlistProvider with ChangeNotifier {
|
||||
WishlistProvider() {
|
||||
getWishlist();
|
||||
}
|
||||
WishlistModel? _wishlistModel;
|
||||
ResultState? _state;
|
||||
|
||||
String _message = '';
|
||||
List _data = [];
|
||||
List get data => _data;
|
||||
set dataWishlist(List value) {
|
||||
_data = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
WishlistModel? get result => _wishlistModel;
|
||||
|
||||
ResultState? get state => _state;
|
||||
|
||||
String get message => _message;
|
||||
|
||||
set wishlistModel(WishlistModel wishlist) {
|
||||
_wishlistModel = wishlist;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<dynamic> getWishlist() async {
|
||||
try {
|
||||
_state = ResultState.Loading;
|
||||
notifyListeners();
|
||||
|
||||
WishlistModel wishlist = await WishlistService().getWishlist();
|
||||
if (wishlist.data.isEmpty) {
|
||||
_data = [];
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'Empty Data';
|
||||
} else {
|
||||
List<DataWihslistModel> wishlistItems = wishlist.data[0];
|
||||
|
||||
bool allCourseIdNull = wishlistItems.every((item) => item.courseId == null);
|
||||
|
||||
if (allCourseIdNull) {
|
||||
_data = [];
|
||||
_state = ResultState.NoData;
|
||||
notifyListeners();
|
||||
return _message = 'course_id nya null';
|
||||
} else {
|
||||
_data = wishlistItems.map((e) => e.courseId).toList();
|
||||
_state = ResultState.HasData;
|
||||
print('wishlist punya data');
|
||||
notifyListeners();
|
||||
return _wishlistModel = wishlist;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
_state = ResultState.Error;
|
||||
notifyListeners();
|
||||
return _message = 'Error --> $e';
|
||||
}
|
||||
}
|
||||
}
|
43
lib/providers/wishlist_post_provider.dart
Normal file
43
lib/providers/wishlist_post_provider.dart
Normal file
@ -0,0 +1,43 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:initial_folder/models/wishlist_model.dart';
|
||||
import 'package:initial_folder/services/wishlist_service.dart';
|
||||
|
||||
class WishlistPostProvider with ChangeNotifier {
|
||||
WishlistPostModel? _wishlistPostModel;
|
||||
WishlistPostModel? get wishlistPostModel => _wishlistPostModel;
|
||||
|
||||
setwishlistPostModel(WishlistPostModel? wishlistPostModel) {
|
||||
_wishlistPostModel = wishlistPostModel;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<bool> addWishlist(int wishlistItem) async {
|
||||
try {
|
||||
WishlistPostModel? wishlistPostModel =
|
||||
await WishlistService().addWishlist(wishlistItem);
|
||||
_wishlistPostModel = wishlistPostModel;
|
||||
return true;
|
||||
} on SocketException {
|
||||
return false;
|
||||
} catch (e) {
|
||||
print("Exception: $e");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> deleteWishlist(int wishlistItem) async {
|
||||
try {
|
||||
WishlistPostModel? wishlistPostModel =
|
||||
await WishlistService().deleteWishlist(wishlistItem);
|
||||
_wishlistPostModel = wishlistPostModel;
|
||||
return true;
|
||||
} on SocketException {
|
||||
return false;
|
||||
} catch (e) {
|
||||
print("Exception: $e");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user