Skip to content

Instantly share code, notes, and snippets.

@ha-yi
Created May 19, 2020 18:32
Show Gist options
  • Save ha-yi/5279d8ef9dff368e15474994bd163872 to your computer and use it in GitHub Desktop.
Save ha-yi/5279d8ef9dff368e15474994bd163872 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
class SplitColorIcon extends StatelessWidget {
final double size;
final Color leftColor;
final Color rightColor;
final IconData iconData;
const SplitColorIcon({
Key key,
@required this.iconData,
this.size = 60,
@required this.leftColor,
@required this.rightColor,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
width: size,
height: size,
child: Stack(
children: [
Positioned(
left: 0,
top: 0,
bottom: 0,
child: ClipRect(
child: Container(
width: size / 2,
child: OverflowBox(
maxWidth: size,
maxHeight: size,
alignment: Alignment.topLeft,
child: Icon(
iconData,
size: size,
color: leftColor,
),
),
),
),
),
Positioned(
right: 0,
top: 0,
bottom: 0,
child: ClipRect(
child: Container(
width: size / 2,
child: OverflowBox(
alignment: Alignment.topRight,
maxWidth: size,
maxHeight: size,
child: Icon(
iconData,
size: size,
color: rightColor,
),
),
),
),
),
],
),
);
}
}
@ha-yi
Copy link
Author

ha-yi commented May 19, 2020

Example:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment