parent
0c381d58f1
commit
124c521f0e
@ -0,0 +1,52 @@
|
||||
import 'package:aku_new_community/painters/progress_bar_painter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:velocity_x/velocity_x.dart';
|
||||
|
||||
class ProgressPaint extends StatelessWidget {
|
||||
final double proportion;
|
||||
final int activity;
|
||||
final int lowLevel;
|
||||
|
||||
const ProgressPaint(
|
||||
{Key? key,
|
||||
required this.proportion,
|
||||
required this.activity,
|
||||
required this.lowLevel})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: 110.w,
|
||||
alignment: Alignment.center,
|
||||
child: CustomPaint(
|
||||
painter:
|
||||
ProgressBarPainter(proportion: proportion, lowLevel: lowLevel),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left: 180.w,
|
||||
bottom: 16.w,
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
padding: EdgeInsets.symmetric(horizontal: 22.w, vertical: 12.w),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(38.w),
|
||||
color: Color(0x000000).withOpacity(0.2),
|
||||
),
|
||||
child: '距离下一级还有 ${activity} 活跃度'
|
||||
.text
|
||||
.size(22.sp)
|
||||
.color(Colors.white)
|
||||
.make(),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
class ProgressBarPainter extends CustomPainter {
|
||||
final double proportion;
|
||||
final int lowLevel;
|
||||
|
||||
ProgressBarPainter({
|
||||
required this.proportion,
|
||||
required this.lowLevel,
|
||||
});
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final startAngle = pi * 1.42;
|
||||
final sweepAngle = pi * 0.03;
|
||||
final animateAngle = pi * 0.1 * proportion;
|
||||
final Gradient gradient = new SweepGradient(
|
||||
startAngle: startAngle,
|
||||
endAngle: startAngle + sweepAngle,
|
||||
colors: [
|
||||
Colors.white.withOpacity(0.0),
|
||||
Colors.white,
|
||||
],
|
||||
);
|
||||
final Gradient endGradient = new SweepGradient(
|
||||
startAngle: startAngle + sweepAngle + pi * 0.1,
|
||||
endAngle: startAngle + sweepAngle + pi * 0.1 + sweepAngle,
|
||||
colors: [
|
||||
Colors.black.withOpacity(0.4),
|
||||
Colors.black.withOpacity(0),
|
||||
],
|
||||
);
|
||||
var center = Offset(size.width / 2, 700 - 30);
|
||||
final Rect rect = Rect.fromCircle(center: center, radius: 700);
|
||||
final foregroundPaint = Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..color = Colors.white
|
||||
..strokeCap = StrokeCap.round
|
||||
..shader = gradient.createShader(rect)
|
||||
..strokeWidth = 10.w;
|
||||
final backPaint = Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeCap = StrokeCap.round
|
||||
..color = Colors.black.withOpacity(0.4)
|
||||
..strokeWidth = 10.w;
|
||||
canvas.drawArc(rect, startAngle, sweepAngle, false, foregroundPaint);
|
||||
canvas.drawArc(rect, startAngle + sweepAngle, pi * 0.1, false, backPaint);
|
||||
canvas.drawCircle(
|
||||
Offset(-110, -21), 12.w, foregroundPaint..style = PaintingStyle.fill);
|
||||
canvas.drawArc(rect, startAngle + sweepAngle, animateAngle, false,
|
||||
foregroundPaint..style = PaintingStyle.stroke);
|
||||
canvas.drawArc(rect, startAngle + sweepAngle + pi * 0.1, sweepAngle, false,
|
||||
backPaint..shader = endGradient.createShader(rect));
|
||||
canvas.drawCircle(
|
||||
Offset(110, -21), 12.w, foregroundPaint..style = PaintingStyle.fill);
|
||||
TextPainter textPainter = TextPainter(
|
||||
text: TextSpan(
|
||||
text: 'LV$lowLevel',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 22.sp,
|
||||
)),
|
||||
textDirection: TextDirection.ltr);
|
||||
textPainter.layout();
|
||||
textPainter.paint(canvas, Offset(-117, -40));
|
||||
textPainter
|
||||
..text = TextSpan(
|
||||
text: 'LV${lowLevel + 1}',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 22.sp,
|
||||
));
|
||||
textPainter.layout();
|
||||
textPainter.paint(canvas, Offset(103, -40));
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(ProgressBarPainter oldDelegate) {
|
||||
return oldDelegate.proportion != proportion;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue