gpt4 book ai didi

flutter - 如何同时使用 AnimatedSwitcher 和 CustomScrollView

转载 作者:行者123 更新时间:2023-12-03 16:28:50 25 4
gpt4 key购买 nike

我想在 CustomScrollView 中使用动画切换状态,但它抛出错误。

class SliverAnimatedSwitcher extends StatefulWidget {
final state;

const SliverAnimatedSwitcher({Key key, this.state}) : super(key: key);

@override
_SliverAnimatedSwitcherState createState() => _SliverAnimatedSwitcherState();
}

class _SliverAnimatedSwitcherState extends State<SliverAnimatedSwitcher> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: Text('SliverAnimatedSwitcher'),
),
_buildContent(),
],
),
);
}

get state => widget.state;

Widget _buildContent() {
var content;
if (state.isNotEmpty == true) {
content = SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
var item = state.items[index];
return ListTile(
title: Text(item.title),
);
},
childCount: state.items.length,
),
);
} else if (state.isError) {
content = SliverFillRemaining(
key: Key('error'),
child: Container(alignment: Alignment.center, child: Text('Error')),
);
} else if (state.isLoading) {
content = SliverFillRemaining(
key: Key('loading'),
child: Container(alignment: Alignment.center, child: Text('Loading')),
);
} else {
content = SliverFillRemaining(
key: Key('empty'),
child: Container(alignment: Alignment.center, child: Text('Empty')),
);
}
return AnimatedSwitcher(
duration: Duration(milliseconds: 300),
child: content,
);
}
}

最佳答案

有一个 sliver_tools pub.dev 上的包具有 SliverAnimatedSwitcher .你会像这样使用它:

SliverAnimatedSwitcher(
duration: kThemeAnimationDuration,
child: content,
)

关于flutter - 如何同时使用 AnimatedSwitcher 和 CustomScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58551756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com