Skip to content
This repository was archived by the owner on Apr 12, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions lib/drag_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class DragScreen extends StatefulWidget {
const DragScreen({super.key});

@override
State<DragScreen> createState() => _DragScreenState();
}

class _DragScreenState extends State<DragScreen> {
List<int> items = [1, 2, 3, 4, 5];
// Target order for Maestro drag-and-drop test validation
static const List<int> targetOrder = [3, 1, 4, 5, 2];

bool get isCorrectOrder => listEquals(items, targetOrder);

void _onReorder(int oldIndex, int newIndex) {
setState(() {
if (newIndex > oldIndex) {
newIndex -= 1;
}
final item = items.removeAt(oldIndex);
items.insert(newIndex, item);
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Drag Test'),
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () => Navigator.of(context).pop(),
),
),
body: Column(
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
'Reorder items to: ${targetOrder.join(", ")}',
style: Theme.of(context).textTheme.titleMedium,
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Text(
'Current order: ${items.join(", ")}',
style: Theme.of(context).textTheme.bodyMedium,
),
),
const SizedBox(height: 16),
Expanded(
child: ReorderableListView.builder(
itemCount: items.length,
onReorder: _onReorder,
buildDefaultDragHandles: false,
proxyDecorator: (child, index, animation) {
return Material(
elevation: 4,
color: Colors.transparent,
child: child,
);
},
itemBuilder: (context, index) {
final item = items[index];
return ReorderableDragStartListener(
key: ValueKey(item),
index: index,
child: Card(
margin: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 4,
),
child: ListTile(
leading: const Icon(Icons.drag_handle),
title: Text(
'Item $item',
style: const TextStyle(fontSize: 18),
semanticsLabel: 'Item $item',
),
),
),
);
},
),
),
if (isCorrectOrder)
Container(
padding: const EdgeInsets.all(24),
color: Colors.green,
width: double.infinity,
child: const Text(
'Drag Success',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
),
],
),
);
}
}
9 changes: 9 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:demo_app/issue_1619_repro.dart';
import 'package:demo_app/issue_1677_repro.dart';
import 'package:demo_app/nesting_screen.dart';
import 'package:demo_app/swiping_screen.dart';
import 'package:demo_app/drag_screen.dart';
import 'package:demo_app/webview.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -106,6 +107,14 @@ class _MyHomePageState extends State<MyHomePage> {
},
child: const Text('Swipe Test'),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => const DragScreen()),
);
},
child: const Text('Drag Test'),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
Expand Down