Skip to content

Instantly share code, notes, and snippets.

@mileskrell
Created August 14, 2019 14:43
Show Gist options
  • Save mileskrell/a383daab6f14be1eb59df2f42c20724c to your computer and use it in GitHub Desktop.
Save mileskrell/a383daab6f14be1eb59df2f42c20724c to your computer and use it in GitHub Desktop.
A Flutter widget that displays diagonal stripes on top of its child
import 'package:flutter/material.dart';
class StripeContainer extends StatelessWidget {
final Widget child;
StripeContainer({@required this.child});
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment(-1.0, -4.0),
end: Alignment(1.0, 4.0),
colors: List.generate(66, (index) {
if (index % 4 == 0 || index % 4 == 1) {
return Colors.transparent;
} else {
return Colors.grey;
}
}),
stops: () {
final List<double> stops = [];
double i = 0;
double increment = 0.05;
while (i < 1) {
stops.add(i);
i += increment;
if (i >= 1) {
stops.add(1);
break;
}
increment = increment == 0.05 ? 0.01 : 0.05;
stops.add(i);
}
return stops;
}(),
),
),
child: child,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment