v1.2.0+54
All checks were successful
Flutter Schmutter / build (push) Successful in 3m37s

- screaming_possum.gif
This commit is contained in:
2025-06-13 13:55:05 +02:00
parent dff9cda829
commit 9655f15927
18 changed files with 628 additions and 878 deletions

View File

@ -1,163 +0,0 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:f0ckapp/models/mediaitem_model.dart';
import 'package:f0ckapp/services/api_service.dart';
const List<String> mediaTypes = ["alles", "image", "video", "audio"];
const List<String> mediaModes = ["sfw", "nsfw", "untagged", "all"];
const _unsetTag = Object();
class MediaState {
final int typeIndex;
final int modeIndex;
final bool random;
final String? tag;
final int crossAxisCount;
final List<MediaItem> mediaItems;
final bool isLoading;
final bool muted;
const MediaState({
this.typeIndex = 0,
this.modeIndex = 0,
this.random = false,
this.tag,
this.crossAxisCount = 0,
this.mediaItems = const [],
this.isLoading = false,
this.muted = false,
});
MediaState replace({
int? typeIndex,
int? modeIndex,
bool? random,
Object? tag = _unsetTag,
int? crossAxisCount,
List<MediaItem>? mediaItems,
bool? isLoading,
bool? muted,
}) {
return MediaState(
typeIndex: typeIndex ?? this.typeIndex,
modeIndex: modeIndex ?? this.modeIndex,
random: random ?? this.random,
tag: identical(tag, _unsetTag) ? this.tag : tag as String?,
crossAxisCount: crossAxisCount ?? this.crossAxisCount,
mediaItems: mediaItems ?? this.mediaItems,
isLoading: isLoading ?? this.isLoading,
muted: muted ?? this.muted,
);
}
}
class MediaNotifier extends StateNotifier<MediaState> {
final _storage = const FlutterSecureStorage(
aOptions: AndroidOptions(encryptedSharedPreferences: true),
);
MediaNotifier() : super(const MediaState()) {
_loadMutedState();
}
Future<void> _loadMutedState() async {
final storedMuted = await _storage.read(key: 'muted');
final isMuted = storedMuted == 'true';
state = state.replace(muted: isMuted);
}
Future<void> _saveMutedState() async {
await _storage.write(key: 'muted', value: state.muted.toString());
}
void setType(String type) {
final newIndex = mediaTypes.indexOf(type);
state = state.replace(typeIndex: newIndex);
resetMedia();
}
void setMode(int modeIndex) {
state = state.replace(modeIndex: modeIndex);
resetMedia();
}
void toggleRandom() {
state = state.replace(random: !state.random);
resetMedia();
}
void setTag(String? tag) {
state = state.replace(tag: tag);
resetMedia();
}
void setCrossAxisCount(int count) {
state = state.replace(crossAxisCount: count);
}
void resetMedia() {
state = state.replace(mediaItems: []);
loadMedia();
}
void addMediaItems(List<MediaItem> newItems) {
final Set<int> existingIds = state.mediaItems
.map((item) => item.id)
.toSet();
final List<MediaItem> filteredItems = newItems
.where((item) => !existingIds.contains(item.id))
.toList();
if (filteredItems.isNotEmpty) {
final List<MediaItem> updated = List<MediaItem>.from(state.mediaItems)
..addAll(filteredItems);
state = state.replace(mediaItems: updated);
}
}
List<MediaItem> mergeMediaItems(
List<MediaItem> current,
List<MediaItem> incoming,
) {
final existingIds = current.map((item) => item.id).toSet();
final newItems = incoming
.where((item) => !existingIds.contains(item.id))
.toList();
return [...current, ...newItems];
}
Future<void> loadMedia({int? id}) async {
if (state.isLoading) return;
state = state.replace(isLoading: true);
try {
final older =
id ?? (state.mediaItems.isNotEmpty ? state.mediaItems.last.id : null);
final newMedia = await fetchMedia(
older: older,
type: mediaTypes[state.typeIndex],
mode: state.modeIndex,
random: state.random,
tag: state.tag,
);
if (newMedia.isNotEmpty) {
state = state.replace(
mediaItems: mergeMediaItems(state.mediaItems, newMedia),
);
}
} catch (e) {
print('Fehler beim Laden der Medien: $e');
} finally {
state = state.replace(isLoading: false);
}
}
void toggleMute() {
state = state.replace(muted: !state.muted);
_saveMutedState();
}
}
final mediaProvider = StateNotifierProvider<MediaNotifier, MediaState>(
(ref) => MediaNotifier(),
);

View File

@ -1,59 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
final Map<String, ThemeData> themeMap = {
'f0ck': f0ckTheme,
'P1nk': p1nkTheme, // done
'Orange': orangeTheme,
'Amoled': amoledTheme,
'Paper': paperTheme,
//'Iced': icedTheme,
'f0ck95': f0ck95Theme,
'f0ck95d': f0ck95dTheme,
};
class ThemeNotifier extends StateNotifier<ThemeData> {
final FlutterSecureStorage secureStorage;
ThemeNotifier({required this.secureStorage}) : super(f0ckTheme) {
_loadTheme();
}
Future<void> _loadTheme() async {
try {
String? savedThemeName = await secureStorage.read(key: 'theme');
if (savedThemeName != null && themeMap.containsKey(savedThemeName)) {
state = themeMap[savedThemeName]!;
}
} catch (error) {
debugPrint('Fehler beim Laden des Themes: $error');
state = f0ckTheme;
}
}
Future<void> updateTheme(String themeName) async {
try {
await secureStorage.write(key: 'theme', value: themeName);
state = themeMap[themeName] ?? f0ckTheme;
} catch (error) {
debugPrint('Fehler beim Aktualisieren des Themes: $error');
}
}
}
final themeNotifierProvider = StateNotifierProvider<ThemeNotifier, ThemeData>((
ref,
) {
return ThemeNotifier(
secureStorage: const FlutterSecureStorage(
aOptions: AndroidOptions(encryptedSharedPreferences: true),
),
);
});
// Definiere deine Themes wie gehabt:
final ThemeData f0ckTheme = ThemeData(
brightness: Brightness.dark,
primaryColor: const Color(0xFF9FFF00),
@ -237,7 +186,7 @@ final ThemeData f0ck95Theme = ThemeData(
backgroundColor: const Color(0xFFE0E0E0),
foregroundColor: Colors.black,
elevation: 4,
centerTitle: true
centerTitle: true,
),
textTheme: const TextTheme(
bodyLarge: TextStyle(color: Colors.black),
@ -286,3 +235,56 @@ final ThemeData f0ck95dTheme = ThemeData(
trackColor: WidgetStateProperty.all<Color>(const Color(0xFF424242)),
),
);
class ThemeController extends GetxController {
final FlutterSecureStorage secureStorage = const FlutterSecureStorage(
aOptions: AndroidOptions(encryptedSharedPreferences: true),
);
final Rx<ThemeData> currentTheme = f0ckTheme.obs;
final Map<String, ThemeData> themeMap = {
'f0ck': f0ckTheme,
'P1nk': p1nkTheme,
'Orange': orangeTheme,
'Amoled': amoledTheme,
'Paper': paperTheme,
'f0ck95': f0ck95Theme,
'f0ck95d': f0ck95dTheme,
};
@override
void onInit() {
super.onInit();
_loadTheme();
}
Future<void> _loadTheme() async {
try {
final String? savedThemeName = await secureStorage.read(key: 'theme');
if (savedThemeName != null && themeMap.containsKey(savedThemeName)) {
currentTheme.value = themeMap[savedThemeName]!;
Get.changeTheme(currentTheme.value);
}
} catch (error) {
debugPrint('Fehler beim Laden des Themes: $error');
currentTheme.value = f0ckTheme;
Get.changeTheme(f0ckTheme);
}
}
Future<void> updateTheme(String themeName) async {
try {
await secureStorage.write(key: 'theme', value: themeName);
if (themeMap.containsKey(themeName)) {
currentTheme.value = themeMap[themeName]!;
Get.changeTheme(currentTheme.value);
} else {
currentTheme.value = f0ckTheme;
Get.changeTheme(f0ckTheme);
}
} catch (error) {
debugPrint('Fehler beim Aktualisieren des Themes: $error');
}
}
}