基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

96 lines
2.5 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_bloc/flutter_bloc.dart';
  3. import 'package:zhiying_base_widget/widgets/home_banner/bloc/bloc.dart';
  4. import 'package:zhiying_base_widget/widgets/home_banner/bloc/home_banner_repository.dart';
  5. import 'package:zhiying_base_widget/widgets/home_banner/home_banner_sk.dart';
  6. import 'package:zhiying_comm/zhiying_comm.dart';
  7. ///
  8. /// 不可以滚动Banner
  9. ///
  10. class HomeBannerWidget extends StatefulWidget {
  11. final Map<String, dynamic> model;
  12. const HomeBannerWidget(this.model);
  13. @override
  14. _HomeBannerWidgetState createState() => _HomeBannerWidgetState();
  15. }
  16. class _HomeBannerWidgetState extends State<HomeBannerWidget> {
  17. @override
  18. Widget build(BuildContext context) {
  19. return BlocProvider<HomeBannerBloc>(
  20. create: (_) => HomeBannerBloc(repository: HomeBannerRepository())..add(HomeBannerInitEvent(widget.model)),
  21. child: HomeBannerContainer(
  22. model: widget.model,
  23. ),
  24. );
  25. }
  26. }
  27. class HomeBannerContainer extends StatefulWidget {
  28. final Map<String, dynamic> model;
  29. const HomeBannerContainer({@required this.model});
  30. @override
  31. _HomeBannerContainerState createState() => _HomeBannerContainerState();
  32. }
  33. class _HomeBannerContainerState extends State<HomeBannerContainer> {
  34. @override
  35. Widget build(BuildContext context) {
  36. return BlocConsumer<HomeBannerBloc, HomeBannerState>(
  37. listener: (context, state) {},
  38. buildWhen: (previous, current) {
  39. if (current is HomeBannerErrorState) {
  40. return false;
  41. }
  42. return true;
  43. },
  44. builder: (context, state) {
  45. print(state);
  46. if (state is HomeBannerLoadedState) {
  47. return ItemWidget(data: [1,2,3],);
  48. }
  49. if (state is HomeBannerCacheState) {
  50. return ItemWidget(data: [1,2],);
  51. }
  52. return HomeBannerSkeleton(widget.model);
  53. },
  54. );
  55. }
  56. }
  57. class ItemWidget extends StatelessWidget {
  58. final List data;
  59. ItemWidget({this.data});
  60. @override
  61. Widget build(BuildContext context) {
  62. return Container(
  63. height: 180.h,
  64. margin: EdgeInsets.only(top: 7.5, left: 2.5, right: 2.5),
  65. child: Row(
  66. children:data.map((index){
  67. return Flexible(
  68. flex: 1,
  69. child: Container(
  70. margin: EdgeInsets.only( left: 5, right: 5),
  71. decoration: BoxDecoration(
  72. color: Colors.lightBlue,
  73. borderRadius: BorderRadius.circular(7.5)
  74. ),
  75. ),
  76. );
  77. }).toList(),
  78. ),
  79. );
  80. }
  81. }