|
@@ -1,10 +1,9 @@ |
|
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:flutter_bloc/flutter_bloc.dart'; |
|
|
import 'package:flutter_bloc/flutter_bloc.dart'; |
|
|
import 'package:flutter_swiper/flutter_swiper.dart'; |
|
|
import 'package:flutter_swiper/flutter_swiper.dart'; |
|
|
import 'package:provider/provider.dart'; |
|
|
import 'package:provider/provider.dart'; |
|
|
import 'package:zhiying_base_widget/pages/goods_details_page/goods_details_page.dart'; |
|
|
|
|
|
import 'package:zhiying_base_widget/pages/main_page/notifier/main_page_bg_notifier.dart'; |
|
|
import 'package:zhiying_base_widget/pages/main_page/notifier/main_page_bg_notifier.dart'; |
|
|
import 'package:cached_network_image/cached_network_image.dart'; |
|
|
|
|
|
import 'package:zhiying_comm/zhiying_comm.dart'; |
|
|
import 'package:zhiying_comm/zhiying_comm.dart'; |
|
|
|
|
|
|
|
|
import 'bloc/bloc.dart'; |
|
|
import 'bloc/bloc.dart'; |
|
@@ -28,7 +27,9 @@ class _HomeSlideBannerState extends State<HomeSlideBanner> { |
|
|
@override |
|
|
@override |
|
|
Widget build(BuildContext context) { |
|
|
Widget build(BuildContext context) { |
|
|
return BlocProvider<HomeSlideBannerBloc>( |
|
|
return BlocProvider<HomeSlideBannerBloc>( |
|
|
create: (_) => HomeSlideBannerBloc(repository: HomeSlideBannerRepository())..add(HomeBannerInitEvent(model: widget?.model)), |
|
|
|
|
|
|
|
|
create: (_) => |
|
|
|
|
|
HomeSlideBannerBloc(repository: HomeSlideBannerRepository()) |
|
|
|
|
|
..add(HomeBannerInitEvent(model: widget?.model)), |
|
|
child: HomeSlideBannerContainer(), |
|
|
child: HomeSlideBannerContainer(), |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
@@ -36,11 +37,11 @@ class _HomeSlideBannerState extends State<HomeSlideBanner> { |
|
|
|
|
|
|
|
|
class HomeSlideBannerContainer extends StatefulWidget { |
|
|
class HomeSlideBannerContainer extends StatefulWidget { |
|
|
@override |
|
|
@override |
|
|
_HomeSlideBannerContainerState createState() => _HomeSlideBannerContainerState(); |
|
|
|
|
|
|
|
|
_HomeSlideBannerContainerState createState() => |
|
|
|
|
|
_HomeSlideBannerContainerState(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
class _HomeSlideBannerContainerState extends State<HomeSlideBannerContainer> { |
|
|
class _HomeSlideBannerContainerState extends State<HomeSlideBannerContainer> { |
|
|
|
|
|
|
|
|
/// 子元素点击事件 |
|
|
/// 子元素点击事件 |
|
|
void _itemOnClick(IndexCarousel model) { |
|
|
void _itemOnClick(IndexCarousel model) { |
|
|
print('点击了 $model'); |
|
|
print('点击了 $model'); |
|
@@ -80,7 +81,17 @@ class _HomeSlideBannerContainerState extends State<HomeSlideBannerContainer> { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Widget _getMainWidget(HomeSlideBannerModel datas) { |
|
|
Widget _getMainWidget(HomeSlideBannerModel datas) { |
|
|
|
|
|
Future.delayed(Duration.zero, () { |
|
|
|
|
|
Provider.of<MainPageBgNotifier>(context, listen: false) |
|
|
|
|
|
.switchBg(Container( |
|
|
|
|
|
width: double.infinity, |
|
|
|
|
|
height: 200, |
|
|
|
|
|
color: Colors.redAccent, |
|
|
|
|
|
)); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
return Container( |
|
|
return Container( |
|
|
|
|
|
margin: EdgeInsets.all(10), |
|
|
width: double.infinity, |
|
|
width: double.infinity, |
|
|
height: 140, |
|
|
height: 140, |
|
|
child: Swiper( |
|
|
child: Swiper( |
|
@@ -98,13 +109,15 @@ class _HomeSlideBannerContainerState extends State<HomeSlideBannerContainer> { |
|
|
loop: true, |
|
|
loop: true, |
|
|
autoplay: true, |
|
|
autoplay: true, |
|
|
onTap: (index) => _itemOnClick(datas.index_carousel_list[index]), |
|
|
onTap: (index) => _itemOnClick(datas.index_carousel_list[index]), |
|
|
pagination: _getSwiperStyleByType(datas, datas?.index_carousel_list?.length ?? 0), |
|
|
|
|
|
|
|
|
pagination: _getSwiperStyleByType( |
|
|
|
|
|
datas, datas?.index_carousel_list?.length ?? 0), |
|
|
onIndexChanged: (index) { |
|
|
onIndexChanged: (index) { |
|
|
//print('切换下一页'); |
|
|
//print('切换下一页'); |
|
|
Provider.of<MainPageBgNotifier>(context, listen: false).switchBg(Container( |
|
|
|
|
|
|
|
|
Provider.of<MainPageBgNotifier>(context, listen: false) |
|
|
|
|
|
.switchBg(Container( |
|
|
width: double.infinity, |
|
|
width: double.infinity, |
|
|
height: 200, |
|
|
height: 200, |
|
|
color: Colors.primaries[(index + 2) % Colors.primaries.length], |
|
|
|
|
|
|
|
|
color: Colors.redAccent, |
|
|
)); |
|
|
)); |
|
|
}, |
|
|
}, |
|
|
), |
|
|
), |
|
@@ -112,50 +125,71 @@ class _HomeSlideBannerContainerState extends State<HomeSlideBannerContainer> { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// 获取进度样式 |
|
|
/// 获取进度样式 |
|
|
SwiperPlugin _getSwiperStyleByType(HomeSlideBannerModel model, int pageCount) { |
|
|
|
|
|
|
|
|
|
|
|
if('1' != model.pagination_open){ |
|
|
|
|
|
|
|
|
SwiperPlugin _getSwiperStyleByType( |
|
|
|
|
|
HomeSlideBannerModel model, int pageCount) { |
|
|
|
|
|
if ('1' != model.pagination_open) { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ('type_number' == model.pagination) { |
|
|
if ('type_number' == model.pagination) { |
|
|
return _getNumswiperPlugin(pageCount, model.pagination_select_color, model.pagination_unselect_color); |
|
|
|
|
|
|
|
|
return _getNumswiperPlugin(pageCount, model.pagination_select_color, |
|
|
|
|
|
model.pagination_unselect_color); |
|
|
} |
|
|
} |
|
|
if ('type_point' == model.pagination) { |
|
|
if ('type_point' == model.pagination) { |
|
|
return _swiperCustomPaginationDito(pageCount, model.pagination_select_color, model.pagination_unselect_color); |
|
|
|
|
|
|
|
|
return _swiperCustomPaginationDito(pageCount, |
|
|
|
|
|
model.pagination_select_color, model.pagination_unselect_color); |
|
|
} |
|
|
} |
|
|
if ('type_bar' == model.pagination) { |
|
|
if ('type_bar' == model.pagination) { |
|
|
return _swiperCustomPagination(pageCount, model.pagination_select_color, model.pagination_unselect_color); |
|
|
|
|
|
|
|
|
return _swiperCustomPagination(pageCount, model.pagination_select_color, |
|
|
|
|
|
model.pagination_unselect_color); |
|
|
} |
|
|
} |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// 数字样式 |
|
|
/// 数字样式 |
|
|
SwiperPlugin _getNumswiperPlugin(int pageCount, String selectColor, String unselectColor) { |
|
|
|
|
|
return SwiperCustomPagination(builder: (BuildContext context, SwiperPluginConfig config) { |
|
|
|
|
|
|
|
|
SwiperPlugin _getNumswiperPlugin( |
|
|
|
|
|
int pageCount, String selectColor, String unselectColor) { |
|
|
|
|
|
return SwiperCustomPagination( |
|
|
|
|
|
builder: (BuildContext context, SwiperPluginConfig config) { |
|
|
return Align( |
|
|
return Align( |
|
|
alignment: Alignment(0.0, 0.9), |
|
|
alignment: Alignment(0.0, 0.9), |
|
|
child: Container( |
|
|
child: Container( |
|
|
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 18), |
|
|
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 18), |
|
|
decoration: BoxDecoration(borderRadius: BorderRadius.circular(13), color: HexColor.fromHex('#4D000000')), |
|
|
|
|
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
|
borderRadius: BorderRadius.circular(13), |
|
|
|
|
|
color: HexColor.fromHex('#4D000000')), |
|
|
child: RichText( |
|
|
child: RichText( |
|
|
text: TextSpan(text: '${config.activeIndex + 1}', style: TextStyle(fontSize: 12, color: HexColor.fromHex(selectColor)), children: [ |
|
|
|
|
|
TextSpan(text: '/', style: TextStyle(fontSize: 12, color: HexColor.fromHex(unselectColor))), |
|
|
|
|
|
TextSpan(text: '$pageCount', style: TextStyle(fontSize: 12, color: HexColor.fromHex(unselectColor))), |
|
|
|
|
|
]), |
|
|
|
|
|
|
|
|
text: TextSpan( |
|
|
|
|
|
text: '${config.activeIndex + 1}', |
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
fontSize: 12, color: HexColor.fromHex(selectColor)), |
|
|
|
|
|
children: [ |
|
|
|
|
|
TextSpan( |
|
|
|
|
|
text: '/', |
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
fontSize: 12, |
|
|
|
|
|
color: HexColor.fromHex(unselectColor))), |
|
|
|
|
|
TextSpan( |
|
|
|
|
|
text: '$pageCount', |
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
fontSize: 12, |
|
|
|
|
|
color: HexColor.fromHex(unselectColor))), |
|
|
|
|
|
]), |
|
|
)), |
|
|
)), |
|
|
); |
|
|
); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// 自定义进度条 |
|
|
/// 自定义进度条 |
|
|
SwiperPlugin _swiperCustomPagination(int pageCount, String selectColor, String unselectColor) { |
|
|
|
|
|
|
|
|
SwiperPlugin _swiperCustomPagination( |
|
|
|
|
|
int pageCount, String selectColor, String unselectColor) { |
|
|
List list = []; |
|
|
List list = []; |
|
|
for (int i = 0; i < pageCount; i++) { |
|
|
for (int i = 0; i < pageCount; i++) { |
|
|
list.add(i); |
|
|
list.add(i); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return SwiperCustomPagination(builder: (BuildContext context, SwiperPluginConfig config) { |
|
|
|
|
|
|
|
|
return SwiperCustomPagination( |
|
|
|
|
|
builder: (BuildContext context, SwiperPluginConfig config) { |
|
|
return Align( |
|
|
return Align( |
|
|
alignment: Alignment(0.0, 0.9), |
|
|
alignment: Alignment(0.0, 0.9), |
|
|
child: Row( |
|
|
child: Row( |
|
@@ -164,10 +198,13 @@ class _HomeSlideBannerContainerState extends State<HomeSlideBannerContainer> { |
|
|
children: list.map((index) { |
|
|
children: list.map((index) { |
|
|
var borderRadius; |
|
|
var borderRadius; |
|
|
if (index == 0) { |
|
|
if (index == 0) { |
|
|
borderRadius = BorderRadius.only(topLeft: Radius.circular(2), bottomLeft: Radius.circular(2)); |
|
|
|
|
|
|
|
|
borderRadius = BorderRadius.only( |
|
|
|
|
|
topLeft: Radius.circular(2), bottomLeft: Radius.circular(2)); |
|
|
} |
|
|
} |
|
|
if (index == list.length - 1) { |
|
|
if (index == list.length - 1) { |
|
|
borderRadius = BorderRadius.only(topRight: Radius.circular(2), bottomRight: Radius.circular(2)); |
|
|
|
|
|
|
|
|
borderRadius = BorderRadius.only( |
|
|
|
|
|
topRight: Radius.circular(2), |
|
|
|
|
|
bottomRight: Radius.circular(2)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (index == config.activeIndex) { |
|
|
if (index == config.activeIndex) { |
|
@@ -177,7 +214,11 @@ class _HomeSlideBannerContainerState extends State<HomeSlideBannerContainer> { |
|
|
return Container( |
|
|
return Container( |
|
|
height: 4, |
|
|
height: 4, |
|
|
width: 25, |
|
|
width: 25, |
|
|
decoration: BoxDecoration(borderRadius: borderRadius, color: index == config.activeIndex ? HexColor.fromHex(selectColor) : HexColor.fromHex(unselectColor)), |
|
|
|
|
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
|
borderRadius: borderRadius, |
|
|
|
|
|
color: index == config.activeIndex |
|
|
|
|
|
? HexColor.fromHex(selectColor) |
|
|
|
|
|
: HexColor.fromHex(unselectColor)), |
|
|
); |
|
|
); |
|
|
}).toList(), |
|
|
}).toList(), |
|
|
), |
|
|
), |
|
@@ -186,7 +227,14 @@ class _HomeSlideBannerContainerState extends State<HomeSlideBannerContainer> { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// 圆形进度条 |
|
|
/// 圆形进度条 |
|
|
SwiperPlugin _swiperCustomPaginationDito(int pageCount, String selectColor, String unselectColor) { |
|
|
|
|
|
return SwiperPagination(margin: const EdgeInsets.only(), builder: DotSwiperPaginationBuilder( color: HexColor.fromHex(unselectColor), activeColor: HexColor.fromHex(selectColor), size: 8, activeSize: 8)); |
|
|
|
|
|
|
|
|
SwiperPlugin _swiperCustomPaginationDito( |
|
|
|
|
|
int pageCount, String selectColor, String unselectColor) { |
|
|
|
|
|
return SwiperPagination( |
|
|
|
|
|
margin: const EdgeInsets.only(), |
|
|
|
|
|
builder: DotSwiperPaginationBuilder( |
|
|
|
|
|
color: HexColor.fromHex(unselectColor), |
|
|
|
|
|
activeColor: HexColor.fromHex(selectColor), |
|
|
|
|
|
size: 8, |
|
|
|
|
|
activeSize: 8)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |