Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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);
});
}
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/material/reorderable_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down