news 2026/7/1 20:50:01

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/6/30 13:08:22

130亿参数实现256K长上下文!腾讯混元A13B开源实测

130亿参数实现256K长上下文&#xff01;腾讯混元A13B开源实测 【免费下载链接】Hunyuan-A13B-Instruct Hunyuan-A13B-Instruct是一款基于混合专家架构的开源大语言模型&#xff0c;以13亿活跃参数实现媲美更大模型的卓越性能。其独特之处在于支持快慢双思维模式&#xff0c;用户…

作者头像 李华
网站建设 2026/7/1 10:49:00

如何免费将手机变身高清摄像头?DroidCam OBS Plugin完整使用指南

如何免费将手机变身高清摄像头&#xff1f;DroidCam OBS Plugin完整使用指南 【免费下载链接】droidcam-obs-plugin DroidCam OBS Source 项目地址: https://gitcode.com/gh_mirrors/dr/droidcam-obs-plugin 还在为昂贵的摄像头设备发愁吗&#xff1f;DroidCam OBS Plug…

作者头像 李华
网站建设 2026/6/30 23:13:26

EPubBuilder 终极指南:快速上手在线电子书制作

EPubBuilder 终极指南&#xff1a;快速上手在线电子书制作 【免费下载链接】EPubBuilder 一款在线的epub格式书籍编辑器 项目地址: https://gitcode.com/gh_mirrors/ep/EPubBuilder 你是否曾经想要将精彩的文章、学习笔记或个人作品制作成专业的电子书&#xff1f;EPubB…

作者头像 李华
网站建设 2026/7/1 10:51:20

Windows平台流媒体服务器终极搭建指南:SRS从零到精通

Windows平台流媒体服务器终极搭建指南&#xff1a;SRS从零到精通 【免费下载链接】srs-windows 项目地址: https://gitcode.com/gh_mirrors/sr/srs-windows 还在为Windows环境下搭建流媒体服务而烦恼吗&#xff1f;想要一个既强大又易用的解决方案&#xff1f;SRS&…

作者头像 李华
网站建设 2026/7/1 10:49:07

OpenWrt Argon主题终极安装指南:3步实现路由器界面美化

OpenWrt Argon主题终极安装指南&#xff1a;3步实现路由器界面美化 【免费下载链接】luci-theme-argon Argon is a clean and tidy OpenWrt LuCI theme that allows users to customize their login interface with images or videos. It also supports automatic and manual s…

作者头像 李华
网站建设 2026/7/1 10:49:06

Google发布300M EmbeddingGemma:移动端也能跑的AI嵌入模型

导语&#xff1a;Google DeepMind推出仅3亿参数的EmbeddingGemma模型&#xff0c;首次实现移动端设备上运行高性能文本嵌入任务&#xff0c;标志着轻量级AI模型在终端设备应用进入新阶段。 【免费下载链接】embeddinggemma-300m-qat-q8_0-unquantized 项目地址: https://ai.…

作者头像 李华