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),
      ),
    );
  }
}


相关推荐
auxor2 小时前
Android 开机动画音频播放优化方案
android
whysqwhw2 小时前
安卓实现屏幕共享
android
深盾科技3 小时前
Kotlin Data Classes 快速上手
android·开发语言·kotlin
一条上岸小咸鱼3 小时前
Kotlin 基本数据类型(五):Array
android·前端·kotlin
森之鸟3 小时前
flutter项目适配鸿蒙
flutter·华为·harmonyos
whysqwhw3 小时前
Room&Paging
android
whysqwhw3 小时前
RecyclerView超长列表优化
android
傅里叶3 小时前
Flutter在OrangePi 5 Plus上视频播放锁死问题
前端·flutter
Tiger_Hu3 小时前
Android系统日历探索
android
whysqwhw3 小时前
RecyclerView卡顿
android