Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ShaderMask
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'ShaderMask Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('ShaderMask Demo'),
),
body: ShaderMaskDemo(),
);
}
}
class ShaderMaskDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.all(10.0),
child: ListView(
children: [
Align(
alignment: Alignment.center,
child: Column(
children: [
ShaderMask(
blendMode: BlendMode.srcIn,
shaderCallback: (Rect bound) {
return LinearGradient(colors: <Color>[
Colors.deepOrange,
Colors.blue,
Colors.green,
Colors.amber,
]).createShader(bound);
},
child: Icon(
Icons.ac_unit,
size: 200,
),
),
ShaderMask(
blendMode: BlendMode.srcIn,
shaderCallback: (Rect bound) {
return LinearGradient(colors: <Color>[
Colors.purple,
Colors.red,
Colors.green,
Colors.orange,
Colors.blue,
]).createShader(bound);
},
child: Column(
children: [
Text(
"Flutter".toUpperCase(),
style: TextStyle(
fontSize: 80, fontWeight: FontWeight.w900),
),
Image.network(
"https://static.thenounproject.com/png/1704225-200.png",
),
MaterialButton(
onPressed: () {},
color: Color(0x55888888),
child: Text(
"Hello world",
style: TextStyle(
fontSize: 50, fontWeight: FontWeight.w900),
),
),
Icon(
Icons.ac_unit,
size: 200,
color: Colors.black54,
),
],
),
),
],
)),
],
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment