news 2026/3/23 10:55:32

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/21 5:22:12

探索硬件检测的5个高效方法:系统信息获取完全指南

探索硬件检测的5个高效方法&#xff1a;系统信息获取完全指南 【免费下载链接】hwinfo cross platform C library for hardware information (CPU, RAM, GPU, ...) 项目地址: https://gitcode.com/gh_mirrors/hw/hwinfo 在当今数字化时代&#xff0c;深入了解计算机硬件…

作者头像 李华
网站建设 2026/3/23 15:05:24

SpiffWorkflow完全指南:5分钟掌握Python工作流引擎的核心用法

SpiffWorkflow完全指南&#xff1a;5分钟掌握Python工作流引擎的核心用法 【免费下载链接】SpiffWorkflow A powerful workflow engine implemented in pure Python 项目地址: https://gitcode.com/gh_mirrors/sp/SpiffWorkflow SpiffWorkflow是一个完全用Python实现的强…

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

Python工作流引擎SpiffWorkflow:如何用纯代码解决复杂业务流程管理难题?

你是否曾经为复杂的业务流程管理而头疼&#xff1f;当审批流程需要跨部门协作、订单处理涉及多个决策点时&#xff0c;传统的硬编码方式往往让系统变得难以维护。今天&#xff0c;我们将深入探索SpiffWorkflow这个纯Python实现的工作流引擎&#xff0c;看看它如何帮助企业将复杂…

作者头像 李华
网站建设 2026/3/20 2:26:29

零基础极速上手:Docker一键部署wvp-GB28181-pro视频监控平台

零基础极速上手&#xff1a;Docker一键部署wvp-GB28181-pro视频监控平台 【免费下载链接】wvp-GB28181-pro 项目地址: https://gitcode.com/GitHub_Trending/wv/wvp-GB28181-pro 你是不是还在为搭建视频监控平台而头疼&#xff1f;各种环境配置、依赖安装、端口冲突让你…

作者头像 李华
网站建设 2026/3/20 15:50:10

BilibiliDown:完全免费的高效B站视频下载完整指南

还在为无法离线收藏B站精彩内容而烦恼吗&#xff1f;BilibiliDown作为专业的B站视频下载解决方案&#xff0c;彻底解决了你的所有痛点。这款基于Java开发的多平台工具支持Windows、Linux和MacOS系统&#xff0c;让你轻松实现B站视频的一键下载、批量处理和永久保存。 【免费下载…

作者头像 李华