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/10 3:48:48

GPT-SoVITS WebUI语音合成终极指南:从零开始打造个性化语音助手

想要快速掌握专业的语音合成技术吗&#xff1f;GPT-SoVITS WebUI为你提供了一个完整的语音合成解决方案&#xff0c;让你轻松实现语音克隆和个性化语音生成。本文将带你深入了解这个强大的工具&#xff0c;并一步步教你如何高效使用它。 【免费下载链接】GPT-SoVITS 项目地址…

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

Delphi逆向工程实战:从零精通IDR反编译工具

Delphi逆向工程实战&#xff1a;从零精通IDR反编译工具 【免费下载链接】IDR Interactive Delphi Reconstructor 项目地址: https://gitcode.com/gh_mirrors/id/IDR 想要深入理解Delphi程序的内部结构吗&#xff1f;&#x1f914; 无论你是误删了源代码的程序员&#xf…

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

阿里云盘Refresh Token扫码获取技术完全指南

阿里云盘Refresh Token扫码获取技术完全指南 【免费下载链接】aliyundriver-refresh-token QR Code扫码获取阿里云盘refresh token For Web 项目地址: https://gitcode.com/gh_mirrors/al/aliyundriver-refresh-token 在云存储应用开发中&#xff0c;阿里云盘API授权是许…

作者头像 李华
网站建设 2026/6/10 15:28:32

AutoGPT与CDN加速结合:提升全球访问性能

AutoGPT与CDN加速结合&#xff1a;提升全球访问性能 在AI智能体正从“能说”迈向“会做”的今天&#xff0c;一个更深层的挑战浮出水面&#xff1a;即便模型再聪明&#xff0c;如果它依赖的资源加载缓慢、工具调用延迟高&#xff0c;其实际效能依然大打折扣。尤其是在全球化部署…

作者头像 李华