Current File : /home/tradevaly/public_html/fresh/lib/data/repository/splash_repo.dart |
import 'package:flutter/material.dart';
import 'package:flutter_grocery/data/datasource/remote/dio/dio_client.dart';
import 'package:flutter_grocery/data/datasource/remote/exception/api_error_handler.dart';
import 'package:flutter_grocery/data/model/response/base/api_response.dart';
import 'package:flutter_grocery/utill/app_constants.dart';
import 'package:shared_preferences/shared_preferences.dart';
class SplashRepo {
final DioClient dioClient;
final SharedPreferences sharedPreferences;
SplashRepo({@required this.sharedPreferences, @required this.dioClient});
Future<ApiResponse> getConfig() async {
try {
final response = await dioClient.get(AppConstants.CONFIG_URI);
return ApiResponse.withSuccess(response);
} catch (e) {
return ApiResponse.withError(ApiErrorHandler.getMessage(e));
}
}
Future<bool> initSharedData() {
if(!sharedPreferences.containsKey(AppConstants.THEME)) {
return sharedPreferences.setBool(AppConstants.THEME, false);
}
if(!sharedPreferences.containsKey(AppConstants.COUNTRY_CODE)) {
return sharedPreferences.setString(AppConstants.COUNTRY_CODE, 'US');
}
if(!sharedPreferences.containsKey(AppConstants.LANGUAGE_CODE)) {
return sharedPreferences.setString(AppConstants.LANGUAGE_CODE, 'en');
}
if(!sharedPreferences.containsKey(AppConstants.CART_LIST)) {
return sharedPreferences.setStringList(AppConstants.CART_LIST, []);
}
if(!sharedPreferences.containsKey(AppConstants.ON_BOARDING_SKIP)) {
return sharedPreferences.setBool(AppConstants.ON_BOARDING_SKIP, false);
}
return Future.value(true);
}
Future<bool> removeSharedData() {
return sharedPreferences.clear();
}
void disableIntro() {
sharedPreferences.setBool(AppConstants.ON_BOARDING_SKIP, false);
}
bool showIntro() {
return sharedPreferences.getBool(AppConstants.ON_BOARDING_SKIP)?? true;
}
}