diff --git a/lib/services/app_initalizer.dart b/lib/services/app_initalizer.dart index 0b948e5..74c1e6c 100644 --- a/lib/services/app_initalizer.dart +++ b/lib/services/app_initalizer.dart @@ -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 setupServices() async { - StorageService.appDocsDir = (await getApplicationDocumentsDirectory()).path; - StorageService.appTempsDir = (await getTemporaryDirectory()).path; - await Hive.initFlutter(); + if (!kIsWeb) { + StorageService.appDocsDir = + (await getApplicationDocumentsDirectory()).path; + StorageService.appTempsDir = (await getTemporaryDirectory()).path; + } } static Future 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; } diff --git a/lib/services/media/media.dart b/lib/services/media/media.dart index b3f6f5d..d8c77f6 100644 --- a/lib/services/media/media.dart +++ b/lib/services/media/media.dart @@ -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), diff --git a/lib/services/network/request_helper.dart b/lib/services/network/request_helper.dart index 8817b8b..fe10939 100644 --- a/lib/services/network/request_helper.dart +++ b/lib/services/network/request_helper.dart @@ -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({ diff --git a/lib/services/storage/storage.dart b/lib/services/storage/storage.dart index eaca3a5..7c398e6 100644 --- a/lib/services/storage/storage.dart +++ b/lib/services/storage/storage.dart @@ -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 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 setBoxData({ - required Map data, - required String boxName, - }) async { - final Box box = await Hive.openBox(boxName); - await box.putAll(data); - await box.close(); - } - - static Future getBoxData({required String boxName}) async { - final Box box = await Hive.openBox(boxName); - await box.close(); - return box.toMap(); - } - - static Future 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 delete({required String key}) async { + _storage.delete(key: key); + } }