refactor: simplify color filter handling in image view

This commit is contained in:
Moustapha Kodjo Amadou 2025-01-22 10:47:34 +01:00
parent 4265ba11fe
commit a89e1b9ba7
3 changed files with 38 additions and 45 deletions

View file

@ -27,19 +27,20 @@ class ImageViewPaged extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final scaleType = ref.watch(scaleTypeStateProvider); final scaleType = ref.watch(scaleTypeStateProvider);
final image = data.getImageProvider(ref, true); final image = data.getImageProvider(ref, true);
final (colorBlendMode, color) = chapterColorFIlterValues(context, ref);
return GestureDetector( return GestureDetector(
onLongPress: () => onLongPressData.call(data), onLongPress: () => onLongPressData.call(data),
child: ColorFilterWidget( child: ExtendedImage(
child: ExtendedImage( image: image,
image: image, colorBlendMode: colorBlendMode,
fit: getBoxFit(scaleType), color: color,
filterQuality: FilterQuality.medium, fit: getBoxFit(scaleType),
mode: ExtendedImageMode.gesture, filterQuality: FilterQuality.medium,
handleLoadingProgress: true, mode: ExtendedImageMode.gesture,
loadStateChanged: loadStateChanged, handleLoadingProgress: true,
initGestureConfigHandler: initGestureConfigHandler, loadStateChanged: loadStateChanged,
onDoubleTap: onDoubleTap), initGestureConfigHandler: initGestureConfigHandler,
), onDoubleTap: onDoubleTap),
); );
} }
} }

View file

@ -26,7 +26,10 @@ class ImageViewVertical extends ConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final (colorBlendMode, color) = chapterColorFIlterValues(context, ref);
final imageWidget = ExtendedImage( final imageWidget = ExtendedImage(
colorBlendMode: colorBlendMode,
color: color,
image: data.getImageProvider(ref, true), image: data.getImageProvider(ref, true),
filterQuality: FilterQuality.medium, filterQuality: FilterQuality.medium,
handleLoadingProgress: true, handleLoadingProgress: true,
@ -92,20 +95,18 @@ class ImageViewVertical extends ConsumerWidget {
}); });
return GestureDetector( return GestureDetector(
onLongPress: () => onLongPressData.call(data), onLongPress: () => onLongPressData.call(data),
child: ColorFilterWidget( child: isHorizontal
child: isHorizontal ? imageWidget
? imageWidget : Column(
: Column( mainAxisAlignment: MainAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center, children: [
children: [ if (data.index == 0)
if (data.index == 0) SizedBox(
SizedBox( height: MediaQuery.of(context).padding.top,
height: MediaQuery.of(context).padding.top, ),
), imageWidget
imageWidget ],
], ),
),
),
); );
} }
} }

View file

@ -6,26 +6,17 @@ import 'package:mangayomi/modules/manga/reader/providers/color_filter_provider.d
import 'package:mangayomi/modules/more/settings/reader/reader_screen.dart'; import 'package:mangayomi/modules/more/settings/reader/reader_screen.dart';
import 'package:mangayomi/utils/extensions/build_context_extensions.dart'; import 'package:mangayomi/utils/extensions/build_context_extensions.dart';
class ColorFilterWidget extends ConsumerWidget { (BlendMode?, Color?) chapterColorFIlterValues(
final Widget child; BuildContext context, WidgetRef ref) {
const ColorFilterWidget({super.key, required this.child}); final customColorFilter = ref.watch(customColorFilterStateProvider);
final colorFilterBlendMode = ref.watch(colorFilterBlendModeStateProvider);
@override return (
Widget build(BuildContext context, WidgetRef ref) { getColorFilterBlendMode(colorFilterBlendMode, context),
final customColorFilter = ref.watch(customColorFilterStateProvider); customColorFilter == null
final colorFilterBlendMode = ref.watch(colorFilterBlendModeStateProvider); ? Colors.transparent
return Container( : Color.fromARGB(customColorFilter.a ?? 0, customColorFilter.r ?? 0,
foregroundDecoration: BoxDecoration( customColorFilter.g ?? 0, customColorFilter.b ?? 0)
backgroundBlendMode: );
getColorFilterBlendMode(colorFilterBlendMode, context),
color: customColorFilter == null
? Colors.transparent
: Color.fromARGB(customColorFilter.a ?? 0, customColorFilter.r ?? 0,
customColorFilter.g ?? 0, customColorFilter.b ?? 0),
),
child: child,
);
}
} }
Widget customColorFilterListTile(String label, int value, Widget customColorFilterListTile(String label, int value,