|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- import 'package:flutter/material.dart';
- import 'package:flutter_bloc/flutter_bloc.dart';
- import 'bloc/search_bloc.dart';
- import 'bloc/search_repository.dart';
- import 'package:zhiying_comm/zhiying_comm.dart';
-
- class SearchPage3 extends StatelessWidget {
- final Map<String, dynamic> data;
-
- const SearchPage3(this.data);
-
- @override
- Widget build(BuildContext context) {
- return BlocProvider<SearchBloc>(
- create: (_) => SearchBloc(repository: SearchRepository())..add(SearchInitEvent(model: data)),
- child: SearchPage3Container(),
- );
- }
- }
-
- class SearchPage3Container extends StatefulWidget {
- @override
- _SearchPage3ContainerState createState() => _SearchPage3ContainerState();
- }
-
- class _SearchPage3ContainerState extends State<SearchPage3Container> {
- @override
- Widget build(BuildContext context) {
- return MediaQuery.removePadding(
- removeTop: true,
- context: context,
- child: Container(
- width: double.infinity,
- child: BlocConsumer<SearchBloc, SearchState>(
- listener: (BuildContext context, SearchState state) {
- if (state is SearchErrorState) {
- print('数据加载出错');
- }
- },
- buildWhen: (previous, current) {
- /// 数据加载出错不进行build
- if (current is SearchErrorState) {
- return false;
- }
-
- /// 搜索成功,跳转结果页面
- if (current is SearchSubmitSuccessState) {
- return false;
- }
-
- /// 搜索失败,不进行build
- if (current is SearchSubmitErrorState) {
- return false;
- }
-
- return true;
- },
- builder: (context, state) {
- print('currente state = $state');
- if (state is SearchLoadedState) {
- return _getMainWidget(state?.model);
- }
-
- /// 骨架屏幕
- return _getMainWidget(null);
- },
- ),
- ),
- );
- }
-
- /// 主视图
- Widget _getMainWidget(List<Map<String, dynamic>> datas){
- return Scaffold(
- backgroundColor: Colors.white,
- body: NestedScrollView(
- headerSliverBuilder: (context, bool){
- return _createHeadWidget(context, datas);
- },
- body: Container(
- child: Text('testssfee'),
- ),
- ),
- );
- }
-
-
- /// 头部视图
- List<Widget> _createHeadWidget(BuildContext context, List<Map<String, dynamic>> datas){
- List<Widget> 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();
-
- /// datas.length - 1 为最后一个在底部
- for (int i = 0; i < datas.length; 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],
- ));
- }
- if (list.length <= 0) {
- list.add(SliverToBoxAdapter(
- child: Container(
- height: 200,
- child: Center(
- child: Text('暂时无数据哦~'),
- ),
- ),
- ));
- }
- return list;
- }
- }
-
|