initial
This commit is contained in:
75
lib/services/environment.dart
Normal file
75
lib/services/environment.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../appflow/model/location.dart';
|
||||
|
||||
class EnvironmentConnector {
|
||||
|
||||
static Future<bool> openBrowser(Uri url) async {
|
||||
if (await canLaunchUrl(url)) {
|
||||
return await launchUrl(url);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static Future<void> openMail(String mail) async {
|
||||
Uri uri = Uri(scheme: 'mailto', path: mail);
|
||||
openBrowser(uri);
|
||||
}
|
||||
|
||||
static Future<void> openPhone(String phoneNumber) async {
|
||||
Uri uri = Uri(scheme: 'tel', path: phoneNumber);
|
||||
openBrowser(uri);
|
||||
}
|
||||
|
||||
static Future<void> openFacebook(String id) async {
|
||||
Uri uri;
|
||||
uri = Uri(scheme: 'fb', path: 'profile', queryParameters: {'id': id});
|
||||
Uri uriBackup = Uri.parse('https://www.facebook.com/$id');
|
||||
//bool launched = await launchUrl(uri);
|
||||
//if (!launched) {
|
||||
await launchUrl(uriBackup);
|
||||
//}
|
||||
}
|
||||
|
||||
static Future<void> openInstagram(String id) async {
|
||||
Uri uri = Uri(scheme: 'instagram', path: id);
|
||||
Uri uriBackup = Uri.parse('https://www.instagram.com/$id');
|
||||
if(!await openBrowser(uri)) {
|
||||
openBrowser(uriBackup);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> openTwitter(String id) async {
|
||||
Uri uri = Uri(scheme: 'twitter', path: id);
|
||||
Uri uriBackup = Uri.parse('https://www.twitter.com/$id');
|
||||
if(!await openBrowser(uri)) {
|
||||
openBrowser(uriBackup);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> openMaps(LocationModel location) async {
|
||||
Uri? uri;
|
||||
Uri? uriBackup;
|
||||
if(location.latitude != null && location.longitude != null) {
|
||||
uri = Uri(scheme: 'geo', path: '${location.latitude},${location.longitude}');
|
||||
} else if (location.address != null) {
|
||||
uri = Uri(
|
||||
scheme: 'maps',
|
||||
host: 'maps.google.com',
|
||||
path: '',
|
||||
queryParameters: {
|
||||
'q': location.address,
|
||||
'daddr': location.address,
|
||||
},
|
||||
);
|
||||
uriBackup = Uri.parse('https://www.google.com/maps/search/?api=1&query='+Uri.encodeFull(location.address!));
|
||||
}
|
||||
if(!await openBrowser(uri!)) {
|
||||
openBrowser(uriBackup!);
|
||||
}
|
||||
}
|
||||
|
||||
static void share(String text, {String? subject}) {
|
||||
Share.share(text, subject: subject);
|
||||
}
|
||||
}
|
||||
31
lib/services/network.dart
Normal file
31
lib/services/network.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hiddingsel_app/constants/constant.dart';
|
||||
|
||||
import '../main.dart';
|
||||
|
||||
|
||||
// TODO Medium-Prio: Connectivity check - https://www.youtube.com/watch?v=P2vaBZDSqzg
|
||||
class BaseService {
|
||||
static Future<T> getSaveFromServer<T>(
|
||||
Future<T> Function() method, T defaultValue) async {
|
||||
try {
|
||||
return method.call();
|
||||
} on SocketException {
|
||||
scaffoldMessengerKey.currentState?.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(UIStrings.serviceKeineInternetverbindung),
|
||||
),
|
||||
);
|
||||
return defaultValue;
|
||||
} on Exception {
|
||||
scaffoldMessengerKey.currentState?.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(UIStrings.serviceKeineInternetverbindung),
|
||||
),
|
||||
);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
30
lib/services/notification.dart
Normal file
30
lib/services/notification.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hiddingsel_app/constants/constant.dart';
|
||||
|
||||
class ExternalNotificationConnector {
|
||||
|
||||
static void initialize() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Firebase.initializeApp();
|
||||
FirebaseMessaging.onBackgroundMessage(_backgroundMessageHandler);
|
||||
FirebaseMessaging.onMessageOpenedApp.listen(_messageOpenedAppHandler);
|
||||
}
|
||||
|
||||
static void _messageOpenedAppHandler(RemoteMessage event) {
|
||||
// Passende stelle öffnen
|
||||
}
|
||||
|
||||
static void subscribe(element) {
|
||||
FirebaseMessaging.instance.subscribeToTopic(SystemStrings.fcmPre + element.id);
|
||||
}
|
||||
|
||||
static void unsubscribe(element) {
|
||||
FirebaseMessaging.instance.unsubscribeFromTopic(SystemStrings.fcmPre + element.id);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _backgroundMessageHandler(RemoteMessage message) async {
|
||||
// Vielleicht Snackbar?
|
||||
}
|
||||
29
lib/services/remote_config.dart
Normal file
29
lib/services/remote_config.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
/*import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:firebase_remote_config/firebase_remote_config.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:hiddingsel_app/services/storage.dart';
|
||||
|
||||
import '../constants/constant.dart';
|
||||
|
||||
class RemoteConfigConnector {
|
||||
|
||||
static void initialize() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Firebase.initializeApp();
|
||||
FirebaseRemoteConfig.instance.setConfigSettings(RemoteConfigSettings(
|
||||
fetchTimeout: const Duration(minutes: 1),
|
||||
minimumFetchInterval: const Duration(hours: 1),
|
||||
));
|
||||
Map<String, dynamic> remoteConfigDefaults = await AssetConnector.getJson(SystemStrings.assetRemoteConfigDefaults);
|
||||
FirebaseRemoteConfig.instance.setDefaults(remoteConfigDefaults);
|
||||
FirebaseRemoteConfig.instance.fetchAndActivate();
|
||||
}
|
||||
|
||||
static Future<bool> getBool(String key) async {
|
||||
return FirebaseRemoteConfig.instance.getBool(key);
|
||||
}
|
||||
|
||||
static Future<int> getInt(String key) async {
|
||||
return FirebaseRemoteConfig.instance.getInt(key);
|
||||
}
|
||||
}*/
|
||||
98
lib/services/storage.dart
Normal file
98
lib/services/storage.dart
Normal file
@@ -0,0 +1,98 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class SettingsConnector {
|
||||
static Future<void> setBool(String key, bool value) async {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
prefs.setBool(key, value);
|
||||
}
|
||||
|
||||
static Future<bool> getBool(String key, bool defaultValue) async {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getBool(key) ?? defaultValue;
|
||||
}
|
||||
|
||||
/*static Future<bool> getRemoteBool(String key) async {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getBool(key) ?? await RemoteConfigConnector.getBool(key);
|
||||
}*/
|
||||
|
||||
static Future<void> setInt(String key, int value) async {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
prefs.setInt(key, value);
|
||||
}
|
||||
|
||||
static Future<int> getInt(String key, int defaultValue) async {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getInt(key) ?? defaultValue;
|
||||
}
|
||||
|
||||
/*static Future<int> getRemoteInt(String key) async {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getInt(key) ?? await RemoteConfigConnector.getInt(key);
|
||||
}*/
|
||||
}
|
||||
|
||||
class AssetConnector {
|
||||
static Future<String> getAssetString(String path) => rootBundle.loadString(path);
|
||||
|
||||
static getJson<JsonEncodable>(asset) async {
|
||||
final jsonString = await AssetConnector.getAssetString(asset);
|
||||
return jsonDecode(jsonString);
|
||||
}
|
||||
}
|
||||
|
||||
class DataConnector {
|
||||
|
||||
static Future<Directory> directory = getApplicationDocumentsDirectory();
|
||||
|
||||
static Future<void> saveJsonEncodable(key, List<JsonEncodable> value) async {
|
||||
var jsonString = json.encode(value);
|
||||
var file = await getFile('$key.json', create: true);
|
||||
await file!.writeAsString(jsonString);
|
||||
}
|
||||
|
||||
static getJson(key) async {
|
||||
var file = await getFile('$key.json');
|
||||
if (file != null && await file.exists()) {
|
||||
var jsonString = await file.readAsString();
|
||||
return json.decode(jsonString);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static Future<JsonEncodable> getJsonEncodable<JsonEncodable>(key, JsonEncodable defaultValue, JsonEncodable Function(Map<String, dynamic>) fromJson) async {
|
||||
Map<String, dynamic>? jsonObject = await getJson(key);
|
||||
if (jsonObject != null) {
|
||||
return fromJson(jsonObject);
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<List<JsonEncodable>> getJsonEncodableList<JsonEncodable>(key, List<JsonEncodable> defaultValue, JsonEncodable Function(Map<String, dynamic>) fromJson) async {
|
||||
List<dynamic>? jsonObject = await getJson(key);
|
||||
if (jsonObject != null) {
|
||||
return jsonObject.map((e) => fromJson(e)).toList().cast<JsonEncodable>();
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<File?> getFile(String fileName, {bool create = false}) async{
|
||||
String path = (await getApplicationDocumentsDirectory()).path;
|
||||
var file = new File('$path/$fileName');
|
||||
if (!await file.exists()){
|
||||
if (!create) return null;
|
||||
await file.create();
|
||||
}
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
mixin JsonEncodable {
|
||||
Map<String, dynamic> toJson();
|
||||
}
|
||||
Reference in New Issue
Block a user