实现监听轮播变化,解决轮播卡顿问题

master
张萌 3 years ago
parent 77b353735c
commit 2e8615f610

@ -26,10 +26,10 @@ import 'package:aku_new_community/widget/others/user_tool.dart';
import 'package:badges/badges.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:card_swiper/card_swiper.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:get/get.dart';
import 'package:jpush_flutter/jpush_flutter.dart';
import 'package:palette_generator/palette_generator.dart';
@ -58,12 +58,14 @@ class _HomePageState extends State<HomePage>
int sysCount = 0;
int sum = 0;
int _currentSwiperIndex = 0;
// ActivityItemModel? _activityItemModel;
List<ActivityItemModel> _activityItemModels = [];
List<BoardItemModel> _boardItemModels = [];
List<SwiperModel> _swiperModels = [];
SwiperController _swiperController = SwiperController();
SwiperController _swiperController = SwiperController();
ValueNotifier<Color> _barColor = ValueNotifier(Colors.transparent);
@override
@ -80,6 +82,10 @@ class _HomePageState extends State<HomePage>
}
_scrollController = ScrollController();
_refreshController = EasyRefreshController();
_swiperController.addListener(() {
//onChangeIndex_currentSwiperIndexindex1+1index;
_swiperBarColor((_currentSwiperIndex + 1) % 3);
});
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: Colors.transparent));
}
@ -487,18 +493,9 @@ class _HomePageState extends State<HomePage>
aspectRatio: 375 / 160,
child: Swiper(
key: UniqueKey(),
controller: _swiperController,
onIndexChanged: (index) async {
if (_swiperModels.isNotEmpty) {
var color = await PaletteGenerator.fromImageProvider(
CachedNetworkImageProvider(
API.image(
ImgModel.first(_swiperModels[index].voResourcesImgList)),
));
_barColor.value =
color.dominantColor?.color ?? Colors.transparent;
} else {
_barColor.value = Colors.transparent;
}
_currentSwiperIndex = index;
},
itemBuilder: (BuildContext context, int index) {
return getSwiperImage(_swiperModels[index]);
@ -536,6 +533,18 @@ class _HomePageState extends State<HomePage>
);
}
Future _swiperBarColor(int index) async {
if (_swiperModels.isNotEmpty) {
var color =
await PaletteGenerator.fromImageProvider(CachedNetworkImageProvider(
API.image(ImgModel.first(_swiperModels[index].voResourcesImgList)),
));
_barColor.value = color.dominantColor?.color ?? Colors.transparent;
} else {
_barColor.value = Colors.transparent;
}
}
Widget getSwiperImage(SwiperModel swiperModel) {
return Container(
child: FadeInImage.assetNetwork(

@ -24,14 +24,12 @@ import 'package:aku_new_community/utils/network/base_list_model.dart';
import 'package:aku_new_community/utils/network/net_util.dart';
import 'package:aku_new_community/widget/home/home_sliver_app_bar.dart';
import 'package:aku_new_community/widget/others/rectIndicator.dart';
import 'package:card_swiper/card_swiper.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:velocity_x/velocity_x.dart';
import 'category/new_category_page.dart';
import 'market_home_goods_card.dart';

@ -176,6 +176,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.1"
card_swiper:
dependency: "direct main"
description:
name: card_swiper
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.1"
carousel_slider:
dependency: "direct main"
description:
@ -503,13 +510,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.6.0"
flutter_swiper_null_safety:
dependency: "direct main"
description:
name: flutter_swiper_null_safety
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.2"
flutter_test:
dependency: "direct dev"
description: flutter

@ -104,7 +104,7 @@ dependencies:
#加载网络图片
cached_network_image: ^3.1.0
#轮播图
flutter_swiper_null_safety: ^1.0.2
card_swiper: ^2.0.1
#划动组件
carousel_slider: ^4.0.0-nullsafety.0
#跳转索引列表

Loading…
Cancel
Save