“yanghuaxuan” 3 years ago
parent
commit
a18bbe84c1
5 changed files with 58 additions and 39 deletions
  1. +2
    -1
      lib/pages/custom_page/bloc/custom_page_bloc.dart
  2. +46
    -37
      lib/pages/search_page/search_page.dart
  3. +1
    -1
      lib/widgets/custom/search/custom_search_widget.dart
  4. +4
    -0
      lib/widgets/custom/search/model/custom_search_model.dart
  5. +5
    -0
      lib/widgets/search/tabbar/search_tab_widget.dart

+ 2
- 1
lib/pages/custom_page/bloc/custom_page_bloc.dart View File

@@ -1,4 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';


import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'custom_page_event.dart'; import 'custom_page_event.dart';
@@ -55,7 +56,7 @@ class CustomPageBloc extends Bloc<CustomPageEvent, CustomPageState> {
var result = await repository.fetchInitData(); var result = await repository.fetchInitData();
List<Map<String, dynamic>> mdata = result.modList; List<Map<String, dynamic>> mdata = result.modList;
for (int i = 0; i < mdata.length; i++) { for (int i = 0; i < mdata.length; i++) {
Logger.log("页面数据: " + mdata[i].toString());
Logger.log("页面数据: " + json.encode(mdata[i]));
} }
if (!EmptyUtil.isEmpty(result) && result is CustomPageData) { if (!EmptyUtil.isEmpty(result) && result is CustomPageData) {
yield CustomPageLoadedState(model: result.modList,backgroundModel: result.backgroundModel); yield CustomPageLoadedState(model: result.modList,backgroundModel: result.backgroundModel);


+ 46
- 37
lib/pages/search_page/search_page.dart View File

@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:zhiying_base_widget/pages/search_page/notifier/search_tag_notifier.dart'; import 'package:zhiying_base_widget/pages/search_page/notifier/search_tag_notifier.dart';
@@ -20,14 +22,10 @@ class SearchPage extends StatelessWidget {


@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Logger.log("数据: "+data.toString());
return MultiProvider( return MultiProvider(
providers: [
ChangeNotifierProvider.value(value: SearchTagNotifier())
],
providers: [ChangeNotifierProvider.value(value: SearchTagNotifier())],
child: MultiProvider( child: MultiProvider(
providers: [ providers: [

/// 搜索页面的bloc /// 搜索页面的bloc
BlocProvider<SearchBloc>( BlocProvider<SearchBloc>(
create: (_) => SearchBloc(repository: SearchRepository())..add(SearchInitEvent(model: data)), create: (_) => SearchBloc(repository: SearchRepository())..add(SearchInitEvent(model: data)),
@@ -35,11 +33,12 @@ class SearchPage extends StatelessWidget {


/// 输入框联想的bloc /// 输入框联想的bloc
BlocProvider<SearchThinkBloc>( BlocProvider<SearchThinkBloc>(
create: (_)=> SearchThinkBloc(SearchThinkRepository()),
create: (_) => SearchThinkBloc(SearchThinkRepository()),
), ),

], ],
child: SearchPageContianer(),
child: SearchPageContianer(
data: data,
),
), ),
// child: BlocProvider<SearchBloc>( // child: BlocProvider<SearchBloc>(
// create: (_) => SearchBloc(repository: SearchRepository())..add(SearchInitEvent(model: data)), // create: (_) => SearchBloc(repository: SearchRepository())..add(SearchInitEvent(model: data)),
@@ -50,6 +49,10 @@ class SearchPage extends StatelessWidget {
} }


class SearchPageContianer extends StatefulWidget { class SearchPageContianer extends StatefulWidget {
final Map<String, dynamic> data;

const SearchPageContianer({Key key, this.data}) : super(key: key);

@override @override
_SearchPageContianerState createState() => _SearchPageContianerState(); _SearchPageContianerState createState() => _SearchPageContianerState();
} }
@@ -72,6 +75,12 @@ class _SearchPageContianerState extends State<SearchPageContianer> {


@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
//设置搜索bar应该选择哪个type的item
Logger.log("数据2: " + json.encode(widget.data));
Logger.log("类型: " + widget.data['default_pvd']);
if(!EmptyUtil.isEmpty(widget.data['default_pvd'])){
Provider.of<SearchTagNotifier>(context, listen: false).setType(widget.data['default_pvd']);
}
return MediaQuery.removePadding( return MediaQuery.removePadding(
removeTop: true, removeTop: true,
context: context, context: context,
@@ -158,33 +167,33 @@ class _SearchPageContianerState extends State<SearchPageContianer> {
return list; return list;
} }


// List<Widget> _createContent(BuildContext context, List<Map<String, dynamic>> datas) {
// List<Widget> list = List();
//
// int length = datas?.length ?? 0;
//
// if (length <= 0) {
// list.add(SliverToBoxAdapter(
// child: Container(
// height: 200,
// child: Center(
// child: Text('暂时无数据哦~'),
// ),
// ),
// ));
// return list;
// }
//
// for (int i = 0; i < 3; i++) {
// WidgetModel item = WidgetModel.fromJson(Map<String, dynamic>.from(datas[i]));
// print('item.modName ${item.modName}');
// list.addAll(WidgetFactory.create(
// item.modName,
// isSliver: true,
// model: datas[i],
// ));
// }
//
// return list;
// }
// List<Widget> _createContent(BuildContext context, List<Map<String, dynamic>> datas) {
// List<Widget> list = List();
//
// int length = datas?.length ?? 0;
//
// if (length <= 0) {
// list.add(SliverToBoxAdapter(
// child: Container(
// height: 200,
// child: Center(
// child: Text('暂时无数据哦~'),
// ),
// ),
// ));
// return list;
// }
//
// for (int i = 0; i < 3; i++) {
// WidgetModel item = WidgetModel.fromJson(Map<String, dynamic>.from(datas[i]));
// print('item.modName ${item.modName}');
// list.addAll(WidgetFactory.create(
// item.modName,
// isSliver: true,
// model: datas[i],
// ));
// }
//
// return list;
// }
} }

+ 1
- 1
lib/widgets/custom/search/custom_search_widget.dart View File

@@ -22,7 +22,7 @@ class CustomSearchWidget extends StatelessWidget {
// 点击事件 // 点击事件
void _onClickListener(BuildContext context, SkipModel skipModel) { void _onClickListener(BuildContext context, SkipModel skipModel) {
if (!EmptyUtil.isEmpty(skipModel)) { if (!EmptyUtil.isEmpty(skipModel)) {
RouterUtil.route(skipModel, skipModel.toJson(), context);
RouterUtil.route(skipModel, model.toJson(), context);
} }
} }




+ 4
- 0
lib/widgets/custom/search/model/custom_search_model.dart View File

@@ -15,6 +15,7 @@ class CustomSearchModel {
String bottomLeftRadius; String bottomLeftRadius;
String bottomRightRadius; String bottomRightRadius;
String bgColor; String bgColor;
String default_pvd;
ListStyle listStyle; ListStyle listStyle;


CustomSearchModel({ CustomSearchModel({
@@ -28,6 +29,7 @@ class CustomSearchModel {
this.topMargin, this.topMargin,
this.leftRightMargin, this.leftRightMargin,
this.bgColor, this.bgColor,
this.default_pvd,
this.listStyle, this.listStyle,
this.topLeftRadius, this.topLeftRadius,
this.topRightRadius, this.topRightRadius,
@@ -46,6 +48,7 @@ class CustomSearchModel {
topMargin = json['top_margin']; topMargin = json['top_margin'];
leftRightMargin = json['left_right_margin']; leftRightMargin = json['left_right_margin'];
bgColor = json['bg_color']; bgColor = json['bg_color'];
default_pvd=json['default_pvd'];
topLeftRadius = json['top_left_radius']; topLeftRadius = json['top_left_radius'];
topRightRadius = json['top_right_radius']; topRightRadius = json['top_right_radius'];
bottomLeftRadius = json['bottom_left_radius']; bottomLeftRadius = json['bottom_left_radius'];
@@ -65,6 +68,7 @@ class CustomSearchModel {
data['top_margin'] = this.topMargin; data['top_margin'] = this.topMargin;
data['left_right_margin'] = this.leftRightMargin; data['left_right_margin'] = this.leftRightMargin;
data['bg_color'] = this.bgColor; data['bg_color'] = this.bgColor;
data['default_pvd']=this.default_pvd;
data['top_left_radius'] = this.topLeftRadius; data['top_left_radius'] = this.topLeftRadius;
data['top_right_radius'] = this.topRightRadius; data['top_right_radius'] = this.topRightRadius;
data['bottom_left_radius'] = this.bottomLeftRadius; data['bottom_left_radius'] = this.bottomLeftRadius;


+ 5
- 0
lib/widgets/search/tabbar/search_tab_widget.dart View File

@@ -68,6 +68,11 @@ class _SearchTabWidgetState extends State<SearchTabWidget> {
} }
} }
}); });
for (int i = 0; i < widget?.model?.search_icon_list?.length ?? 0; i++) {
if (Provider.of<SearchTagNotifier>(context, listen: false).getType() == widget?.model?.search_icon_list[i].type) {
_tabController.animateTo(i);
}
}
WidgetsBinding.instance.addPostFrameCallback((_) => setTabSelect()); WidgetsBinding.instance.addPostFrameCallback((_) => setTabSelect());
super.initState(); super.initState();
} }


Loading…
Cancel
Save