Unverified Commit b1f88a65 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

`ReorderableListView`: fix broken dartpad example & update examples, add tests (#102723)

parent b333fe2e
......@@ -6,33 +6,30 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const ReorderableApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
class ReorderableApp extends StatelessWidget {
const ReorderableApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatefulWidget(),
appBar: AppBar(title: const Text('ReorderableListView Sample')),
body: const ReorderableExample(),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
class ReorderableExample extends StatefulWidget {
const ReorderableExample({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<ReorderableExample> createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _MyStatefulWidgetState extends State<ReorderableExample> {
final List<int> _items = List<int>.generate(50, (int index) => index);
@override
......
......@@ -7,33 +7,30 @@ import 'dart:ui';
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const ReorderableApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
class ReorderableApp extends StatelessWidget {
const ReorderableApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatefulWidget(),
appBar: AppBar(title: const Text('ReorderableListView Sample')),
body: const ReorderableExample(),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
class ReorderableExample extends StatefulWidget {
const ReorderableExample({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<ReorderableExample> createState() => _ReorderableExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _ReorderableExampleState extends State<ReorderableExample> {
final List<int> _items = List<int>.generate(50, (int index) => index);
@override
......
......@@ -6,33 +6,30 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const ReorderableApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
class ReorderableApp extends StatelessWidget {
const ReorderableApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatefulWidget(),
appBar: AppBar(title: const Text('ReorderableListView Sample')),
body: const ReorderableExample(),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
class ReorderableExample extends StatefulWidget {
const ReorderableExample({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<ReorderableExample> createState() => _ReorderableExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _ReorderableExampleState extends State<ReorderableExample> {
final List<int> _items = List<int>.generate(50, (int index) => index);
@override
......
......@@ -6,35 +6,32 @@
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
void main() => runApp(const ReorderableApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
class ReorderableApp extends StatelessWidget {
const ReorderableApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
appBar: AppBar(title: const Text('ReorderableListView Sample')),
body: const Center(
child: MyStatefulWidget(),
child: ReorderableExample(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
class ReorderableExample extends StatefulWidget {
const ReorderableExample({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
State<ReorderableExample> createState() => _ReorderableExampleState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
class _ReorderableExampleState extends State<ReorderableExample> {
final List<int> _items = List<int>.generate(50, (int index) => index);
@override
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/reorderable_list/reorderable_list_view.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
Future<void> longPressDrag(WidgetTester tester, Offset start, Offset end) async {
final TestGesture drag = await tester.startGesture(start);
await tester.pump(kLongPressTimeout + kPressTimeout);
await drag.moveTo(end);
await tester.pump(kPressTimeout);
await drag.up();
}
testWidgets('Reorder list item', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: example.ReorderableApp(),
),
);
expect(tester.getCenter(find.text('Item 3')).dy, 252.0);
await longPressDrag(
tester,
tester.getCenter(find.text('Item 3')),
tester.getCenter(find.text('Item 2')),
);
await tester.pumpAndSettle();
expect(tester.getCenter(find.text('Item 3')).dy, 196.0);
});
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/reorderable_list/reorderable_list_view.1.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
Future<void> longPressDrag(WidgetTester tester, Offset start, Offset end) async {
final TestGesture drag = await tester.startGesture(start);
await tester.pump(kLongPressTimeout + kPressTimeout);
await drag.moveTo(end);
await tester.pump(kPressTimeout);
await drag.up();
}
testWidgets('Reorder list item', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: example.ReorderableApp(),
),
);
expect(tester.getCenter(find.text('Item 3')).dy, 252.0);
await longPressDrag(
tester,
tester.getCenter(find.text('Item 3')),
tester.getCenter(find.text('Item 2')),
);
await tester.pumpAndSettle();
expect(tester.getCenter(find.text('Item 3')).dy, 196.0);
});
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/reorderable_list/reorderable_list_view.build_default_drag_handles.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
Future<void> longPressDrag(WidgetTester tester, Offset start, Offset end) async {
final TestGesture drag = await tester.startGesture(start);
await tester.pump(kLongPressTimeout + kPressTimeout);
await drag.moveTo(end);
await tester.pump(kPressTimeout);
await drag.up();
}
testWidgets('Reorder list item', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: example.ReorderableApp(),
),
);
expect(tester.getCenter(find.text('Item 3')).dy, 280.0);
await longPressDrag(
tester,
tester.getCenter(find.text('Item 3')),
tester.getCenter(find.text('Item 2')),
);
await tester.pumpAndSettle();
expect(tester.getCenter(find.text('Item 3')).dy, 216.0);
});
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/reorderable_list/reorderable_list_view.reorderable_list_view_builder.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
Future<void> longPressDrag(WidgetTester tester, Offset start, Offset end) async {
final TestGesture drag = await tester.startGesture(start);
await tester.pump(kLongPressTimeout + kPressTimeout);
await drag.moveTo(end);
await tester.pump(kPressTimeout);
await drag.up();
}
testWidgets('Reorder list item', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: example.ReorderableApp(),
),
);
expect(tester.getCenter(find.text('Item 3')).dy, 252.0);
await longPressDrag(
tester,
tester.getCenter(find.text('Item 3')),
tester.getCenter(find.text('Item 2')),
);
await tester.pumpAndSettle();
expect(tester.getCenter(find.text('Item 3')).dy, 196.0);
});
}
......@@ -38,7 +38,7 @@ import 'theme.dart';
///
/// This example demonstrates using the [proxyDecorator] callback to customize
/// the appearance of a list item while it's being dragged.
/// {@tool snippet}
/// {@tool dartpad}
///
/// While a drag is underway, the widget returned by the [proxyDecorator]
/// serves as a "proxy" (a substitute) for the item in the list. The proxy is
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment