Skip to content

Commit

Permalink
feat:添加拖拽代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Tecode committed Mar 5, 2024
1 parent 392393d commit 66d6bce
Show file tree
Hide file tree
Showing 5 changed files with 647 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/containers/mine.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:dynamic_theme/containers/new_view.dart';
import 'package:dynamic_theme/containers/position_exchange.dart';
import 'package:dynamic_theme/helpers/options.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -111,7 +112,7 @@ class _MineState extends State<Mine> {
),
),
TextButton(
onPressed: () => Navigator.of(context).pushNamed(NavigationPositioning.routeName),
onPressed: () => Navigator.of(context).pushNamed(PositionExchange.routeName),
child: Text(
'拖动排图',
style: TextStyle(
Expand Down
2 changes: 1 addition & 1 deletion lib/containers/order.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class _OrderState extends State<Order> {
}

class OrderCard extends StatelessWidget {
const OrderCard({Key? key}):super(key: key);
const OrderCard({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
Expand Down
45 changes: 45 additions & 0 deletions lib/containers/position_exchange.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:dynamic_theme/widgets/common/reorderable_list.dart';
import 'package:flutter/material.dart' hide ReorderableListView;

class PositionExchange extends StatefulWidget {
static const routeName = '/position_exchange';
const PositionExchange({Key? key}) : super(key: key);

@override
State<PositionExchange> createState() => _PositionExchangeState();
}

class _PositionExchangeState extends State<PositionExchange> {
final List<int> _items = List<int>.generate(50, (int index) => index);

@override
Widget build(BuildContext context) {
final ColorScheme colorScheme = Theme.of(context).colorScheme;
final Color oddItemColor = colorScheme.primary.withOpacity(0.05);
final Color evenItemColor = colorScheme.primary.withOpacity(0.15);

return Scaffold(
appBar: AppBar(title: const Text('拖动排序')),
body: ReorderableListView(
padding: const EdgeInsets.symmetric(horizontal: 10),
children: <Widget>[
for (int index = 0; index < _items.length; index += 1)
ListTile(
key: Key('$index'),
tileColor: _items[index].isOdd ? oddItemColor : evenItemColor,
title: Text('Item ${_items[index]}'),
),
],
onReorder: (int oldIndex, int newIndex) {
setState(() {
if (oldIndex < newIndex) {
newIndex -= 1;
}
final int item = _items.removeAt(oldIndex);
_items.insert(newIndex, item);
});
},
),
);
}
}
5 changes: 3 additions & 2 deletions lib/router/router_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:dynamic_theme/containers/chat_list.dart';
import 'package:dynamic_theme/containers/detail.dart';
import 'package:dynamic_theme/containers/navigation_positioning.dart';
import 'package:dynamic_theme/containers/new_view.dart';
import 'package:dynamic_theme/containers/position_exchange.dart';
import 'package:dynamic_theme/router/router_unit.dart';
import 'package:flutter/widgets.dart';

Expand Down Expand Up @@ -35,8 +36,8 @@ List<RouterUnit> _buildRouter() {
),
RouterUnit(
title: '拖动排图',
routeName: NavigationPositioning.routeName,
buildRoute: (BuildContext context) => const NavigationPositioning(),
routeName: PositionExchange.routeName,
buildRoute: (BuildContext context) => const PositionExchange(),
),
];
return routerList;
Expand Down
Loading

0 comments on commit 66d6bce

Please sign in to comment.