Câu hỏi phỏng vấn Flutter
Câu hỏi

Làm sao để tạo animation đơn giản với AnimatedContainer?

Câu trả lời

markdown Copy
Để 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à. 

```dart
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();
}

class _AnimatedContainerDemoState extends State<AnimatedContainerDemo> {
  double _width = 200.0;
  ...
middle

middle

Gợi ý câu hỏi phỏng vấn

middle

Làm sao để tối ưu số lượng widget render lại?

middle

Giải thích các loại luồng khác nhau?

middle

Sự khác biệt giữa Scaffold và Container trong Flutter là gì?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào