| @@ -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<String, dynamic> model; | |||
| Map<String, dynamic> _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<String, dynamic>.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<HomeSreachContainer> { | |||
| @override | |||
| Widget build(BuildContext context) { | |||
| return _getMainWidget(); | |||
| } | |||
| List<Widget> 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: <Widget>[ | |||
| /// 搜索框 | |||
| Expanded( | |||
| child: _getSreachWidget(), | |||
| ), | |||
| const SizedBox(width: 10), | |||
| /// 消息 | |||
| _getMessageWidget(), | |||
| ], | |||
| children: widgets, | |||
| ), | |||
| ); | |||
| } | |||
| @@ -89,35 +125,29 @@ class _HomeSreachContainerState extends State<HomeSreachContainer> { | |||
| /// 搜索栏 | |||
| 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: <Widget>[ | |||
| 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), | |||
| ) | |||
| ], | |||
| )); | |||
| } | |||
| } | |||