Làm sao để tạo animation đơn giản với AnimatedContainer?
Làm sao để tạo animation đơn giản với AnimatedContainer?
Để tạo animation đơn giản với AnimatedContainer, bạn cần chú ý các bước chính: khởi tạo AnimatedContainer với các thuộc tính như width, height, color, vv. mà bạn muốn thay đổi. Thay đổi giá trị các thuộc tính thông qua hàm setState để kích hoạt animation. Chọn duration phù hợp để animation diễn ra mượt mà.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('AnimatedContainer Demo')),
body: Center(child: AnimatedContainerDemo()),
),
);
}
}
class AnimatedContainerDemo extends StatefulWidget {
@override
_AnimatedContainerDemoState createState() => _AnimatedContainerDemoState();
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.