skywood/lib/pages/widgets/pixel_widgets.dart

219 lines
5.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:skywood/main/lib_file.dart';
class PixelPageBackground extends StatelessWidget {
const PixelPageBackground({super.key, required this.child});
final Widget child;
@override
Widget build(BuildContext context) {
return Stack(
children: [
const Positioned.fill(child: ColoredBox(color: Colors.white)),
const Positioned.fill(child: CustomPaint(painter: _GridPainter())),
Positioned(
left: -18.w,
top: 178.h,
child: Container(
width: 52.w,
height: 132.h,
color: const Color(0xFF08F214),
),
),
Positioned(
right: -20.w,
top: 282.h,
child: Container(
width: 58.w,
height: 286.h,
color: const Color(0xFF08F214),
),
),
child,
],
);
}
}
class PixelPanel extends StatelessWidget {
const PixelPanel({
super.key,
required this.child,
this.padding,
this.color = Colors.white,
this.borderColor = const Color(0xFF1C1E1F),
this.shadowColor = const Color(0xFF653CFA),
});
final Widget child;
final EdgeInsets? padding;
final Color color;
final Color borderColor;
final Color shadowColor;
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: color,
border: Border.all(color: borderColor, width: 1.5.w),
boxShadow: [
BoxShadow(color: shadowColor, offset: Offset(4.w, 4.h)),
BoxShadow(color: shadowColor, offset: Offset(-4.w, 4.h)),
],
),
padding: padding ?? EdgeInsets.all(10.w),
child: child,
);
}
}
class PixelSectionLabel extends StatelessWidget {
const PixelSectionLabel({
super.key,
required this.label,
this.width,
this.trailing,
});
final String label;
final double? width;
final Widget? trailing;
@override
Widget build(BuildContext context) {
return Container(
height: 20.h,
width: width?.w,
padding: EdgeInsets.symmetric(horizontal: 8.w),
decoration: BoxDecoration(
color: const Color(0xFF7B54F6),
border: Border.all(color: const Color(0xFF1C1E1F), width: 1.w),
),
child: Row(
children: [
Container(width: 7.w, height: 7.w, color: const Color(0xFF34F04F)),
SizedBox(width: 5.w),
Expanded(
child: Text(
label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.white,
fontSize: 12.sp,
fontWeight: FontWeight.w700,
height: 1,
),
),
),
trailing ?? const SizedBox.shrink(),
],
),
);
}
}
class PixelButton extends StatelessWidget {
const PixelButton({
super.key,
required this.label,
this.onTap,
this.width = 116,
this.height = 28,
this.color = const Color(0xFF8D62F7),
});
final String label;
final VoidCallback? onTap;
final double width;
final double height;
final Color color;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Container(
width: width.w,
height: height.h,
alignment: Alignment.center,
decoration: BoxDecoration(
color: color,
border: Border.all(color: const Color(0xFF1C1E1F), width: 1.w),
),
child: Text(
label,
style: TextStyle(
color: Colors.white,
fontSize: 12.sp,
fontWeight: FontWeight.w800,
height: 1,
shadows: const [
Shadow(color: Color(0xFF1C1E1F), offset: Offset(1, 1)),
],
),
),
),
);
}
}
class PosterImage extends StatelessWidget {
const PosterImage({
super.key,
this.width,
this.height,
this.borderRadius = 3,
this.showBorder = true,
});
final double? width;
final double? height;
final double borderRadius;
final bool showBorder;
@override
Widget build(BuildContext context) {
return Container(
width: width?.w,
height: height?.h,
decoration: BoxDecoration(
border: showBorder
? Border.all(color: const Color(0xFF1C1E1F), width: 0.8.w)
: null,
borderRadius: BorderRadius.circular(borderRadius.r),
),
clipBehavior: Clip.antiAlias,
child: HelpImg.asset(ConstImg.homeCardBg, fit: BoxFit.cover),
);
}
}
class _GridPainter extends CustomPainter {
const _GridPainter();
@override
void paint(Canvas canvas, Size size) {
final gridPaint = Paint()
..color = const Color(0xFFE0D8FF)
..strokeWidth = 0.8;
const step = 10.0;
for (double x = 0; x <= size.width; x += step) {
canvas.drawLine(Offset(x, 0), Offset(x, size.height), gridPaint);
}
for (double y = 0; y <= size.height; y += step) {
canvas.drawLine(Offset(0, y), Offset(size.width, y), gridPaint);
}
final blockPaint = Paint()..color = const Color(0xFFE0D8FF);
canvas.drawRect(Rect.fromLTWH(80, 0, 34, 96), blockPaint);
canvas.drawRect(Rect.fromLTWH(228, 0, 34, 32), blockPaint);
canvas.drawRect(Rect.fromLTWH(278, 112, 34, 34), blockPaint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}