news 2026/4/3 3:39:42

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/1 23:30:19

树莓派5安装ROS2前必看的系统兼容性深度剖析

树莓派5跑ROS2踩坑实录&#xff1a;别再被“一键安装”误导了 最近在折腾一个小型自主移动机器人项目&#xff0c;主控平台选的是 树莓派5 ——毕竟它现在是Raspberry Pi家族里性能最强的存在。原本以为按照网上那些“三步搞定ROS2”的教程走一遍就行&#xff0c;结果从系统…

作者头像 李华
网站建设 2026/3/31 23:54:58

全面讲解usb_burning_tool在Windows下的安装配置

从零开始掌握 Amlogic 烧录利器&#xff1a;usb_burning_tool 的实战配置与避坑指南你有没有遇到过这样的场景&#xff1f;手里的开发板死机了&#xff0c;串口没输出&#xff0c;adb 连不上&#xff0c;系统卡在开机画面动弹不得。重启无数次无果&#xff0c;最后只能干瞪眼—…

作者头像 李华
网站建设 2026/4/1 13:08:33

【毕业设计】基于Python主流汽车价格分析可视化系统的设计与实现

&#x1f49f;博主&#xff1a;程序员陈辰&#xff1a;CSDN作者、博客专家、全栈领域优质创作者 &#x1f49f;专注于计算机毕业设计&#xff0c;大数据、深度学习、Java、小程序、python、安卓等技术领域 &#x1f4f2;文章末尾获取源码数据库 &#x1f308;还有大家在毕设选题…

作者头像 李华
网站建设 2026/4/1 4:32:33

【毕业设计】基于Python豆瓣电影数据可视化分析设计与实现

&#x1f49f;博主&#xff1a;程序员陈辰&#xff1a;CSDN作者、博客专家、全栈领域优质创作者 &#x1f49f;专注于计算机毕业设计&#xff0c;大数据、深度学习、Java、小程序、python、安卓等技术领域 &#x1f4f2;文章末尾获取源码数据库 &#x1f308;还有大家在毕设选题…

作者头像 李华
网站建设 2026/4/1 23:23:55

IBM Granite-4.0-Micro:3B参数全能AI模型深度解析

导语&#xff1a;IBM最新发布的30亿参数大语言模型Granite-4.0-Micro以其"小而全"的特性重新定义了轻量级AI模型的能力边界&#xff0c;在保持高效部署优势的同时&#xff0c;实现了多语言处理、工具调用与代码生成等企业级功能的突破。 【免费下载链接】granite-4.0…

作者头像 李华
网站建设 2026/3/31 8:26:15

一键重现经典B站界面:告别繁琐操作,重拾怀旧体验

一键重现经典B站界面&#xff1a;告别繁琐操作&#xff0c;重拾怀旧体验 【免费下载链接】Bilibili-Old 恢复旧版Bilibili页面&#xff0c;为了那些念旧的人。 项目地址: https://gitcode.com/gh_mirrors/bi/Bilibili-Old 厌倦了B站新版界面的复杂操作&#xff1f;Bilib…

作者头像 李华