flutter - 当我按下某些东西时隐藏带有动画的小部件
问题描述
我想添加一个动画来隐藏一个小部件并在页面上移动/同步其他没有它的小部件。
我做了一个应用程序,这是一个我的世界启动器,我想在关闭开关时隐藏密码文本字段。我在这方面取得了一些进展,但我无法添加动画以使其更流畅。
这是我的代码;
import 'package:flutter/material.dart';
import 'forget_password_text.dart';
import 'password_text_field.dart';
import 'premium_mode_switch.dart';
class FrontLayerLeftSidePasswordHiding extends StatefulWidget {
const FrontLayerLeftSidePasswordHiding({Key? key}) : super(key: key);
@override
_FrontLayerLeftSidePasswordHidingState createState() =>
_FrontLayerLeftSidePasswordHidingState();
}
class _FrontLayerLeftSidePasswordHidingState
extends State<FrontLayerLeftSidePasswordHiding> {
bool _visible = true;
Widget? _switch;
@override
void initState() {
this._switch = PremiumModeSwitch(
onChanged: () {
setState(() {
this._visible = !this._visible;
});
},
);
super.initState();
}
@override
Widget build(BuildContext context) {
// This is working but, it's instant, the duration does not affect.
return AnimatedSwitcher(
duration: Duration(seconds: 10),
child: _visible ? this._on() : this._off(),
);
}
// This widget shows when I close the switch
Widget _off() {
return Column(
children: [
Spacer(flex: 1),
this._switcher(),
Spacer(flex: 14),
],
);
}
// This widget shows when I open the switch
Widget _on() {
return Column(
children: [
Expanded(
flex: 15,
child: Column(
children: [
Spacer(flex: 5),
Expanded(
flex: 10,
child: PasswordTextField(),
),
],
),
),
Expanded(
flex: 10,
child: this._switcher(),
),
],
);
}
Widget _switcher() {
return Row(
children: [
Spacer(flex: 13),
Expanded(
flex: 10,
child: ForgetPasswordText(),
),
Spacer(flex: 20),
Expanded(
flex: 10,
child: this._switch!,
),
Spacer(flex: 10),
],
);
}
}
解决方案
推荐阅读
- excel - 要对位于列中单元格之间的 excel 列中的单元格求和,请符合特定条件
- dart - Flutter 应用程序冻结并且无法按预期工作
- websphere - 在 WebSphere 中,resources.xml 文件中创建的 JDBCProvider 默认为 xa="true"?
- angular - Jvectormap 悬停显示省名两次
- spring-boot - INVALID 不是有效的开始令牌
- angular - Angular matSort,标题可点击但没有排序?
- javascript - 如何使用 Highcharts 制作带有象限的图表
- json - 当它是 JSON 节点名称的一部分时,你如何处理它?
- powershell - 通过 Powershell 拒绝域内组织单位的读取权限
- itext - 字体未正确嵌入使用 itextsharp 5.0.5.0 生成的 PDF