From b3135f3f0f992af25a4e013d72745cf4ec1f35c4 Mon Sep 17 00:00:00 2001 From: Weller <1812208341@qq.com> Date: Wed, 23 Sep 2020 16:41:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A6=96=E9=A1=B5=E5=A4=B4?= =?UTF-8?q?=E9=83=A8=E6=82=AC=E6=B5=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../home/home_sreach/home_sreach_widget.dart | 164 +++++++++++------- 1 file changed, 97 insertions(+), 67 deletions(-) diff --git a/lib/widgets/home/home_sreach/home_sreach_widget.dart b/lib/widgets/home/home_sreach/home_sreach_widget.dart index 2882038..bf736d4 100644 --- a/lib/widgets/home/home_sreach/home_sreach_widget.dart +++ b/lib/widgets/home/home_sreach/home_sreach_widget.dart @@ -1,28 +1,35 @@ - -import 'package:zhiying_comm/zhiying_comm.dart'; -import 'package:flutter/material.dart'; +import 'dart:convert' as convert; import 'dart:ui'; import 'package:cached_network_image/cached_network_image.dart'; +import 'package:flutter/material.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; -class HomeSreachDeleagater extends SliverPersistentHeaderDelegate{ - +class HomeSreachDeleagater extends SliverPersistentHeaderDelegate { final Map model; + Map _json; HomeSreachWidget _searchWidget; double _height; HomeSreachDeleagater(this.model) : super() { _height = MediaQueryData.fromWindow(window).padding.top + 44; - _searchWidget = HomeSreachWidget(model); + + String d = model['data']; + _json = Map.from(convert.jsonDecode(d)); + _searchWidget = HomeSreachWidget(_json); } @override - Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) { + Widget build( + BuildContext context, double shrinkOffset, bool overlapsContent) { print('${shrinkOffset.toString()}'); double percent = shrinkOffset / _height; print('${percent.toString()}'); - return _searchWidget; + return Container( + color: HexColor.fromHex(_json['sliding_bg'] ?? 'FF4242') + .withOpacity(percent), + child: _searchWidget); } @override @@ -35,10 +42,8 @@ class HomeSreachDeleagater extends SliverPersistentHeaderDelegate{ bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) { return false; } - } - /// /// 首页搜索框 /// @@ -49,39 +54,70 @@ class HomeSreachWidget extends StatelessWidget { @override Widget build(BuildContext context) { - return HomeSreachContainer(); - } -} - -class HomeSreachContainer extends StatefulWidget { - @override - _HomeSreachContainerState createState() => _HomeSreachContainerState(); -} - -class _HomeSreachContainerState extends State { - @override - Widget build(BuildContext context) { - return _getMainWidget(); - } + List widgets = List(); + if (model.containsKey('left_icons')) { + List icons = model['left_icons']; + widgets.addAll(icons.map((data) { + return GestureDetector( + child: Container( + width: 30, + height: 30, + margin: EdgeInsets.only(right: 10), + child: CachedNetworkImage( + imageUrl: data['icon'] ?? '', + fit: BoxFit.fitHeight, + ), + ), + onTap: () { + SkipModel skipModel = SkipModel.fromJson(data); + RouterUtil.route(skipModel, null, context); + }, + ); + }).toList()); + } + + widgets.add(Expanded( + child: GestureDetector( + child: _getSreachWidget(), + onTap: () { + SkipModel skipModel = SkipModel.fromJson(model); + RouterUtil.route(skipModel, null, context); + }, + ), + )); + + if (model.containsKey('right_icons')) { + List icons = model['right_icons']; + widgets.addAll(icons.map((data) { + return GestureDetector( + child: Container( + width: 30, + height: 30, + margin: EdgeInsets.only(left: 10), + child: CachedNetworkImage( + imageUrl: data['icon'] ?? '', + fit: BoxFit.fitHeight, + ), + ), + onTap: () { + SkipModel skipModel = SkipModel.fromJson(data); + RouterUtil.route(skipModel, null, context); + }, + ); + }).toList()); + } - /// 主视图 - Widget _getMainWidget() { return Container( color: Colors.transparent, height: 30, width: double.infinity, - margin: EdgeInsets.only(left: 12.5, right: 12.5, bottom: 7, top: MediaQueryData.fromWindow(window).padding.top + 7), + margin: EdgeInsets.only( + left: 12.5, + right: 12.5, + bottom: 7, + top: MediaQueryData.fromWindow(window).padding.top + 7), child: Row( - children: [ - /// 搜索框 - Expanded( - child: _getSreachWidget(), - ), - const SizedBox(width: 10), - - /// 消息 - _getMessageWidget(), - ], + children: widgets, ), ); } @@ -89,35 +125,29 @@ class _HomeSreachContainerState extends State { /// 搜索栏 Widget _getSreachWidget() { return Container( - height: 30, - width: double.infinity, - child: TextField( - autofocus: false, - style: TextStyle(color: HexColor.fromHex('#FFFFFF'), fontSize: 14), - readOnly: true, - decoration: InputDecoration( - hintText: '输入搜索内容,领券省钱', - hintStyle: TextStyle( - color: Colors.white, - fontSize: 14, - ), - contentPadding: EdgeInsets.zero, - prefixIcon: Icon(Icons.search, color: Colors.white,), - filled: true, - fillColor: Color(0x50cccccc), - focusedBorder: OutlineInputBorder(borderSide: BorderSide(color: Color(0x00000000)), borderRadius: BorderRadius.all(Radius.circular(30))), - enabledBorder: OutlineInputBorder(borderSide: BorderSide(color: Color(0x00000000)), borderRadius: BorderRadius.all(Radius.circular(30))), - ), - ), - ); - } - - /// 消息widget - Widget _getMessageWidget() { - return Container( - width: 30, - height: 30, - color: Colors.red, - ); + height: 30, + width: double.infinity, + decoration: BoxDecoration( + color: HexColor.fromHex('#ffffff').withOpacity(0.3), + borderRadius: BorderRadius.circular(15)), + child: Row( + children: [ + Padding( + padding: const EdgeInsets.only(left: 10, right: 4), + child: Icon( + Icons.search, + color: HexColor.fromHex( + model['search_input_hint_text_color'] ?? '#ffffff'), + ), + ), + Text( + model['search_input_hint_text'], + style: TextStyle( + color: HexColor.fromHex( + model['search_input_hint_text_color'] ?? '#ffffff'), + fontSize: 13), + ) + ], + )); } }