Я не уверен, что это хорошее решение. Это сделает свое дело.
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(home: FirstPage()));
class FirstPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Demo")),
body: Stack(
fit: StackFit.expand,
children: <Widget>[
Image.network(
"https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg",
fit: BoxFit.cover,
),
CustomPaint(
painter: MyPainter(),
)
],
),
);
}
}
class MyPainter extends CustomPainter {
final Color color;
final double opacity;
///ratio of max(height, width)
final double radius;
MyPainter({
Color color,
double radius = 0.3,
this.opacity = 0.4,
}) : assert(opacity != null && opacity >= 0.0 && opacity <= 1.0),
color = color ?? Colors.black,
radius = radius ?? 0.3;
@override
void paint(Canvas canvas, Size size) {
var rect = Offset.zero & size;
var gradient = RadialGradient(
center: Alignment.center,
radius: radius,
colors: [const Color(0x0000000), color.withOpacity(opacity)],
stops: [1.0, 1.0],
);
canvas.drawRect(
rect,
Paint()..shader = gradient.createShader(rect),
);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}