+79
-40
@@ -1,5 +1,4 @@
|
|||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter/rendering.dart";
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MainApp());
|
runApp(const MainApp());
|
||||||
@@ -8,59 +7,99 @@ void main() {
|
|||||||
class MainApp extends StatelessWidget {
|
class MainApp extends StatelessWidget {
|
||||||
const MainApp({super.key});
|
const MainApp({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return const Background();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Background extends StatelessWidget {
|
||||||
|
const new({
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return LayoutBuilder(
|
return LayoutBuilder(
|
||||||
builder: (context, constraints) => CustomPaint(
|
builder: (context, constraints) => Stack(
|
||||||
size: constraints.biggest,
|
textDirection: TextDirection.ltr,
|
||||||
painter: Sky(),
|
children: [
|
||||||
|
CustomPaint(
|
||||||
|
size: constraints.biggest,
|
||||||
|
painter: Ceiling(),
|
||||||
|
),
|
||||||
|
CustomPaint(
|
||||||
|
size: constraints.biggest,
|
||||||
|
painter: Floor(),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sky extends CustomPainter {
|
class Ceiling extends CustomPainter {
|
||||||
@override
|
@override
|
||||||
void paint(Canvas canvas, Size size) {
|
void paint(Canvas canvas, Size size) {
|
||||||
final Rect rect = Offset.zero & size;
|
final Rect rect = Offset.zero & size;
|
||||||
const RadialGradient gradient = RadialGradient(
|
final double halfHeight = rect.height / 2;
|
||||||
center: Alignment(0.7, -0.6),
|
final Rect topHalf = Rect.fromLTWH(
|
||||||
radius: 0.2,
|
rect.left,
|
||||||
colors: <Color>[Color(0xFFFFFF00), Color(0xFF0099FF)],
|
rect.top,
|
||||||
stops: <double>[0.4, 1.0],
|
rect.width,
|
||||||
|
halfHeight,
|
||||||
|
);
|
||||||
|
|
||||||
|
const LinearGradient gradient = LinearGradient(
|
||||||
|
begin: Alignment.topCenter,
|
||||||
|
end: Alignment.bottomCenter,
|
||||||
|
colors: [
|
||||||
|
Color.fromRGBO(32, 32, 32, 1.0),
|
||||||
|
Color.fromRGBO(96, 96, 96, 1.0),
|
||||||
|
],
|
||||||
|
stops: [0.0, 1.0],
|
||||||
|
);
|
||||||
|
canvas.drawRect(
|
||||||
|
topHalf,
|
||||||
|
Paint()..shader = gradient.createShader(topHalf),
|
||||||
);
|
);
|
||||||
canvas.drawRect(rect, Paint()..shader = gradient.createShader(rect));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
SemanticsBuilderCallback get semanticsBuilder {
|
bool shouldRepaint(covariant oldDelegate) => false;
|
||||||
return (Size size) {
|
|
||||||
// Annotate a rectangle containing the picture of the sun
|
|
||||||
// with the label "Sun". When text to speech feature is enabled on the
|
|
||||||
// device, a user will be able to locate the sun on this picture by
|
|
||||||
// touch.
|
|
||||||
Rect rect = Offset.zero & size;
|
|
||||||
final double width = size.shortestSide * 0.4;
|
|
||||||
rect = const Alignment(0.8, -0.9).inscribe(Size(width, width), rect);
|
|
||||||
return <CustomPainterSemantics>[
|
|
||||||
CustomPainterSemantics(
|
|
||||||
rect: rect,
|
|
||||||
properties: const SemanticsProperties(
|
|
||||||
label: "Sun",
|
|
||||||
textDirection: TextDirection.ltr,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Since this Sky painter has no fields, it always paints
|
|
||||||
// the same thing and semantics information is the same.
|
|
||||||
// Therefore we return false here. If we had fields (set
|
|
||||||
// from the constructor) then we would return true if any
|
|
||||||
// of them differed from the same fields on the oldDelegate.
|
|
||||||
@override
|
@override
|
||||||
bool shouldRepaint(Sky oldDelegate) => false;
|
bool shouldRebuildSemantics(covariant oldDelegate) => false;
|
||||||
@override
|
}
|
||||||
bool shouldRebuildSemantics(Sky oldDelegate) => false;
|
|
||||||
|
class Floor extends CustomPainter {
|
||||||
|
@override
|
||||||
|
void paint(Canvas canvas, Size size) {
|
||||||
|
final Rect rect = Offset.zero & size;
|
||||||
|
final double halfHeight = rect.height / 2;
|
||||||
|
final Rect bottomHalf = Rect.fromLTWH(
|
||||||
|
rect.left,
|
||||||
|
halfHeight,
|
||||||
|
rect.width,
|
||||||
|
rect.bottom,
|
||||||
|
);
|
||||||
|
|
||||||
|
const LinearGradient gradient = LinearGradient(
|
||||||
|
begin: Alignment.topCenter,
|
||||||
|
end: Alignment.bottomCenter,
|
||||||
|
colors: [
|
||||||
|
Color.fromRGBO(32, 32, 0, 1.0),
|
||||||
|
Color.fromRGBO(96, 96, 0, 1.0),
|
||||||
|
],
|
||||||
|
stops: [0.0, 1.0],
|
||||||
|
);
|
||||||
|
canvas.drawRect(
|
||||||
|
bottomHalf,
|
||||||
|
Paint()..shader = gradient.createShader(bottomHalf),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool shouldRepaint(covariant oldDelegate) => false;
|
||||||
|
@override
|
||||||
|
bool shouldRebuildSemantics(covariant oldDelegate) => false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user