news 2026/6/10 0:44:37

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/9 14:14:02

AMD Ryzen调试终极技巧与实战指南

AMD Ryzen调试终极技巧与实战指南 【免费下载链接】SMUDebugTool A dedicated tool to help write/read various parameters of Ryzen-based systems, such as manual overclock, SMU, PCI, CPUID, MSR and Power Table. 项目地址: https://gitcode.com/gh_mirrors/smu/SMUDe…

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

5分钟掌握跨平台语音识别:Whisper.cpp实战深度解析

5分钟掌握跨平台语音识别&#xff1a;Whisper.cpp实战深度解析 【免费下载链接】whisper.cpp OpenAI 的 Whisper 模型在 C/C 中的移植版本。 项目地址: https://gitcode.com/GitHub_Trending/wh/whisper.cpp 还在为语音识别部署复杂、依赖网络、隐私安全等问题而烦恼&am…

作者头像 李华
网站建设 2026/6/9 21:08:53

百度网盘分享链接解析工具完全使用指南

百度网盘分享链接解析工具完全使用指南 【免费下载链接】baidu-wangpan-parse 获取百度网盘分享文件的下载地址 项目地址: https://gitcode.com/gh_mirrors/ba/baidu-wangpan-parse 百度网盘作为国内主流的云存储服务&#xff0c;在为用户提供便捷文件分享服务的同时&am…

作者头像 李华
网站建设 2026/6/9 22:16:35

ArkLights明日方舟智能托管助手:解放双手的终极游戏伴侣

ArkLights明日方舟智能托管助手&#xff1a;解放双手的终极游戏伴侣 【免费下载链接】ArkLights 明日方舟速通 arknights 本仓库不再维护&#xff0c;请使用 https://github.com/AegirTech/ArkLights 项目地址: https://gitcode.com/gh_mirrors/ar/ArkLights 还在为每日…

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

微信小程序大文件上传终极方案:性能对比与实战指南

微信小程序大文件上传终极方案&#xff1a;性能对比与实战指南 【免费下载链接】miniprogram-file-uploader 项目地址: https://gitcode.com/gh_mirrors/mi/miniprogram-file-uploader 用户痛点与需求深度分析 在处理微信小程序大文件上传时&#xff0c;开发者面临的核…

作者头像 李华