Created
July 10, 2023 22:48
-
-
Save jonahwilliams/80d0af639ec8952a3e31bac084fb202b to your computer and use it in GitHub Desktop.
Gradient stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2014 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'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Center(child: CustomPaint( | |
painter: FooPainter(), | |
size: const Size(400, 400) | |
)); | |
} | |
} | |
class FooPainter extends CustomPainter { | |
@override | |
void paint(Canvas canvas, Size size) { | |
canvas.drawRect(Rect.fromLTWH(0, 0, size.width, size.height), Paint() | |
..shader = ui.Gradient.linear( | |
const Offset(25, 25), | |
Offset(size.width - 25, size.height - 25), | |
<Color>[Colors.red, Colors.blue], | |
[0, 1.0], | |
TileMode.decal, | |
) | |
// Try changing or removing blend mode | |
..colorFilter = ui.ColorFilter.mode(Colors.orange, BlendMode.src) | |
); | |
canvas.drawRect(Rect.fromLTWH(0, 0, size.width, size.height), Paint()..color = Colors.green ..style = PaintingStyle.stroke); | |
} | |
@override | |
bool shouldRepaint(covariant CustomPainter oldDelegate) { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment