//flutter import 'package:flutter/material.dart'; void main() { return runApp(TestPage()); } //リスト4.30 class TestPage extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'ReorderableListView', home: Scaffold( appBar: AppBar(title: Text('ReorderableListView')), body: MyStatefulWidget() ) ); } } class MyStatefulWidget extends StatefulWidget { const MyStatefulWidget({Key? key}) : super(key: key); @override State<MyStatefulWidget> createState() => _MyStatefulWidgetState(); } class _MyStatefulWidgetState extends State<MyStatefulWidget> { final List<int> _itemList = List<int>.generate(50, (int i) => i); @override Widget build(BuildContext context) { return ReorderableListView( onReorder: (int oldIndex, int newIndex) { setState(() { if (oldIndex < newIndex) { newIndex -= 1; } final item = _itemList.removeAt(oldIndex); _itemList.insert(newIndex, item); }); }, children: <Widget> [ for (int i = 0; i < _itemList.length; i++) ListTile( key: Key('$i'), trailing: Icon(Icons.more_vert), subtitle: Text('Item${_itemList[i]}'), title: Text('タイトル'), ), ], ); } }