Flutter:AnimatedPadding动态修改padding

html 复制代码
// 默认top为10,点击后修改为100,此时方块会向下移动
padding: EdgeInsets.fromLTRB(left, top, right, bottom),
js 复制代码
class _MyHomePageState extends State<MyHomePage> {
  bool flag = true;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('标题'),
      ),
      body: AnimatedPadding(
        curve: Curves.easeIn, // 动画属性
        duration: Duration(milliseconds: 500),
        // 默认
        padding: EdgeInsets.fromLTRB(10, flag ?10 : 100, 0, 0),
        child: Container(
          width: 100,
          height: 100,
          color: Colors.red,
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: (){
          flag = !flag;
          setState(() {});
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}


相关推荐
LawrenceLan17 分钟前
Flutter 零基础入门(十一):空安全(Null Safety)基础
开发语言·flutter·dart
行者961 小时前
Flutter与OpenHarmony跨平台分享组件深度实践
flutter·harmonyos·鸿蒙
行者961 小时前
Flutter跨平台开发在OpenHarmony上的评分组件实现与优化
开发语言·flutter·harmonyos·鸿蒙
my_power5202 小时前
车载安卓面试题汇总
android
csj502 小时前
安卓基础之《(15)—内容提供者(1)在应用之间共享数据》
android
yeziyfx3 小时前
kotlin中 ?:的用法
android·开发语言·kotlin
cn_mengbei4 小时前
Flutter for OpenHarmony 实战:IconButton 图标按钮详解
flutter
cn_mengbei4 小时前
Flutter for OpenHarmony 实战:OutlinedButton 边框按钮详解
flutter
2501_915918414 小时前
只有 Flutter IPA 文件,通过多工具组合完成有效混淆与保护
android·flutter·ios·小程序·uni-app·iphone·webview
robotx5 小时前
AOSP 设置-提示音和振动 添加一个带有开关(Switch)的设置项
android