如何解决Flutter AnimatedContainer无法在其他类上工作
“动画容器”向右移动以显示导航抽屉,该导航抽屉使用堆栈显示在其下方。
第三页 TagsPage被提取为不同的类,导航菜单按钮未执行该类的动画
从首页
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
if (Constants.isDrawerOpen == true) changeDrawer();
},child: AnimatedContainer(
transform:
Matrix4.translationValues(Constants.xOffset,Constants.yOffset,0)
..scale(Constants.scaleFactor),duration: Duration(milliseconds: 250),decoration: Boxdecoration(
borderRadius: BorderRadius.circular(50),),child: Scaffold(
body: selectedBarIndex == 2
? TagsPage()
: Column(
children: [
SizedBox(
height: 45,Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [
Padding(
padding: const EdgeInsets.only(left: 9),child: IconButton(
icon: Icon(Constants.isDrawerOpen
? Icons.clear
: Icons.menu),iconSize: 30,onpressed: () {
changeDrawer();
},],);
}
void changeDrawer() {
Constants.isDrawerOpen?
setState(() {
Constants.xOffset = 0;
Constants.yOffset = 0;
Constants.scaleFactor = 1;
Constants.isDrawerOpen = false;
}):
setState(() {
Constants.xOffset = 180;
Constants.yOffset = 90;
Constants.scaleFactor = 0.8;
Constants.isDrawerOpen = true;
});
print('chala toh hai');
}
从TagPage
import 'package:document_organizer/utils/consts.dart';
import 'package:Flutter/material.dart';
class TagsPage extends StatefulWidget {
@override
_TagsPageState createState() => _TagsPageState();
}
class _TagsPageState extends State<TagsPage> {
@override
Widget build(BuildContext context) {
return Container(
color: Colors.yellow[50],child: Stack(
children: [
Container(
width: 500,height: 120,margin: EdgeInsets.only(bottom: 18),decoration: Boxdecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(36),bottomright: Radius.circular(36)),color: Colors.yellow[100],Column(
children: [
SizedBox(
height: 45,Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [
Padding(
padding: const EdgeInsets.only(left: 9),child: Constants.isDrawerOpen
? IconButton(
icon: Icon(Icons.clear),onpressed: () {
setState(() {
Constants.xOffset = 0;
Constants.yOffset = 0;
Constants.scaleFactor = 1;
Constants.isDrawerOpen = false;
});
},)
: IconButton(
icon: Icon(Icons.menu),onpressed: () {
setState(() {
Constants.xOffset = 180;
Constants.yOffset = 90;
Constants.scaleFactor = 0.8;
Constants.isDrawerOpen = true;
});
},);
}
}
常量类
class Constants {
static double xOffset = 0;
static double yOffset = 0;
static double scaleFactor = 1;
static bool isDrawerOpen = false;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。