news 2026/4/18 3:51:26

Flutter与OpenHarmony大师详情页面实现

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Flutter与OpenHarmony大师详情页面实现

前言

大师详情页面是展示创作者完整信息的重要页面。它需要展示大师的个人资料、作品集、成就荣誉、粉丝互动等内容。本文将详细介绍如何在Flutter和OpenHarmony平台上实现一个功能完善的大师详情页面。

大师详情页面的设计需要突出创作者的专业形象,同时展示其作品和成就,帮助用户决定是否关注。

Flutter大师详情页面实现

页面结构设计

大师详情页面接收大师信息参数。

classMasterDetailPageextendsStatefulWidget{finalStringname;finalStringspecialty;constMasterDetailPage({super.key,requiredthis.name,requiredthis.specialty});@overrideState<MasterDetailPage>createState()=>_MasterDetailPageState();}class_MasterDetailPageStateextendsState<MasterDetailPage>{bool _isFollowed=false;

使用StatefulWidget管理关注状态。name和specialty通过构造函数传入。

头部信息区域

展示大师头像、名称、头衔和统计数据。

@overrideWidgetbuild(BuildContextcontext){returnScaffold(appBar:AppBar(title:constText('大师主页',style:TextStyle(color:Colors.white)),backgroundColor:constColor(0xFF8B4513),leading:IconButton(icon:constIcon(Icons.arrow_back,color:Colors.white),onPressed:()=>Navigator.pop(context),),),body:SingleChildScrollView(child:Column(children:[Container(padding:constEdgeInsets.all(24),decoration:constBoxDecoration(gradient:LinearGradient(begin:Alignment.topCenter,end:Alignment.bottomCenter,colors:[Color(0xFF8B4513),Color(0xFFD2691E)],),),child:Column(children:[CircleAvatar(radius:50,backgroundColor:Colors.white,child:CircleAvatar(radius:46,backgroundColor:constColor(0xFFF5F5DC),child:Text(widget.name[0],style:constTextStyle(fontSize:36,fontWeight:FontWeight.bold,color:Color(0xFF8B4513))),),),constSizedBox(height:16),Row(mainAxisAlignment:MainAxisAlignment.center,children:[Text(widget.name,style:constTextStyle(fontSize:22,fontWeight:FontWeight.bold,color:Colors.white)),constSizedBox(width:8),constIcon(Icons.verified,color:Colors.blue,size:20),],),constSizedBox(height:4),Text(widget.specialty,style:TextStyle(fontSize:14,color:Colors.white.withOpacity(0.9))),constSizedBox(height:16),

渐变背景增强视觉效果。双层CircleAvatar创建白色边框效果。认证图标显示在名称旁边。

统计数据与关注按钮

展示作品数、粉丝数等统计信息。

Row(mainAxisAlignment:MainAxisAlignment.spaceEvenly,children:[_buildStatColumn('作品','156'),_buildStatColumn('粉丝','2.3K'),_buildStatColumn('获赞','12.8K'),],),constSizedBox(height:20),SizedBox(width:double.infinity,child:ElevatedButton(onPressed:()=>setState(()=>_isFollowed=!_isFollowed),style:ElevatedButton.styleFrom(backgroundColor:_isFollowed?Colors.white.withOpacity(0.2):Colors.white,padding:constEdgeInsets.symmetric(vertical:12),shape:RoundedRectangleBorder(borderRadius:BorderRadius.circular(25)),),child:Text(_isFollowed?'已关注':'+ 关注',style:TextStyle(fontSize:16,color:_isFollowed?Colors.white:constColor(0xFF8B4513)),),),),],),),

统计数据均匀分布。关注按钮根据状态显示不同样式。

作品展示区域

展示大师的作品列表。

Padding(padding:constEdgeInsets.all(16),child:Column(crossAxisAlignment:CrossAxisAlignment.start,children:[constText('代表作品',style:TextStyle(fontSize:18,fontWeight:FontWeight.bold,color:Color(0xFF8B4513))),constSizedBox(height:12),GridView.count(crossAxisCount:3,shrinkWrap:true,physics:constNeverScrollableScrollPhysics(),crossAxisSpacing:8,mainAxisSpacing:8,children:List.generate(6,(index)=>Container(decoration:BoxDecoration(color:Colors.grey[200],borderRadius:BorderRadius.circular(8),),child:constCenter(child:Icon(Icons.image,color:Colors.grey)),)),),],),),],),),);}Widget_buildStatColumn(Stringlabel,Stringvalue){returnColumn(children:[Text(value,style:constTextStyle(fontSize:20,fontWeight:FontWeight.bold,color:Colors.white)),constSizedBox(height:4),Text(label,style:TextStyle(fontSize:12,color:Colors.white.withOpacity(0.8))),],);}}

GridView展示作品网格。shrinkWrap和NeverScrollableScrollPhysics使其嵌套在ScrollView中正常工作。

OpenHarmony鸿蒙实现

页面定义

鸿蒙平台使用路由参数接收大师信息。

@Entry@Componentstruct MasterDetailPage{@Statename:string=''@Statespecialty:string=''@StateisFollowed:boolean=falseaboutToAppear(){constparams=router.getParams()asRecord<string,string>this.name=params?.name||'大师'this.specialty=params?.specialty||'刺绣艺术家'}

页面布局实现

使用Scroll构建可滚动页面。

build(){Column(){Row(){Image($r('app.media.back')).width(24).height(24).fillColor(Color.White).onClick(()=>router.back())Text('大师主页').fontSize(18).fontColor(Color.White).layoutWeight(1).textAlign(TextAlign.Center)Blank().width(24)}.width('100%').height(56).padding({left:16,right:16}).backgroundColor('#8B4513')Scroll(){Column(){Column(){Text(this.name.charAt(0)).fontSize(36).fontWeight(FontWeight.Bold).fontColor('#8B4513').width(92).height(92).borderRadius(46).backgroundColor('#F5F5DC').textAlign(TextAlign.Center).border({width:4,color:Color.White})Row(){Text(this.name).fontSize(22).fontWeight(FontWeight.Bold).fontColor(Color.White)Image($r('app.media.verified')).width(20).height(20).margin({left:8})}.margin({top:16})Text(this.specialty).fontSize(14).fontColor('#FFFFFFE6').margin({top:4})Row(){this.StatColumn('作品','156')this.StatColumn('粉丝','2.3K')this.StatColumn('获赞','12.8K')}.width('100%').justifyContent(FlexAlign.SpaceEvenly).margin({top:16})Button(this.isFollowed?'已关注':'+ 关注').width('90%').height(44).fontSize(16).fontColor(this.isFollowed?Color.White:'#8B4513').backgroundColor(this.isFollowed?'#FFFFFF33':Color.White).borderRadius(22).margin({top:20}).onClick(()=>{this.isFollowed=!this.isFollowed})}.width('100%').padding(24).linearGradient({direction:GradientDirection.Bottom,colors:[['#8B4513',0],['#D2691E',1]]})Column(){Text('代表作品').fontSize(18).fontWeight(FontWeight.Bold).fontColor('#8B4513').width('100%')Grid(){ForEach([1,2,3,4,5,6],()=>{GridItem(){Stack(){Image($r('app.media.placeholder')).width('100%').height('100%').objectFit(ImageFit.Cover)}.width('100%').height('100%').backgroundColor('#F0F0F0').borderRadius(8)}})}.columnsTemplate('1fr 1fr 1fr').rowsGap(8).columnsGap(8).height(240).margin({top:12})}.width('100%').padding(16)}}.layoutWeight(1)}.width('100%').height('100%')}@BuilderStatColumn(label:string,value:string){Column(){Text(value).fontSize(20).fontWeight(FontWeight.Bold).fontColor(Color.White)Text(label).fontSize(12).fontColor('#FFFFFFCC').margin({top:4})}}}

@Builder定义可复用的统计列构建函数。Grid组件展示作品网格。

总结

本文介绍了Flutter和OpenHarmony平台上大师详情页面的实现方法。大师详情页面是展示创作者形象的重要页面,其设计需要突出专业性并提供便捷的关注入口。

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/16 21:48:04

Flutter与OpenHarmony商品详情页面开发

前言 商品详情页面是电商应用中最重要的转化页面。它需要展示商品图片、价格、规格、描述、评价等信息&#xff0c;并提供加入购物车和立即购买的入口。本文将详细介绍如何在Flutter和OpenHarmony平台上实现一个功能完善的商品详情页面。 商品详情页面的设计直接影响用户的购买…

作者头像 李华
网站建设 2026/4/18 3:34:00

ZXPInstaller:轻松解决Adobe扩展安装难题的终极工具

ZXPInstaller&#xff1a;轻松解决Adobe扩展安装难题的终极工具 【免费下载链接】ZXPInstaller Open Source ZXP Installer for Adobe Extensions 项目地址: https://gitcode.com/gh_mirrors/zx/ZXPInstaller 还记得第一次面对Adobe扩展安装时的困惑吗&#xff1f;当Ext…

作者头像 李华
网站建设 2026/4/17 22:32:52

【C++】STL--从零实现stack栈和queue队列的所有关键操作

.2. stack的使用及其模拟实现函数说明接口说明stack()构造空的栈empty()检测 stack 是否为空size()返回 stack 中元素的个数push()将元素 val 压入 stack 中pop()将 stack 中尾部的元素弹出1.2.1. stack()因为我们是将stack写成一个自定义类型&#xff0c;所以构造函数、析构函…

作者头像 李华
网站建设 2026/4/18 3:32:34

模组管理革命:智能工具重构你的游戏世界

模组管理革命&#xff1a;智能工具重构你的游戏世界 【免费下载链接】IronyModManager Mod Manager for Paradox Games. Official Discord: https://discord.gg/t9JmY8KFrV 项目地址: https://gitcode.com/gh_mirrors/ir/IronyModManager 还在为游戏模组管理而头疼吗&am…

作者头像 李华
网站建设 2026/4/18 3:27:05

PaddleSlim模型剪枝实战:轻量化部署移动端AI应用

PaddleSlim模型剪枝实战&#xff1a;轻量化部署移动端AI应用 在智能手机、IoT设备和嵌入式系统日益普及的今天&#xff0c;用户对“即时响应”“低功耗运行”的AI功能需求愈发强烈。然而&#xff0c;一个训练得再精准的深度学习模型&#xff0c;若在手机上识别一张图片要两秒、…

作者头像 李华
网站建设 2026/4/18 3:34:54

如何快速配置Zotero插件:Ethereal Style完整使用指南

如何快速配置Zotero插件&#xff1a;Ethereal Style完整使用指南 【免费下载链接】zotero-style zotero-style - 一个 Zotero 插件&#xff0c;提供了一系列功能来增强 Zotero 的用户体验&#xff0c;如阅读进度可视化和标签管理&#xff0c;适合研究人员和学者。 项目地址: …

作者头像 李华