refactor: simplify color filter handling in image view
This commit is contained in:
parent
4265ba11fe
commit
a89e1b9ba7
3 changed files with 38 additions and 45 deletions
|
|
@ -27,11 +27,13 @@ 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,
|
||||||
|
color: color,
|
||||||
fit: getBoxFit(scaleType),
|
fit: getBoxFit(scaleType),
|
||||||
filterQuality: FilterQuality.medium,
|
filterQuality: FilterQuality.medium,
|
||||||
mode: ExtendedImageMode.gesture,
|
mode: ExtendedImageMode.gesture,
|
||||||
|
|
@ -39,7 +41,6 @@ class ImageViewPaged extends ConsumerWidget {
|
||||||
loadStateChanged: loadStateChanged,
|
loadStateChanged: loadStateChanged,
|
||||||
initGestureConfigHandler: initGestureConfigHandler,
|
initGestureConfigHandler: initGestureConfigHandler,
|
||||||
onDoubleTap: onDoubleTap),
|
onDoubleTap: onDoubleTap),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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,7 +95,6 @@ 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(
|
||||||
|
|
@ -105,7 +107,6 @@ class ImageViewVertical extends ConsumerWidget {
|
||||||
imageWidget
|
imageWidget
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,27 +6,18 @@ 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});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
|
||||||
final customColorFilter = ref.watch(customColorFilterStateProvider);
|
final customColorFilter = ref.watch(customColorFilterStateProvider);
|
||||||
final colorFilterBlendMode = ref.watch(colorFilterBlendModeStateProvider);
|
final colorFilterBlendMode = ref.watch(colorFilterBlendModeStateProvider);
|
||||||
return Container(
|
return (
|
||||||
foregroundDecoration: BoxDecoration(
|
|
||||||
backgroundBlendMode:
|
|
||||||
getColorFilterBlendMode(colorFilterBlendMode, context),
|
getColorFilterBlendMode(colorFilterBlendMode, context),
|
||||||
color: customColorFilter == null
|
customColorFilter == null
|
||||||
? Colors.transparent
|
? Colors.transparent
|
||||||
: Color.fromARGB(customColorFilter.a ?? 0, customColorFilter.r ?? 0,
|
: Color.fromARGB(customColorFilter.a ?? 0, customColorFilter.r ?? 0,
|
||||||
customColorFilter.g ?? 0, customColorFilter.b ?? 0),
|
customColorFilter.g ?? 0, customColorFilter.b ?? 0)
|
||||||
),
|
|
||||||
child: child,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Widget customColorFilterListTile(String label, int value,
|
Widget customColorFilterListTile(String label, int value,
|
||||||
void Function((double, bool, String))? onChanged, BuildContext context) {
|
void Function((double, bool, String))? onChanged, BuildContext context) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue