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

Hạn chế của Flutter là gì?

middle

Các toán tử nhận biết giá trị null là gì?

middle

Flutter build() được gọi bao nhiêu lần? Khi nào bị gọi lại?

Bình luận

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

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