nikolaydymura/flutter_image_filters

Memory overflow may cause the app to crash.

Opened this issue · 0 comments

import 'package:flutter_image_filters/flutter_image_filters.dart';

class FiltersUtil {
static GroupShaderConfiguration groupConfiguration = GroupShaderConfiguration();

static BrightnessShaderConfiguration brightnessConfiguration = BrightnessShaderConfiguration();

static BulgeDistortionShaderConfiguration bulgeConfiguration = BulgeDistortionShaderConfiguration();

static dispose() {
bulgeConfiguration.dispose();
brightnessConfiguration.dispose();
groupConfiguration.clear();
groupConfiguration.dispose();
}
}

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_image_filters/flutter_image_filters.dart';
import 'package:get/get.dart';
import '../../utils/filters_util/filters_util.dart';
import 'logic.dart';

class ImageFiltersPage extends StatelessWidget {
ImageFiltersPage({super.key});

final logic = Get.put(ImageFiltersLogic());

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('编辑图片'),
),
body: Column(
children: [
Expanded(
flex: 4,
child: Obx(
() => logic.texture.value == null ? Image.file(
File(logic.imagePath ?? ''),
) : Obx(() => _buildImageShaderPreview()),
)),
Expanded(flex: 1, child: Row(
children: [
Obx(() => Slider(value: logic.brightness.value, min: -1, max: 1, onChanged: (val){
logic.changeBrightnessValue(val);
})),
],
)),
],
),
);
}

Widget _buildImageShaderPreview() {
FiltersUtil.groupConfiguration.clear();
FiltersUtil.brightnessConfiguration.brightness = logic.brightness.value;
FiltersUtil.groupConfiguration.add(FiltersUtil.brightnessConfiguration);
FiltersUtil.groupConfiguration.add(FiltersUtil.bulgeConfiguration);
return PipelineImageShaderPreview(configuration: FiltersUtil.groupConfiguration, texture: logic.texture.value!);
}
}

class ImageFiltersLogic extends GetxController {

String? get imagePath => Get.parameters['imagePath'];

Rx brightness = Rx(0);

Rx<TextureSource?> texture = Rx<TextureSource?>(null);

@OverRide
void onInit() {
// TODO: implement onInit
super.onInit();
_fetchTexture();
}
changeBrightnessValue(double val) {
brightness.value = val;
}
_fetchTexture() async {
texture.value = await TextureSource.fromFile(File(imagePath ?? ''));
}

@OverRide
void dispose() {
// TODO: implement dispose
super.dispose();
texture.dispose();
brightness.dispose();
FiltersUtil.dispose();
}
}

When quickly sliding the slider on iOS, memory usage spikes, causing the app to crash.