curved_gradient 0.2.2 curved_gradient: ^0.2.2 copied to clipboard
Generate a gradient using a custom curve function. Can be used in place of `LinearGradient`.
import 'dart:math';
import 'package:curved_gradient/curved_gradient.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Row(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Expanded(
flex: 1,
child: Container(
decoration: BoxDecoration(
gradient: CurvedGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.grey, Colors.transparent],
granularity: 50,
curveGenerator: (x) => pow(sin(x * 10), 2).toDouble(),
),
),
),
),
Expanded(
flex: 1,
child: Container(
decoration: BoxDecoration(
gradient: CurvedGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.grey, Colors.transparent],
granularity: 50,
curveGenerator: (x) => pow(1 - x, 5).toDouble(),
),
),
),
),
Expanded(
flex: 1,
child: Container(
decoration: BoxDecoration(
gradient: CurvedGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.grey, Colors.transparent],
stops: [0.2, 0.8],
granularity: 50,
curveGenerator: (x) => pow(1 - x, 5).toDouble(),
),
),
),
),
]),
),
);
}
}