[flutter] 플러터 GridView에서 아이템의 위치를 동적으로 변경하는 방법은?
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('Reorderable List'),
        ),
        body: MyList(),
      ),
    );
  }
}

class MyList extends StatefulWidget {
  @override
  _MyListState createState() => _MyListState();
}

class _MyListState extends State<MyList> {
  List<String> items = ['Item 1', 'Item 2', 'Item 3', 'Item 4'];

  @override
  Widget build(BuildContext context) {
    return ReorderableListView(
      children: items
          .map((item) => ListTile(
                key: Key(item),
                title: Text(item),
                leading: Icon(Icons.drag_handle),
              ))
          .toList(),
      onReorder: (int oldIndex, int newIndex) {
        setState(() {
          if (newIndex > oldIndex) {
            newIndex -= 1;
          }
          final item = items.removeAt(oldIndex);
          items.insert(newIndex, item);
        });
      },
    );
  }
}

이 예제는 ReorderableListView를 사용하여 드래그 앤 드롭으로 아이템을 재배치하는 방법을 보여줍니다. 위젯을 사용하면 아이템의 위치를 동적으로 변경할 수 있습니다.

자세한 내용은 플러터 공식 문서를 참고하시기 바랍니다: ReorderableListView Class