[flutter] 플러터 Container에서 사용자 입력을 처리하는 방법은 무엇인가요?

플러터에서 Container 위젯을 사용하여 사용자 입력을 처리하는 방법은 간단합니다. 다음은 플러터에서 Container에서의 기본적인 사용자 입력 처리 방법에 대한 예제입니다.

GestureDetector를 사용하여 탭 처리하기

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: GestureDetector(
            onTap: () {
              // 탭이 발생했을 때 처리할 로직 작성
              print("탭이 발생했습니다!");
            },
            child: Container(
              width: 200,
              height: 200,
              color: Colors.blue,
              child: Center(child: Text('탭하세요', style: TextStyle(fontSize: 20, color: Colors.white)),
              )
            ),
          ),
        ),
      ),
    );
  }
}

위 예제에서는 GestureDetector를 사용하여 Container를 감싸고, onTap 콜백을 통해 탭 처리 로직을 작성합니다.

참고 자료