Created
May 23, 2020 03:16
-
-
Save erluxman/b6f1166ac19b7b2654ee2102c58a8837 to your computer and use it in GitHub Desktop.
ShaderMask
This file contains 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
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