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

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)), ); }), ); } }

http://www.cnnetsun.cn/news/56451.html

相关文章:

  • Unity反向遮罩技术深度解析:从原理到实战应用
  • 多模态生成革命:Lumina-DiMOO全能模型重塑跨模态交互新范式
  • MarkText主题定制完全攻略:打造专属写作空间的5个关键步骤
  • 21、网络命名服务:NIS、NIS+、DNS 与 LDAP 详解
  • 22、OpenLDAP与负载均衡技术解析
  • TaskFlow:重新定义Java任务流程管理的轻量级编排框架
  • AppleRa1n终极教程:iOS设备激活锁完全绕过方案
  • 零基础入门Whisper.cpp:5分钟搭建离线语音识别系统
  • YoloMouse游戏光标自定义工具:终极使用配置指南
  • 34、Unix系统下SMB/CIFS共享访问工具全解析
  • 40、Samba使用的额外资源与命令详解
  • 27、Google 演示文稿使用指南:文本操作与格式设置全攻略
  • 微信小程序大文件上传终极解决方案:miniprogram-file-uploader深度解析
  • 快速掌握Luckysheet:终极免费在线Excel替代方案
  • BlenderGIS 3D地形建模终极指南:从地理数据到逼真场景
  • WebLaTeX:免费开源的Overleaf替代方案完整指南
  • 6、Windows 8 用户导航与启动界面的个性化定制
  • LiquidAI发布两款轻量级文本生成模型,1.2B与350M参数版本引领行业效率革新
  • 5分钟精通M3U8视频下载神器:MediaGo全流程操作指南
  • 小米MiMo-Audio震撼发布:音频大模型开启少样本学习新纪元
  • DeepSeek-OCR横空出世:以视觉压缩技术突破大模型上下文瓶颈,开启文本处理新纪元
  • 63、工程领域的概率模型与可靠性分析
  • 5个高效技巧:精通照片元数据管理的终极指南
  • 强力指南:5分钟掌握.brd电路板文件查看的完整解决方案
  • decimal.js 终极指南:彻底解决JavaScript高精度计算难题
  • Nugget命令行工具:极简文件下载的终极解决方案
  • openpilot自动驾驶系统终极指南:从零开始掌握开源驾驶辅助技术
  • 探索StarryDivineSky:汇聚10K+开源项目的机器学习与数据科学宝库
  • 【论文自动阅读】HiF-VLA: Hindsight, Insight and Foresight through Motion Representation for Vision-Language-
  • 终极方案:如何在Linux上完美运行B站客户端?