news 2026/4/18 13:33:54

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/4/18 3:26:06

Qwen3-235B-A22B-Instruct-2507:新一代大语言模型技术突破与应用指南

Qwen3-235B-A22B-Instruct-2507&#xff1a;新一代大语言模型技术突破与应用指南 【免费下载链接】Qwen3-235B-A22B-Instruct-2507 Qwen3-235B-A22B-Instruct-2507是一款强大的开源大语言模型&#xff0c;拥有2350亿参数&#xff0c;其中220亿参数处于激活状态。它在指令遵循、…

作者头像 李华
网站建设 2026/4/18 3:28:20

终极解决方案:Windows快速安装苹果设备驱动完整指南

终极解决方案&#xff1a;Windows快速安装苹果设备驱动完整指南 【免费下载链接】Apple-Mobile-Drivers-Installer Powershell script to easily install Apple USB and Mobile Device Ethernet (USB Tethering) drivers on Windows! 项目地址: https://gitcode.com/gh_mirro…

作者头像 李华
网站建设 2026/4/18 3:29:30

人工智能如何重塑未来工作格局:机遇与挑战并存

随着人工智能技术的飞速发展&#xff0c;其对全球工作市场的影响正日益显现。从自动化生产线到智能客服系统&#xff0c;从数据分析算法到内容生成工具&#xff0c;人工智能正在各个行业和领域引发深刻的变革。这种变革不仅改变了工作的方式和效率&#xff0c;也对劳动者的技能…

作者头像 李华
网站建设 2026/4/18 5:25:16

Xcode调试兼容难题终极解决方案:iOS设备支持文件完整指南

Xcode调试兼容难题终极解决方案&#xff1a;iOS设备支持文件完整指南 【免费下载链接】iOSDeviceSupport All versions of iOS Device Support 项目地址: https://gitcode.com/gh_mirrors/ios/iOSDeviceSupport 当你满怀期待地连接iPhone到Mac准备调试&#xff0c;Xcode…

作者头像 李华
网站建设 2026/4/18 7:56:17

如何快速构建高效信息流:智能订阅工具的终极指南

在信息爆炸的时代&#xff0c;你是否曾感到被海量资讯淹没&#xff1f;每天面对无数网站更新、博客文章和新闻动态&#xff0c;如何从中筛选出真正有价值的内容成为现代人的共同挑战。智能订阅工具正是解决这一痛点的利器&#xff0c;它能帮助你自动发现、筛选和管理信息源&…

作者头像 李华