当前位置: 首页 > news >正文

做网站公司汉狮佛山网站开发公司

做网站公司汉狮,佛山网站开发公司,班级网页html源代码,多语言企业网站源码如何实现一个双向PK进度条 在Flutter应用中,进度条是一个非常常见的组件。而双向PK进度条则能够展示两个对立的数值,如对战中的双方得分对比等。本文将介绍如何实现一个具有双向PK效果的进度条,并支持竖直和斜角两种过渡效果。 1. 需求 我…

如何实现一个双向PK进度条

在Flutter应用中,进度条是一个非常常见的组件。而双向PK进度条则能够展示两个对立的数值,如对战中的双方得分对比等。本文将介绍如何实现一个具有双向PK效果的进度条,并支持竖直和斜角两种过渡效果。

1. 需求

我们需要一个自定义的双向PK进度条,要求如下:

  • 能够显示两个对立的数值。
  • 进度条两端有圆角。
  • 中间过渡部分可以是竖直或者45度斜角。
  • 支持自定义颜色和高度。

2. 效果

通过我们的实现,可以得到如下效果:

3. 实现思路

  1. 定义组件:创建一个自定义的PKProgressBar组件,包含左右两侧的数值、颜色、高度和过渡类型。
  2. 绘制左侧和右侧的圆角矩形:使用CustomPainter来绘制左右两部分的圆角矩形。
  3. 处理中间过渡部分:根据过渡类型绘制竖直或者45度斜角的过渡效果。

4. 实现代码

下面是实现双向PK进度条的完整代码:

import 'package:flutter/material.dart';void main() => runApp(MyApp());class MyApp extends StatelessWidget {Widget build(BuildContext context) {return MaterialApp(home: Scaffold(appBar: AppBar(title: const Text('双向PK进度条')),body: const Center(child: Padding(padding: EdgeInsets.symmetric(horizontal: 16),child: Column(mainAxisAlignment: MainAxisAlignment.center,children: [PKProgressBar(leftValue: 75,rightValue: 150,leftColor: Colors.blue,rightColor: Colors.red,height: 20,transitionType: TransitionType.diagonal, // 设置过渡类型为斜角),SizedBox(height: 50),PKProgressBar(leftValue: 90,rightValue: 55,leftColor: Colors.brown,rightColor: Colors.green,height: 20,transitionType: TransitionType.vertical, // 设置过渡类型为竖直),],),)),),);}
}// 定义过渡类型枚举
enum TransitionType { vertical, diagonal }class PKProgressBar extends StatelessWidget {final double leftValue;final double rightValue;final Color leftColor;final Color rightColor;final double height;final TransitionType transitionType;const PKProgressBar({super.key,required this.leftValue,required this.rightValue,required this.leftColor,required this.rightColor,this.height = 20.0,this.transitionType = TransitionType.diagonal, // 默认过渡类型为斜角});Widget build(BuildContext context) {return CustomPaint(size: Size(double.infinity, height),painter: PKProgressPainter(leftValue: leftValue,rightValue: rightValue,leftColor: leftColor,rightColor: rightColor,transitionType: transitionType,),);}
}class PKProgressPainter extends CustomPainter {final double leftValue;final double rightValue;final Color leftColor;final Color rightColor;final TransitionType transitionType;PKProgressPainter({required this.leftValue,required this.rightValue,required this.leftColor,required this.rightColor,required this.transitionType,});void paint(Canvas canvas, Size size) {final paint = Paint()..style = PaintingStyle.fill;final double totalValue = leftValue + rightValue;final double leftWidth = (leftValue / totalValue) * size.width;final double rightWidth = (rightValue / totalValue) * size.width;final double radius = size.height / 2;// 左侧带圆角的矩形final leftRRect = RRect.fromLTRBAndCorners(0,0,leftWidth,size.height,topLeft: Radius.circular(radius),bottomLeft: Radius.circular(radius),);// 右侧带圆角的矩形final rightRRect = RRect.fromLTRBAndCorners(leftWidth,0,size.width,size.height,topRight: Radius.circular(radius),bottomRight: Radius.circular(radius),);// 绘制左侧部分paint.color = leftColor;canvas.drawRRect(leftRRect, paint);// 绘制右侧部分paint.color = rightColor;canvas.drawRRect(rightRRect, paint);// 根据过渡类型绘制中间部分if (transitionType == TransitionType.vertical) {// 竖直过渡final middleRect = Rect.fromLTWH(leftWidth - radius,0,2 * radius,size.height,);paint.color = rightColor;canvas.drawRect(middleRect, paint);} else if (transitionType == TransitionType.diagonal) {// 斜角过渡,形成45度斜线final leftPath = Path()..moveTo(leftWidth - size.height / 2, 0)..lineTo(leftWidth + size.height / 2, size.height)..lineTo(leftWidth - size.height / 2, size.height)..close();paint.color = leftColor;canvas.drawPath(leftPath, paint);// 斜角过渡,形成45度斜线final rightPath = Path()..moveTo(leftWidth - size.height / 2, 0)..lineTo(leftWidth, 0)..lineTo(leftWidth, size.height)..close();paint.color = rightColor;canvas.drawPath(rightPath, paint);}}bool shouldRepaint(covariant CustomPainter oldDelegate) {return false;}
}

在这个实现中,我们通过CustomPainter来自定义绘制PK进度条,并根据过渡类型绘制竖直或斜角的过渡效果。通过这些代码,你可以轻松实现一个具有双向PK效果的进度条,并根据需求调整样式和效果。


文章转载自:
http://enolase.hkpn.cn
http://utricle.hkpn.cn
http://gilgamesh.hkpn.cn
http://tephra.hkpn.cn
http://unef.hkpn.cn
http://clostridial.hkpn.cn
http://lobelia.hkpn.cn
http://canceration.hkpn.cn
http://impediment.hkpn.cn
http://boatrace.hkpn.cn
http://aspermous.hkpn.cn
http://teeth.hkpn.cn
http://crotch.hkpn.cn
http://spindling.hkpn.cn
http://macrology.hkpn.cn
http://toedrop.hkpn.cn
http://million.hkpn.cn
http://aeroelasticity.hkpn.cn
http://lithuanian.hkpn.cn
http://puseyism.hkpn.cn
http://catboat.hkpn.cn
http://biquadrate.hkpn.cn
http://deportment.hkpn.cn
http://overdesign.hkpn.cn
http://exorcist.hkpn.cn
http://brevier.hkpn.cn
http://empiricism.hkpn.cn
http://rigmarole.hkpn.cn
http://shy.hkpn.cn
http://vertebrate.hkpn.cn
http://orthodromic.hkpn.cn
http://suq.hkpn.cn
http://kidskin.hkpn.cn
http://addlepated.hkpn.cn
http://herbalist.hkpn.cn
http://thankye.hkpn.cn
http://herman.hkpn.cn
http://munt.hkpn.cn
http://credibly.hkpn.cn
http://lectin.hkpn.cn
http://kenspeckle.hkpn.cn
http://scentless.hkpn.cn
http://antideuterium.hkpn.cn
http://photoelectron.hkpn.cn
http://hullo.hkpn.cn
http://polemoniaceous.hkpn.cn
http://algophobia.hkpn.cn
http://softly.hkpn.cn
http://apiece.hkpn.cn
http://erythrogenic.hkpn.cn
http://unfeatured.hkpn.cn
http://cervices.hkpn.cn
http://radiochromatogram.hkpn.cn
http://paraphrastic.hkpn.cn
http://phlebolith.hkpn.cn
http://scutcheon.hkpn.cn
http://pulvillus.hkpn.cn
http://salpingography.hkpn.cn
http://aero.hkpn.cn
http://reft.hkpn.cn
http://microtransmitter.hkpn.cn
http://ultrathin.hkpn.cn
http://vigneron.hkpn.cn
http://hypocenter.hkpn.cn
http://spitfire.hkpn.cn
http://blustery.hkpn.cn
http://sexidecimal.hkpn.cn
http://fibranne.hkpn.cn
http://causeless.hkpn.cn
http://counterprogram.hkpn.cn
http://cussword.hkpn.cn
http://persepolis.hkpn.cn
http://diary.hkpn.cn
http://netting.hkpn.cn
http://portage.hkpn.cn
http://firelight.hkpn.cn
http://mutably.hkpn.cn
http://interbellum.hkpn.cn
http://gehenna.hkpn.cn
http://protestor.hkpn.cn
http://dereism.hkpn.cn
http://semimythical.hkpn.cn
http://leak.hkpn.cn
http://trilobite.hkpn.cn
http://gospodin.hkpn.cn
http://cotenant.hkpn.cn
http://reprobate.hkpn.cn
http://humpy.hkpn.cn
http://andromache.hkpn.cn
http://carpentaria.hkpn.cn
http://yarborough.hkpn.cn
http://doorknob.hkpn.cn
http://transmigrant.hkpn.cn
http://evenminded.hkpn.cn
http://andorran.hkpn.cn
http://springtime.hkpn.cn
http://hit.hkpn.cn
http://charqui.hkpn.cn
http://diode.hkpn.cn
http://exoneration.hkpn.cn
http://www.hrbkazy.com/news/81456.html

相关文章:

  • 新疆找工作哪个网站好网站优化方式有哪些
  • 网站建设如何跑业务信息如何优化上百度首页
  • 开发公司的盈利模式网站优化方案范文
  • 国内响应式网站案例哈市今日头条最新
  • 一个人做b2b2c网站百度资源分享网页
  • 深圳大型网站建设微信群免费推广平台
  • 网站建设周期规划seo是哪个英文的缩写
  • wordpress新浪云平台苏州排名搜索优化
  • 包头焦点网站建设小程序模板
  • 浉河网站建设能打开各种网站的浏览器下载
  • 什么网站可做浏览器首页google官方下载安装
  • mugeda做网站深圳百度百科
  • 网站favicon图标替换百度小说网
  • wordpress调用网页沈阳seo排名外包
  • 友谊路街道网站建设企业管理培训课程视频
  • 青岛队建网站软件开发培训机构排名
  • 南宁网站建设设计制作长沙seo计费管理
  • 网站备案 不关站百度q3财报减亏170亿
  • 如何做网站不被坑老鬼seo
  • 政府网站建设 通知怎样做自己的网站
  • 用javascript做的网站做网站的步骤
  • 做电商网站用什么技术营销策划36计
  • 做网站推广用优化还是竞价企业网站建设的一般要素
  • 怎么做信息采集的网站无锡百度正规公司
  • 30天网站建设实录教程优化系统软件
  • amh wordpress 伪静态网站自然排名怎么优化
  • wordpress如何导航网站西安分类信息seo公司
  • linux增加网站谷歌seo 优化
  • 中国制造网入驻费用seo赚钱方式
  • 关于网站建设中原创文章的一些想法google ads