Skip to content

Commit

Permalink
Fixed UI representation of server reorder page (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaperCube committed Jun 4, 2024
1 parent 94d6d80 commit ee88923
Showing 1 changed file with 46 additions and 14 deletions.
60 changes: 46 additions & 14 deletions lib/view/page/setting/seq/srv_seq.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:ui';
import 'package:fl_lib/fl_lib.dart';
import 'package:flutter/material.dart';
import 'package:toolbox/core/extension/context/locale.dart';
Expand All @@ -22,6 +23,29 @@ class _ServerOrderPageState extends State<ServerOrderPage> {
);
}

Widget _proxyDecorator(Widget child, int index, Animation<double> animation) {
return AnimatedBuilder(
animation: animation,
builder: (BuildContext context, Widget? child) {
final double animValue = Curves.easeInOut.transform(animation.value);
final double elevation = lerpDouble(1, 6, animValue)!;
final double scale = lerpDouble(1, 1.02, animValue)!;
return Transform.scale(
scale: scale,
// Create a Card based on the color and the content of the dragged one
// and set its elevation to the animated value.
child: Card(
elevation: elevation,
// color: cards[index].color,
// child: cards[index].child,
child: _buildCardTile(index),
),
);
},
// child: child,
);
}

Widget _buildBody() {
if (Pros.server.serverOrder.isEmpty) {
return Center(child: Text(l10n.noServerAvailable));
Expand All @@ -37,28 +61,36 @@ class _ServerOrderPageState extends State<ServerOrderPage> {
}),
padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 3),
buildDefaultDragHandles: false,
itemBuilder: (_, idx) => _buildItem(idx, Pros.server.serverOrder[idx]),
itemBuilder: (_, idx) => _buildItem(idx),
itemCount: Pros.server.serverOrder.length,
proxyDecorator: _proxyDecorator,
);
}

Widget _buildItem(int index, String id) {
Widget _buildItem(int index) {
return ReorderableDelayedDragStartListener(
key: ValueKey('$index'),
index: index,
child: CardX(child: _buildCardTile(index)),
);
}

Widget _buildCardTile(int index) {
final id = Pros.server.serverOrder[index];
final spi = Pros.server.pick(id: id)?.spi;
if (spi == null) {
return const SizedBox();
}
return ReorderableDelayedDragStartListener(
key: ValueKey('$index'),
index: index,
child: CardX(
child: ListTile(
title: Text(spi.name),
subtitle: Text(spi.id, style: UIs.textGrey),
leading: CircleAvatar(
child: Text(spi.name[0]),
),
trailing: const Icon(Icons.drag_handle),
),

return ListTile(
title: Text(spi.name),
subtitle: Text(spi.id, style: UIs.textGrey),
leading: CircleAvatar(
child: Text(spi.name[0]),
),
trailing: ReorderableDragStartListener(
index: index,
child: const Icon(Icons.drag_handle),
),
);
}
Expand Down

0 comments on commit ee88923

Please sign in to comment.