当模态底部 sheet 出现时,动画图标不会反转(图标在应用栏上)
when modal bottom sheet comes up the animated icon will not reverse (the icon is on app bar)
我在应用栏上有一个动画图标(图标是 menu_close)。当我按下图标时,模式底部 sheet 出现并且图标发生变化,但是在我关闭模式底部 sheet 之后,图标不会反转(它不会更改为菜单并保持接近!!!)
谁能帮我解决这个问题?
class TabsScreen extends StatefulWidget {
const TabsScreen({Key? key}) : super(key: key);
@override
_TabsScreenState createState() => _TabsScreenState();
}
class _TabsScreenState extends State<TabsScreen>
with SingleTickerProviderStateMixin {
late AnimationController _animationController;
bool isPlaying = false;
@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 450),
reverseDuration: const Duration(microseconds: 450));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'title',
),
actions: <Widget>[
IconButton(
icon: AnimatedIcon(
icon: AnimatedIcons.menu_close,
progress: _animationController,
),
onPressed: () {
setState(() {
if (!isPlaying) {
_animationController.forward();
showModalBottomSheet(
context: context,
builder: (context) => Container(
color: Colors.deepPurple,
),
);
} else {
_animationController.reverse();
}
});
}),
],
));
}
}
showModalBottomSheet
returns 以后可以像
那样处理动画
onPressed: () async {
_animationController.forward();
showModalBottomSheet(
context: context,
builder: (context) => Container(
color: Colors.deepPurple,
),
).then((value) {
_animationController.reverse();
});
}
我在应用栏上有一个动画图标(图标是 menu_close)。当我按下图标时,模式底部 sheet 出现并且图标发生变化,但是在我关闭模式底部 sheet 之后,图标不会反转(它不会更改为菜单并保持接近!!!) 谁能帮我解决这个问题?
class TabsScreen extends StatefulWidget {
const TabsScreen({Key? key}) : super(key: key);
@override
_TabsScreenState createState() => _TabsScreenState();
}
class _TabsScreenState extends State<TabsScreen>
with SingleTickerProviderStateMixin {
late AnimationController _animationController;
bool isPlaying = false;
@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 450),
reverseDuration: const Duration(microseconds: 450));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'title',
),
actions: <Widget>[
IconButton(
icon: AnimatedIcon(
icon: AnimatedIcons.menu_close,
progress: _animationController,
),
onPressed: () {
setState(() {
if (!isPlaying) {
_animationController.forward();
showModalBottomSheet(
context: context,
builder: (context) => Container(
color: Colors.deepPurple,
),
);
} else {
_animationController.reverse();
}
});
}),
],
));
}
}
showModalBottomSheet
returns 以后可以像
onPressed: () async {
_animationController.forward();
showModalBottomSheet(
context: context,
builder: (context) => Container(
color: Colors.deepPurple,
),
).then((value) {
_animationController.reverse();
});
}