🚀 闪屏页动画性能优化

This commit is contained in:
toly
2020-12-10 21:38:12 +08:00
parent a5fa4c5fa0
commit 6fc195a620
3 changed files with 26 additions and 15 deletions

View File

@@ -4,6 +4,7 @@ import 'package:flutter_unit/app/router/unit_router.dart';
import 'package:flutter_unit/blocs/bloc_exp.dart';
import 'package:flutter_unit/views/pages/splash/unit_splash.dart';
/// create by 张风捷特烈 on 2020/4/28
/// contact me by email 1981462002@qq.com
/// 说明: 主程序
@@ -14,7 +15,7 @@ class FlutterUnit extends StatelessWidget {
return BlocBuilder<GlobalBloc, GlobalState>(builder: (_, state) {
return MaterialApp(
// debugShowMaterialGrid: true,
showPerformanceOverlay: state.showPerformanceOverlay,
showPerformanceOverlay: true,
// showSemanticsDebugger: true,
// checkerboardOffscreenLayers:true,
// checkerboardRasterCacheImages:true,

View File

@@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
class UnitPainter extends CustomPainter {
Paint _paint;
double width;
double factor;
Animation repaint;
Color color;
Path _path1 = Path();
@@ -15,12 +15,17 @@ class UnitPainter extends CustomPainter {
Path _path3 = Path();
Path _path4 = Path();
UnitPainter({this.width = 200.0, this.factor, this.color = Colors.blue}) {
UnitPainter({this.width = 200.0, this.repaint, this.color = Colors.blue}):super(repaint: repaint) {
_paint = Paint();
}
@override
void paint(Canvas canvas, Size size) {
_path1.reset();
_path2.reset();
_path3.reset();
_path4.reset();
var factor = repaint.value;
canvas.translate(
size.width / 2 - width * 0.5, size.height / 2 - width * 0.5);
@@ -50,11 +55,12 @@ class UnitPainter extends CustomPainter {
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
bool shouldRepaint(UnitPainter oldDelegate) {
return oldDelegate.repaint!=repaint;
}
void drawColor1(Canvas canvas) {
var factor = repaint.value;
_path1.moveTo(0, 0);
_path1.lineTo(width * 0.618 * factor - 1, 0);
_path1.lineTo(width * 0.5 - 1, width * 0.5 - 1);
@@ -64,6 +70,7 @@ class UnitPainter extends CustomPainter {
}
void drawColor2(Canvas canvas) {
var factor = repaint.value;
_path2.moveTo(width * 0.618 * factor, 0);
_path2.lineTo(width, 0);
_path2.lineTo(width, width * 0.618 * factor);
@@ -73,6 +80,7 @@ class UnitPainter extends CustomPainter {
}
void drawColor3(Canvas canvas) {
var factor = repaint.value;
_path3.moveTo(width * 0.5 + 1, width * 0.5 + 1);
_path3.lineTo(width, width * 0.618 * factor + 1);
_path3.lineTo(width, width);
@@ -81,6 +89,7 @@ class UnitPainter extends CustomPainter {
}
void drawColor4(Canvas canvas) {
var factor = repaint.value;
_path4.moveTo(0, width * (1 - 0.618) * factor);
_path4.lineTo(width * 0.5, width * 0.5);
_path4.lineTo(width * (1 - 0.618) * factor, width);

View File

@@ -20,32 +20,33 @@ class UnitSplash extends StatefulWidget {
class _UnitSplashState extends State<UnitSplash> with TickerProviderStateMixin {
AnimationController _controller;
double _factor;
// double _factor;
Animation _curveAnim;
bool _animEnd = false;
@override
void initState() {
super.initState();
SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(statusBarColor: Colors.transparent);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
_controller =
AnimationController(duration: Duration(milliseconds: 1000), vsync: this)
..addListener(_listenAnimation)
..addStatusListener(_listenStatus)
..forward();
..addStatusListener(_listenStatus)..forward();
_curveAnim = CurvedAnimation(parent: _controller, curve: Curves.fastOutSlowIn);
super.initState();
}
void _listenAnimation() {
setState(() {
return _factor = _curveAnim.value;
});
@override
void dispose() {
_controller.dispose();
super.dispose();
}
void _listenStatus(AnimationStatus status) {
if (status == AnimationStatus.completed) {
setState(() {
@@ -71,7 +72,7 @@ class _UnitSplashState extends State<UnitSplash> with TickerProviderStateMixin {
width: winW,
height: winH,
child: CustomPaint(
painter: UnitPainter(factor: _factor),
painter: UnitPainter(repaint: _curveAnim),
),
),
_buildText(winH, winW),