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:didvan/services/storage/storage.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hive_flutter/hive_flutter.dart';
|
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
class AppInitializer {
|
class AppInitializer {
|
||||||
static Future<void> setupServices() async {
|
static Future<void> setupServices() async {
|
||||||
StorageService.appDocsDir = (await getApplicationDocumentsDirectory()).path;
|
if (!kIsWeb) {
|
||||||
StorageService.appTempsDir = (await getTemporaryDirectory()).path;
|
StorageService.appDocsDir =
|
||||||
await Hive.initFlutter();
|
(await getApplicationDocumentsDirectory()).path;
|
||||||
|
StorageService.appTempsDir = (await getTemporaryDirectory()).path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<ThemeMode> initilizeSettings() async {
|
static Future<ThemeMode> initilizeSettings() async {
|
||||||
final bool settingsBoxExists = await StorageService.boxExists(
|
final brightness = await StorageService.getValue(key: 'brightness');
|
||||||
boxName: 'settings',
|
if (brightness != null) {
|
||||||
);
|
|
||||||
if (settingsBoxExists) {
|
|
||||||
final String brightness =
|
|
||||||
await StorageService.getValue(key: 'brightness', boxName: 'settings');
|
|
||||||
return brightness == 'dark' ? ThemeMode.dark : ThemeMode.light;
|
return brightness == 'dark' ? ThemeMode.dark : ThemeMode.light;
|
||||||
} else {
|
} else {
|
||||||
final SettingsData settingsData = SettingsData(
|
await StorageService.setValue(
|
||||||
'light',
|
key: 'notificationTimeRangeStart',
|
||||||
['00:00', '23:59'],
|
value: '00:00',
|
||||||
'Dana-FA',
|
|
||||||
1,
|
|
||||||
);
|
);
|
||||||
await StorageService.setBoxData(
|
await StorageService.setValue(
|
||||||
data: settingsData.toJson(),
|
key: 'notificationTimeRangeEnd',
|
||||||
boxName: 'settings',
|
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;
|
return ThemeMode.light;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:image_cropper/image_cropper.dart';
|
import 'package:image_cropper/image_cropper.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
|
|
||||||
|
|
@ -10,6 +11,9 @@ class MediaService {
|
||||||
if (pickedFile == null) {
|
if (pickedFile == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (kIsWeb) {
|
||||||
|
return File(pickedFile.path);
|
||||||
|
}
|
||||||
final cropedFile = await ImageCropper.cropImage(
|
final cropedFile = await ImageCropper.cropImage(
|
||||||
sourcePath: pickedFile.path,
|
sourcePath: pickedFile.path,
|
||||||
aspectRatio: const CropAspectRatio(ratioX: 1, ratioY: 1),
|
aspectRatio: const CropAspectRatio(ratioX: 1, ratioY: 1),
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
class RequestHelper {
|
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 _baseUserUrl = baseUrl + '/user';
|
||||||
static const String _baseRadarUrl = baseUrl + '/radar';
|
static const String _baseRadarUrl = baseUrl + '/radar';
|
||||||
static const String _baseNewsUrl = baseUrl + '/news';
|
static const String _baseNewsUrl = baseUrl + '/news';
|
||||||
|
|
@ -18,10 +18,10 @@ class RequestHelper {
|
||||||
|
|
||||||
static String direct(int id) => _baseUserUrl + '/direct/$id';
|
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 radarDetails(int id) => _baseRadarUrl + '/$id';
|
||||||
static String radarComments(int id) => _baseRadarUrl + '/$id/comments';
|
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 newsDetails(int id) => _baseNewsUrl + '/$id';
|
||||||
static String newsComments(int id) => _baseNewsUrl + '/$id/comments';
|
static String newsComments(int id) => _baseNewsUrl + '/$id/comments';
|
||||||
static String radarOverviews({
|
static String radarOverviews({
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,23 @@
|
||||||
import 'package:hive/hive.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
|
|
||||||
class StorageService {
|
class StorageService {
|
||||||
static late String appDocsDir;
|
static late String appDocsDir;
|
||||||
static late String appTempsDir;
|
static late String appTempsDir;
|
||||||
|
static const FlutterSecureStorage _storage = FlutterSecureStorage();
|
||||||
|
|
||||||
static Future<void> setValue({
|
static Future<void> setValue({
|
||||||
required String key,
|
required String key,
|
||||||
required dynamic value,
|
required dynamic value,
|
||||||
required String boxName,
|
|
||||||
}) async {
|
}) async {
|
||||||
final Box box = await Hive.openBox(boxName);
|
await _storage.write(key: key, value: value);
|
||||||
await box.put(key, value);
|
|
||||||
await box.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future getValue({required String key, required String boxName}) async {
|
static Future getValue({required String key}) async {
|
||||||
final Box box = await Hive.openBox(boxName);
|
final result = await _storage.read(key: key);
|
||||||
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);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<void> delete({required String key}) async {
|
||||||
|
_storage.delete(key: key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue