news 2026/3/4 20:22:43

21天学会OpenHarmony跨平台开发 - windows + Flutter【Day10】

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
21天学会OpenHarmony跨平台开发 - windows + Flutter【Day10】

继续写下一个组件:顶部的搜索栏、分类滚动

import 'package:flutter/material.dart'; class Hmsearch extends StatefulWidget { final TextEditingController? controller; final String hintText; final VoidCallback? onSearchPressed; final VoidCallback? onCameraPressed; final ValueChanged<String>? onSubmitted; final bool showCameraIcon; final bool showSearchButton; const Hmsearch({ super.key, this.controller, this.hintText = '华为matebook触控屏', this.onSearchPressed, this.onCameraPressed, this.onSubmitted, this.showCameraIcon = true, this.showSearchButton = true, }); @override State<Hmsearch> createState() => _HmsearchState(); } class _HmsearchState extends State<Hmsearch> { @override Widget build(BuildContext context) { return Container( height: 48, decoration: BoxDecoration( border: Border.all( color: Colors.red, // 细红色边框 width: 1.5, ), borderRadius: BorderRadius.circular(8), color: Colors.white, ), child: Row( children: [ // 左侧搜索图标 const Padding( padding: EdgeInsets.symmetric(horizontal: 12), child: Icon( Icons.search, color: Colors.red, // 深红色 size: 20, ), ), // 搜索输入框 Expanded( child: TextField( controller: widget.controller, decoration: InputDecoration( hintText: widget.hintText, hintStyle: const TextStyle( color: Colors.black54, fontSize: 16, ), border: InputBorder.none, contentPadding: const EdgeInsets.only(bottom: 4), ), style: const TextStyle( color: Colors.black87, fontSize: 16, ), onSubmitted: widget.onSubmitted, ), ), // 相机图标 if (widget.showCameraIcon) Padding( padding: const EdgeInsets.only(right: 12), child: GestureDetector( onTap: widget.onCameraPressed, child: const Icon( Icons.camera_alt_outlined, color: Color(0xFF9E9E9E), // 浅灰色 size: 20, ), ), ), // 搜索按钮 if (widget.showSearchButton) Container( width: 80, height: 48, margin: const EdgeInsets.only(right: 1), decoration: const BoxDecoration( color: Colors.red, // 红色背景 borderRadius: BorderRadius.only( topRight: Radius.circular(7), bottomRight: Radius.circular(7), ), ), child: Material( color: Colors.transparent, child: InkWell( onTap: widget.onSearchPressed, borderRadius: const BorderRadius.only( topRight: Radius.circular(7), bottomRight: Radius.circular(7), ), child: const Center( child: Text( '搜索', style: TextStyle( color: Colors.white, fontSize: 16, fontWeight: FontWeight.w500, ), ), ), ), ), ), ], ), ); } }

分类滚动栏:

import 'package:flutter/material.dart'; class Hmcategory extends StatefulWidget { const Hmcategory({super.key}); @override State<Hmcategory> createState() => _HmcategoryState(); } class _HmcategoryState extends State<Hmcategory> { @override Widget build(BuildContext context) { return SizedBox( height: 100, child: ListView.builder( scrollDirection: Axis.horizontal, itemCount: 10, itemBuilder: (BuildContext context, int index) { return Container( alignment: Alignment.center, width: 80, height: 100, margin: EdgeInsets.symmetric(horizontal: 10), color: Colors.blue, child: Text("分类$index", style: TextStyle(color: Colors.white)), ); }), ); } }

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

极速掌握5步搞定YOLOv11分割标注转换:实战场景全指南

极速掌握5步搞定YOLOv11分割标注转换&#xff1a;实战场景全指南 【免费下载链接】ultralytics ultralytics - 提供 YOLOv8 模型&#xff0c;用于目标检测、图像分割、姿态估计和图像分类&#xff0c;适合机器学习和计算机视觉领域的开发者。 项目地址: https://gitcode.com/…

作者头像 李华
网站建设 2026/3/3 8:23:02

Luckysheet终极指南:轻松打造专业级在线表格的5个步骤

Luckysheet终极指南&#xff1a;轻松打造专业级在线表格的5个步骤 【免费下载链接】Luckysheet 项目地址: https://gitcode.com/gh_mirrors/luc/Luckysheet 想要像Excel一样强大的在线表格工具&#xff0c;但又不想支付高昂的费用&#xff1f;Luckysheet作为一款完全免…

作者头像 李华
网站建设 2026/3/4 14:02:41

Python工作流引擎终极指南:用SpiffWorkflow实现企业级BPMN自动化

在当今数字化转型浪潮中&#xff0c;企业面临着业务流程日益复杂的挑战。传统的手动处理方式效率低下、容易出错&#xff0c;而复杂的编程实现又需要大量技术资源。SpiffWorkflow作为纯Python实现的工作流引擎&#xff0c;完美解决了这一痛点&#xff0c;让非技术背景的业务人员…

作者头像 李华
网站建设 2026/3/3 13:58:45

DSub Android客户端:打造你的专属私人音乐云

DSub Android客户端&#xff1a;打造你的专属私人音乐云 【免费下载链接】Subsonic Home of the DSub Android client fork 项目地址: https://gitcode.com/gh_mirrors/su/Subsonic 你是否厌倦了商业音乐平台的版权限制&#xff1f;想要随时随地聆听自己珍藏的音乐库&am…

作者头像 李华
网站建设 2026/3/3 14:52:01

Unity反向遮罩技术:突破传统UI设计的5大创意应用

Unity反向遮罩技术&#xff1a;突破传统UI设计的5大创意应用 【免费下载链接】UIMask Reverse Mask of Unity "Mask" component 项目地址: https://gitcode.com/gh_mirrors/ui/UIMask 你是否曾为Unity默认遮罩的局限性而苦恼&#xff1f;想要实现圆形进度条、…

作者头像 李华
网站建设 2026/3/3 14:11:39

完全掌控Mac桌面歌词:LyricsX深度使用全攻略

完全掌控Mac桌面歌词&#xff1a;LyricsX深度使用全攻略 【免费下载链接】Lyrics Swift-based iTunes plug-in to display lyrics on the desktop. 项目地址: https://gitcode.com/gh_mirrors/lyr/Lyrics 还在为Mac音乐播放器缺乏专业的歌词显示功能而烦恼吗&#xff1f…

作者头像 李华