You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
samples/next_gen_ui_demo/lib/common/shader_painter.dart

29 lines
765 B

// Copyright 2023 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
class ShaderPainter extends CustomPainter {
ShaderPainter(this.shader, {this.update});
final ui.FragmentShader shader;
final void Function(ui.FragmentShader, Size)? update;
@override
void paint(Canvas canvas, Size size) {
update?.call(shader, size);
canvas.drawRect(
Rect.fromLTWH(0, 0, size.width, size.height),
Paint()..shader = shader,
);
}
@override
bool shouldRepaint(covariant ShaderPainter oldDelegate) {
return oldDelegate.shader != shader || oldDelegate.update != update;
}
}