D1APP-22 service updates (new storage package)
This commit is contained in:
parent
33d9971747
commit
58f02ba483
|
|
@ -1,34 +1,41 @@
|
|||
import 'package:didvan/models/settings_data.dart';
|
||||
import 'package:didvan/services/storage/storage.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class AppInitializer {
|
||||
static Future<void> setupServices() async {
|
||||
StorageService.appDocsDir = (await getApplicationDocumentsDirectory()).path;
|
||||
if (!kIsWeb) {
|
||||
StorageService.appDocsDir =
|
||||
(await getApplicationDocumentsDirectory()).path;
|
||||
StorageService.appTempsDir = (await getTemporaryDirectory()).path;
|
||||
await Hive.initFlutter();
|
||||
}
|
||||
}
|
||||
|
||||
static Future<ThemeMode> initilizeSettings() async {
|
||||
final bool settingsBoxExists = await StorageService.boxExists(
|
||||
boxName: 'settings',
|
||||
);
|
||||
if (settingsBoxExists) {
|
||||
final String brightness =
|
||||
await StorageService.getValue(key: 'brightness', boxName: 'settings');
|
||||
final brightness = await StorageService.getValue(key: 'brightness');
|
||||
if (brightness != null) {
|
||||
return brightness == 'dark' ? ThemeMode.dark : ThemeMode.light;
|
||||
} else {
|
||||
final SettingsData settingsData = SettingsData(
|
||||
'light',
|
||||
['00:00', '23:59'],
|
||||
'Dana-FA',
|
||||
1,
|
||||
await StorageService.setValue(
|
||||
key: 'notificationTimeRangeStart',
|
||||
value: '00:00',
|
||||
);
|
||||
await StorageService.setBoxData(
|
||||
data: settingsData.toJson(),
|
||||
boxName: 'settings',
|
||||
await StorageService.setValue(
|
||||
key: 'notificationTimeRangeEnd',
|
||||
value: '23:59',
|
||||
);
|
||||
await StorageService.setValue(
|
||||
key: 'fontFamily',
|
||||
value: 'Dana-FA',
|
||||
);
|
||||
await StorageService.setValue(
|
||||
key: 'fontSizeScale',
|
||||
value: '1',
|
||||
);
|
||||
await StorageService.setValue(
|
||||
key: 'brightness',
|
||||
value: 'light',
|
||||
);
|
||||
return ThemeMode.light;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:image_cropper/image_cropper.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
|
|
@ -10,6 +11,9 @@ class MediaService {
|
|||
if (pickedFile == null) {
|
||||
return null;
|
||||
}
|
||||
if (kIsWeb) {
|
||||
return File(pickedFile.path);
|
||||
}
|
||||
final cropedFile = await ImageCropper.cropImage(
|
||||
sourcePath: pickedFile.path,
|
||||
aspectRatio: const CropAspectRatio(ratioX: 1, ratioY: 1),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class RequestHelper {
|
||||
static const String baseUrl = 'https://didvan-greatsam.fandogh.cloud';
|
||||
static const String baseUrl = 'https://api.didvan.app';
|
||||
static const String _baseUserUrl = baseUrl + '/user';
|
||||
static const String _baseRadarUrl = baseUrl + '/radar';
|
||||
static const String _baseNewsUrl = baseUrl + '/news';
|
||||
|
|
@ -18,10 +18,10 @@ class RequestHelper {
|
|||
|
||||
static String direct(int id) => _baseUserUrl + '/direct/$id';
|
||||
|
||||
static String markRadar(int id) => _baseRadarUrl + '/mark/$id';
|
||||
static String markRadar(int id) => _baseRadarUrl + '$id/mark';
|
||||
static String radarDetails(int id) => _baseRadarUrl + '/$id';
|
||||
static String radarComments(int id) => _baseRadarUrl + '/$id/comments';
|
||||
static String markNews(int id) => _baseNewsUrl + '/mark/$id';
|
||||
static String markNews(int id) => _baseNewsUrl + '$id/mark';
|
||||
static String newsDetails(int id) => _baseNewsUrl + '/$id';
|
||||
static String newsComments(int id) => _baseNewsUrl + '/$id/comments';
|
||||
static String radarOverviews({
|
||||
|
|
|
|||
|
|
@ -1,43 +1,23 @@
|
|||
import 'package:hive/hive.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
class StorageService {
|
||||
static late String appDocsDir;
|
||||
static late String appTempsDir;
|
||||
static const FlutterSecureStorage _storage = FlutterSecureStorage();
|
||||
|
||||
static Future<void> setValue({
|
||||
required String key,
|
||||
required dynamic value,
|
||||
required String boxName,
|
||||
}) async {
|
||||
final Box box = await Hive.openBox(boxName);
|
||||
await box.put(key, value);
|
||||
await box.close();
|
||||
await _storage.write(key: key, value: value);
|
||||
}
|
||||
|
||||
static Future getValue({required String key, required String boxName}) async {
|
||||
final Box box = await Hive.openBox(boxName);
|
||||
final value = await box.get(key);
|
||||
await box.close();
|
||||
return value;
|
||||
}
|
||||
|
||||
static Future<void> setBoxData({
|
||||
required Map data,
|
||||
required String boxName,
|
||||
}) async {
|
||||
final Box box = await Hive.openBox(boxName);
|
||||
await box.putAll(data);
|
||||
await box.close();
|
||||
}
|
||||
|
||||
static Future<Map> getBoxData({required String boxName}) async {
|
||||
final Box box = await Hive.openBox(boxName);
|
||||
await box.close();
|
||||
return box.toMap();
|
||||
}
|
||||
|
||||
static Future<bool> boxExists({required String boxName}) async {
|
||||
final bool result = await Hive.boxExists(boxName);
|
||||
static Future getValue({required String key}) async {
|
||||
final result = await _storage.read(key: key);
|
||||
return result;
|
||||
}
|
||||
|
||||
static Future<void> delete({required String key}) async {
|
||||
_storage.delete(key: key);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue