Skip to content

Commit

Permalink
feat:首页Tab进行懒加载
Browse files Browse the repository at this point in the history
  • Loading branch information
Tecode committed Aug 21, 2024
1 parent 1b12232 commit 1fbf0e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
19 changes: 10 additions & 9 deletions lib/containers/discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,23 @@ class _DiscoveryState extends State<Discovery> with AutomaticKeepAliveClientMixi
const opacityCurve = Interval(0.0, 0.75, curve: Curves.fastOutSlowIn);
// 过渡动画
return AnimatedBuilder(
animation: animation,
builder: (BuildContext context, Widget? child) => Opacity(
opacity: opacityCurve.transform(animation.value),
child: DiscoveryDetail(
tag: '$index TAG${data.imgId}',
url: data.url,
),
));
animation: animation,
builder: (BuildContext context, Widget? child) => Opacity(
opacity: opacityCurve.transform(animation.value),
child: DiscoveryDetail(
tag: '$index TAG${data.imgId}',
url: data.url,
),
),
);
}),
),
behavior: HitTestBehavior.opaque,
child: FadeInImage.assetNetwork(
placeholder: 'assets/images/loading.gif',
image: data.url,
imageCacheWidth: 80,
fit: BoxFit.cover,
imageCacheWidth: 80,
),
),
);
Expand Down
8 changes: 6 additions & 2 deletions lib/containers/entrance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ class _EntranceState extends State<Entrance> {
int activeIndex = 0;
final UniLinksType _type = UniLinksType.string;
late StreamSubscription _sub;
late PageController controller;

@override
void initState() {
super.initState();
controller = PageController(initialPage: activeIndex);
// scheme初始化,保证有上下文,需要跳转页面
initPlatformState();
}
Expand Down Expand Up @@ -98,8 +100,9 @@ class _EntranceState extends State<Entrance> {
child: Column(
children: <Widget>[
Expanded(
child: IndexedStack(
index: activeIndex,
child: PageView(
controller: controller,
physics: const NeverScrollableScrollPhysics(),
children: <Widget>[
const Home(),
const Discovery(),
Expand All @@ -115,6 +118,7 @@ class _EntranceState extends State<Entrance> {
activeKey: Entrance.navList[activeIndex]['key'] as String,
onChange: (int index) => setState(() {
activeIndex = index;
controller.jumpToPage(index);
}),
),
],
Expand Down

0 comments on commit 1fbf0e7

Please sign in to comment.