Browse Source

1、添加swiper Controller dispose事件

tags/0.0.2+5
PH2 4 years ago
parent
commit
2e070bb215
10 changed files with 265 additions and 68 deletions
  1. +174
    -61
      lib/pages/custom_page/custom_page.dart
  2. +1
    -1
      lib/pages/favorites_page/favorites_page.dart
  3. +10
    -0
      lib/pages/invited_friends/invited_friends.dart
  4. +17
    -0
      lib/pages/vip_center_page/vip_center_page.dart
  5. +1
    -1
      lib/register.dart
  6. +10
    -0
      lib/widgets/goods_details/slide_banner/goods_details_slide_banner_widget.dart
  7. +15
    -0
      lib/widgets/home/home_quick_entry/home_quick_entry.dart
  8. +16
    -0
      lib/widgets/home/home_quick_entry/home_quick_entry_widget.dart
  9. +20
    -4
      lib/widgets/home/home_slide_banner/home_slide_banner.dart
  10. +1
    -1
      lib/widgets/home/home_slide_banner/model/home_slide_banner_model.dart

+ 174
- 61
lib/pages/custom_page/custom_page.dart View File

@@ -23,9 +23,7 @@ class CustomPage extends StatelessWidget {


@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// return MultiProvider(
// providers: [],
// child:
// return NestedScrollDemoPage();
return BlocProvider<CustomPageBloc>( return BlocProvider<CustomPageBloc>(
create: (_) => CustomPageBloc(CustomPageRepository(data: data))..add(CustomPageInitEvent()), create: (_) => CustomPageBloc(CustomPageRepository(data: data))..add(CustomPageInitEvent()),
child: _CommonPageContainer(), child: _CommonPageContainer(),
@@ -41,6 +39,7 @@ class _CommonPageContainer extends StatefulWidget {


class __CommonPageContainerState extends State<_CommonPageContainer> with SingleTickerProviderStateMixin { class __CommonPageContainerState extends State<_CommonPageContainer> with SingleTickerProviderStateMixin {
ScrollController _controller; ScrollController _controller;
ScrollController _controller2;
RefreshController _refreshController; RefreshController _refreshController;
TabController _tabController; TabController _tabController;
bool _isEnded = false; bool _isEnded = false;
@@ -48,7 +47,7 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single
/// 回到顶点 /// 回到顶点
void _scrollTop() { void _scrollTop() {
// _controller.jumpTo(0); // _controller.jumpTo(0);
_controller.animateTo(0, duration: Duration(seconds: 1), curve: Curves.linear);
_controller.animateTo(0, duration: Duration(milliseconds: 200), curve: Curves.linear);
} }


/// 刷新 /// 刷新
@@ -62,6 +61,7 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single
@override @override
void initState() { void initState() {
_controller = ScrollController(); _controller = ScrollController();
_controller2 = ScrollController();
_refreshController = RefreshController(initialRefresh: false); _refreshController = RefreshController(initialRefresh: false);
_tabController = TabController(length: 10, vsync: this); _tabController = TabController(length: 10, vsync: this);
super.initState(); super.initState();
@@ -72,6 +72,7 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single
_controller?.dispose(); _controller?.dispose();
_refreshController?.dispose(); _refreshController?.dispose();
_tabController?.dispose(); _tabController?.dispose();
_controller2?.dispose();
super.dispose(); super.dispose();
} }


@@ -86,7 +87,7 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single
return false; return false;
} }
if (current is CustomPageRefreshSuccessState) { if (current is CustomPageRefreshSuccessState) {
_refreshController.refreshCompleted(resetFooterState: true);
_refreshController.refreshCompleted(resetFooterState: true);
return false; return false;
} }
if (current is CustomPageRefreshErrorState) { if (current is CustomPageRefreshErrorState) {
@@ -96,13 +97,15 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single
return true; return true;
}, },
builder: (context, state) { builder: (context, state) {
if (state is CustomPageLoadedState) {
return _buildMainWidget();
}
if (state is CustomPageInitErrorState) {
return _buildMainWidget();
}
return _buildSkeletonWidget();
// if (state is CustomPageLoadedState) {
// return _buildMain2Widget();
// }
// if (state is CustomPageInitErrorState) {
// return _buildMain2Widget();
// }
// return _buildMain2Widget();

return _buildMain2Widget();
}, },
), ),
); );
@@ -116,7 +119,7 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single
floatingActionButton: _buildFloatWidget(), floatingActionButton: _buildFloatWidget(),
floatingActionButtonLocation: _CustomFloatingActionButtonLocation(FloatingActionButtonLocation.endFloat, 0, -100), floatingActionButtonLocation: _CustomFloatingActionButtonLocation(FloatingActionButtonLocation.endFloat, 0, -100),
body: SmartRefresher( body: SmartRefresher(
enablePullDown: false,
enablePullDown: true,
enablePullUp: false, enablePullUp: false,
header: RefreshHeader( header: RefreshHeader(
offsetY: top, offsetY: top,
@@ -125,6 +128,7 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single
onLoading: _onLoadEvent, onLoading: _onLoadEvent,
onRefresh: _onRefreshEvent, onRefresh: _onRefreshEvent,
child: CustomScrollView( child: CustomScrollView(
key: UniqueKey(),
controller: _controller, controller: _controller,
slivers: [ slivers: [
/// 标题 /// 标题
@@ -134,69 +138,178 @@ class __CommonPageContainerState extends State<_CommonPageContainer> with Single
pinned: true, pinned: true,
), ),



/// 轮播图
_buildSliverBanner(),

/// 搜索 /// 搜索
SliverPersistentHeader(
delegate: CustomSliverPersistentHeaderDelegate(
max: 40,
min: 40,
child: Container(
height: double.infinity,
width: double.infinity,
color: Colors.yellowAccent,
),
),
// pinned: true,
),
_buildSearch(),


/// TAB BAR /// TAB BAR
SliverPersistentHeader(
delegate: CustomSliverPersistentHeaderDelegate(
max: 40,
min: 40,
child: Container(
_buildTabbar(),

SliverFillRemaining(
child: TabBarView(
controller: _tabController,
children: List.generate(10, (index) => Container(
height: double.infinity, height: double.infinity,
width: double.infinity, width: double.infinity,
color: Colors.redAccent,
child: TabBar(
isScrollable: true,
controller: _tabController,
tabs: List.generate(10, (index) => Text('$index')),
color: Colors.white,
child: MediaQuery.removePadding(
context: context,
removeTop: true,
child: CustomScrollView(
controller: _controller2,
key: UniqueKey(),
slivers: <Widget>[
_buildQucikEntry(),
_buildSearch(),
_buildSliverBanner(),
_buildGoodsList(),

],
),
), ),
),
)),
), ),
// pinned: true,
),
)


/// 轮播图
SliverToBoxAdapter(
child: Container(
height: 140,
width: double.infinity,
color: Colors.blueAccent,
),
),
],
),
),
);
}


/// 多眼导航
SliverToBoxAdapter(
child: Container(
height: 70,
width: double.infinity,
color: Colors.yellowAccent,
/// 有数据2
Widget _buildMain2Widget(){
return Scaffold(
appBar: AppBar(title: Text('标题'),centerTitle: true,),
backgroundColor: HexColor.fromHex('#F9F9F9'),
floatingActionButton: _buildFloatWidget(),
floatingActionButtonLocation: _CustomFloatingActionButtonLocation(FloatingActionButtonLocation.endFloat, 0, -100),
body: Column(
children: <Widget>[
Container(height: 40, width: double.infinity, color: Colors.green,),
Container(
height: 40,
width: double.infinity,
color: Colors.red,
child: TabBar(
isScrollable: true,
controller: _tabController,
tabs: List.generate(10, (index) => Text('$index')),
), ),
), ),
Expanded(
child: TabBarView(
controller: _tabController,
children: List.generate(10, (index) => Container(
height: double.infinity,
width: double.infinity,
color: Colors.white,
child: MediaQuery.removePadding(
context: context,
removeTop: true,
child: CustomScrollView(
controller: _controller,
key: UniqueKey(),
slivers: <Widget>[
_buildQucikEntry(),
_buildSearch(),
_buildSliverBanner(),
_buildSearch(title: '商品列表'),
_buildGoodsList(),


/// 商品列表
SliverList(
delegate: SliverChildBuilderDelegate((context, index) {
return Container(
height: 50,
width: double.infinity,
color: Colors.green[(index % 9 + 1) * 100],
);
}, childCount: 50)),
],
),
),
)),
),
)
], ],
), ),
);
}

/// tabBar
Widget _buildTabbar(){
return SliverPersistentHeader(
delegate: CustomSliverPersistentHeaderDelegate(
max: 40,
min: 40,
child: Container(
height: double.infinity,
width: double.infinity,
color: Colors.redAccent,
child: TabBar(
isScrollable: true,
controller: _tabController,
tabs: List.generate(10, (index) => Text('$index')),
),
),
),
pinned: true,
);
}

/// 多眼导航
Widget _buildQucikEntry(){
return SliverToBoxAdapter(
child: Container(
alignment: Alignment.center,
child: Text('多眼导航'),
height: 70,
width: double.infinity,
color: Colors.green,
),
);
}

/// 搜索
Widget _buildSearch({String title}){
return SliverPersistentHeader(
delegate: CustomSliverPersistentHeaderDelegate(
max: 40,
min: 40,
child: Container(
alignment: Alignment.center,
child: Text(title ?? '搜索'),
height: double.infinity,
width: double.infinity,
color: Colors.blueAccent,
),
),
pinned: true,
);
}

/// 商品列表
Widget _buildGoodsList(){
return SliverList(
delegate: SliverChildBuilderDelegate((context, index) {
return Container(
height: 50,
width: double.infinity,
color: Colors.green[(index % 9 + 1) * 100],
);
}, childCount: 50));
}

/// 轮播图
Widget _buildSliverBanner(){
return SliverPersistentHeader(
delegate: CustomSliverPersistentHeaderDelegate(
max: 140,
min: 140,
child: Container(
child: Text('轮播图'),
alignment: Alignment.center,
height: double.infinity,
width: double.infinity,
color: Colors.yellowAccent,
),
), ),
pinned: false,
); );
} }




+ 1
- 1
lib/pages/favorites_page/favorites_page.dart View File

@@ -128,7 +128,7 @@ class _FavoritesPageContainerState extends State<_FavoritesPageContainer> with T
body: Column( body: Column(
children: <Widget>[ children: <Widget>[
/// 搜索框 /// 搜索框
Padding(padding: const EdgeInsets.only(left: 12.5, right: 12.5, top: 4), child: _buildSearchWidget(model)),
Padding(padding: const EdgeInsets.only(left: 12.5, right: 12.5, top: 0), child: _buildSearchWidget(model)),


/// tabBar /// tabBar
Padding(padding: const EdgeInsets.only(top: 4), child: _buildTabBarWidget(model)), Padding(padding: const EdgeInsets.only(top: 4), child: _buildTabBarWidget(model)),


+ 10
- 0
lib/pages/invited_friends/invited_friends.dart View File

@@ -53,13 +53,22 @@ class _InvitedFriendsContainerState extends State<_InvitedFriendsContainer> {
int _currentIndex = 0; // 邀请海报下标 int _currentIndex = 0; // 邀请海报下标
List<GlobalKey> _contentKeys; List<GlobalKey> _contentKeys;


SwiperController _controller;

@override @override
void initState() { void initState() {
_bloc = BlocProvider.of<InvitedFriendshBloc>(context); _bloc = BlocProvider.of<InvitedFriendshBloc>(context);
_bloc.loadData(widget.data['skip_identifier']); _bloc.loadData(widget.data['skip_identifier']);
_controller = SwiperController();
super.initState(); super.initState();
} }


@override
void dispose() {
_controller?.dispose();
super.dispose();
}

@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return StreamBuilder<InvitedFriendsModel>( return StreamBuilder<InvitedFriendsModel>(
@@ -160,6 +169,7 @@ class _InvitedFriendsContainerState extends State<_InvitedFriendsContainer> {
return Container( return Container(
width: double.infinity, width: double.infinity,
child: Swiper( child: Swiper(
controller: _controller,
onIndexChanged: (index) { onIndexChanged: (index) {
_currentIndex = index; _currentIndex = index;
}, },


+ 17
- 0
lib/pages/vip_center_page/vip_center_page.dart View File

@@ -33,6 +33,10 @@ class _VipCenterPageContainer extends StatefulWidget {
} }


class __VipCenterPageContainerState extends State<_VipCenterPageContainer> { class __VipCenterPageContainerState extends State<_VipCenterPageContainer> {


SwiperController _swiperController;

/// 分享 /// 分享
void _onShareClick() {} void _onShareClick() {}


@@ -48,6 +52,18 @@ class __VipCenterPageContainerState extends State<_VipCenterPageContainer> {
}); });
} }


@override
void initState() {
_swiperController = SwiperController();
super.initState();
}

@override
void dispose() {
_swiperController?.dispose();
super.dispose();
}

@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocConsumer<VipCenterBloc, VipCenterState>( return BlocConsumer<VipCenterBloc, VipCenterState>(
@@ -154,6 +170,7 @@ class __VipCenterPageContainerState extends State<_VipCenterPageContainer> {
height: 123, height: 123,
// color: HexColor.fromHex('#eeF0D199'), // color: HexColor.fromHex('#eeF0D199'),
child: Swiper( child: Swiper(
controller: _swiperController,
itemCount: 4, itemCount: 4,
itemBuilder: (context, index) { itemBuilder: (context, index) {
return Container( return Container(


+ 1
- 1
lib/register.dart View File

@@ -203,7 +203,7 @@ class BaseWidgetRegister {
'pub.flutter.my_wallet_detail', (model) => BilDetailPage(model)); 'pub.flutter.my_wallet_detail', (model) => BilDetailPage(model));


/// 通用模块 /// 通用模块
PageFactory.regist('pub.flutter.custom', (model) => CustomPage(model));
PageFactory.regist('pub.flutter.custom', (model) => EmptyPage());
} }


// 注册控件 // 注册控件


+ 10
- 0
lib/widgets/goods_details/slide_banner/goods_details_slide_banner_widget.dart View File

@@ -51,13 +51,22 @@ class _GoodsDetailsSlideBannerContainerState
} }
} }


SwiperController _control;

@override @override
void initState() { void initState() {
BlocProvider.of<GoodsDetailsSlideBannerBloc>(context) BlocProvider.of<GoodsDetailsSlideBannerBloc>(context)
.add(GoodsDetailsSlideBannerInitEvent(model: widget?.model)); .add(GoodsDetailsSlideBannerInitEvent(model: widget?.model));
_control = SwiperController();
super.initState(); super.initState();
} }


@override
void dispose() {
_control?.dispose();
super.dispose();
}

@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocConsumer<GoodsDetailsSlideBannerBloc, return BlocConsumer<GoodsDetailsSlideBannerBloc,
@@ -94,6 +103,7 @@ class _GoodsDetailsSlideBannerContainerState
width: double.infinity, width: double.infinity,
height: 375, height: 375,
child: Swiper( child: Swiper(
controller: _control,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
String items = datas.image_list[index]; String items = datas.image_list[index];
return Container( return Container(


+ 15
- 0
lib/widgets/home/home_quick_entry/home_quick_entry.dart View File

@@ -37,6 +37,20 @@ class _HomeQuickEntryContianerState extends State<HomeQuickEntryContianer> {
RouterUtil.route(model, model.toJson(), context); RouterUtil.route(model, model.toJson(), context);
} }


SwiperController _controller;

@override
void initState() {
_controller = SwiperController();
super.initState();
}

@override
void dispose() {
_controller?.dispose();
super.dispose();
}

@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocConsumer<HomeQuickEntryBloc, HomeQuickEntryState>( return BlocConsumer<HomeQuickEntryBloc, HomeQuickEntryState>(
@@ -109,6 +123,7 @@ class _HomeQuickEntryContianerState extends State<HomeQuickEntryContianer> {
width: double.infinity, width: double.infinity,
color: Colors.white, color: Colors.white,
child: Swiper( child: Swiper(
controller: _controller,
itemCount: totalPage, itemCount: totalPage,
loop: false, loop: false,
itemBuilder: (context, index) { itemBuilder: (context, index) {


+ 16
- 0
lib/widgets/home/home_quick_entry/home_quick_entry_widget.dart View File

@@ -35,6 +35,21 @@ class HomeQuickEntryWidgetContianer extends StatefulWidget {


class _HomeQuickEntryWidgetContianerState class _HomeQuickEntryWidgetContianerState
extends State<HomeQuickEntryWidgetContianer> { extends State<HomeQuickEntryWidgetContianer> {

SwiperController _swiperController;

@override
void initState() {
_swiperController = SwiperController();
super.initState();
}

@override
void dispose() {
_swiperController?.dispose();
super.dispose();
}

@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocConsumer<HomeQuickEntryBloc, HomeQuickEntryState>( return BlocConsumer<HomeQuickEntryBloc, HomeQuickEntryState>(
@@ -101,6 +116,7 @@ class _HomeQuickEntryWidgetContianerState
child: Container( child: Container(
// color: Colors.yellowAccent, // color: Colors.yellowAccent,
child: Swiper( child: Swiper(
controller: _swiperController,
itemHeight: double.infinity, itemHeight: double.infinity,
itemWidth: double.infinity, itemWidth: double.infinity,
duration: 100, duration: 100,


+ 20
- 4
lib/widgets/home/home_slide_banner/home_slide_banner.dart View File

@@ -40,6 +40,7 @@ class _HomeSlideBannerState extends State<HomeSlideBanner> {
} }


class HomeSlideBannerContainer extends StatefulWidget { class HomeSlideBannerContainer extends StatefulWidget {

@override @override
_HomeSlideBannerContainerState createState() => _HomeSlideBannerContainerState createState() =>
_HomeSlideBannerContainerState(); _HomeSlideBannerContainerState();
@@ -53,6 +54,20 @@ class _HomeSlideBannerContainerState extends State<HomeSlideBannerContainer> {
// Navigator.push(context, CupertinoPageRoute(builder: (_) => VipCenterPage(null))); // Navigator.push(context, CupertinoPageRoute(builder: (_) => VipCenterPage(null)));
} }


SwiperController _swiperController;

@override
void initState() {
_swiperController = SwiperController();
super.initState();
}

@override
void dispose() {
_swiperController?.dispose();
super.dispose();
}

@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocConsumer<HomeSlideBannerBloc, HomeSlideBannerState>( return BlocConsumer<HomeSlideBannerBloc, HomeSlideBannerState>(
@@ -97,6 +112,7 @@ class _HomeSlideBannerContainerState extends State<HomeSlideBannerContainer> {
width: double.infinity, width: double.infinity,
height: 140, height: 140,
child: Swiper( child: Swiper(
controller: _swiperController,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
IndexCarousel items = datas.index_carousel_list[index]; IndexCarousel items = datas.index_carousel_list[index];
return Container( return Container(
@@ -129,7 +145,7 @@ class _HomeSlideBannerContainerState extends State<HomeSlideBannerContainer> {
/// 获取进度样式 /// 获取进度样式
SwiperPlugin _getSwiperStyleByType( SwiperPlugin _getSwiperStyleByType(
HomeSlideBannerModel model, int pageCount) { HomeSlideBannerModel model, int pageCount) {
if ('type_null' != model.pagination) {
if ('type_null' == model.pagination) {
return null; return null;
} }


@@ -154,12 +170,12 @@ class _HomeSlideBannerContainerState extends State<HomeSlideBannerContainer> {
return SwiperCustomPagination( return SwiperCustomPagination(
builder: (BuildContext context, SwiperPluginConfig config) { builder: (BuildContext context, SwiperPluginConfig config) {
return Align( return Align(
alignment: Alignment(0.0, 0.9),
alignment: Alignment(0.9, 0.9),
child: Container( child: Container(
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 18), padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 18),
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(13),
color: HexColor.fromHex('#4D000000')),
borderRadius: BorderRadius.circular(3),
color: HexColor.fromHex('#80333333')),
child: RichText( child: RichText(
text: TextSpan( text: TextSpan(
text: '${config.activeIndex + 1}', text: '${config.activeIndex + 1}',


+ 1
- 1
lib/widgets/home/home_slide_banner/model/home_slide_banner_model.dart View File

@@ -44,7 +44,7 @@ class IndexCarousel extends SkipModel {
IndexCarousel({this.img, this.skip_identifier}); IndexCarousel({this.img, this.skip_identifier});


IndexCarousel.fromJson(Map<String, dynamic> json) { IndexCarousel.fromJson(Map<String, dynamic> json) {
super.toJson();
super.fromJson(json);
img = json['img']; img = json['img'];
skip_identifier = json['skip_identifier']; skip_identifier = json['skip_identifier'];
} }


Loading…
Cancel
Save