news 2026/6/23 18:44:11

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/6/23 4:04:43

Unity反向遮罩技术深度解析:从原理到实战应用

Unity反向遮罩技术深度解析&#xff1a;从原理到实战应用 【免费下载链接】UIMask Reverse Mask of Unity "Mask" component 项目地址: https://gitcode.com/gh_mirrors/ui/UIMask 在Unity UI开发中&#xff0c;传统遮罩组件的局限性往往成为创意实现的障碍。…

作者头像 李华
网站建设 2026/6/23 18:35:41

多模态生成革命:Lumina-DiMOO全能模型重塑跨模态交互新范式

多模态生成革命&#xff1a;Lumina-DiMOO全能模型重塑跨模态交互新范式 【免费下载链接】Lumina-DiMOO 项目地址: https://ai.gitcode.com/hf_mirrors/Alpha-VLLM/Lumina-DiMOO 在人工智能多模态交互领域&#xff0c;一场静默的技术革命正在悄然发生。近日&#xff0c;…

作者头像 李华
网站建设 2026/6/23 18:38:47

MarkText主题定制完全攻略:打造专属写作空间的5个关键步骤

MarkText主题定制完全攻略&#xff1a;打造专属写作空间的5个关键步骤 【免费下载链接】marktext &#x1f4dd;A simple and elegant markdown editor, available for Linux, macOS and Windows. 项目地址: https://gitcode.com/gh_mirrors/ma/marktext 想要在MarkText…

作者头像 李华
网站建设 2026/6/23 18:37:37

21、网络命名服务:NIS、NIS+、DNS 与 LDAP 详解

网络命名服务:NIS、NIS+、DNS 与 LDAP 详解 1. NIS 与 NIS+ 服务介绍 1.1 NIS 概述 网络信息服务(NIS)常用于存储和共享用户登录数据(如密码、主目录和账户状态)、用户组以及主机 IP 地址等。它独立于 DNS 开发,侧重点有所不同。DNS 主要专注于主机名和地址之间的转换…

作者头像 李华
网站建设 2026/6/23 18:38:45

22、OpenLDAP与负载均衡技术解析

OpenLDAP与负载均衡技术解析 1. OpenLDAP简介 OpenLDAP源自密歇根大学的LDAP v 3.3,它包含以下组件: | 组件名称 | 功能描述 | | ---- | ---- | | slapd | 独立的LDAP目录服务器 | | slurpd | 用于将数据发送到其他只读服务器的复制服务器 | | ldapd | LDAP到X.500的网…

作者头像 李华
网站建设 2026/6/23 18:38:46

TaskFlow:重新定义Java任务流程管理的轻量级编排框架

TaskFlow&#xff1a;重新定义Java任务流程管理的轻量级编排框架 【免费下载链接】taskflow taskflow是一款轻量、简单易用、可灵活扩展的通用任务编排框架&#xff0c;基于有向无环图(DAG)的方式实现&#xff0c;框架提供了组件复用、同步/异步编排、条件判断、分支选择等能力…

作者头像 李华