52 lines
1.5 KiB
Dart
52 lines
1.5 KiB
Dart
import 'package:cheminova/models/profile_response.dart';
|
|
import 'package:cheminova/services/api_client.dart';
|
|
import 'package:cheminova/services/api_urls.dart';
|
|
import 'package:cheminova/services/secure__storage_service.dart';
|
|
import 'package:dio/dio.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../models/get_pd_response.dart';
|
|
import '../screens/login_screen.dart';
|
|
|
|
class HomeProvider extends ChangeNotifier {
|
|
final _apiClient = ApiClient();
|
|
ProfileResponse? profileResponse;
|
|
bool _isLoading = false;
|
|
|
|
bool get isLoading => _isLoading;
|
|
|
|
void setLoading(bool loading) {
|
|
_isLoading = loading;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> getProfile() async {
|
|
setLoading(true);
|
|
try {
|
|
Response response = await _apiClient.get(ApiUrls.getProfileUrl);
|
|
setLoading(false);
|
|
if (response.statusCode == 200) {
|
|
profileResponse = ProfileResponse.fromJson(response.data);
|
|
} else {}
|
|
} catch (e) {
|
|
setLoading(false);
|
|
}
|
|
}
|
|
|
|
Future<void> logOut(BuildContext context) async {
|
|
Response response = await _apiClient.get(ApiUrls.logOutUrl);
|
|
if (response.statusCode == 200) {
|
|
ScaffoldMessenger.of(context)
|
|
.showSnackBar(SnackBar(
|
|
content:
|
|
Text(response.data['message'].toString())));
|
|
SecureStorageService().clear();
|
|
Navigator.pushReplacement(context,
|
|
MaterialPageRoute(builder: (context) => const LoginPage()));
|
|
}
|
|
|
|
|
|
}
|
|
}
|